Skip to content

Commit

Permalink
Cleaned up API to match bld operations and options APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Aug 27, 2024
1 parent e63c1a6 commit 2b6b4a5
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 52 deletions.
9 changes: 4 additions & 5 deletions src/bld/java/rife/bld/extension/PmdOperationBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PmdOperationBuild extends Project {
public PmdOperationBuild() {
pkg = "rife.bld.extension";
name = "bld-pmd";
version = version(1, 1, 4);
version = version(1, 1, 5, "SNAPSHOT");

javaRelease = 17;

Expand All @@ -44,11 +44,10 @@ public PmdOperationBuild() {
.include(dependency("com.uwyn.rife2", "bld", version(2, 0, 1)))
.include(dependency("net.sourceforge.pmd", "pmd-java", pmd));
scope(runtime)
.include(dependency("net.sourceforge.pmd", "pmd-java", pmd))
.include(dependency("org.slf4j", "slf4j-simple", version(2, 0, 13)));
.include(dependency("org.slf4j", "slf4j-simple", version(2, 0, 16)));
scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 0)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 0)))
.include(dependency("org.assertj", "assertj-core", version(3, 26, 3)));

javadocOperation()
Expand Down
143 changes: 107 additions & 36 deletions src/main/java/rife/bld/extension/PmdOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* @see #inputPaths(Path...)
*/
public PmdOperation addInputPaths(Path... inputPath) {
inputPaths_.addAll(List.of(inputPath));
return this;
return inputPaths(List.of(inputPath));
}

/**
Expand All @@ -154,20 +153,18 @@ public PmdOperation addInputPaths(Path... inputPath) {
* @see #inputPaths(File...)
*/
public PmdOperation addInputPaths(File... inputPath) {
inputPaths_.addAll(Arrays.stream(inputPath).map(File::toPath).toList());
return this;
return addInputPathsFiles(List.of(inputPath));
}

/**
* Adds paths to source files, or directories containing source files to analyze.
*
* @param inputPath one or more paths
* @return this operation
* @see #addInputPaths(String...)
* @see #inputPaths(String...)
*/
public PmdOperation addInputPaths(String... inputPath) {
inputPaths_.addAll(Arrays.stream(inputPath).map(Paths::get).toList());
return this;
return addInputPathsStrings(List.of(inputPath));
}

/**
Expand All @@ -182,6 +179,28 @@ public PmdOperation addInputPaths(Collection<Path> inputPath) {
return this;
}

/**
* Adds paths to source files, or directories containing source files to analyze.
*
* @param inputPath a collection of input paths
* @return this operation
* @see #inputPathsFiles(Collection)
*/
public PmdOperation addInputPathsFiles(Collection<File> inputPath) {
return addInputPaths(inputPath.stream().map(File::toPath).toList());
}

/**
* Adds paths to source files, or directories containing source files to analyze.
*
* @param inputPath a collection of input paths
* @return this operation
* @see #inputPathsStrings(Collection)
*/
public PmdOperation addInputPathsStrings(Collection<String> inputPath) {
return addInputPaths(inputPath.stream().map(Paths::get).toList());
}

/**
* Adds new rule set paths.
* <p>
Expand All @@ -203,8 +222,7 @@ public PmdOperation addInputPaths(Collection<Path> inputPath) {
* @see #ruleSets(String...)
*/
public PmdOperation addRuleSet(String... ruleSet) {
ruleSets_.addAll(List.of(ruleSet));
return this;
return addRuleSet(List.of(ruleSet));
}

