mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 10:15:19 +00:00
[configuration] Initial setup for configuration app
This commit is contained in:
1 parent
2f0d7614d4
commit
deb694033a
3 files changed
+165
No files matched your search
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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 java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.ConfigurationKeys;
|
||||
import lombok.core.LombokApp;
|
||||
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
import com.zwitserloot.cmdreader.CmdReader;
|
||||
import com.zwitserloot.cmdreader.Description;
|
||||
import com.zwitserloot.cmdreader.Excludes;
|
||||
import com.zwitserloot.cmdreader.InvalidCommandLineException;
|
||||
import com.zwitserloot.cmdreader.Mandatory;
|
||||
import com.zwitserloot.cmdreader.Sequential;
|
||||
import com.zwitserloot.cmdreader.Shorthand;
|
||||
|
||||
@ProviderFor(LombokApp.class)
|
||||
public class ConfigurationApp extends LombokApp {
|
||||
|
||||
@Override public String getAppName() {
|
||||
return "configuration";
|
||||
}
|
||||
|
||||
@Override public String getAppDescription() {
|
||||
return "Prints the configurations for the provided paths to standard out.";
|
||||
}
|
||||
|
||||
@Override public List<String> getAppAliases() {
|
||||
return Arrays.asList("configuration", "config");
|
||||
}
|
||||
|
||||
public static class CmdArgs {
|
||||
@Sequential
|
||||
@Mandatory(onlyIfNot={"help", "generate"})
|
||||
@Description("Paths to java files or directories the configuration is to be printed for.")
|
||||
private List<String> paths = new ArrayList<String>();
|
||||
|
||||
@Shorthand("g")
|
||||
@Excludes("paths")
|
||||
@Description("Generates a list containing all the available configuration parameters. Add --verbose to print more information.")
|
||||
boolean generate = false;
|
||||
|
||||
@Shorthand("v")
|
||||
@Description("Displays more information.")
|
||||
boolean verbose = false;
|
||||
|
||||
@Shorthand({"h", "?"})
|
||||
@Description("Shows this help text.")
|
||||
boolean help = false;
|
||||
}
|
||||
|
||||
@Override public int runApp(List<String> raw) throws Exception {
|
||||
CmdReader<CmdArgs> reader = CmdReader.of(CmdArgs.class);
|
||||
CmdArgs args;
|
||||
try {
|
||||
args = reader.make(raw.toArray(new String[0]));
|
||||
if (args.help) {
|
||||
System.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"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ConfigurationKeys.ensureKeysLoaded();
|
||||
|
||||
if (args.generate) {
|
||||
printConfiguration(System.out, args.verbose);
|
||||
} else {
|
||||
System.out.println("Not generating anything...");
|
||||
}
|
||||
|
||||
|
||||
// List<File> filesToProcess = PostCompilerApp.cmdArgsToFiles(args.classFiles);
|
||||
int filesVisited = 0;
|
||||
// boolean moreThanOne = filesToProcess.size() > 1;
|
||||
// for (File file : filesToProcess) {
|
||||
// if (!file.exists() || !file.isFile()) {
|
||||
// System.out.printf("Cannot find file '%s'\n", file.getAbsolutePath());
|
||||
// continue;
|
||||
// }
|
||||
// filesVisited++;
|
||||
// if (moreThanOne) System.out.printf("Processing '%s'\n", file.getAbsolutePath());
|
||||
// System.out.println(new ClassFileMetaData(PostCompilerApp.readFile(file)).poolContent());
|
||||
// }
|
||||
//
|
||||
// if (moreThanOne) System.out.printf("Total files visited: %d\n", filesVisited);
|
||||
|
||||
return filesVisited == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
private void printConfiguration(PrintStream out, boolean verbose) {
|
||||
for (ConfigurationKey<?> key : ConfigurationKey.registeredKeys()) {
|
||||
String keyName = key.getKeyName();
|
||||
ConfigurationDataType type = key.getType();
|
||||
if (!verbose) {
|
||||
out.printf("# %s (%s)\n", keyName, type);
|
||||
continue;
|
||||
}
|
||||
out.printf("### Key %s type %s\n", keyName, type);
|
||||
out.printf("#clear %s\n", keyName);
|
||||
if (type.isList()) {
|
||||
out.printf("#%s += %s\n", keyName, exampleValue(type));
|
||||
out.printf("#%s -= %s\n", keyName, exampleValue(type));
|
||||
} else {
|
||||
out.printf("#%s = %s\n", keyName, exampleValue(type));
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
private String exampleValue(ConfigurationDataType type) {
|
||||
return type.getParser().exampleValue();
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ package lombok.core.configuration;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -38,6 +39,9 @@ public final class ConfigurationDataType {
|
||||
@Override public String description() {
|
||||
return "String";
|
||||
}
|
||||
@Override public String exampleValue() {
|
||||
return "<text>";
|
||||
}
|
||||
});
|
||||
map.put(Integer.class, new ConfigurationValueParser() {
|
||||
@Override public Object parse(String value) {
|
||||
@@ -46,6 +50,9 @@ public final class ConfigurationDataType {
|
||||
@Override public String description() {
|
||||
return "Integer";
|
||||
}
|
||||
@Override public String exampleValue() {
|
||||
return "<int>";
|
||||
}
|
||||
});
|
||||
map.put(Long.class, new ConfigurationValueParser() {
|
||||
@Override public Object parse(String value) {
|
||||
@@ -54,6 +61,9 @@ public final class ConfigurationDataType {
|
||||
@Override public String description() {
|
||||
return "Long";
|
||||
}
|
||||
@Override public String exampleValue() {
|
||||
return "<long>";
|
||||
}
|
||||
});
|
||||
map.put(Double.class, new ConfigurationValueParser() {
|
||||
@Override public Object parse(String value) {
|
||||
@@ -62,6 +72,9 @@ public final class ConfigurationDataType {
|
||||
@Override public String description() {
|
||||
return "Double";
|
||||
}
|
||||
@Override public String exampleValue() {
|
||||
return "<double>";
|
||||
}
|
||||
});
|
||||
map.put(Boolean.class, new ConfigurationValueParser() {
|
||||
@Override public Object parse(String value) {
|
||||
@@ -70,6 +83,9 @@ public final class ConfigurationDataType {
|
||||
@Override public String description() {
|
||||
return "Boolean";
|
||||
}
|
||||
@Override public String exampleValue() {
|
||||
return "[false | true]";
|
||||
}
|
||||
});
|
||||
map.put(TypeName.class, new ConfigurationValueParser() {
|
||||
@Override public Object parse(String value) {
|
||||
@@ -78,6 +94,9 @@ public final class ConfigurationDataType {
|
||||
@Override public String description() {
|
||||
return "TypeName";
|
||||
}
|
||||
@Override public String exampleValue() {
|
||||
return "<fully.qualified.Type>";
|
||||
}
|
||||
});
|
||||
SIMPLE_TYPES = map;
|
||||
}
|
||||
@@ -96,6 +115,9 @@ public final class ConfigurationDataType {
|
||||
@Override public String description() {
|
||||
return rawType.getName();
|
||||
}
|
||||
@Override public String exampleValue() {
|
||||
return Arrays.toString(rawType.getEnumConstants()).replace(",", " |");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -24,4 +24,5 @@ package lombok.core.configuration;
|
||||
interface ConfigurationValueParser {
|
||||
Object parse(String value);
|
||||
String description();
|
||||
String exampleValue();
|
||||
}
|
||||
Reference in new issue
Block a user