|
5 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
6 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
7 | 7 | */ |
| 8 | + |
8 | 9 | import java.io.File; |
9 | 10 | import java.net.URLDecoder; |
10 | 11 | import java.nio.file.Path; |
11 | 12 | import java.security.CodeSource; |
12 | 13 | import java.util.ArrayList; |
13 | | -import java.util.Collections; |
14 | 14 | import java.util.HashSet; |
| 15 | +import java.util.LinkedHashSet; |
15 | 16 | import java.util.List; |
16 | 17 | import java.util.Map; |
17 | | -import java.util.Set; |
18 | 18 | import java.util.regex.Matcher; |
19 | 19 |
|
20 | 20 | 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"); |
22 | 26 | private static final String CLASSPATH = "capsule.classpath"; |
23 | 27 | private final String homePath = getHomePath(); |
24 | 28 | private final String startupPath = getStartupPath(); |
@@ -60,28 +64,32 @@ private String getStartupPath() { |
60 | 64 | @SuppressWarnings("unchecked") |
61 | 65 | protected <T> T attribute(Map.Entry<String, T> attr) { |
62 | 66 | 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<>(); |
67 | 68 |
|
| 69 | + // Runtime classpath |
68 | 70 | String runtimeClasspath = System.getProperty(CLASSPATH); |
69 | 71 | 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 | + } |
71 | 75 | } |
72 | 76 |
|
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)); |
75 | 80 | } |
76 | 81 |
|
| 82 | + // App classpath |
| 83 | + resolvedClasspath.add(lookup("*.jar", ATTR_APP_CLASS_PATH)); |
| 84 | + |
77 | 85 | return (T) new ArrayList<>(resolvedClasspath); |
78 | 86 | } else { |
79 | 87 | return super.attribute(attr); |
80 | 88 | } |
81 | 89 | } |
82 | 90 |
|
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<>(); |
85 | 93 |
|
86 | 94 | if (path.startsWith("~")) { |
87 | 95 | if (homePath == null) { |
@@ -114,7 +122,7 @@ private Set<Path> resolvePath(String path) { |
114 | 122 | result.add(normalizePath(file)); |
115 | 123 | } |
116 | 124 |
|
117 | | - return result; |
| 125 | + return new ArrayList<>(result); |
118 | 126 | } |
119 | 127 |
|
120 | 128 | private Path normalizePath(File file) { |
|
0 commit comments