Skip to content

Commit 7113a84

Browse files
committed
Can use alternative parameters instead of required parameters
1 parent ca49dac commit 7113a84

File tree

3 files changed

+60
-29
lines changed

3 files changed

+60
-29
lines changed

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,7 @@ Copyright (c) 2013-2015 Esko Luontola <www.orfjackal.net>
9696
This software is released under the Apache License 2.0.
9797
The license text is at http://www.apache.org/licenses/LICENSE-2.0
9898
99-
Required system properties:
100-
101-
retrolambda.inputDir
102-
Input directory from where the original class files are read.
103-
104-
retrolambda.classpath
105-
Classpath containing the original class files and their dependencies.
106-
Uses ; or : as the path separator, see java.io.File#pathSeparatorChar
107-
108-
Optional system properties:
99+
Configurable system properties:
109100
110101
retrolambda.bytecodeVersion
111102
Major version number for the generated bytecode. For a list, see
@@ -119,11 +110,18 @@ Optional system properties:
119110
with one execution of Retrolambda.
120111
Disabled by default. Enable by setting to "true"
121112
113+
retrolambda.inputDir (required)
114+
Input directory from where the original class files are read.
115+
122116
retrolambda.outputDir
123117
Output directory into where the generated class files are written.
124118
Defaults to same as retrolambda.inputDir
125119
126-
retrolambda.classpathFile
120+
retrolambda.classpath (required)
121+
Classpath containing the original class files and their dependencies.
122+
Uses ; or : as the path separator, see java.io.File#pathSeparatorChar
123+
124+
retrolambda.classpathFile (alternative)
127125
File listing the classpath entries.
128126
Alternative to retrolambda.classpath for avoiding the command line
129127
length limit. The file must list one file per line with UTF-8 encoding.
@@ -133,7 +131,7 @@ Optional system properties:
133131
This is useful for a build tool to support incremental compilation.
134132
Uses ; or : as the path separator, see java.io.File#pathSeparatorChar
135133
136-
retrolambda.includedFilesFile
134+
retrolambda.includedFilesFile (alternative)
137135
File listing the files to process, instead of processing all files.
138136
Alternative to retrolambda.includedFiles for avoiding the command line
139137
length limit. The file must list one file per line with UTF-8 encoding.