/**
Expand All @@ -225,7 +243,7 @@ public PmdOperation addRuleSet(String... ruleSet) {
*
* @param ruleSet a collection of rule set paths
* @return this operation
* @see #ruleSets(Collection
* @see #ruleSets(Collection)
*/
public PmdOperation addRuleSet(Collection<String> ruleSet) {
ruleSets_.addAll(ruleSet);
Expand All @@ -240,15 +258,29 @@ public PmdOperation cache(Path cache) {
return this;
}

/**
* Sets the location of the cache file for incremental analysis.
*/
public PmdOperation cache(File cache) {
return cache(cache.toPath());
}

/**
* Sets the location of the cache file for incremental analysis.
*/
public PmdOperation cache(String cache) {
return cache(Path.of(cache));
}


/**
* Sets the default language version to be used for all input files.
*
* @param languageVersion one or more language version
* @return this operation
*/
public PmdOperation defaultLanguageVersions(LanguageVersion... languageVersion) {
languageVersions_.addAll(List.of(languageVersion));
return this;
return languageVersions(List.of(languageVersion));
}

/**
Expand All @@ -268,8 +300,7 @@ public PmdOperation defaultLanguageVersions(Collection<LanguageVersion> language
* <p>The valid values are the standard character sets of {@link java.nio.charset.Charset Charset}.</p>
*/
public PmdOperation encoding(String encoding) {
encoding_ = Charset.forName(encoding);
return this;
return encoding(Charset.forName(encoding));
}

/**
Expand Down Expand Up @@ -385,8 +416,7 @@ public PmdOperation ignoreFile(Path ignoreFile) {
* @return this operation
*/
public PmdOperation ignoreFile(File ignoreFile) {
ignoreFile_ = ignoreFile.toPath();
return this;
return ignoreFile(ignoreFile.toPath());
}

/**
Expand All @@ -396,8 +426,7 @@ public PmdOperation ignoreFile(File ignoreFile) {
* @return this operation
*/
public PmdOperation ignoreFile(String ignoreFile) {
ignoreFile_ = Paths.get(ignoreFile);
return this;
return ignoreFile(Path.of(ignoreFile));
}

/**
Expand Down Expand Up @@ -495,9 +524,7 @@ public PMDConfiguration initConfiguration(String commandName) {
* @see #addInputPaths(Path...)
*/
public PmdOperation inputPaths(Path... inputPath) {
inputPaths_.clear();
inputPaths_.addAll(List.of(inputPath));
return this;
return inputPaths(List.of(inputPath));
}

/**
Expand All @@ -510,9 +537,7 @@ public PmdOperation inputPaths(Path... inputPath) {
* @see #addInputPaths(File...)
*/
public PmdOperation inputPaths(File... inputPath) {
inputPaths_.clear();
inputPaths_.addAll(Arrays.stream(inputPath).map(File::toPath).toList());
return this;
return inputPathsFiles(List.of(inputPath));
}

/**
Expand All @@ -525,9 +550,7 @@ public PmdOperation inputPaths(File... inputPath) {
* @see #addInputPaths(String...)
*/
public PmdOperation inputPaths(String... inputPath) {
inputPaths_.clear();
inputPaths_.addAll(Arrays.stream(inputPath).map(Paths::get).toList());
return this;
return inputPathsStrings(List.of(inputPath));
}

/**
Expand All @@ -537,7 +560,7 @@ public PmdOperation inputPaths(String... inputPath) {
*
* @param inputPath a collection of input paths
* @return this operation
* @see #addInputPaths(Collection)
* @see #addInputPaths(Path...)
*/
public PmdOperation inputPaths(Collection<Path> inputPath) {
inputPaths_.clear();
Expand All @@ -554,15 +577,40 @@ public Collection<Path> inputPaths() {
return inputPaths_;
}

/**
* Sets paths to source files, or directories containing source files to analyze.
* <p>
* Previous entries are disregarded.
*
* @param inputPath a collection of input paths
* @return this operation
* @see #addInputPaths(File...)
*/
public PmdOperation inputPathsFiles(Collection<File> inputPath) {
return inputPaths(inputPath.stream().map(File::toPath).toList());
}

/**
* Sets paths to source files, or directories containing source files to analyze.
* <p>
* Previous entries are disregarded.
*
* @param inputPath a collection of input paths
* @return this operation
* @see #addInputPaths(String...)
*/
public PmdOperation inputPathsStrings(Collection<String> inputPath) {
return inputPaths(inputPath.stream().map(Paths::get).toList());
}

/**
* Sets the default language versions.
*
* @param languageVersion one or more language versions
* @return this operation
*/
public PmdOperation languageVersions(LanguageVersion... languageVersion) {
languageVersions_.addAll(List.of(languageVersion));
return this;
return languageVersions(List.of(languageVersion));
}

/**
Expand Down Expand Up @@ -667,39 +715,40 @@ public int performPmdAnalysis(String commandName, PMDConfiguration config) throw
*
* @param relativeRoot one or more relative root paths
* @return this operations
* @see #relativizeRoots(Collection)
*/
public PmdOperation relativizeRoots(Path... relativeRoot) {
relativizeRoots_.addAll(List.of(relativeRoot));
return this;
return relativizeRoots(List.of(relativeRoot));
}

/**
* Adds several paths to shorten paths that are output in the report.
*
* @param relativeRoot one or more relative root paths
* @return this operations
* @see #relativizeRootsFiles(Collection)
*/
public PmdOperation relativizeRoots(File... relativeRoot) {
relativizeRoots_.addAll(Arrays.stream(relativeRoot).map(File::toPath).toList());
return this;
return relativizeRootsFiles(List.of(relativeRoot));
}

/**
* Adds several paths to shorten paths that are output in the report.
*
* @param relativeRoot one or more relative root paths
* @return this operations
* @see #relativizeRootsStrings(Collection)
*/
public PmdOperation relativizeRoots(String... relativeRoot) {
relativizeRoots_.addAll(Arrays.stream(relativeRoot).map(Paths::get).toList());
return this;
return relativizeRootsStrings(List.of(relativeRoot));
}

/**
* Adds several paths to shorten paths that are output in the report.
*
* @param relativeRoot a collection of relative root paths
* @return this operations
* @see #relativizeRoots(Path...)
*/
public PmdOperation relativizeRoots(Collection<Path> relativeRoot) {
relativizeRoots_.addAll(relativeRoot);
Expand All @@ -715,6 +764,28 @@ public Collection<Path> relativizeRoots() {
return relativizeRoots_;
}

/**
* Adds several paths to shorten paths that are output in the report.
*
* @param relativeRoot a collection of relative root paths
* @return this operations
* @see #relativizeRoots(File...)
*/
public PmdOperation relativizeRootsFiles(Collection<File> relativeRoot) {
return relativizeRoots(relativeRoot.stream().map(File::toPath).toList());
}

/**
* Adds several paths to shorten paths that are output in the report.
*
* @param relativeRoot a collection of relative root paths
* @return this operations
* @see #relativizeRoots(String...)
*/
public PmdOperation relativizeRootsStrings(Collection<String> relativeRoot) {
return relativizeRoots(relativeRoot.stream().map(Paths::get).toList());
}

/**
* Sets the path to the report page.
*
Expand Down
Loading

0 comments on commit 2b6b4a5

Please sign in to comment.