Minor cleanups

This commit is contained in:
Erik C. Thauvin 2024-08-30 12:12:39 -07:00
parent c93c9ea2d0
commit 0a2a2f4b03
Signed by: erik
GPG key ID: 776702A6A2DA330E
2 changed files with 38 additions and 27 deletions

View file

@ -93,7 +93,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @return the checkstyle operation
*/
public CheckstyleOperation configurationFile(Path file) {
return configurationFile(file.toFile());
return configurationFile(file.toFile().getAbsolutePath());
}
/**
@ -117,7 +117,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
*
* @param path one or more paths
* @return the checkstyle operation
* @see #sourceDir(Collection)
* @see #excludeStrings(Collection)
*/
public CheckstyleOperation exclude(String... path) {
return excludeStrings(List.of(path));
@ -129,7 +129,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
*
* @param path one or more paths
* @return the checkstyle operation
* @see #sourceDir(Collection)
* @see #exclude(Collection)
*/
public CheckstyleOperation exclude(File... path) {
return exclude(List.of(path));
@ -141,7 +141,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
*
* @param path one or more paths
* @return the checkstyle operation
* @see #sourceDir(Collection)
* @see #excludePaths(Collection)
*/
public CheckstyleOperation exclude(Path... path) {
return excludePaths(List.of(path));
@ -153,7 +153,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
*
* @param paths the paths
* @return the checkstyle operation
* @see #exclude(String...)
* @see #exclude(File...)
*/
public CheckstyleOperation exclude(Collection<File> paths) {
exclude_.addAll(paths);
@ -166,7 +166,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
*
* @param paths the paths
* @return the checkstyle operation
* @see #exclude(String...)
* @see #exclude(Path...)
*/
public CheckstyleOperation excludePaths(Collection<Path> paths) {
return exclude(paths.stream().map(Path::toFile).toList());
@ -180,8 +180,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @see #excludeRegex(Collection)
*/
public CheckstyleOperation excludeRegex(String... regex) {
excludeRegex_.addAll(List.of(regex));
return this;
return excludeRegex(List.of(regex));
}
/**
@ -205,8 +204,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @see #exclude(String...)
*/
public CheckstyleOperation excludeStrings(Collection<String> paths) {
exclude_.addAll(paths.stream().map(File::new).toList());
return this;
return exclude(paths.stream().map(File::new).toList());
}
@Override
@ -401,7 +399,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @return the checkstyle operation
*/
public CheckstyleOperation outputPath(Path file) {
return outputPath(file.toFile());
return outputPath(file.toFile().getAbsolutePath());
}
/**
@ -434,7 +432,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @return the checkstyle operation
*/
public CheckstyleOperation propertiesFile(Path file) {
return propertiesFile(file.toFile());
return propertiesFile(file.toFile().getAbsolutePath());
}
/**
@ -510,8 +508,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @see #sourceDir(String...)
*/
public CheckstyleOperation sourceDirStrings(Collection<String> dirs) {
sourceDir_.addAll(dirs.stream().map(File::new).toList());
return this;
return sourceDir(dirs.stream().map(File::new).toList());
}
/**

View file

@ -120,21 +120,30 @@ class CheckstyleOperationTest {
void exclude() {
var foo = new File(SRC_MAIN_JAVA);
var bar = new File(SRC_TEST_JAVA);
var op = new CheckstyleOperation().fromProject(new Project()).exclude(SRC_MAIN_JAVA, SRC_TEST_JAVA);
var e = "-e ";
assertThat(op.executeConstructProcessCommandList()).as("strings")
var op = new CheckstyleOperation().fromProject(new Project()).exclude(SRC_MAIN_JAVA, SRC_TEST_JAVA);
assertThat(op.executeConstructProcessCommandList()).as("String...")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
op = new CheckstyleOperation().fromProject(new Project()).excludeStrings(List.of(SRC_MAIN_JAVA, SRC_TEST_JAVA));
assertThat(op.executeConstructProcessCommandList()).as("List(String...)")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
op = new CheckstyleOperation().fromProject(new Project()).exclude(foo, bar);
assertThat(op.executeConstructProcessCommandList()).as("files")
assertThat(op.executeConstructProcessCommandList()).as("File...")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(foo, bar));
assertThat(op.executeConstructProcessCommandList()).as("list")
assertThat(op.executeConstructProcessCommandList()).as("List(File...)")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
op = new CheckstyleOperation().fromProject(new Project()).exclude(foo.toPath(), bar.toPath());
assertThat(op.executeConstructProcessCommandList()).as("list")
assertThat(op.executeConstructProcessCommandList()).as("Path...")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
op = new CheckstyleOperation().fromProject(new Project()).excludePaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.executeConstructProcessCommandList()).as("List(Path...)")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
}
@ -252,24 +261,29 @@ class CheckstyleOperationTest {
var foo = new File(FOO);
var bar = new File(BAR);
var op = new CheckstyleOperation().fromProject(new Project()).sourceDir(FOO);
assertThat(op.sourceDir()).contains(foo);
var op = new CheckstyleOperation().fromProject(new Project()).sourceDir(FOO, BAR);
assertThat(op.sourceDir()).as("String...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
op = op.sourceDirStrings(List.of(FOO, BAR));
assertThat(op.sourceDir()).as("List(String...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
op = op.sourceDir(foo, bar);
assertThat(op.sourceDir()).as("foo, bar").hasSize(2)
.contains(foo).contains(bar);
assertThat(op.sourceDir()).as("File...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
op = op.sourceDir(List.of(foo, bar));
assertThat(op.sourceDir()).as("List.of(foo, bar)").hasSize(2)
.contains(foo).contains(bar);
assertThat(op.sourceDir()).as("List(File...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
op = op.sourceDir(foo.toPath(), bar.toPath());
assertThat(op.sourceDir()).as("foo.toPath(), bar.toPath()").hasSize(2)
.contains(foo).contains(bar);
assertThat(op.sourceDir()).as("Path...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
op = op.sourceDirPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.sourceDir()).as("List(Path...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
}