Skip to content

Commit

Permalink
Renamed Config to SystemPropertiesConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
luontola committed Dec 15, 2015
1 parent 689240e commit 665fe6a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
Expand Up @@ -126,12 +126,12 @@ private void processClassesInCurrentProcess() throws MojoExecutionException {
getLog().info("Processing classes with Retrolambda"); getLog().info("Processing classes with Retrolambda");
try { try {
Properties p = new Properties(); Properties p = new Properties();
p.setProperty(Config.BYTECODE_VERSION, "" + targetBytecodeVersions.get(target)); p.setProperty(SystemPropertiesConfig.BYTECODE_VERSION, "" + targetBytecodeVersions.get(target));
p.setProperty(Config.DEFAULT_METHODS, "" + defaultMethods); p.setProperty(SystemPropertiesConfig.DEFAULT_METHODS, "" + defaultMethods);
p.setProperty(Config.INPUT_DIR, getInputDir().getAbsolutePath()); p.setProperty(SystemPropertiesConfig.INPUT_DIR, getInputDir().getAbsolutePath());
p.setProperty(Config.OUTPUT_DIR, getOutputDir().getAbsolutePath()); p.setProperty(SystemPropertiesConfig.OUTPUT_DIR, getOutputDir().getAbsolutePath());
p.setProperty(Config.CLASSPATH, getClasspath()); p.setProperty(SystemPropertiesConfig.CLASSPATH, getClasspath());
Retrolambda.run(new Config(p)); Retrolambda.run(new SystemPropertiesConfig(p));
} catch (Throwable t) { } catch (Throwable t) {
throw new MojoExecutionException("Failed to run Retrolambda", t); throw new MojoExecutionException("Failed to run Retrolambda", t);
} }
Expand Down
2 changes: 1 addition & 1 deletion retrolambda/pom.xml
Expand Up @@ -64,7 +64,7 @@
<arg value="-Dretrolambda.bytecodeVersion=50"/> <arg value="-Dretrolambda.bytecodeVersion=50"/>
<arg value="-Dretrolambda.inputDir=${project.build.outputDirectory}"/> <arg value="-Dretrolambda.inputDir=${project.build.outputDirectory}"/>
<arg value="-Dretrolambda.classpath=${compile_classpath}"/> <arg value="-Dretrolambda.classpath=${compile_classpath}"/>
<arg value="-Dretrolambda.includedFiles=${project.build.outputDirectory}/net/orfjackal/retrolambda/Main.class${path.separator}${project.build.outputDirectory}/net/orfjackal/retrolambda/Config.class${path.separator}${project.build.outputDirectory}/net/orfjackal/retrolambda/Retrolambda.class"/> <arg value="-Dretrolambda.includedFiles=${project.build.outputDirectory}/net/orfjackal/retrolambda/Main.class${path.separator}${project.build.outputDirectory}/net/orfjackal/retrolambda/SystemPropertiesConfig.class${path.separator}${project.build.outputDirectory}/net/orfjackal/retrolambda/Retrolambda.class"/>
<arg value="-cp"/> <arg value="-cp"/>
<arg value="${project.build.outputDirectory}"/> <arg value="${project.build.outputDirectory}"/>
<arg value="-cp"/> <arg value="-cp"/>
Expand Down
4 changes: 2 additions & 2 deletions retrolambda/src/main/java/net/orfjackal/retrolambda/Main.java
@@ -1,4 +1,4 @@
// Copyright © 2013-2014 Esko Luontola <www.orfjackal.net> // Copyright © 2013-2015 Esko Luontola <www.orfjackal.net>
// This software is released under the Apache License 2.0. // This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0 // The license text is at http://www.apache.org/licenses/LICENSE-2.0


Expand All @@ -17,7 +17,7 @@ public static void main(String[] args) {
System.exit(1); System.exit(1);
} }


