Combined options and optionsWithArgs
This commit is contained in:
parent
7efca76693
commit
948e06c6db
2 changed files with 50 additions and 50 deletions
|
@ -35,11 +35,8 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
/**
|
/**
|
||||||
* The command line options.
|
* The command line options.
|
||||||
*/
|
*/
|
||||||
protected final List<String> options = new ArrayList<>();
|
protected final Map<String, String> options = new ConcurrentHashMap<>();
|
||||||
/**
|
|
||||||
* The command line options with arguments.
|
|
||||||
*/
|
|
||||||
protected final Map<String, String> optionsWithArg = new ConcurrentHashMap<>();
|
|
||||||
/**
|
/**
|
||||||
* The source files(s) or folder(s).
|
* The source files(s) or folder(s).
|
||||||
*/
|
*/
|
||||||
|
@ -50,7 +47,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* Shows Abstract Syntax Tree(AST) branches that match given XPath query.
|
* Shows Abstract Syntax Tree(AST) branches that match given XPath query.
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation branchMatchingXpath(String xPathQuery) {
|
public CheckstyleOperation branchMatchingXpath(String xPathQuery) {
|
||||||
optionsWithArg.put("-b", xPathQuery);
|
options.put("-b", xPathQuery);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +57,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* method. A configuration file is required.
|
* method. A configuration file is required.
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation configurationFile(String file) {
|
public CheckstyleOperation configurationFile(String file) {
|
||||||
optionsWithArg.put("-c", file);
|
options.put("-c", file);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +66,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation debug(boolean isDebug) {
|
public CheckstyleOperation debug(boolean isDebug) {
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
options.add("-d");
|
options.put("-d", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-d");
|
options.remove("-d");
|
||||||
}
|
}
|
||||||
|
@ -84,7 +81,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation exclude(String... path) {
|
public CheckstyleOperation exclude(String... path) {
|
||||||
for (var p : path) {
|
for (var p : path) {
|
||||||
optionsWithArg.put("-e", p);
|
options.put("-e", p);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +94,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation exclude(Collection<String> path) {
|
public CheckstyleOperation exclude(Collection<String> path) {
|
||||||
for (var p : path) {
|
for (var p : path) {
|
||||||
optionsWithArg.put("-e", p);
|
options.put("-e", p);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +103,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* Directory/file pattern to exclude from CheckStyle. Multiple excludes are allowed.
|
* Directory/file pattern to exclude from CheckStyle. Multiple excludes are allowed.
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation excludedPathPattern(String pattern) {
|
public CheckstyleOperation excludedPathPattern(String pattern) {
|
||||||
optionsWithArg.put("-x", pattern);
|
options.put("-x", pattern);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,15 +124,18 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
|
|
||||||
final List<String> args = new ArrayList<>();
|
final List<String> args = new ArrayList<>();
|
||||||
args.add(javaTool());
|
args.add(javaTool());
|
||||||
|
|
||||||
args.add("-cp");
|
args.add("-cp");
|
||||||
args.add(String.format("%s:%s:%s:%s", Path.of(project_.libTestDirectory().getPath(), "*"),
|
args.add(String.format("%s:%s:%s:%s", Path.of(project_.libTestDirectory().getPath(), "*"),
|
||||||
Path.of(project_.libCompileDirectory().getPath(), "*"), project_.buildMainDirectory(),
|
Path.of(project_.libCompileDirectory().getPath(), "*"), project_.buildMainDirectory(),
|
||||||
project_.buildTestDirectory()));
|
project_.buildTestDirectory()));
|
||||||
args.add("com.puppycrawl.tools.checkstyle.Main");
|
args.add("com.puppycrawl.tools.checkstyle.Main");
|
||||||
args.addAll(options);
|
|
||||||
optionsWithArg.forEach((k, v) -> {
|
options.forEach((k, v) -> {
|
||||||
args.add(k);
|
args.add(k);
|
||||||
args.add(v);
|
if (!v.isEmpty()) {
|
||||||
|
args.add(v);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
args.addAll(sourceDirs);
|
args.addAll(sourceDirs);
|
||||||
|
@ -157,7 +157,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation executeIgnoredModules(boolean isAllowIgnoreModules) {
|
public CheckstyleOperation executeIgnoredModules(boolean isAllowIgnoreModules) {
|
||||||
if (isAllowIgnoreModules) {
|
if (isAllowIgnoreModules) {
|
||||||
options.add("-E");
|
options.put("-E", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-E");
|
options.remove("-E");
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* default logger respectively. Defaults to {@code plain}.
|
* default logger respectively. Defaults to {@code plain}.
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation format(String format) {
|
public CheckstyleOperation format(String format) {
|
||||||
optionsWithArg.put("-f", format);
|
options.put("-f", format);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation generateXpathSuppression(boolean xPathSuppression) {
|
public CheckstyleOperation generateXpathSuppression(boolean xPathSuppression) {
|
||||||
if (xPathSuppression) {
|
if (xPathSuppression) {
|
||||||
options.add("-g");
|
options.put("-g", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-g");
|
options.remove("-g");
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation javadocTree(boolean isTree) {
|
public CheckstyleOperation javadocTree(boolean isTree) {
|
||||||
if (isTree) {
|
if (isTree) {
|
||||||
options.add("-j");
|
options.put("-j", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-j");
|
options.remove("-j");
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* ok, but might result in undesirable matching and suppress other issues.
|
* ok, but might result in undesirable matching and suppress other issues.
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation lineColumn(String lineColumn) {
|
public CheckstyleOperation lineColumn(String lineColumn) {
|
||||||
optionsWithArg.put("-s", lineColumn);
|
options.put("-s", lineColumn);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* Sets the output file. Defaults to stdout.
|
* Sets the output file. Defaults to stdout.
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation output(String file) {
|
public CheckstyleOperation output(String file) {
|
||||||
optionsWithArg.put("-o", file);
|
options.put("-o", file);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* Sets the property files to load.
|
* Sets the property files to load.
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation propertiesFile(String file) {
|
public CheckstyleOperation propertiesFile(String file) {
|
||||||
optionsWithArg.put("-p", file);
|
options.put("-p", file);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* Default value is {@code 8}.
|
* Default value is {@code 8}.
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation tabWith(int length) {
|
public CheckstyleOperation tabWith(int length) {
|
||||||
optionsWithArg.put("-w", String.valueOf(length));
|
options.put("-w", String.valueOf(length));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation tree(boolean isTree) {
|
public CheckstyleOperation tree(boolean isTree) {
|
||||||
if (isTree) {
|
if (isTree) {
|
||||||
options.add("-t");
|
options.put("-t", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-t");
|
options.remove("-t");
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation treeWithComments(boolean isTree) {
|
public CheckstyleOperation treeWithComments(boolean isTree) {
|
||||||
if (isTree) {
|
if (isTree) {
|
||||||
options.add("-T");
|
options.put("-T", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-T");
|
options.remove("-T");
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation treeWithJavadoc(boolean isTree) {
|
public CheckstyleOperation treeWithJavadoc(boolean isTree) {
|
||||||
if (isTree) {
|
if (isTree) {
|
||||||
options.add("-J");
|
options.put("-J", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-J");
|
options.remove("-J");
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,35 +39,35 @@ class CheckstyleOperationTest {
|
||||||
@Test
|
@Test
|
||||||
void branchMatchingXpath() {
|
void branchMatchingXpath() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).branchMatchingXpath(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).branchMatchingXpath(FOO);
|
||||||
assertThat(op.optionsWithArg.get("-b")).isEqualTo(FOO);
|
assertThat(op.options.get("-b")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void configurationFile() {
|
void configurationFile() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).configurationFile(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).configurationFile(FOO);
|
||||||
assertThat(op.optionsWithArg.get("-c")).isEqualTo(FOO);
|
assertThat(op.options.get("-c")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void debug() {
|
void debug() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).debug(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).debug(true);
|
||||||
assertThat(op.options.contains("-d")).as(ADD).isTrue();
|
assertThat(op.options.containsKey("-d")).as(ADD).isTrue();
|
||||||
op = op.debug(false);
|
op = op.debug(false);
|
||||||
assertThat(op.options.contains("-d")).as(REMOVE).isFalse();
|
assertThat(op.options.containsKey("-d")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void exclude() {
|
void exclude() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).exclude(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).exclude(FOO);
|
||||||
assertThat(op.optionsWithArg.get("-e")).isEqualTo(FOO);
|
assertThat(op.options.get("-e")).isEqualTo(FOO);
|
||||||
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(FOO));
|
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(FOO));
|
||||||
assertThat(op.optionsWithArg.get("-e")).as("as list").isEqualTo(FOO);
|
assertThat(op.options.get("-e")).as("as list").isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void excludedPathPattern() {
|
void excludedPathPattern() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).excludedPathPattern(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).excludedPathPattern(FOO);
|
||||||
assertThat(op.optionsWithArg.get("-x")).isEqualTo(FOO);
|
assertThat(op.options.get("-x")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -96,19 +96,19 @@ class CheckstyleOperationTest {
|
||||||
.startsWith("java -cp ")
|
.startsWith("java -cp ")
|
||||||
.endsWith(
|
.endsWith(
|
||||||
"com.puppycrawl.tools.checkstyle.Main " +
|
"com.puppycrawl.tools.checkstyle.Main " +
|
||||||
"-d -E " +
|
|
||||||
"-p config/checkstyle.properties " +
|
"-p config/checkstyle.properties " +
|
||||||
"-b xpath " +
|
"-b xpath " +
|
||||||
"-c config/checkstyle.xml " +
|
"-c config/checkstyle.xml " +
|
||||||
|
"-d -E " +
|
||||||
"src/main/java src/test/java");
|
"src/main/java src/test/java");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void executeIgnoredModules() {
|
void executeIgnoredModules() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).executeIgnoredModules(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).executeIgnoredModules(true);
|
||||||
assertThat(op.options.contains("-E")).as(ADD).isTrue();
|
assertThat(op.options.containsKey("-E")).as(ADD).isTrue();
|
||||||
op = op.executeIgnoredModules(false);
|
op = op.executeIgnoredModules(false);
|
||||||
assertThat(op.options.contains("-E")).as(REMOVE).isFalse();
|
assertThat(op.options.containsKey("-E")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -127,41 +127,41 @@ class CheckstyleOperationTest {
|
||||||
@Test
|
@Test
|
||||||
void format() {
|
void format() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).format(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).format(FOO);
|
||||||
assertThat(op.optionsWithArg.get("-f")).isEqualTo(FOO);
|
assertThat(op.options.get("-f")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void generateXpathSuppression() {
|
void generateXpathSuppression() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).generateXpathSuppression(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).generateXpathSuppression(true);
|
||||||
assertThat(op.options.contains("-g")).as(ADD).isTrue();
|
assertThat(op.options.containsKey("-g")).as(ADD).isTrue();
|
||||||
op = op.generateXpathSuppression(false);
|
op = op.generateXpathSuppression(false);
|
||||||
assertThat(op.options.contains("-g")).as(REMOVE).isFalse();
|
assertThat(op.options.containsKey("-g")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void javadocTree() {
|
void javadocTree() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).javadocTree(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).javadocTree(true);
|
||||||
assertThat(op.options.contains("-j")).as(ADD).isTrue();
|
assertThat(op.options.containsKey("-j")).as(ADD).isTrue();
|
||||||
op = op.javadocTree(false);
|
op = op.javadocTree(false);
|
||||||
assertThat(op.options.contains("-j")).as(REMOVE).isFalse();
|
assertThat(op.options.containsKey("-j")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void lineColumn() {
|
void lineColumn() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).lineColumn(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).lineColumn(FOO);
|
||||||
assertThat(op.optionsWithArg.get("-s")).isEqualTo(FOO);
|
assertThat(op.options.get("-s")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void output() {
|
void output() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).output(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).output(FOO);
|
||||||
assertThat(op.optionsWithArg.get("-o")).isEqualTo(FOO);
|
assertThat(op.options.get("-o")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void propertiesFile() {
|
void propertiesFile() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).propertiesFile(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).propertiesFile(FOO);
|
||||||
assertThat(op.optionsWithArg.get("-p")).isEqualTo(FOO);
|
assertThat(op.options.get("-p")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -175,30 +175,30 @@ class CheckstyleOperationTest {
|
||||||
@Test
|
@Test
|
||||||
void tabWith() {
|
void tabWith() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).tabWith(9);
|
var op = new CheckstyleOperation().fromProject(new Project()).tabWith(9);
|
||||||
assertThat(op.optionsWithArg.get("-w")).isEqualTo("9");
|
assertThat(op.options.get("-w")).isEqualTo("9");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void tree() {
|
void tree() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).tree(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).tree(true);
|
||||||
assertThat(op.options.contains("-t")).as(ADD).isTrue();
|
assertThat(op.options.containsKey("-t")).as(ADD).isTrue();
|
||||||
op = op.tree(false);
|
op = op.tree(false);
|
||||||
assertThat(op.options.contains("-t")).as(REMOVE).isFalse();
|
assertThat(op.options.containsKey("-t")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void treeWithComments() {
|
void treeWithComments() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).treeWithComments(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).treeWithComments(true);
|
||||||
assertThat(op.options.contains("-T")).as(ADD).isTrue();
|
assertThat(op.options.containsKey("-T")).as(ADD).isTrue();
|
||||||
op = op.treeWithComments(false);
|
op = op.treeWithComments(false);
|
||||||
assertThat(op.options.contains("-T")).as(REMOVE).isFalse();
|
assertThat(op.options.containsKey("-T")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void treeWithJavadoc() {
|
void treeWithJavadoc() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).treeWithJavadoc(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).treeWithJavadoc(true);
|
||||||
assertThat(op.options.contains("-J")).as(ADD).isTrue();
|
assertThat(op.options.containsKey("-J")).as(ADD).isTrue();
|
||||||
op = op.treeWithJavadoc(false);
|
op = op.treeWithJavadoc(false);
|
||||||
assertThat(op.options.contains("-J")).as(REMOVE).isFalse();
|
assertThat(op.options.containsKey("-J")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue