use of com.googlecode.jslint4java.Option in project jslint4java by happygiraffe.
the class JSLintTask method setOptions.
/**
* Set the options for running JSLint. This is a comma separated list of
* {@link Option} names. The names are case-insensitive.
*
* <p>
* NB: If you want to put an {@link Option#PREDEF} in here, you should use a
* {@code <predef>} child element instead. Otherwise, it could be difficult
* to specify a comma separated list as an element of a comma separated
* list…
*/
public void setOptions(String optionList) throws BuildException {
for (String name : optionList.split("\\s*,\\s*")) {
String[] parts = name.split("=", 2);
String optName = parts[0];
try {
// The Option constants are upper case…
Option o = Option.valueOf(optName.toUpperCase(Locale.getDefault()));
// If an argument has been specified, use it.
String value = parts.length == 2 ? parts[1] : null;
options.put(o, value);
} catch (IllegalArgumentException e) {
throw new BuildException("Unknown option " + optName);
}
}
}
use of com.googlecode.jslint4java.Option in project jslint4java by happygiraffe.
the class Main method processOptions.
private List<String> processOptions(String[] args) {
JSLintFlags jslintFlags = new JSLintFlags();
Flags flags = new Flags();
JCommander jc = new JCommander(new Object[] { flags, jslintFlags });
jc.setProgramName(FULL_PROGRAM_NAME);
try {
jc.parse(args);
} catch (ParameterException e) {
info(e.getMessage());
usage(jc);
}
if (flags.version) {
version();
}
if (flags.help) {
usage(jc);
}
if (flags.encoding != null) {
encoding = flags.encoding;
}
lint = makeLint(flags);
setResultFormatter(flags.report);
for (ParameterDescription pd : jc.getParameters()) {
Parameterized p = pd.getParameterized();
// Is it declared on JSLintFlags?
if (!pd.getObject().getClass().isAssignableFrom(JSLintFlags.class)) {
continue;
}
try {
// Need to get Option.
Option o = getOption(p.getName());
// Need to get value.
Object val = p.get(jslintFlags);
if (val == null) {
continue;
}
Class<?> type = p.getType();
if (type.isAssignableFrom(Boolean.class)) {
lint.addOption(o);
} else // In theory, everything else should be a String for later parsing.
if (type.isAssignableFrom(String.class)) {
lint.addOption(o, (String) val);
} else {
die("unknown type \"" + type + "\" (for " + p.getName() + ")");
}
} catch (IllegalArgumentException e) {
die(e.getMessage());
}
}
if (flags.files.isEmpty()) {
usage(jc);
// can never happen
return null;
} else {
return flags.files;
}
}
use of com.googlecode.jslint4java.Option in project jslint4java by happygiraffe.
the class JSLintMojo method applyOptions.
private void applyOptions(JSLint jsLint) throws MojoExecutionException {
for (Entry<String, String> entry : options.entrySet()) {
if (entry.getValue() == null || entry.getValue().equals("")) {
continue;
}
Option option;
try {
option = Option.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
throw new MojoExecutionException("unknown option: " + entry.getKey());
}
jsLint.addOption(option, entry.getValue());
}
}
Aggregations