Skip to content

Commit a3e2018

Browse files
committed
add tests
1 parent dde7817 commit a3e2018

File tree

38 files changed

+431
-78
lines changed

38 files changed

+431
-78
lines changed

core.loaders/maven/src/main/java/net/lecousin/core/loaders/maven/MavenPOM.java

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -933,50 +933,56 @@ private void resolveProperties(Map<String, String> toResolve, Map<String, String
933933
if (!changed) break;
934934
}
935935
}
936-
937-
private String resolve(String value, Map<String, String> properties) {
938-
if (value == null) return null;
939-
int i = value.indexOf("${");
940-
if (i < 0) return value;
941-
int j = value.indexOf('}', i + 2);
942-
if (j < 0) return value;
943-
String name = value.substring(i + 2, j).trim();
944-
if (properties.containsKey(name)) {
945-
StringBuilder s = new StringBuilder();
946-
if (i > 0) s.append(value.substring(0, i));
947-
s.append(properties.get(name));
948-
if (j < value.length() - 1) s.append(value.substring(j + 1));
949-
return resolve(s.toString(), properties);
950-
}
951-
if (name.equals("project.groupId"))
952-
return groupId;
953-
if (name.equals("project.artifactId"))
954-
return artifactId;
955-
if (name.equals("project.version"))
956-
return version;
957-
if (name.equals("parent.groupId")) {
958-
if (parentLoading != null) return parentLoading.getResult().groupId;
959-
return null;
960-
}
961-
if (name.equals("parent.artifactId")) {
962-
if (parentLoading != null) return parentLoading.getResult().artifactId;
963-
return null;
964-
}
965-
if (name.equals("parent.version")) {
966-
if (parentLoading != null) return parentLoading.getResult().version;
967-
return null;
968-
}
969-
if (name.startsWith("env.")) {
970-
return System.getenv(name.substring(4));
971-
}
972-
if (name.startsWith("settings.")) {
973-
// TODO
974-
return null;
975-
}
976-
return System.getProperty(name);
977-
}
936+
}
937+
938+
/** Resolve the given value with properties from this POM. */
939+
public String resolveProperty(String value) {
940+
return resolve(value, properties);
978941
}
979942

943+
944+
private String resolve(String value, Map<String, String> properties) {
945+
if (value == null) return null;
946+
int i = value.indexOf("${");
947+
if (i < 0) return value;
948+
int j = value.indexOf('}', i + 2);
949+
if (j < 0) return value;
950+
String name = value.substring(i + 2, j).trim();
951+
if (properties.containsKey(name)) {
952+
StringBuilder s = new StringBuilder();
953+
if (i > 0) s.append(value.substring(0, i));
954+
s.append(properties.get(name));
955+
if (j < value.length() - 1) s.append(value.substring(j + 1));
956+
return resolve(s.toString(), properties);
957+
}
958+
if (name.equals("project.groupId"))
959+
return groupId;
960+
if (name.equals("project.artifactId"))
961+
return artifactId;
962+
if (name.equals("project.version"))
963+
return version;
964+
if (name.equals("parent.groupId")) {
965+
if (parentLoading != null) return parentLoading.getResult().groupId;
966+
return null;
967+
}
968+
if (name.equals("parent.artifactId")) {
969+
if (parentLoading != null) return parentLoading.getResult().artifactId;
970+
return null;
971+
}
972+
if (name.equals("parent.version")) {
973+
if (parentLoading != null) return parentLoading.getResult().version;
974+
return null;
975+
}
976+
if (name.startsWith("env.")) {
977+
return System.getenv(name.substring(4));
978+
}
979+
if (name.startsWith("settings.")) {
980+
// TODO
981+
return null;
982+
}
983+
return System.getProperty(name);
984+
}
985+
980986
/** Parse a version specification in POM format. */
981987
public static VersionSpecification parseVersionSpecification(String s) {
982988
if (s == null) return null;

core.loaders/maven/src/test/java/net/lecousin/core/loaders/maven/tests/TestLocalRepository.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ public void testPOMWithRepositories() throws Exception {
233233

234234
List<LibrariesRepository> repos = pom.getDependenciesAdditionalRepositories();
235235
Assert.assertEquals(2, repos.size());
236+
pom.toString();
236237
} finally {
237238
outFile.delete();
238239
}
@@ -257,6 +258,26 @@ public void testPOMWithAdditionalFields() throws Exception {
257258
outFile.delete();
258259
}
259260
}
261+
262+
@Test
263+
public void testPOMWithProperties() throws Exception {
264+
File outFile = new File("./test-properties.pom.xml");
265+
outFile.createNewFile();
266+
outFile.deleteOnExit();
267+
try {
268+
new File("./target/test-out").mkdir();
269+
FileIO.WriteOnly out = new FileIO.WriteOnly(outFile, Task.PRIORITY_NORMAL);
270+
IOUtil.copy(
271+
((IOProvider.Readable)IOProviderFromURI.getInstance().get(new URI("classpath:test-maven/test-properties.pom.xml"))).provideIOReadable(Task.PRIORITY_NORMAL),
272+
out,
273+
-1, true, null, 0).blockThrow(15000);
274+
275+
AsyncSupplier<MavenPOM, LibraryManagementException> load = MavenPOM.load(new File("./test-properties.pom.xml").toURI(), Task.PRIORITY_NORMAL, pomLoader, false);
276+
load.blockResult(30000);
277+
} finally {
278+
outFile.delete();
279+
}
280+
}
260281

