Compare commits

..

No commits in common. "25bce33323f205f7ab6030ca1931f995c9f4f0b5" and "28f9d29d9af396244167c0ee08913ac02509ead4" have entirely different histories.

4 changed files with 20 additions and 141 deletions

View file

@ -47,11 +47,11 @@ jobs:
uses: actions/configure-pages@v3 uses: actions/configure-pages@v3
- name: Upload artifact - name: Upload artifact
uses: actions/upload-pages-artifact@v3 uses: actions/upload-pages-artifact@v1
with: with:
# Upload generated Javadocs repository # Upload generated Javadocs repository
path: "build/javadoc/" path: "build/javadoc/"
- name: Deploy to GitHub Pages - name: Deploy to GitHub Pages
id: deployment id: deployment
uses: actions/deploy-pages@v4 uses: actions/deploy-pages@v1

View file

@ -31,7 +31,7 @@ public class PmdOperationBuild extends Project {
public PmdOperationBuild() { public PmdOperationBuild() {
pkg = "rife.bld.extension"; pkg = "rife.bld.extension";
name = "bld-pmd"; name = "bld-pmd";
version = version(1, 1, 11); version = version(1, 1, 10);
javaRelease = 17; javaRelease = 17;
@ -40,7 +40,7 @@ public class PmdOperationBuild extends Project {
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS); repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS);
var pmd = version(7, 10, 0); var pmd = version(7, 9, 0);
scope(compile) scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(2, 2, 0))) .include(dependency("com.uwyn.rife2", "bld", version(2, 2, 0)))
.include(dependency("net.sourceforge.pmd", "pmd-java", pmd)); .include(dependency("net.sourceforge.pmd", "pmd-java", pmd));
@ -49,7 +49,7 @@ public class PmdOperationBuild extends Project {
scope(test) scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 4))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 4)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 4))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 4)))
.include(dependency("org.assertj", "assertj-core", version(3, 27, 3))); .include(dependency("org.assertj", "assertj-core", version(3, 27, 2)));
javadocOperation() javadocOperation()
.javadocOptions() .javadocOptions()

View file

