Skip to content

Commit e32432b

Browse files
committed
Use System's path separator for classpaths
1 parent 5879d77 commit e32432b

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public final class BuildParameterBuilder {
6565
private static final Logger LOGGER = Logger.getLogger(BuildParameterBuilder.class.getName());
6666
private static final String SMITHY_TAG_PROPERTY = "Smithy-Tags";
6767
private static final String SOURCE = "source";
68+
private static final String PATH_SEPARATOR = "path.separator";
6869

6970
private String projectionSource = SOURCE;
7071
private Set<String> projectionSourceTags = new LinkedHashSet<>();
@@ -135,7 +136,7 @@ public BuildParameterBuilder addSourcesIfExists(Collection<String> sources) {
135136
* @return Returns the builder.
136137
*/
137138
public BuildParameterBuilder buildClasspath(String buildClasspath) {
138-
this.buildClasspath.addAll(splitAndFilterString(":", buildClasspath));
139+
this.buildClasspath.addAll(splitAndFilterString(System.getProperty(PATH_SEPARATOR), buildClasspath));
139140
return this;
140141
}
141142

@@ -157,7 +158,7 @@ private static Set<String> splitAndFilterString(String delimiter, String value)
157158
* @return Returns the builder.
158159
*/
159160
public BuildParameterBuilder libClasspath(String libClasspath) {
160-
this.libClasspath.addAll(splitAndFilterString(":", libClasspath));
161+
this.libClasspath.addAll(splitAndFilterString(System.getProperty(PATH_SEPARATOR), libClasspath));
161162
return this;
162163
}
163164

@@ -357,7 +358,9 @@ private Result configureSourceProjection() {
357358
Set<String> combined = new LinkedHashSet<>(libClasspath);
358359
combined.addAll(buildClasspath);
359360

360-
return new Result(this, String.join(":", computedDiscovery), String.join(":", combined), sources);
361+
String discoveryClasspath = String.join(System.getProperty(PATH_SEPARATOR), computedDiscovery);
362+
String classpath = String.join(System.getProperty(PATH_SEPARATOR), combined);
363+
return new Result(this, discoveryClasspath, classpath, sources);
361364
}
362365

363366
/**
@@ -373,7 +376,7 @@ private Result configureProjection() {
373376
LOGGER.warning("No projection source tags were set for the projection `" + projection + "`, so the "
374377
+ "projection will not have any sources in it other than files found in the sources of "
375378
+ "the package being built.");
376-
String buildCp = String.join(":", buildClasspath);
379+
String buildCp = String.join(System.getProperty(PATH_SEPARATOR), buildClasspath);
377380
return new Result(this, buildCp, buildCp, sources);
378381
}
379382

@@ -390,8 +393,9 @@ private Result configureProjection() {
390393
Set<String> computedDiscovery = new LinkedHashSet<>(buildClasspath);
391394
computedDiscovery.removeAll(computedSources);
392395

393-
return new Result(this, String.join(":", computedDiscovery),
394-
String.join(":", buildClasspath), computedSources);
396+
String discoveryClasspath = String.join(System.getProperty(PATH_SEPARATOR), computedDiscovery);
397+
String classpath = String.join(System.getProperty(PATH_SEPARATOR), buildClasspath);
398+
return new Result(this, discoveryClasspath, classpath, computedSources);
395399
}
396400

397401
/**

smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ private static void handleModelDiscovery(Arguments arguments, ModelAssembler ass
7070
private static void discoverModelsWithClasspath(Arguments arguments, ModelAssembler assembler) {
7171
String rawClasspath = arguments.parameter(SmithyCli.DISCOVER_CLASSPATH);
7272
LOGGER.finer("Discovering models with classpath: " + rawClasspath);
73-
String[] classpath = rawClasspath.split(":");
73+
74+
// Use System.getProperty here each time since it allows the value to be changed.
75+
String[] classpath = rawClasspath.split(System.getProperty("path.separator"));
7476
URL[] urls = new URL[classpath.length];
7577

7678
for (int i = 0; i < classpath.length; i++) {

smithy-cli/src/test/java/software/amazon/smithy/cli/BuildParameterBuilderTest.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ public void findsProjectionJarsWithSourceTags() {
217217
String a = getClass().getResource("jars/a/a.jar").getPath();
218218
String b = getClass().getResource("jars/b/b.jar").getPath();
219219
String c = getClass().getResource("jars/c/c.jar").getPath();
220-
String buildCp = a + ":" + b + ":" + c;
220+
String separator = System.getProperty("path.separator");
221+
String buildCp = a + separator + b + separator + c;
221222

222223
BuildParameterBuilder.Result result = new BuildParameterBuilder()
223224
.projectionSource("foo")
@@ -230,8 +231,35 @@ public void findsProjectionJarsWithSourceTags() {
230231
// The classpath keeps all of the JARs.
231232
assertThat(result.classpath, equalTo(buildCp));
232233
// The discovery classpath removes a because it's JAR matched the source tag.
233-
assertThat(result.discoveryClasspath, equalTo(b + ":" + c));
234+
assertThat(result.discoveryClasspath, equalTo(b + separator + c));
234235
// The sources now contains a because it matched a source tag.
235236
assertThat(result.sources, contains(a));
236237
}
238+
239+
@Test
240+
public void usesCustomSeparator() {
241+
String currentSeparator = System.getProperty("path.separator");
242+
243+
try {
244+
System.setProperty("path.separator", "|");
245+
String a = getClass().getResource("jars/a/a.jar").getPath();
246+
String b = getClass().getResource("jars/b/b.jar").getPath();
247+
String c = getClass().getResource("jars/c/c.jar").getPath();
248+
String buildCp = a + "|" + b + "|" + c;
249+
250+
BuildParameterBuilder.Result result = new BuildParameterBuilder()
251+
.projectionSource("foo")
252+
.projectionSourceTags("X, Blah")
253+
.libClasspath("abc.jar")
254+
.buildClasspath(buildCp)
255+
.discover(true)
256+
.build();
257+
258+
assertThat(result.classpath, equalTo(buildCp));
259+
assertThat(result.discoveryClasspath, equalTo(b + "|" + c));
260+
assertThat(result.sources, contains(a));
261+
} finally {
262+
System.setProperty("path.separator", currentSeparator);
263+
}
264+
}
237265
}

0 commit comments

Comments
 (0)