Skip to content

Commit

Permalink
Refactored: prepare for adding classpathFile parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
luontola committed Dec 15, 2015
1 parent 7d9941a commit d3f8a33
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
10 changes: 7 additions & 3 deletions retrolambda/src/main/java/net/orfjackal/retrolambda/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.*;

public class Config {

Expand Down Expand Up @@ -130,8 +130,12 @@ public Path getOutputDir() {
"Uses ; or : as the path separator, see java.io.File#pathSeparatorChar");
}

public String getClasspath() {
return getRequiredProperty(CLASSPATH);
public List<Path> getClasspath() {
String classpath = getRequiredProperty(CLASSPATH);
return Stream.of(classpath.split(File.pathSeparator))
.filter(path -> !path.isEmpty())
.map(Paths::get)
.collect(Collectors.toList());
}

private String getRequiredProperty(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void run(Config config) throws Throwable {
boolean defaultMethodsEnabled = config.isDefaultMethodsEnabled();
Path inputDir = config.getInputDir();
Path outputDir = config.getOutputDir();
String classpath = config.getClasspath();
List<Path> classpath = config.getClasspath();
List<Path> includedFiles = config.getIncludedFiles();
System.out.println("Bytecode version: " + bytecodeVersion + " (" + config.getJavaVersion() + ")");
System.out.println("Default methods: " + defaultMethodsEnabled);
Expand Down Expand Up @@ -92,10 +92,9 @@ static void visitFiles(Path inputDir, List<Path> includedFiles, FileVisitor<Path
Files.walkFileTree(inputDir, visitor);
}

private static URL[] asUrls(String classpath) {
String[] paths = classpath.split(System.getProperty("path.separator"));
return Arrays.asList(paths).stream()
.map(s -> Paths.get(s).toUri())
private static URL[] asUrls(List<Path> classpath) {
return classpath.stream()
.map(Path::toUri)
.map(Retrolambda::uriToUrl)
.toArray(URL[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ public void output_directory() {
assertThat("can override the default", config().getOutputDir(), is(Paths.get("output dir")));
}

@Test
public void classpath() {
systemProperties.setProperty(Config.CLASSPATH, "");
assertThat("zero values", config().getClasspath(), is(empty()));

systemProperties.setProperty(Config.CLASSPATH, "one.jar");
assertThat("one value", config().getClasspath(), is(Arrays.asList(Paths.get("one.jar"))));

systemProperties.setProperty(Config.CLASSPATH, "one.jar" + File.pathSeparator + "two.jar");
assertThat("multiple values", config().getClasspath(), is(Arrays.asList(Paths.get("one.jar"), Paths.get("two.jar"))));
}

@Ignore // TODO
@Test
public void classpath_file() {
}

@Test
public void classpath_is_required() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Missing required property: retrolambda.classpath");
config().getClasspath();
}

@Test
public void included_files() {
assertThat("not set", config().getIncludedFiles(), is(nullValue()));
Expand Down

0 comments on commit d3f8a33

Please sign in to comment.