aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.xml7
-rw-r--r--src/core/lombok/core/configuration/ConfigurationApp.java43
-rw-r--r--test/configuration/resource/configurationRoot/d1/d11/d111/f1.txt0
-rw-r--r--test/configuration/resource/configurationRoot/d1/d11/d111/lombok.config2
-rw-r--r--test/configuration/resource/configurationRoot/d1/d11/lombok.config5
-rw-r--r--test/configuration/resource/configurationRoot/d1/d12/lombok.config3
-rw-r--r--test/configuration/resource/configurationRoot/d1/lombok.config3
-rw-r--r--test/configuration/resource/configurationRoot/err.txt0
-rw-r--r--test/configuration/resource/configurationRoot/out.txt90
-rw-r--r--test/configuration/src/lombok/core/configuration/RunConfigurationTests.java31
-rw-r--r--test/configuration/src/lombok/core/configuration/TestConfiguration.java95
-rw-r--r--test/core/src/lombok/RunAllTests.java4
12 files changed, 265 insertions, 18 deletions
diff --git a/build.xml b/build.xml
index b44d6673..c423366a 100644
--- a/build.xml
+++ b/build.xml
@@ -247,6 +247,7 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
<srcdir dir="test/transform/src" test="true" />
<srcdir dir="test/core/src" test="true" />
<srcdir dir="test/bytecode/src" test="true" />
+ <srcdir dir="test/configuration/src" test="true" />
</module>
<settings>
<url url="http://projectlombok.org/downloads/lombok.intellij.settings" />
@@ -267,6 +268,7 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
<srcdir dir="test/transform/src" />
<srcdir dir="test/core/src" />
<srcdir dir="test/bytecode/src" />
+ <srcdir dir="test/configuration/src" />
<conf name="build" sources="contrib" />
<conf name="test" sources="contrib" />
<settings>
@@ -292,10 +294,12 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
<src path="test/core/src" />
<src path="test/transform/src" />
<src path="test/bytecode/src" />
+ <src path="test/configuration/src" />
</ivy:compile>
<copy todir="build/tests">
<fileset dir="test/pretty/resource" />
<fileset dir="test/transform/resource" />
+ <fileset dir="test/configuration/resource" />
</copy>
</target>
@@ -426,6 +430,9 @@ You can also create your own by writing a 'testenvironment.properties' file. The
<fileset dir="test/bytecode/src">
<include name="**/Test*.java" />
</fileset>
+ <fileset dir="test/configuration/src">
+ <include name="**/Test*.java" />
+ </fileset>
</batchtest>
</junit>
<echo level="info">All tests successful.</echo>
diff --git a/src/core/lombok/core/configuration/ConfigurationApp.java b/src/core/lombok/core/configuration/ConfigurationApp.java
index 70701adf..a1ca3597 100644
--- a/src/core/lombok/core/configuration/ConfigurationApp.java
+++ b/src/core/lombok/core/configuration/ConfigurationApp.java
@@ -58,6 +58,9 @@ import com.zwitserloot.cmdreader.Shorthand;
public class ConfigurationApp extends LombokApp {
private static final URI NO_CONFIG = URI.create("");
+ private PrintStream out = System.out;
+ private PrintStream err = System.err;
+
@Override public String getAppName() {
return "config";
}
@@ -100,12 +103,12 @@ public class ConfigurationApp extends LombokApp {
try {
args = reader.make(raw.toArray(new String[0]));
if (args.help) {
- System.out.println(reader.generateCommandLineHelp("java -jar lombok.jar configuration"));
+ out.println(reader.generateCommandLineHelp("java -jar lombok.jar configuration"));
return 0;
}
} catch (InvalidCommandLineException e) {
- System.err.println(e.getMessage());
- System.err.println(reader.generateCommandLineHelp("java -jar lombok.jar configuration"));
+ err.println(e.getMessage());
+ err.println(reader.generateCommandLineHelp("java -jar lombok.jar configuration"));
return 1;
}
@@ -113,17 +116,21 @@ public class ConfigurationApp extends LombokApp {
Collection<ConfigurationKey<?>> keys = checkKeys(args.key);
if (keys == null) return 1;
+ boolean verbose = args.verbose;
if (args.generate) {
- return generate(System.out, args.verbose, keys);
+ return generate(keys, verbose);
}
- TreeMap<URI, Set<String>> sharedDirectories = findSharedDirectories(args.paths);
- if (sharedDirectories == null) return 1;
-
- return display(System.out, args.verbose, sharedDirectories, keys, args.paths.size() == 1, !args.key.isEmpty());
+ return display(keys, verbose, args.paths, !args.key.isEmpty());
+ }
+
+ public ConfigurationApp redirectOutput(PrintStream out, PrintStream err) {
+ if (out != null) this.out = out;
+ if (err != null) this.err = err;
+ return this;
}
- private int generate(PrintStream out, boolean verbose, Collection<ConfigurationKey<?>> keys) {
+ public int generate(Collection<ConfigurationKey<?>> keys, boolean verbose) {
for (ConfigurationKey<?> key : keys) {
String keyName = key.getKeyName();
ConfigurationDataType type = key.getType();
@@ -159,7 +166,11 @@ public class ConfigurationApp extends LombokApp {
return 0;
}
- private int display(PrintStream out, boolean verbose, TreeMap<URI, Set<String>> sharedDirectories, Collection<ConfigurationKey<?>> keys, boolean onlyOne, boolean explicitKeys) throws Exception {
+ public int display(Collection<ConfigurationKey<?>> keys, boolean verbose, Collection<String> argsPaths, boolean explicitKeys) throws Exception {
+ TreeMap<URI, Set<String>> sharedDirectories = findSharedDirectories(argsPaths);
+
+ if (sharedDirectories == null) return 1;
+
Set<String> none = sharedDirectories.remove(NO_CONFIG);
if (none != null) {
if (none.size() == 1) {
@@ -185,7 +196,7 @@ public class ConfigurationApp extends LombokApp {
}
Set<String> paths = entry.getValue();
if (paths.size() == 1) {
- if (!onlyOne) out.printf("Configuration for '%s'.\n\n", paths.iterator().next());
+ if (!(argsPaths.size() == 1)) out.printf("Configuration for '%s'.\n\n", paths.iterator().next());
} else {
out.printf("Configuration for:\n", paths.iterator().next());
for (String path : paths) out.printf("- %s\n", path);
@@ -200,7 +211,7 @@ public class ConfigurationApp extends LombokApp {
Collection<String> modifications = traces.get(key);
if (!modifications.isEmpty() || explicitKeys) {
if (printed && verbose) out.println();
- printValue(out, key, value, verbose, modifications);
+ printValue(key, value, verbose, modifications);
printed = true;
}
}
@@ -216,7 +227,7 @@ public class ConfigurationApp extends LombokApp {
return 0;
}
- private void printValue(PrintStream out, ConfigurationKey<?> key, Object value, boolean verbose, Collection<String> history) {
+ private void printValue(ConfigurationKey<?> key, Object value, boolean verbose, Collection<String> history) {
if (verbose) out.printf("# %s\n", key.getDescription());
if (value == null) {
out.printf("clear %s\n", key.getKeyName());
@@ -319,7 +330,7 @@ public class ConfigurationApp extends LombokApp {
for (String keyName : keyList) {
ConfigurationKey<?> key = registeredKeys.get(keyName);
if (key == null) {
- System.err.printf("Unknown key '%s'\n", keyName);
+ err.printf("Unknown key '%s'\n", keyName);
return null;
}
keys.remove(key);
@@ -328,7 +339,7 @@ public class ConfigurationApp extends LombokApp {
return keys;
}
- private TreeMap<URI, Set<String>> findSharedDirectories(List<String> paths) {
+ private TreeMap<URI, Set<String>> findSharedDirectories(Collection<String> paths) {
TreeMap<URI,Set<String>> sharedDirectories = new TreeMap<URI, Set<String>>(new Comparator<URI>() {
@Override public int compare(URI o1, URI o2) {
return o1.toString().compareTo(o2.toString());
@@ -337,7 +348,7 @@ public class ConfigurationApp extends LombokApp {
for (String path : paths) {
File file = new File(path);
if (!file.exists()) {
- System.err.printf("File not found: '%s'\n", path);
+ err.printf("File not found: '%s'\n", path);
return null;
}
URI first = findFirstLombokDirectory(file);
diff --git a/test/configuration/resource/configurationRoot/d1/d11/d111/f1.txt b/test/configuration/resource/configurationRoot/d1/d11/d111/f1.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/d11/d111/f1.txt
diff --git a/test/configuration/resource/configurationRoot/d1/d11/d111/lombok.config b/test/configuration/resource/configurationRoot/d1/d11/d111/lombok.config
new file mode 100644
index 00000000..bcea2a72
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/d11/d111/lombok.config
@@ -0,0 +1,2 @@
+clear lombok.Accessors.chain
+lombok.Accessors.prefix += m_ \ No newline at end of file
diff --git a/test/configuration/resource/configurationRoot/d1/d11/lombok.config b/test/configuration/resource/configurationRoot/d1/d11/lombok.config
new file mode 100644
index 00000000..fcdc4823
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/d11/lombok.config
@@ -0,0 +1,5 @@
+stop-bubbling=true
+
+lombok.Accessors.chain = false
+lombok.Accessors.flagUsage = ERROR
+lombok.Accessors.prefix += f \ No newline at end of file
diff --git a/test/configuration/resource/configurationRoot/d1/d12/lombok.config b/test/configuration/resource/configurationRoot/d1/d12/lombok.config
new file mode 100644
index 00000000..a18a4756
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/d12/lombok.config
@@ -0,0 +1,3 @@
+stop-bubbling=true
+
+lombok.Accessors.chain = true \ No newline at end of file
diff --git a/test/configuration/resource/configurationRoot/d1/lombok.config b/test/configuration/resource/configurationRoot/d1/lombok.config
new file mode 100644
index 00000000..dec482e6
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/lombok.config
@@ -0,0 +1,3 @@
+stop-bubbling=true
+# this file shouldn't be read
+no error expected \ No newline at end of file
diff --git a/test/configuration/resource/configurationRoot/err.txt b/test/configuration/resource/configurationRoot/err.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/err.txt
diff --git a/test/configuration/resource/configurationRoot/out.txt b/test/configuration/resource/configurationRoot/out.txt
new file mode 100644
index 00000000..54e91094
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/out.txt
@@ -0,0 +1,90 @@
+Configuration for 'BASE/d1/d11'.
+
+# Emit a warning or error if @Accessors is used.
+lombok.Accessors.flagUsage = ERROR
+# BASE/d1/lombok.config:
+# <'lombok.Accessors.flagUsage' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 3: lombok.Accessors.flagUsage = ERROR
+
+# Generate setters that return 'this' instead of 'void'.
+lombok.Accessors.chain = false
+# BASE/d1/lombok.config:
+# <'lombok.Accessors.chain' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 2: lombok.Accessors.chain = false
+
+# Strip this field prefix, like 'f' or 'm_', from the names of generated getters and setters.
+lombok.Accessors.prefix += f
+# BASE/d1/lombok.config:
+# <'lombok.Accessors.prefix' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 4: lombok.Accessors.prefix += f
+
+# Use this name for the generated logger fields (default: 'log')
+clear lombok.log.fieldName
+
+
+Configuration for:
+- BASE/d1/d11/d111
+- BASE/d1/d11/d111/f1.txt
+
+# Emit a warning or error if @Accessors is used.
+lombok.Accessors.flagUsage = ERROR
+# BASE/d1/lombok.config:
+# <'lombok.Accessors.flagUsage' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 3: lombok.Accessors.flagUsage = ERROR
+#
+# BASE/d1/d11/d111/lombok.config:
+# <'lombok.Accessors.flagUsage' not mentioned>
+
+# Generate setters that return 'this' instead of 'void'.
+clear lombok.Accessors.chain
+# BASE/d1/lombok.config:
+# <'lombok.Accessors.chain' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 2: lombok.Accessors.chain = false
+#
+# BASE/d1/d11/d111/lombok.config:
+# 1: clear lombok.Accessors.chain
+
+# Strip this field prefix, like 'f' or 'm_', from the names of generated getters and setters.
+lombok.Accessors.prefix += f
+lombok.Accessors.prefix += m_
+# BASE/d1/lombok.config:
+# <'lombok.Accessors.prefix' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 4: lombok.Accessors.prefix += f
+#
+# BASE/d1/d11/d111/lombok.config:
+# 2: lombok.Accessors.prefix += m_
+
+# Use this name for the generated logger fields (default: 'log')
+clear lombok.log.fieldName
+
+
+Configuration for 'BASE/d1/d12'.
+
+# Emit a warning or error if @Accessors is used.
+clear lombok.Accessors.flagUsage
+
+# Generate setters that return 'this' instead of 'void'.
+lombok.Accessors.chain = true
+# BASE/d1/lombok.config:
+# <'lombok.Accessors.chain' not mentioned>
+#
+# BASE/d1/d12/lombok.config:
+# 2: lombok.Accessors.chain = true
+
+# Strip this field prefix, like 'f' or 'm_', from the names of generated getters and setters.
+clear lombok.Accessors.prefix
+
+# Use this name for the generated logger fields (default: 'log')
+clear lombok.log.fieldName \ No newline at end of file
diff --git a/test/configuration/src/lombok/core/configuration/RunConfigurationTests.java b/test/configuration/src/lombok/core/configuration/RunConfigurationTests.java
new file mode 100644
index 00000000..40e0a7f4
--- /dev/null
+++ b/test/configuration/src/lombok/core/configuration/RunConfigurationTests.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 The Project Lombok Authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package lombok.core.configuration;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({TestConfiguration.class})
+public class RunConfigurationTests {
+}
diff --git a/test/configuration/src/lombok/core/configuration/TestConfiguration.java b/test/configuration/src/lombok/core/configuration/TestConfiguration.java
new file mode 100644
index 00000000..4ded8cf2
--- /dev/null
+++ b/test/configuration/src/lombok/core/configuration/TestConfiguration.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2014 The Project Lombok Authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package lombok.core.configuration;
+
+import static lombok.ConfigurationKeys.*;
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+public class TestConfiguration {
+
+ @Test
+ public void testIt() throws Exception {
+
+ @SuppressWarnings("unchecked")
+ Collection<ConfigurationKey<?>> keys = Arrays.asList(ACCESSORS_FLAG_USAGE, ACCESSORS_CHAIN, ACCESSORS_PREFIX, LOG_ANY_FIELD_NAME);
+
+ String baseName = "test/configuration/resource/configurationRoot/";
+ File directory = new File(baseName);
+ String normalizedName = new File(directory.getAbsoluteFile().toURI().normalize()).toString().replace('\\', '/') + "/";
+ Collection<String> paths = Arrays.asList(normalizedName + "d1/d11", normalizedName + "d1/d12", normalizedName + "d1/d11/d111", normalizedName + "d1/d11/d111/f1.txt");
+
+ ByteArrayOutputStream rawOut = new ByteArrayOutputStream();
+ ByteArrayOutputStream rawErr = new ByteArrayOutputStream();
+ PrintStream outStream = new PrintStream(rawOut);
+ PrintStream errStream = new PrintStream(rawErr);
+
+ int result = new ConfigurationApp().redirectOutput(outStream, errStream).display(keys, true, paths, true);
+
+ outStream.flush();
+ errStream.flush();
+
+ String out = new String(rawOut.toByteArray()).replace("\r\n", "\n").replace('\\', '/').replaceAll(Pattern.quote(normalizedName) + "|" + Pattern.quote(baseName), "BASE/").trim();
+ String err = new String(rawErr.toByteArray()).replace("\r\n", "\n").replace('\\', '/').replaceAll(Pattern.quote(normalizedName) + "|" + Pattern.quote(baseName), "BASE/").trim();
+
+ checkContent(directory, out, "out");
+ checkContent(directory, err, "err");
+ assertEquals(0, result);
+ }
+
+ private void checkContent(File dir, String actual, String type) throws Exception {
+ String expected = fileToString(new File(dir, type + ".txt")).trim();
+ if (!expected.equals(actual)) {
+ System.out.printf("**** Expected %s:\n", type);
+ System.out.println(expected);
+ System.out.printf("**** Actual %s:\n", type);
+ System.out.println(actual);
+ System.out.println("****");
+ }
+ assertEquals(expected, actual);
+ }
+
+ static String fileToString(File configFile) throws Exception {
+ byte[] b = new byte[65536];
+ FileInputStream fis = new FileInputStream(configFile);
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ while (true) {
+ int r = fis.read(b);
+ if (r == -1) break;
+ out.write(b, 0, r);
+ }
+ return new String(out.toByteArray(), "UTF-8");
+ } finally {
+ fis.close();
+ }
+ }
+}
diff --git a/test/core/src/lombok/RunAllTests.java b/test/core/src/lombok/RunAllTests.java
index 0076e662..9f56b45b 100644
--- a/test/core/src/lombok/RunAllTests.java
+++ b/test/core/src/lombok/RunAllTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Project Lombok Authors.
+ * Copyright (C) 2011-2014 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,6 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses({lombok.transform.RunTransformTests.class, lombok.bytecode.RunBytecodeTests.class})
+@SuiteClasses({lombok.transform.RunTransformTests.class, lombok.bytecode.RunBytecodeTests.class, lombok.core.configuration.RunConfigurationTests.class})
public class RunAllTests {
}