Skip to content

Commit db601be

Browse files
committed
Updating versions and adding travis.yml
1 parent 39a31b4 commit db601be

File tree

7 files changed

+225
-169
lines changed

7 files changed

+225
-169
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8
4+
os:
5+
- linux
6+
before_cache:
7+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
8+
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
9+
cache:
10+
directories:
11+
- $HOME/.gradle/caches/
12+
- $HOME/.gradle/wrapper/

Jenkinsfile

Lines changed: 0 additions & 31 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ For each regions, first you need to set the proper repository:
7777
Then set the dependency:
7878
```groovy
7979
dependencies {
80-
testCompile group: 'com.amazonaws', name: 'DynamoDBLocal', version: '1.11.86'
80+
testCompile group: 'com.amazonaws', name: 'DynamoDBLocal', version: '1.11.119'
8181
}
8282
```
8383

@@ -93,7 +93,7 @@ You can get the version numbers from each regions:
9393

9494
AWS DynamoDB provides possibility to test locally and it requires `sqlite4java.library.path` system property to be set. In the [official example](https://github.com/aws-samples/aws-dynamodb-examples) it is set for the Maven project.
9595

96-
If you run it from Gradle or from your IDE, local database might not start as the sqlite4java native libraries are not avaialiable. These are downloaded as a dependency of `DynamoDBLocal` artifact, but it is not visible by default. Sqlite4java loads it from the path defined by `sqlite4java.library.path` system property.
96+
If you run it from Gradle or from your IDE, local database might not start as the sqlite4java native libraries are not available. These are downloaded as a dependency of `DynamoDBLocal` artifact, but it is not visible by default. Sqlite4java loads it from the path defined by `sqlite4java.library.path` system property.
9797

9898
If it is not set or not valid, you probably see something similar in the logs:
9999
```

build.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ repositories {
4141

4242
dependencies {
4343

44-
compile group: 'com.amazonaws', name:'aws-java-sdk-dynamodb', version: '1.11.319'
45-
compile group: 'com.google.guava', name: 'guava', version: '25.0-jre'
44+
compile 'com.google.guava:guava:26.0-jre'
45+
compile 'com.amazonaws:aws-java-sdk-dynamodb:1.11.434'
46+
47+
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
48+
testCompile 'org.junit.jupiter:junit-jupiter-params:5.3.1'
49+
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
4650

4751
// Version numbers for each regions can be get from:
4852
// dynamodb-local-mumbai - https://s3.ap-south-1.amazonaws.com/dynamodb-local-mumbai/release/com/amazonaws/DynamoDBLocal/maven-metadata.xml
@@ -51,6 +55,5 @@ dependencies {
5155
// dynamodb-local-frankfurt - https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/release/com/amazonaws/DynamoDBLocal/maven-metadata.xml
5256
// dynamodb-local-sao-paulo - https://s3-sa-east-1.amazonaws.com/dynamodb-local-sao-paulo/release/com/amazonaws/DynamoDBLocal/maven-metadata.xml
5357
// dynamodb-local-oregon - https://s3-us-west-2.amazonaws.com/dynamodb-local/release/com/amazonaws/DynamoDBLocal/maven-metadata.xml
54-
testCompile group: 'com.amazonaws', name: 'DynamoDBLocal', version: '1.11.86'
55-
testCompile group: 'junit', name: 'junit', version: '4.12'
58+
testCompile 'com.amazonaws:DynamoDBLocal:1.11.119'
5659
}

src/test/java/io/redskap/java/aws/dynamodb/example/local/testing/AwsDynamoDbHelper.java

Lines changed: 0 additions & 118 deletions
This file was deleted.
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
package io.redskap.java.aws.dynamodb.example.local.testing;
2+
3+
import com.google.common.base.Splitter;
4+
import com.google.common.collect.Lists;
5+
6+
import java.io.File;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
import java.util.Locale;
10+
import java.util.function.Supplier;
11+
12+
/**
13+
* Helper class for initializing AWS DynamoDB to run with sqlite4java for local testing.
14+
*
15+
* Copied from: https://github.com/redskap/aws-dynamodb-java-example-local-testing
16+
*/
17+
public class AwsDynamoDbLocalTestUtils {
18+
19+
private static final String BASE_LIBRARY_NAME = "sqlite4java";
20+
21+
/**
22+
* Static helper class.
23+
*/
24+
private AwsDynamoDbLocalTestUtils() {
25+
}
26+
27+
/**
28+
* Sets the sqlite4java library path system parameter if it is not set already.
29+
*/
30+
public static void initSqLite() {
31+
initSqLite(() -> {
32+
final List<String> classPath = getClassPathList(System.getProperty("java.class.path"), File.pathSeparator);
33+
34+
final String libPath = getLibPath(System.getProperty("os.name"), System.getProperty("java.runtime.name"),
35+
System.getProperty("os.arch"), classPath);
36+
37+
return libPath;
38+
});
39+
}
40+
41+
/**
42+
* Sets the sqlite4java library path system parameter if it is not set already.
43+
*
44+
* @param libPathSupplier Calculates lib path for sqlite4java.
45+
*/
46+
public static void initSqLite(Supplier<String> libPathSupplier) {
47+
if (System.getProperty("sqlite4java.library.path") == null) {
48+
System.setProperty("sqlite4java.library.path", libPathSupplier.get());
49+
}
50+
}
51+
52+
/**
53+
* Calculates the possible Library Names for finding the proper sqlite4j native library and returns the directory with the most specific matching library.
54+
*
55+
* @param osName The value of <code>"os.name"</code> system property (<code>System.getProperty("os.name")</code>).
56+
* @param runtimeName The value of <code>"java.runtime.name"</code> system property (<code>System.getProperty("java.runtime.name")</code>).
57+
* @param osArch The value of <code>"os.arch"</code> system property (<code>System.getProperty("os.arch")</code>).
58+
* @param osArch The classpath split into strings by path separator. Value of <code>"java.class.path"</code> system property
59+
* (<code>System.getProperty("os.arch")</code>) split by <code>File.pathSeparator</code>.
60+
* @return
61+
*/
62+
public static String getLibPath(final String osName, final String runtimeName, final String osArch, final List<String> classPath) {
63+
final String os = getOs(osName, runtimeName);
64+
final List<String> libNames = getLibNames(os, getArch(os, osArch));
65+
66+
for (final String libName : libNames) {
67+
for (final String classPathLib : classPath) {
68+
if (classPathLib.contains(libName)) {
69+
return new File(classPathLib).getParent();
70+
}
71+
}
72+
}
73+
74+
throw new IllegalStateException("SQLite library \"" + libNames + "\" is missing from classpath");
75+
}
76+
77+
/**
78+
* Calculates the possible Library Names for finding the proper sqlite4java native library.
79+
*
80+
* Based on the internal calculation of the sqlite4java wrapper <a href="https://bitbucket
81+
* .org/almworks/sqlite4java/src/fa4bb0fe7319a5f1afe008284146ac83e027de60/java/com/almworks/sqlite4java/Internal
82+
* .java?at=master&fileviewer=file-view-default#Internal.java-160">Internal
83+
* class</a>.
84+
*
85+
* @param os Operating System Name used by sqlite4java to get native library.
86+
* @param arch Operating System Architecture used by sqlite4java to get native library.
87+
* @return Possible Library Names used by sqlite4java to get native library.
88+
*/
89+
public static List<String> getLibNames(final String os, final String arch) {
90+
List<String> result = new ArrayList<>();
91+
92+
final String base = BASE_LIBRARY_NAME + "-" + os;
93+
94+
result.add(base + "-" + arch);
95+
96+
if (arch.equals("x86_64") || arch.equals("x64")) {
97+
result.add(base + "-amd64");
98+
} else if (arch.equals("x86")) {
99+
result.add(base + "-i386");
100+
} else if (arch.equals("i386")) {
101+
result.add(base + "-x86");
102+
} else if (arch.startsWith("arm") && arch.length() > 3) {
103+
if (arch.length() > 5 && arch.startsWith("armv") && Character.isDigit(arch.charAt(4))) {
104+
result.add(base + "-" + arch.substring(0, 5));
105+
}
106+
result.add(base + "-arm");
107+
}
108+
109+
result.add(base);
110+
result.add(BASE_LIBRARY_NAME);
111+
112+
return result;
113+
}
114+
115+
/**
116+
* Calculates the Operating System Architecture for finding the proper sqlite4java native library.
117+
*
118+
* Based on the internal calculation of the sqlite4java wrapper <a href="https://bitbucket
119+
* .org/almworks/sqlite4java/src/fa4bb0fe7319a5f1afe008284146ac83e027de60/java/com/almworks/sqlite4java/Internal
120+
* .java?at=master&fileviewer=file-view-default#Internal.java-204">Internal
121+
* class</a>.
122+
*
123+
* @param osArch The value of <code>"os.arch"</code> system property (<code>System.getProperty("os.arch")</code>).
124+
* @param os Operating System Name used by sqlite4java to get native library.
125+
* @return Operating System Architecture used by sqlite4java to get native library.
126+
*/
127+
public static String getArch(final String os, final String osArch) {
128+
String result;
129+
130+
if (osArch == null) {
131+
result = "x86";
132+
} else {
133+
final String loweCaseOsArch = osArch.toLowerCase(Locale.US);
134+
result = loweCaseOsArch;
135+
if ("win32".equals(os) && "amd64".equals(loweCaseOsArch)) {
136+
result = "x64";
137+
}
138+
}
139+
140+
return result;
141+
}
142+
143+
/**
144+
* Calculates the Operating System Name for finding the proper sqlite4java native library.
145+
*
146+
* Based on the internal calculation of the sqlite4java wrapper <a href="https://bitbucket
147+
* .org/almworks/sqlite4java/src/fa4bb0fe7319a5f1afe008284146ac83e027de60/java/com/almworks/sqlite4java/Internal
148+
* .java?at=master&fileviewer=file-view-default#Internal.java-219">Internal
149+
* class</a>.*
150+
*
151+
* @param osName The value of <code>"os.name"</code> system property (<code>System.getProperty("os.name")</code>).
152+
* @param runtimeName The value of <code>"java.runtime.name"</code> system property (<code>System.getProperty("java.runtime.name")</code>).
153+
* @return Operating System Name used by sqlite4java to get native library.
154+
*/
155+
public static String getOs(final String osName, final String runtimeName) {
156+
157+
String result;
158+
if (osName == null) {
159+
result = "linux";
160+
} else {
161+
final String loweCaseOsName = osName.toLowerCase(Locale.US);
162+
if (loweCaseOsName.startsWith("mac") || loweCaseOsName.startsWith("darwin") || loweCaseOsName.startsWith("os x")) {
163+
result = "osx";
164+
} else if (loweCaseOsName.startsWith("windows")) {
165+
result = "win32";
166+
} else {
167+
if (runtimeName != null && runtimeName.toLowerCase(Locale.US).contains("android")) {
168+
result = "android";
169+
} else {
170+
result = "linux";
171+
}
172+
}
173+
}
174+
175+
return result;
176+
}
177+
178+
/**
179+
* Splits classpath string by path separator value.
180+
*
181+
* @param classPath Value of <code>"java.class.path"</code> system property (<code>System.getProperty("os.arch")</code>).
182+
* @param pathSeparator Value of path separator (<code>File.pathSeparator</code>).
183+
* @return The list of each classpath elements.
184+
*/
185+
public static List<String> getClassPathList(final String classPath, final String pathSeparator) {
186+
return Lists.newArrayList(Splitter.on(pathSeparator).split(classPath));
187+
}
188+
189+
}

0 commit comments

Comments
 (0)