261282
private void testError(String errorName) throws IOException, CancelException, URISyntaxException {
262283
File outFile = new File("./test-error-" + errorName + ".pom.xml");
@@ -287,6 +308,9 @@ public void testErrors() throws Exception {
287308
testError("invalid-root");
288309
testError("invalid-xml");
289310
testError("invalid-xml2");
311+
testError("invalid-xml3");
312+
testError("invalid-xml4");
313+
testError("invalid-xml5");
290314
testError("empty");
291315
}
292316

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>test</groupId>
6+
<artifactId>maven</artifactId>
7+
<version>1</version>
8+
<packaging>bundle</packaging>
9+
10+
<repositories>
11+
<repository>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>test</groupId>
6+
<artifactId>maven</artifactId>
7+
<version>1</version>
8+
<packaging>bundle</packaging>
9+
10+
<repositories>
11+
<repository>
12+
<releases>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>test</groupId>
6+
<artifactId>maven</artifactId>
7+
<version>1</version>
8+
<packaging>bundle</packaging>
9+
10+
<repositories>
11+
<repository>
12+
<snapshots>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>test</groupId>
6+
<artifactId>maven</artifactId>
7+
<version>1</version>
8+
<packaging>bundle</packaging>
9+
10+
<parent>
11+
<groupId>junit</groupId>
12+
<artifactId>junit</artifactId>
13+
<version>4.12</version>
14+
</parent>
15+
16+
<properties>
17+
<test-junit-version>${parent.version}</test-junit-version>
18+
<test-junit-groupId>${parent.groupId}</test-junit-groupId>
19+
<test-junit-artifactId>${parent.artifactId}</test-junit-artifactId>
20+
<test-env>${env.user}</test-env>
21+
<test-settings>${settings.test}</test-settings>
22+
</properties>
23+
24+
</project>

core.loaders/maven/src/test/resources/test-maven/test-repositories.pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@
3030
<releases>true</releases>
3131
<snapshots>false</snapshots>
3232
</repository>
33+
<repository>
34+
<id>closed</id>
35+
<releases/>
36+
</repository>
37+
<repository/>
3338
</repositories>
3439
</project>

net.lecousin.core/src/main/java/net/lecousin/framework/application/libraries/classpath/DefaultLibrariesManager.java

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ public DefaultApplicationClassLoader start(Application app) {
6363
private File[] additionalClassPath;
6464
private ArrayList<File> classPath;
6565

66+
private static BufferedReadableCharacterStream loadNextFile(Enumeration<URL> urls, Async<Exception> sp) {
67+
if (!urls.hasMoreElements()) {
68+
sp.unblock();
69+
return null;
70+
}
71+
URL url = urls.nextElement();
72+
InputStream input;
73+
try { input = url.openStream(); }
74+
catch (IOException e) {
75+
sp.error(e);
76+
return null;
77+
}
78+
IOFromInputStream io = new IOFromInputStream(
79+
input, url.toString(), Threading.getUnmanagedTaskManager(), Task.PRIORITY_IMPORTANT);
80+
return new BufferedReadableCharacterStream(io, StandardCharsets.UTF_8, 256, 32);
81+
}
82+
6683
private class Start extends Task.Cpu<Void, NoException> {
6784
private Start() {
6885
super("Start DefaultLibrariesManager", Task.PRIORITY_IMPORTANT);
@@ -111,20 +128,8 @@ private Async<Exception> loadExtensionPoints() {
111128
}
112129

113130
private void loadExtensionPoints(Enumeration<URL> urls, Async<Exception> sp) {
114-
if (!urls.hasMoreElements()) {
115-
sp.unblock();
116-
return;
117-
}
118-
URL url = urls.nextElement();
119-
InputStream input;
120-
try { input = url.openStream(); }
121-
catch (IOException e) {
122-
sp.error(e);
123-
return;
124-
}
125-
IOFromInputStream io = new IOFromInputStream(
126-
input, url.toString(), Threading.getUnmanagedTaskManager(), Task.PRIORITY_IMPORTANT);
127-
BufferedReadableCharacterStream stream = new BufferedReadableCharacterStream(io, StandardCharsets.UTF_8, 256, 32);
131+
BufferedReadableCharacterStream stream = loadNextFile(urls, sp);
132+
if (stream == null) return;
128133
LoadLibraryExtensionPointsFile load = new LoadLibraryExtensionPointsFile(stream, acl);
129134
load.start().onDone(() -> loadExtensionPoints(urls, sp), sp);
130135
stream.closeAfter(sp);
@@ -182,20 +187,8 @@ private void loadPlugins(Async<Exception> sp) {
182187
}
183188

184189
private void loadPlugins(Enumeration<URL> urls, Async<Exception> sp) {
185-
if (!urls.hasMoreElements()) {
186-
sp.unblock();
187-
return;
188-
}
189-
URL url = urls.nextElement();
190-
InputStream input;
191-
try { input = url.openStream(); }
192-
catch (IOException e) {
193-
sp.error(e);
194-
return;
195-
}
196-
IOFromInputStream io = new IOFromInputStream(
197-
input, url.toString(), Threading.getUnmanagedTaskManager(), Task.PRIORITY_IMPORTANT);
198-
BufferedReadableCharacterStream stream = new BufferedReadableCharacterStream(io, StandardCharsets.UTF_8, 256, 32);
190+
BufferedReadableCharacterStream stream = loadNextFile(urls, sp);
191+
if (stream == null) return;
199192
LoadLibraryPluginsFile load = new LoadLibraryPluginsFile(stream, acl);
200193
load.start().onDone(() -> loadPlugins(urls, sp), sp);
201194
stream.closeAfter(sp);

net.lecousin.core/src/test/java/net/lecousin/framework/core/test/runners/LCConcurrentRunner.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ public long getMaxBlockingTimeInNanoBeforeToLog() {
6868
@Override
6969
public void finished() {
7070
jp.start();
71-
jp.block(10L * 60 * 1000);
71+
int lastNb = jp.getToJoin();
72+
do {
73+
jp.block(10L * 60 * 1000);
74+
if (lastNb == jp.getToJoin())
75+
break;
76+
lastNb = jp.getToJoin();
77+
} while (!jp.isDone());
7278
if (!jp.isDone())
73-
throw new RuntimeException("Some tests are not finished after 10 minutes");
79+
throw new RuntimeException("Some tests are not finished after 10 minutes: still waiting for " + jp.getToJoin());
7480
}
7581
};
7682
};

0 commit comments

Comments
 (0)