diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml index 2d50ee7..3c9d30a 100644 --- a/.github/workflows/bld.yml +++ b/.github/workflows/bld.yml @@ -22,12 +22,17 @@ jobs: distribution: "zulu" java-version: ${{ matrix.java-version }} - - name: Download dependencies + - name: Grant execute permission for bld + run: chmod +x bld + + - name: Download the dependencies run: ./bld download - - name: Download dependencies [examples] - working-directory: examples - run: ./bld download + - name: Download the examples dependencies + run: | + cd examples + chmod +x bld + ./bld download - - name: Run tests + - name: Run tests with bld run: ./bld compile test diff --git a/.idea/libraries/bld.xml b/.idea/libraries/bld.xml index 2fb5ff0..a2969be 100644 --- a/.idea/libraries/bld.xml +++ b/.idea/libraries/bld.xml @@ -2,12 +2,12 @@ - + - + diff --git a/.vscode/settings.json b/.vscode/settings.json index 33a9922..d136e4d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,7 @@ ], "java.configuration.updateBuildConfiguration": "automatic", "java.project.referencedLibraries": [ - "${HOME}/.bld/dist/bld-2.0.0-SNAPSHOT.jar", + "${HOME}/.bld/dist/bld-1.9.1.jar", "lib/**/*.jar" ] } diff --git a/README.md b/README.md index 3798237..c983fff 100755 --- a/README.md +++ b/README.md @@ -45,7 +45,3 @@ public void detektBaseline() throws ExitStatusException, IOException, Interrupte - [View Examples Project](https://github.com/rife2/bld-detekt/tree/main/examples) Please check the [DetektOperation documentation](https://rife2.github.io/bld-detekt/rife/bld/extension/DetektOperation.html#method-summary) for all available configuration options. - -## Template Project - -There is also a [Kotlin Template Project](https://github.com/rife2/kotlin-bld-example) with support for [Dokka](https://github.com/rife2/bld-dokka) and the Detekt extensions. diff --git a/examples/.idea/libraries/bld.xml b/examples/.idea/libraries/bld.xml index 2fb5ff0..a2969be 100644 --- a/examples/.idea/libraries/bld.xml +++ b/examples/.idea/libraries/bld.xml @@ -2,12 +2,12 @@ - + - + diff --git a/examples/.vscode/settings.json b/examples/.vscode/settings.json index 33a9922..d136e4d 100644 --- a/examples/.vscode/settings.json +++ b/examples/.vscode/settings.json @@ -9,7 +9,7 @@ ], "java.configuration.updateBuildConfiguration": "automatic", "java.project.referencedLibraries": [ - "${HOME}/.bld/dist/bld-2.0.0-SNAPSHOT.jar", + "${HOME}/.bld/dist/bld-1.9.1.jar", "lib/**/*.jar" ] } diff --git a/examples/lib/bld/bld-wrapper.jar b/examples/lib/bld/bld-wrapper.jar index 3f131d1..ef31ff4 100644 Binary files a/examples/lib/bld/bld-wrapper.jar and b/examples/lib/bld/bld-wrapper.jar differ diff --git a/examples/lib/bld/bld-wrapper.properties b/examples/lib/bld/bld-wrapper.properties index c865830..fbc3fc9 100644 --- a/examples/lib/bld/bld-wrapper.properties +++ b/examples/lib/bld/bld-wrapper.properties @@ -5,4 +5,4 @@ bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.5-SNAPSHOT bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.0-SNAPSHOT bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.sourceDirectories= -bld.version=2.0.0-SNAPSHOT +bld.version=1.9.1 diff --git a/examples/src/bld/java/com/example/ExampleBuild.java b/examples/src/bld/java/com/example/ExampleBuild.java index b877e17..32e06e4 100644 --- a/examples/src/bld/java/com/example/ExampleBuild.java +++ b/examples/src/bld/java/com/example/ExampleBuild.java @@ -36,8 +36,8 @@ public class ExampleBuild extends Project { .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin)); scope(test) .include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin)) - .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, 10, 2))) + .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2))); // Include the Kotlin source directory when creating or publishing sources Java Archives jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin")); @@ -45,21 +45,21 @@ public class ExampleBuild extends Project { public static void main(String[] args) { // Enable detailed logging -// var level = Level.ALL; -// var logger = Logger.getLogger("rife.bld.extension"); -// var consoleHandler = new ConsoleHandler(); -// -// consoleHandler.setLevel(level); -// logger.addHandler(consoleHandler); -// logger.setLevel(level); -// logger.setUseParentHandlers(false); + // var level = Level.ALL; + // var logger = Logger.getLogger("rife.bld.extension"); + // var consoleHandler = new ConsoleHandler(); + + // consoleHandler.setLevel(level); + // logger.addHandler(consoleHandler); + // logger.setLevel(level); + // logger.setUseParentHandlers(false); new ExampleBuild().start(args); } @BuildCommand(summary = "Compiles the Kotlin project") @Override - public void compile() throws Exception { + public void compile() throws IOException { new CompileKotlinOperation() .fromProject(this) .execute(); diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index 725cdf3..044c7e8 100644 Binary files a/lib/bld/bld-wrapper.jar and b/lib/bld/bld-wrapper.jar differ diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index 3037315..80d6f54 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -2,7 +2,7 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true bld.downloadLocation= bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.1 -bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.2 +bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.0 bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.sourceDirectories= -bld.version=2.0.0-SNAPSHOT +bld.version=1.9.1 diff --git a/src/bld/java/rife/bld/extension/DetektOperationBuild.java b/src/bld/java/rife/bld/extension/DetektOperationBuild.java index f8d441e..5e687e0 100644 --- a/src/bld/java/rife/bld/extension/DetektOperationBuild.java +++ b/src/bld/java/rife/bld/extension/DetektOperationBuild.java @@ -24,7 +24,8 @@ import rife.bld.publish.PublishScm; import java.util.List; -import static rife.bld.dependencies.Repository.*; +import static rife.bld.dependencies.Repository.MAVEN_CENTRAL; +import static rife.bld.dependencies.Repository.RIFE2_RELEASES; import static rife.bld.dependencies.Scope.compile; import static rife.bld.dependencies.Scope.test; import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING; @@ -38,15 +39,15 @@ public class DetektOperationBuild extends Project { javaRelease = 17; downloadSources = true; autoDownloadPurge = true; - repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS); + repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES); scope(compile) - .include(dependency("com.uwyn.rife2", "bld", version(2, 0, 0, "SNAPSHOT"))) + .include(dependency("com.uwyn.rife2", "bld", version(1, 9, 1))) .include(dependency("io.gitlab.arturbosch.detekt", "detekt-cli", version(1, 23, 6))); 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.assertj", "assertj-core", version(3, 26, 3))); + .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2))) + .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2))) + .include(dependency("org.assertj", "assertj-core", version(3, 26, 0))); javadocOperation() .javadocOptions() .author() @@ -88,7 +89,7 @@ public class DetektOperationBuild extends Project { } @BuildCommand(summary = "Checks source code with PMD") - public void pmd() throws Exception { + public void pmd() { new PmdOperation() .fromProject(this) .ruleSets("config/pmd.xml") diff --git a/src/main/java/rife/bld/extension/DetektOperation.java b/src/main/java/rife/bld/extension/DetektOperation.java index 97aecc5..b1d1bf1 100644 --- a/src/main/java/rife/bld/extension/DetektOperation.java +++ b/src/main/java/rife/bld/extension/DetektOperation.java @@ -21,6 +21,7 @@ import rife.bld.extension.detekt.Report; import rife.bld.extension.detekt.ReportId; import rife.bld.operations.AbstractProcessOperation; import rife.bld.operations.exceptions.ExitStatusException; +import rife.tools.exceptions.FileUtilsErrorException; import java.io.File; import java.io.IOException; @@ -59,7 +60,6 @@ public class DetektOperation extends AbstractProcessOperation { private final Collection classpath_ = new ArrayList<>(); private final Collection config_ = new ArrayList<>(); private final Collection excludes_ = new ArrayList<>(); - private final Collection includes_ = new ArrayList<>(); private final Collection input_ = new ArrayList<>(); private final Collection plugins_ = new ArrayList<>(); private final Collection report_ = new ArrayList<>(); @@ -73,6 +73,7 @@ public class DetektOperation extends AbstractProcessOperation { private boolean debug_; private boolean disableDefaultRuleSets_; private boolean generateConfig_; + private final Collection includes_ = new ArrayList<>(); private String jdkHome_; private String jvmTarget_; private String languageVersion_; @@ -347,26 +348,20 @@ public class DetektOperation extends AbstractProcessOperation { /** * Performs the operation. * - * @throws InterruptedException when the operation was interrupted - * @throws IOException when an exception occurred during the execution of the process - * @throws ExitStatusException when the exit status was changed during the operation + * @throws InterruptedException when the operation was interrupted + * @throws IOException when an exception occurred during the execution of the process + * @throws FileUtilsErrorException when an exception occurred during the retrieval of the operation output + * @throws ExitStatusException when the exit status was changed during the operation */ @Override - public void execute() throws IOException, InterruptedException, ExitStatusException { - if (project_ == null) { - if (LOGGER.isLoggable(Level.SEVERE) && !silent()) { - LOGGER.severe("A project must be specified."); - } - throw new ExitStatusException(ExitStatusException.EXIT_FAILURE); - } else { - super.execute(); - if (successful_ && LOGGER.isLoggable(Level.INFO) && !silent()){ - if (createBaseline_) { - LOGGER.info("Detekt baseline generated successfully: " - + "file://" + new File(baseline_).toURI().getPath()); - } else { - LOGGER.info("Detekt operation finished successfully."); - } + public void execute() throws IOException, FileUtilsErrorException, InterruptedException, ExitStatusException { + super.execute(); + if (successful_ && LOGGER.isLoggable(Level.INFO)) { + if (createBaseline_) { + LOGGER.info("Detekt baseline generated successfully: " + + "file://" + new File(baseline_).toURI().getPath()); + } else { + LOGGER.info("Detekt operation finished successfully."); } } } @@ -377,142 +372,144 @@ public class DetektOperation extends AbstractProcessOperation { */ @Override protected List executeConstructProcessCommandList() { + if (project_ == null) { + LOGGER.severe("A project must be specified."); + } + final List args = new ArrayList<>(); - if (project_ != null) { - args.add(javaTool()); - args.add("-cp"); - args.add(getDetektJarList(project_.libBldDirectory())); - args.add("io.gitlab.arturbosch.detekt.cli.Main"); + args.add(javaTool()); + args.add("-cp"); + args.add(getDetektJarList(project_.libBldDirectory())); + args.add("io.gitlab.arturbosch.detekt.cli.Main"); - // all-rules - if (allRules_) { - args.add("--all-rules"); - } + // all-rules + if (allRules_) { + args.add("--all-rules"); + } - // auto-correct - if (autoCorrect_) { - args.add("--auto-correct"); - } + // auto-correct + if (autoCorrect_) { + args.add("--auto-correct"); + } - // base-path - if (isNotBlank(basePath_)) { - args.add("--base-path"); - args.add(basePath_); - } + // base-path + if (isNotBlank(basePath_)) { + args.add("--base-path"); + args.add(basePath_); + } - // baseline - if (isNotBlank(baseline_)) { - args.add("--baseline"); - args.add(baseline_); - } + // baseline + if (isNotBlank(baseline_)) { + args.add("--baseline"); + args.add(baseline_); + } - // build-upon-default-config - if (buildUponDefaultConfig_) { - args.add("--build-upon-default-config"); - } + // build-upon-default-config + if (buildUponDefaultConfig_) { + args.add("--build-upon-default-config"); + } - // classpath - if (!classpath_.isEmpty()) { - args.add("--classpath"); - args.add(String.join(File.pathSeparator, classpath_.stream().map(File::getAbsolutePath).toList())); - } + // classpath + if (!classpath_.isEmpty()) { + args.add("--classpath"); + args.add(String.join(File.pathSeparator, classpath_.stream().map(File::getAbsolutePath).toList())); + } - // config - if (!config_.isEmpty()) { - args.add("-config"); - args.add(String.join(";", config_.stream().map(File::getAbsolutePath).toList())); - } + // config + if (!config_.isEmpty()) { + args.add("-config"); + args.add(String.join(";", config_.stream().map(File::getAbsolutePath).toList())); + } - // config-resource - if (isNotBlank(configResource_)) { - args.add("--config-resource"); - args.add(configResource_); - } + // config-resource + if (isNotBlank(configResource_)) { + args.add("--config-resource"); + args.add(configResource_); + } - // create-baseline - if (createBaseline_) { - args.add("--create-baseline"); - } + // create-baseline + if (createBaseline_) { + args.add("--create-baseline"); + } - // debug - if (debug_) { - args.add("--debug"); - } + // debug + if (debug_) { + args.add("--debug"); + } - // disable-default-rulesets - if (disableDefaultRuleSets_) { - args.add("--disable-default-rulesets"); - } + // disable-default-rulesets + if (disableDefaultRuleSets_) { + args.add("--disable-default-rulesets"); + } - // excludes - if (!excludes_.isEmpty()) { - args.add("--excludes"); - args.add(String.join(",", excludes_)); - } + // excludes + if (!excludes_.isEmpty()) { + args.add("--excludes"); + args.add(String.join(",", excludes_)); + } - // generate-config - if (generateConfig_) { - args.add("--generate-config"); - } + // generate-config + if (generateConfig_) { + args.add("--generate-config"); + } - // includes - if (!includes_.isEmpty()) { - args.add("--includes"); - args.add(String.join(",", includes_)); - } + // includes + if (!includes_.isEmpty()) { + args.add("--includes"); + args.add(String.join(",", includes_)); + } - // input - if (!input_.isEmpty()) { - args.add("--input"); - args.add(String.join(",", input_.stream().map(File::getAbsolutePath).toList())); - } + // input + if (!input_.isEmpty()) { + args.add("--input"); + args.add(String.join(",", input_.stream().map(File::getAbsolutePath).toList())); + } - // jdk-home - if (isNotBlank(jdkHome_)) { - args.add("--jdk-home"); - args.add(jdkHome_); - } + // jdk-home + if (isNotBlank(jdkHome_)) { + args.add("--jdk-home"); + args.add(jdkHome_); + } - // jvm-target - if (isNotBlank(jvmTarget_)) { - args.add("--jvm-target"); - args.add(jvmTarget_); - } + // jvm-target + if (isNotBlank(jvmTarget_)) { + args.add("--jvm-target"); + args.add(jvmTarget_); + } - // language-version - if (isNotBlank(languageVersion_)) { - args.add("--language-version"); - args.add(languageVersion_); - } + // language-version + if (isNotBlank(languageVersion_)) { + args.add("--language-version"); + args.add(languageVersion_); + } - // max-issues - if (maxIssues_ > 0) { - args.add("--max-issues"); - args.add(String.valueOf(maxIssues_)); - } + // max-issues + if (maxIssues_ > 0) { + args.add("--max-issues"); + args.add(String.valueOf(maxIssues_)); + } - // parallel - if (parallel_) { - args.add("--parallel"); - } + // parallel + if (parallel_) { + args.add("--parallel"); + } - // plugins - if (!plugins_.isEmpty()) { - args.add("--plugins"); - args.add(String.join(",", plugins_.stream().map(File::getAbsolutePath).toList())); - } + // plugins + if (!plugins_.isEmpty()) { + args.add("--plugins"); + args.add(String.join(",", plugins_.stream().map(File::getAbsolutePath).toList())); + } - // report - if (!report_.isEmpty()) { - report_.forEach(it -> { - args.add("--report"); - args.add(it.id().name().toLowerCase() + ":" + it.path()); - }); - } + // report + if (!report_.isEmpty()) { + report_.forEach(it -> { + args.add("--report"); + args.add(it.id().name().toLowerCase() + ":" + it.path()); + }); + } - if (LOGGER.isLoggable(Level.FINE) && !silent()) { - LOGGER.fine(String.join(" ", args.stream().filter(this::isNotBlank).toList())); - } + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine(String.join(" ", args.stream().filter(this::isNotBlank).toList())); } return args; @@ -554,7 +551,9 @@ public class DetektOperation extends AbstractProcessOperation { return this; } - // Retrieves the matching JARs files from the given directory. + /* + * Retrieves the matching JARs files from the given directory. + */ private String getDetektJarList(File directory) { var jars = new ArrayList(); diff --git a/src/test/java/rife/bld/extension/DetektOperationTest.java b/src/test/java/rife/bld/extension/DetektOperationTest.java index c45b3fa..760d824 100644 --- a/src/test/java/rife/bld/extension/DetektOperationTest.java +++ b/src/test/java/rife/bld/extension/DetektOperationTest.java @@ -61,7 +61,6 @@ class DetektOperationTest { } @Test - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") void testCheckAllParameters() throws IOException { var args = Files.readAllLines(Paths.get("src", "test", "resources", "detekt-args.txt")); @@ -109,10 +108,10 @@ class DetektOperationTest { for (var i = 1; i < 6; i++) { assertThat(op.classPath()).as("classPath[" + i + ']').hasSize(5).contains(new File("path" + i)); - assertThat(op.config()).as("config[" + i + ']').hasSize(5).contains(new File("config" + i)); - assertThat(op.includes()).as("includes[" + i + ']').hasSize(5).contains("includes" + i); - assertThat(op.input()).as("input[" + i + ']').hasSize(5).contains(new File("input" + i)); - assertThat(op.plugins()).as("plugins[" + i + ']').hasSize(5).contains(new File("jar" + i)); + assertThat(op.config()).as("config[" + i + ']').hasSize(5).contains(new File("config" + i)); + assertThat(op.includes()).as("includes[" + i + ']').hasSize(5).contains("includes" + i); + assertThat(op.input()).as("input[" + i + ']').hasSize(5).contains(new File("input" + i)); + assertThat(op.plugins()).as("plugins[" + i + ']').hasSize(5).contains(new File("jar" + i)); } var params = op.executeConstructProcessCommandList(); @@ -191,10 +190,4 @@ class DetektOperationTest { .debug(true); assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class); } - - @Test - void testExecuteNoProject() { - var op = new DetektOperation(); - assertThatCode(op::execute).isInstanceOf(ExitStatusException.class); - } }