@ -49,10 +49,6 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
public static final String RULE_SET_DEFAULT = "rulesets/java/quickstart.xml"; public static final String RULE_SET_DEFAULT = "rulesets/java/quickstart.xml";
private static final Logger LOGGER = Logger.getLogger(PmdOperation.class.getName()); private static final Logger LOGGER = Logger.getLogger(PmdOperation.class.getName());
private static final String PMD_DIR = "pmd"; private static final String PMD_DIR = "pmd";
/**
* The list of paths to exclude.
*/
private final List<Path> excludes_ = new ArrayList<>();
/** /**
* The input paths (source) list. * The input paths (source) list.
*/ */
@ -105,10 +101,6 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* The default language version(s). * The default language version(s).
*/ */
private Collection<LanguageVersion> languageVersions_ = new ArrayList<>(); private Collection<LanguageVersion> languageVersions_ = new ArrayList<>();
/**
* The classpath to prepend.
*/
private String prependClasspath_;
/** /**
* The project reference. * The project reference.
*/ */
@ -280,6 +272,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
return cache(Path.of(cache)); return cache(Path.of(cache));
} }
/** /**
* Sets the default language version to be used for all input files. * Sets the default language version to be used for all input files.
* *
@ -321,37 +314,6 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
return this; return this;
} }
/**
* Adds paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
*/
public PmdOperation excludes(Path... excludes) {
excludes_.addAll(List.of(excludes));
return this;
}
/**
* Adds paths to exclude from the analysis.
*
* @param excludes paths to exclude
* @return this operation
*/
public PmdOperation excludes(Collection<Path> excludes) {
excludes_.addAll(excludes);
return this;
}
/**
* Returns the paths to exclude from the analysis.
*
* @return the exclude paths
*/
public List<Path> excludes() {
return excludes_;
}
/** /**
* Performs the PMD code analysis operation. * Performs the PMD code analysis operation.
*/ */
@ -494,17 +456,8 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* @return this operation * @return this operation
*/ */
public PMDConfiguration initConfiguration(String commandName) { public PMDConfiguration initConfiguration(String commandName) {
var config = new PMDConfiguration(); PMDConfiguration config = new PMDConfiguration();
// addRelativizeRoots
config.addRelativizeRoots(relativizeRoots_.stream().toList());
// prependAuxClasspath
if (prependClasspath_ != null) {
config.prependAuxClasspath(prependClasspath_);
}
// setAnalysisCacheLocation
if (cache_ == null && project_ != null && incrementalAnalysis_) { if (cache_ == null && project_ != null && incrementalAnalysis_) {
config.setAnalysisCacheLocation( config.setAnalysisCacheLocation(
Paths.get(project_.buildDirectory().getPath(), PMD_DIR, PMD_DIR + "-cache").toFile().getAbsolutePath()); Paths.get(project_.buildDirectory().getPath(), PMD_DIR, PMD_DIR + "-cache").toFile().getAbsolutePath());
@ -512,50 +465,38 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
config.setAnalysisCacheLocation(cache_.toFile().getAbsolutePath()); config.setAnalysisCacheLocation(cache_.toFile().getAbsolutePath());
} }
// setDefaultLanguageVersions config.setFailOnError(failOnError_);
config.setFailOnViolation(failOnViolation_);
if (languageVersions_ != null) { if (languageVersions_ != null) {
config.setDefaultLanguageVersions(languageVersions_.stream().toList()); config.setDefaultLanguageVersions(languageVersions_.stream().toList());
} }
// setExcludes
if (!excludes_.isEmpty()) {
config.setExcludes(excludes_);
}
// setFailOnError
config.setFailOnError(failOnError_);
// setFailOnViolation
config.setFailOnViolation(failOnViolation_);
// setForceLanguageVersion
if (forcedLanguageVersion_ != null) { if (forcedLanguageVersion_ != null) {
config.setForceLanguageVersion(forcedLanguageVersion_); config.setForceLanguageVersion(forcedLanguageVersion_);
} }
// setIgnoreFilePath
if (ignoreFile_ != null) { if (ignoreFile_ != null) {
config.setIgnoreFilePath(ignoreFile_); config.setIgnoreFilePath(ignoreFile_);
} }
// setIgnoreIncrementalAnalysis
config.setIgnoreIncrementalAnalysis(!incrementalAnalysis_); config.setIgnoreIncrementalAnalysis(!incrementalAnalysis_);
// setInputPathList
if (inputPaths_.isEmpty()) { if (inputPaths_.isEmpty()) {
throw new IllegalArgumentException(commandName + ": InputPaths required."); throw new IllegalArgumentException(commandName + ": InputPaths required.");
} else { } else {
config.setInputPathList(inputPaths_.stream().toList()); config.setInputPathList(inputPaths_.stream().toList());
} }
if (reportProperties_ != null) {
config.setReportProperties(reportProperties_);
}
// setInputUri
if (inputUri_ != null) { if (inputUri_ != null) {
config.setInputUri(inputUri_); config.setInputUri(inputUri_);
} }
// setMinimumPriority
config.setMinimumPriority(rulePriority_); config.setMinimumPriority(rulePriority_);
// setReportFile
if (project_ != null) { if (project_ != null) {
config.setReportFile(Objects.requireNonNullElseGet(reportFile_, config.setReportFile(Objects.requireNonNullElseGet(reportFile_,
() -> Paths.get(project_.buildDirectory().getPath(), () -> Paths.get(project_.buildDirectory().getPath(),
@ -564,25 +505,12 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
config.setReportFile(reportFile_); config.setReportFile(reportFile_);
} }
// setReportFormat config.addRelativizeRoots(relativizeRoots_.stream().toList());
config.setReportFormat(reportFormat_); config.setReportFormat(reportFormat_);
// setReportProperties
if (reportProperties_ != null) {
config.setReportProperties(reportProperties_);
}
// setRuleSets
config.setRuleSets(ruleSets_.stream().toList()); config.setRuleSets(ruleSets_.stream().toList());
// setShowSuppressedViolations
config.setShowSuppressedViolations(showSuppressed_); config.setShowSuppressedViolations(showSuppressed_);
// setSourceEncoding
config.setSourceEncoding(encoding_); config.setSourceEncoding(encoding_);
// setSuppressMarker
config.setSuppressMarker(suppressedMarker_); config.setSuppressMarker(suppressedMarker_);
// setThreads
config.setThreads(threads_); config.setThreads(threads_);
return config; return config;
@ -782,36 +710,11 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
return numViolations; return numViolations;
} }
/**
* Prepend the specified classpath like string to the current ClassLoader of the configuration. If no ClassLoader
* is currently configured, the ClassLoader used to load the PMDConfiguration class will be used as the parent
* ClassLoader of the created ClassLoader.
* <p>
* If the classpath String looks like a URL to a file (i.e. starts with {@code file://}) the file will be read with
* each line representing an entry on the classpath.
*
* @param classpath one or more classpath
* @return this operation
*/
public PmdOperation prependAuxClasspath(String... classpath) {
prependClasspath_ = String.join(File.pathSeparator, classpath);
return this;
}
/**
* Returns the prepended classpath.
*
* @return the classpath
*/
public String prependAuxClasspath() {
return prependClasspath_;
}
/** /**
* Adds several paths to shorten paths that are output in the report. * Adds several paths to shorten paths that are output in the report.
* *
* @param relativeRoot one or more relative root paths * @param relativeRoot one or more relative root paths
* @return this operation * @return this operations
* @see #relativizeRoots(Collection) * @see #relativizeRoots(Collection)
*/ */
public PmdOperation relativizeRoots(Path... relativeRoot) { public PmdOperation relativizeRoots(Path... relativeRoot) {
@ -822,7 +725,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* Adds several paths to shorten paths that are output in the report. * Adds several paths to shorten paths that are output in the report.
* *
* @param relativeRoot one or more relative root paths * @param relativeRoot one or more relative root paths
* @return this operation * @return this operations
* @see #relativizeRootsFiles(Collection) * @see #relativizeRootsFiles(Collection)
*/ */
public PmdOperation relativizeRoots(File... relativeRoot) { public PmdOperation relativizeRoots(File... relativeRoot) {
@ -833,7 +736,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* Adds several paths to shorten paths that are output in the report. * Adds several paths to shorten paths that are output in the report.
* *
* @param relativeRoot one or more relative root paths * @param relativeRoot one or more relative root paths
* @return this operation * @return this operations
* @see #relativizeRootsStrings(Collection) * @see #relativizeRootsStrings(Collection)
*/ */
public PmdOperation relativizeRoots(String... relativeRoot) { public PmdOperation relativizeRoots(String... relativeRoot) {
@ -844,7 +747,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* Adds several paths to shorten paths that are output in the report. * Adds several paths to shorten paths that are output in the report.
* *
* @param relativeRoot a collection of relative root paths * @param relativeRoot a collection of relative root paths
* @return this operation * @return this operations
* @see #relativizeRoots(Path...) * @see #relativizeRoots(Path...)
*/ */
public PmdOperation relativizeRoots(Collection<Path> relativeRoot) { public PmdOperation relativizeRoots(Collection<Path> relativeRoot) {
@ -865,7 +768,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* Adds several paths to shorten paths that are output in the report. * Adds several paths to shorten paths that are output in the report.
* *
* @param relativeRoot a collection of relative root paths * @param relativeRoot a collection of relative root paths
* @return this operation * @return this operations
* @see #relativizeRoots(File...) * @see #relativizeRoots(File...)
*/ */
public PmdOperation relativizeRootsFiles(Collection<File> relativeRoot) { public PmdOperation relativizeRootsFiles(Collection<File> relativeRoot) {
@ -876,7 +779,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* Adds several paths to shorten paths that are output in the report. * Adds several paths to shorten paths that are output in the report.
* *
* @param relativeRoot a collection of relative root paths * @param relativeRoot a collection of relative root paths
* @return this operation * @return this operations
* @see #relativizeRoots(String...) * @see #relativizeRoots(String...)
*/ */
public PmdOperation relativizeRootsStrings(Collection<String> relativeRoot) { public PmdOperation relativizeRootsStrings(Collection<String> relativeRoot) {

View file

@ -166,24 +166,6 @@ class PmdOperationTest {
assertThat(config.getSourceEncoding()).as("ISO_8859").isEqualTo(StandardCharsets.ISO_8859_1); assertThat(config.getSourceEncoding()).as("ISO_8859").isEqualTo(StandardCharsets.ISO_8859_1);
} }
@Test
void testExcludes() {
var foo = Path.of("foo/bar");
var bar = Path.of("bar/foo");
var foz = Path.of("foz/baz");
var baz = Path.of("baz/foz");
var excludes = List.of(foo, bar);
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludes(excludes);
var config = pmd.initConfiguration(COMMAND_NAME);
assertThat(config.getExcludes()).containsExactly(excludes.toArray(new Path[0]));
pmd = pmd.excludes(baz, foz);
assertThat(pmd.excludes()).hasSize(4);
config = pmd.initConfiguration(COMMAND_NAME);
assertThat(config.getExcludes()).hasSize(4).contains(bar, foz);
}
@Test @Test
void testExecute() throws ExitStatusException { void testExecute() throws ExitStatusException {
var pmd = new PmdOperation().fromProject(new BaseProject()); var pmd = new PmdOperation().fromProject(new BaseProject());
@ -386,12 +368,6 @@ class PmdOperationTest {
assertThat(pmd).isEqualTo(0); assertThat(pmd).isEqualTo(0);
} }
@Test
void testPrependAuxClasspath() {
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).prependAuxClasspath("foo", "bar");
assertThat(pmd.prependAuxClasspath()).isEqualTo("foo" + File.pathSeparator + "bar");
}
@Test @Test
void testPriority() throws ExitStatusException { void testPriority() throws ExitStatusException {
var pmd = newPmdOperation().inputPaths(CODE_STYLE_SAMPLE).minimumPriority(RulePriority.HIGH); var pmd = newPmdOperation().inputPaths(CODE_STYLE_SAMPLE).minimumPriority(RulePriority.HIGH);