Config config = new Config(System.getProperties()); SystemPropertiesConfig config = new SystemPropertiesConfig(System.getProperties());
if (!config.isFullyConfigured()) { if (!config.isFullyConfigured()) {
System.out.print(config.getHelp()); System.out.print(config.getHelp());
return; return;
Expand Down
Expand Up @@ -15,7 +15,7 @@


public class Retrolambda { public class Retrolambda {


public static void run(Config config) throws Throwable { public static void run(SystemPropertiesConfig config) throws Throwable {
int bytecodeVersion = config.getBytecodeVersion(); int bytecodeVersion = config.getBytecodeVersion();
boolean defaultMethodsEnabled = config.isDefaultMethodsEnabled(); boolean defaultMethodsEnabled = config.isDefaultMethodsEnabled();
Path inputDir = config.getInputDir(); Path inputDir = config.getInputDir();
Expand Down
Expand Up @@ -11,7 +11,7 @@
import java.util.*; import java.util.*;
import java.util.stream.*; import java.util.stream.*;


public class Config { public class SystemPropertiesConfig {


private static final String PREFIX = "retrolambda."; private static final String PREFIX = "retrolambda.";
public static final String BYTECODE_VERSION = PREFIX + "bytecodeVersion"; public static final String BYTECODE_VERSION = PREFIX + "bytecodeVersion";
Expand Down Expand Up @@ -41,7 +41,7 @@ public class Config {


private final Properties p; private final Properties p;


public Config(Properties p) { public SystemPropertiesConfig(Properties p) {
this.p = p; this.p = p;
} }


Expand Down
@@ -1,4 +1,4 @@
// Copyright © 2013 Esko Luontola <www.orfjackal.net> // Copyright © 2013-2015 Esko Luontola <www.orfjackal.net>
// This software is released under the Apache License 2.0. // This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0 // The license text is at http://www.apache.org/licenses/LICENSE-2.0


Expand All @@ -18,7 +18,7 @@ public class DocumentationTest {
@Test @Test
public void README_contains_the_usage_instructions() throws IOException { public void README_contains_the_usage_instructions() throws IOException {
String readme = toString(findInClosestParentDir("README.md")); String readme = toString(findInClosestParentDir("README.md"));
String help = new Config(new Properties()).getHelp(); String help = new SystemPropertiesConfig(new Properties()).getHelp();


assertTrue("Expected README to contain the following text:\n\n" + help, readme.contains(help)); assertTrue("Expected README to contain the following text:\n\n" + help, readme.contains(help));
} }
Expand Down
Expand Up @@ -77,11 +77,11 @@ public void ignores_included_files_that_are_outside_the_input_directory() throws
@Test @Test
public void copies_resources_to_output_directory() throws Throwable { public void copies_resources_to_output_directory() throws Throwable {
Properties p = new Properties(); Properties p = new Properties();
p.setProperty(Config.INPUT_DIR, inputDir.toString()); p.setProperty(SystemPropertiesConfig.INPUT_DIR, inputDir.toString());
p.setProperty(Config.OUTPUT_DIR, outputDir.toString()); p.setProperty(SystemPropertiesConfig.OUTPUT_DIR, outputDir.toString());
p.setProperty(Config.CLASSPATH, ""); p.setProperty(SystemPropertiesConfig.CLASSPATH, "");


Retrolambda.run(new Config(p)); Retrolambda.run(new SystemPropertiesConfig(p));


assertIsFile(outputDir.resolve("file1.txt")); assertIsFile(outputDir.resolve("file1.txt"));
assertIsFile(outputDir.resolve("subdir/file.txt")); assertIsFile(outputDir.resolve("subdir/file.txt"));
Expand Down
Expand Up @@ -14,7 +14,7 @@
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;


public class ConfigTest { public class SystemPropertiesConfigTest {


@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); public final ExpectedException thrown = ExpectedException.none();
Expand All @@ -24,24 +24,24 @@ public class ConfigTest {


private final Properties systemProperties = new Properties(); private final Properties systemProperties = new Properties();


private Config config() { private SystemPropertiesConfig config() {
return new Config(systemProperties); return new SystemPropertiesConfig(systemProperties);
} }


@Test @Test
public void is_fully_configured_when_required_properties_are_set() { public void is_fully_configured_when_required_properties_are_set() {
assertThat("before", config().isFullyConfigured(), is(false)); assertThat("before", config().isFullyConfigured(), is(false));


systemProperties.setProperty(Config.INPUT_DIR, ""); systemProperties.setProperty(SystemPropertiesConfig.INPUT_DIR, "");
systemProperties.setProperty(Config.CLASSPATH, ""); systemProperties.setProperty(SystemPropertiesConfig.CLASSPATH, "");


assertThat("after", config().isFullyConfigured(), is(true)); assertThat("after", config().isFullyConfigured(), is(true));
} }


@Test @Test
public void can_use_alternative_parameter_instead_of_required_parameter() { public void can_use_alternative_parameter_instead_of_required_parameter() {
systemProperties.setProperty(Config.INPUT_DIR, ""); systemProperties.setProperty(SystemPropertiesConfig.INPUT_DIR, "");
systemProperties.setProperty(Config.CLASSPATH_FILE, ""); systemProperties.setProperty(SystemPropertiesConfig.CLASSPATH_FILE, "");


assertThat("is fully configured?", config().isFullyConfigured(), is(true)); assertThat("is fully configured?", config().isFullyConfigured(), is(true));
} }
Expand All @@ -51,7 +51,7 @@ public void bytecode_version() {
assertThat("defaults to Java 7", config().getBytecodeVersion(), is(51)); assertThat("defaults to Java 7", config().getBytecodeVersion(), is(51));
assertThat("human printable format", config().getJavaVersion(), is("Java 7")); assertThat("human printable format", config().getJavaVersion(), is("Java 7"));


systemProperties.setProperty(Config.BYTECODE_VERSION, "50"); systemProperties.setProperty(SystemPropertiesConfig.BYTECODE_VERSION, "50");
assertThat("can override the default", config().getBytecodeVersion(), is(50)); assertThat("can override the default", config().getBytecodeVersion(), is(50));
assertThat("human printable format", config().getJavaVersion(), is("Java 6")); assertThat("human printable format", config().getJavaVersion(), is("Java 6"));
} }
Expand All @@ -60,7 +60,7 @@ public void bytecode_version() {
public void default_methods() { public void default_methods() {
assertThat("defaults to disabled", config().isDefaultMethodsEnabled(), is(false)); assertThat("defaults to disabled", config().isDefaultMethodsEnabled(), is(false));


systemProperties.setProperty(Config.DEFAULT_METHODS, "true"); systemProperties.setProperty(SystemPropertiesConfig.DEFAULT_METHODS, "true");
assertThat("can override the default", config().isDefaultMethodsEnabled(), is(true)); assertThat("can override the default", config().isDefaultMethodsEnabled(), is(true));
} }


Expand All @@ -73,22 +73,22 @@ public void input_directory_is_required() {


@Test @Test
public void output_directory() { public void output_directory() {
systemProperties.setProperty(Config.INPUT_DIR, "input dir"); systemProperties.setProperty(SystemPropertiesConfig.INPUT_DIR, "input dir");
assertThat("defaults to input dir", config().getOutputDir(), is(Paths.get("input dir"))); assertThat("defaults to input dir", config().getOutputDir(), is(Paths.get("input dir")));


systemProperties.setProperty(Config.OUTPUT_DIR, "output dir"); systemProperties.setProperty(SystemPropertiesConfig.OUTPUT_DIR, "output dir");
assertThat("can override the default", config().getOutputDir(), is(Paths.get("output dir"))); assertThat("can override the default", config().getOutputDir(), is(Paths.get("output dir")));
} }


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


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


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


Expand All @@ -97,15 +97,15 @@ public void classpath_file() throws IOException {
Path file = tempDir.newFile("classpath.txt").toPath(); Path file = tempDir.newFile("classpath.txt").toPath();


Files.write(file, Arrays.asList("", "", "")); // empty lines are ignored Files.write(file, Arrays.asList("", "", "")); // empty lines are ignored
systemProperties.setProperty(Config.CLASSPATH_FILE, file.toString()); systemProperties.setProperty(SystemPropertiesConfig.CLASSPATH_FILE, file.toString());
assertThat("zero values", config().getClasspath(), is(empty())); assertThat("zero values", config().getClasspath(), is(empty()));


Files.write(file, Arrays.asList("one.jar")); Files.write(file, Arrays.asList("one.jar"));
systemProperties.setProperty(Config.CLASSPATH_FILE, file.toString()); systemProperties.setProperty(SystemPropertiesConfig.CLASSPATH_FILE, file.toString());
assertThat("one value", config().getClasspath(), is(Arrays.asList(Paths.get("one.jar")))); assertThat("one value", config().getClasspath(), is(Arrays.asList(Paths.get("one.jar"))));


Files.write(file, Arrays.asList("one.jar", "two.jar")); Files.write(file, Arrays.asList("one.jar", "two.jar"));
systemProperties.setProperty(Config.CLASSPATH_FILE, file.toString()); systemProperties.setProperty(SystemPropertiesConfig.CLASSPATH_FILE, file.toString());
assertThat("multiple values", config().getClasspath(), is(Arrays.asList(Paths.get("one.jar"), Paths.get("two.jar")))); assertThat("multiple values", config().getClasspath(), is(Arrays.asList(Paths.get("one.jar"), Paths.get("two.jar"))));
} }


Expand All @@ -120,13 +120,13 @@ public void classpath_is_required() {
public void included_files() { public void included_files() {
assertThat("not set", config().getIncludedFiles(), is(nullValue())); assertThat("not set", config().getIncludedFiles(), is(nullValue()));


systemProperties.setProperty(Config.INCLUDED_FILES, ""); systemProperties.setProperty(SystemPropertiesConfig.INCLUDED_FILES, "");
assertThat("zero values", config().getIncludedFiles(), is(empty())); assertThat("zero values", config().getIncludedFiles(), is(empty()));


systemProperties.setProperty(Config.INCLUDED_FILES, "/foo/one.class"); systemProperties.setProperty(SystemPropertiesConfig.INCLUDED_FILES, "/foo/one.class");
assertThat("one value", config().getIncludedFiles(), is(Arrays.asList(Paths.get("/foo/one.class")))); assertThat("one value", config().getIncludedFiles(), is(Arrays.asList(Paths.get("/foo/one.class"))));


systemProperties.setProperty(Config.INCLUDED_FILES, "/foo/one.class" + File.pathSeparator + "/foo/two.class"); systemProperties.setProperty(SystemPropertiesConfig.INCLUDED_FILES, "/foo/one.class" + File.pathSeparator + "/foo/two.class");
assertThat("multiple values", config().getIncludedFiles(), is(Arrays.asList(Paths.get("/foo/one.class"), Paths.get("/foo/two.class")))); assertThat("multiple values", config().getIncludedFiles(), is(Arrays.asList(Paths.get("/foo/one.class"), Paths.get("/foo/two.class"))));
} }


Expand All @@ -136,15 +136,15 @@ public void included_files_file() throws IOException {
assertThat("not set", config().getIncludedFiles(), is(nullValue())); assertThat("not set", config().getIncludedFiles(), is(nullValue()));


Files.write(file, Arrays.asList("", "", "")); // empty lines are ignored Files.write(file, Arrays.asList("", "", "")); // empty lines are ignored
systemProperties.setProperty(Config.INCLUDED_FILES_FILE, file.toString()); systemProperties.setProperty(SystemPropertiesConfig.INCLUDED_FILES_FILE, file.toString());
assertThat("zero values", config().getIncludedFiles(), is(empty())); assertThat("zero values", config().getIncludedFiles(), is(empty()));


Files.write(file, Arrays.asList("one.class")); Files.write(file, Arrays.asList("one.class"));
systemProperties.setProperty(Config.INCLUDED_FILES_FILE, file.toString()); systemProperties.setProperty(SystemPropertiesConfig.INCLUDED_FILES_FILE, file.toString());
assertThat("one value", config().getIncludedFiles(), is(Arrays.asList(Paths.get("one.class")))); assertThat("one value", config().getIncludedFiles(), is(Arrays.asList(Paths.get("one.class"))));


Files.write(file, Arrays.asList("one.class", "two.class")); Files.write(file, Arrays.asList("one.class", "two.class"));
systemProperties.setProperty(Config.INCLUDED_FILES_FILE, file.toString()); systemProperties.setProperty(SystemPropertiesConfig.INCLUDED_FILES_FILE, file.toString());
assertThat("multiple values", config().getIncludedFiles(), is(Arrays.asList(Paths.get("one.class"), Paths.get("two.class")))); assertThat("multiple values", config().getIncludedFiles(), is(Arrays.asList(Paths.get("one.class"), Paths.get("two.class"))));
} }
} }

0 comments on commit 665fe6a

Please sign in to comment.