retrolambda/src/main/java/net/orfjackal/retrolambda/Config.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class Config {
2424
public static final String INCLUDED_FILES_FILE = INCLUDED_FILES + "File";
2525

2626
private static final List<String> requiredProperties = new ArrayList<>();
27-
private static final List<String> requiredPropertiesHelp = new ArrayList<>();
28-
private static final List<String> optionalPropertiesHelp = new ArrayList<>();
27+
private static final Map<String, String> alternativeProperties = new HashMap<>();
28+
private static final List<String> propertiesHelp = new ArrayList<>();
2929
private static final Map<Integer, String> bytecodeVersionNames = new HashMap<>();
3030

3131
static {
@@ -51,13 +51,26 @@ public boolean isFullyConfigured() {
5151

5252
private boolean hasAllRequiredProperties() {
5353
for (String requiredParameter : requiredProperties) {
54-
if (p.getProperty(requiredParameter) == null) {
54+
if (!isConfigured(requiredParameter)) {
5555
return false;
5656
}
5757
}
5858
return true;
5959
}
6060

61+
private boolean isConfigured(String parameter) {
62+
if (p.getProperty(parameter) != null) {
63+
return true;
64+
}
65+
for (Map.Entry<String, String> alt : alternativeProperties.entrySet()) {
66+
if (alt.getValue().equals(parameter) &&
67+
p.getProperty(alt.getKey()) != null) {
68+
return true;
69+
}
70+
}
71+
return false;
72+
}
73+
6174

6275
// bytecode version
6376

@@ -133,7 +146,7 @@ public Path getOutputDir() {
133146
requiredParameterHelp(CLASSPATH,
134147
"Classpath containing the original class files and their dependencies.",
135148
"Uses ; or : as the path separator, see java.io.File#pathSeparatorChar");
136-
optionalParameterHelp(CLASSPATH_FILE,
149+
alternativeParameterHelp(CLASSPATH_FILE, CLASSPATH,
137150
"File listing the classpath entries.",
138151
"Alternative to " + CLASSPATH + " for avoiding the command line",
139152
"length limit. The file must list one file per line with UTF-8 encoding.");
@@ -177,7 +190,7 @@ private static List<Path> readPathList(Path file) {
177190
"List of files to process, instead of processing all files.",
178191
"This is useful for a build tool to support incremental compilation.",
179192
"Uses ; or : as the path separator, see java.io.File#pathSeparatorChar");
180-
optionalParameterHelp(INCLUDED_FILES_FILE,
193+
alternativeParameterHelp(INCLUDED_FILES_FILE, INCLUDED_FILES,
181194
"File listing the files to process, instead of processing all files.",
182195
"Alternative to " + INCLUDED_FILES + " for avoiding the command line",
183196
"length limit. The file must list one file per line with UTF-8 encoding.");
@@ -213,13 +226,9 @@ public String getHelp() {
213226
"This software is released under the Apache License 2.0.\n" +
214227
"The license text is at http://www.apache.org/licenses/LICENSE-2.0\n" +
215228
"\n" +
216-
"Required system properties:\n" +
229+
"Configurable system properties:\n" +
217230
"\n" +
218-
requiredPropertiesHelp.stream().reduce((a, b) -> a + "\n" + b).get() +
219-
"\n" +
220-
"Optional system properties:\n" +
221-
"\n" +
222-
optionalPropertiesHelp.stream().reduce((a, b) -> a + "\n" + b).get() +
231+
propertiesHelp.stream().reduce((a, b) -> a + "\n" + b).get() +
223232
"\n" +
224233
"If the Java agent is used, then Retrolambda will use it to capture the\n" +
225234
"lambda classes generated by Java. Otherwise Retrolambda will hook into\n" +
@@ -229,18 +238,24 @@ public String getHelp() {
229238

230239
private static void requiredParameterHelp(String key, String... lines) {
231240
requiredProperties.add(key);
232-
requiredPropertiesHelp.add(formatPropertyHelp(key, lines));
241+
propertiesHelp.add(formatPropertyHelp(key, "required", lines));
242+
}
243+
244+
private static void alternativeParameterHelp(String key, String replaces, String... lines) {
245+
alternativeProperties.put(key, replaces);
246+
propertiesHelp.add(formatPropertyHelp(key, "alternative", lines));
233247
}
234248

235249
private static void optionalParameterHelp(String key, String... lines) {
236-
optionalPropertiesHelp.add(formatPropertyHelp(key, lines));
250+
propertiesHelp.add(formatPropertyHelp(key, "", lines));
237251
}
238252

239-
private static String formatPropertyHelp(String key, String... lines) {
240-
String s = " " + key + "\n";
253+
private static String formatPropertyHelp(String key, String tag, String... lines) {
254+
tag = tag.isEmpty() ? "" : " (" + tag + ")";
255+
String help = " " + key + tag + "\n";
241256
for (String line : lines) {
242-
s += " " + line + "\n";
257+
help += " " + line + "\n";
243258
}
244-
return s;
259+
return help;
245260
}
246261
}

retrolambda/src/test/java/net/orfjackal/retrolambda/ConfigTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ private Config config() {
2828
return new Config(systemProperties);
2929
}
3030

31+
@Test
32+
public void is_fully_configured_when_required_properties_are_set() {
33+
assertThat("before", config().isFullyConfigured(), is(false));
34+
35+
systemProperties.setProperty(Config.INPUT_DIR, "");
36+
systemProperties.setProperty(Config.CLASSPATH, "");
37+
38+
assertThat("after", config().isFullyConfigured(), is(true));
39+
}
40+
41+
@Test
42+
public void can_use_alternative_parameter_instead_of_required_parameter() {
43+
systemProperties.setProperty(Config.INPUT_DIR, "");
44+
systemProperties.setProperty(Config.CLASSPATH_FILE, "");
45+
46+
assertThat("is fully configured?", config().isFullyConfigured(), is(true));
47+
}
48+
3149
@Test
3250
public void bytecode_version() {
3351
assertThat("defaults to Java 7", config().getBytecodeVersion(), is(51));

0 commit comments

Comments
 (0)