Skip to content

Commit f58ae9d

Browse files
committed
Fix classpath order
1 parent 4f6faff commit f58ae9d

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Version 2.7.4 (2019-03-11)
2+
3+
* [fix] Preserve classpath order in packaged capsules (CLI having precedence over POM having precedence over application manifest).
4+
15
# Version 2.7.3 (2018-12-04)
26

37
* [chg] Built and tested with OpenJDK 11 (minimum Java version still being 8).

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<groupId>org.seedstack</groupId>
2121
<artifactId>seedstack-maven-plugin</artifactId>
22-
<version>2.7.3-SNAPSHOT</version>
22+
<version>2.7.4-SNAPSHOT</version>
2323
<packaging>maven-plugin</packaging>
2424

2525
<properties>
@@ -174,7 +174,7 @@
174174
<dependency>
175175
<groupId>co.paralleluniverse</groupId>
176176
<artifactId>capsule</artifactId>
177-
<version>1.0.2</version>
177+
<version>1.0.3</version>
178178
<scope>provided</scope>
179179
</dependency>
180180
<dependency>

src/license/THIRD-PARTY.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# Please fill the missing licenses for dependencies :
1414
#
1515
#
16-
#Tue Dec 04 16:12:43 CET 2018
16+
#Mon Mar 11 15:55:38 CET 2019
1717
classworlds--classworlds--1.1-alpha-2=
1818
org.codehaus.plexus--plexus-container-default--1.0-alpha-9-stable-1=
1919
jdom--jdom--1.0=

src/main/java/SeedStackCaplet.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
import java.io.File;
910
import java.net.URLDecoder;
1011
import java.nio.file.Path;
1112
import java.security.CodeSource;
1213
import java.util.ArrayList;
13-
import java.util.Collections;
1414
import java.util.HashSet;
15+
import java.util.LinkedHashSet;
1516
import java.util.List;
1617
import java.util.Map;
17-
import java.util.Set;
1818
import java.util.regex.Matcher;
1919

2020
public class SeedStackCaplet extends Capsule {
21-
private static final Map.Entry<String, List<String>> RAW_ATTR_APP_CLASS_PATH = ATTRIBUTE("App-Class-Path", T_LIST(T_STRING()), null, true, "A list of entries that are added to the classpath on runtime");
21+
private static final Map.Entry<String, List<String>> RAW_ATTR_APP_CLASS_PATH = ATTRIBUTE("App-Class-Path",
22+
T_LIST(T_STRING()),
23+
null,
24+
true,
25+
"A list of entries that are added to the classpath on runtime");
2226
private static final String CLASSPATH = "capsule.classpath";
2327
private final String homePath = getHomePath();
2428
private final String startupPath = getStartupPath();
@@ -60,28 +64,32 @@ private String getStartupPath() {
6064
@SuppressWarnings("unchecked")
6165
protected <T> T attribute(Map.Entry<String, T> attr) {
6266
if (attr.getKey().equals(RAW_ATTR_APP_CLASS_PATH.getKey())) {
63-
final List<String> rawClasspath = new ArrayList<>(super.attribute(RAW_ATTR_APP_CLASS_PATH));
64-
final Set<Object> resolvedClasspath = new HashSet<>();
65-
66-
resolvedClasspath.add(lookup("*.jar", ATTR_APP_CLASS_PATH));
67+
final List<Object> resolvedClasspath = new ArrayList<>();
6768

69+
// Runtime classpath
6870
String runtimeClasspath = System.getProperty(CLASSPATH);
6971
if (runtimeClasspath != null && !runtimeClasspath.isEmpty()) {
70-
Collections.addAll(rawClasspath, runtimeClasspath.split(File.pathSeparator));
72+
for (String rawPath : runtimeClasspath.split(File.pathSeparator)) {
73+
resolvedClasspath.add(resolvePath(rawPath));
74+
}
7175
}
7276

73-
for (String rawPath : rawClasspath) {
74-
resolvedClasspath.addAll(resolvePath(rawPath));
77+
// Static POM classpath
78+
for (String rawPath : super.attribute(RAW_ATTR_APP_CLASS_PATH)) {
79+
resolvedClasspath.add(resolvePath(rawPath));
7580
}
7681

82+
// App classpath
83+
resolvedClasspath.add(lookup("*.jar", ATTR_APP_CLASS_PATH));
84+
7785
return (T) new ArrayList<>(resolvedClasspath);
7886
} else {
7987
return super.attribute(attr);
8088
}
8189
}
8290

83-
private Set<Path> resolvePath(String path) {
84-
HashSet<Path> result = new HashSet<>();
91+
private List<Path> resolvePath(String path) {
92+
HashSet<Path> result = new LinkedHashSet<>();
8593

8694
if (path.startsWith("~")) {
8795
if (homePath == null) {
@@ -114,7 +122,7 @@ private Set<Path> resolvePath(String path) {
114122
result.add(normalizePath(file));
115123
}
116124

117-
return result;
125+
return new ArrayList<>(result);
118126
}
119127

120128
private Path normalizePath(File file) {

0 commit comments

Comments
 (0)