Compare commits

...

22 commits
0.9.9 ... main

Author SHA1 Message Date
71df82b1c0
Bump Kotlin to version 2.2.0 2025-06-23 14:58:24 -07:00
7bc0b0fa54
Bump PMD extension to version 1.3.0 2025-06-23 14:56:56 -07:00
ec61f69926
Bump JUnit to version 5.13.1 2025-06-23 14:56:29 -07:00
f8968dbd04
Generate and convert JUnit reports for xunit-viewer 2025-05-31 08:20:23 -07:00
e69d4b1176
Cleanup tests 2025-05-28 15:38:52 -07:00
27ca328b0a
Bump PMD extension to version 1.2.3 2025-05-04 04:50:45 -07:00
407926624d
Update extensions
Bump PMD to version 1.2.2
Bump Exec to version 1.0.5
2025-04-12 21:05:14 -07:00
7f98154c80
Bump JUnit to version 5.12.2 2025-04-12 21:04:22 -07:00
ea10fd012f
Disable cleanPath() for testing 2025-03-24 19:01:12 -07:00
69a9eac414
Add baseline file for testing 2025-03-24 17:36:30 -07:00
5a2824507f
Removed paths quoting 2025-03-24 16:12:15 -07:00
3e350e617a
Bump detekt extension to version 0.9.10-SNAPSHOT 2025-03-24 16:11:11 -07:00
432e5ffed1
Enable extension logging in examples 2025-03-24 16:09:45 -07:00
e6d5c6c38f
Quote and clean path in the process command list 2025-03-24 10:06:41 -07:00
7d5b50641c
Add OS matrix to test the project and examples on Ubuntu, Windows and macOS 2025-03-24 01:44:39 -07:00
30f92d1262
Bump Kotlin extension to version 1.1.0-SNAPSHOT 2025-03-24 01:39:53 -07:00
8d4643d99a
Bump Kotlin to version 2.1.20 2025-03-24 01:38:50 -07:00
0efd5ab2fe
JDK 24 2025-03-18 23:34:19 -07:00
3df50c2e79
Add generic installation instructions 2025-03-18 13:07:29 -07:00
012cd14067
Bump PMD extension to version 1.2.1 2025-03-18 13:06:22 -07:00
e39302bf8b
Bump JUnit to version 5.12.1 2025-03-18 13:06:07 -07:00
41d6667dca
Bump bld to version 2.2.1 2025-02-24 22:48:05 -08:00
21 changed files with 603 additions and 417 deletions

View file

@ -4,11 +4,13 @@ on: [push, pull_request, workflow_dispatch]
jobs: jobs:
build-bld-project: build-bld-project:
runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
java-version: [17, 21, 23] java-version: [ 17, 21, 24 ]
kotlin-version: [ 1.9.25, 2.0.21, 2.2.0 ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout source repository - name: Checkout source repository
@ -22,12 +24,16 @@ jobs:
distribution: "zulu" distribution: "zulu"
java-version: ${{ matrix.java-version }} java-version: ${{ matrix.java-version }}
- name: Download dependencies
run: ./bld download
- name: Download dependencies [examples] - name: Download dependencies [examples]
working-directory: examples working-directory: examples
run: ./bld download run: ./bld download
- name: Run Detekt [examples]
working-directory: examples
run: ./bld compile test-ci
- name: Download dependencies
run: ./bld download
- name: Run tests - name: Run tests
run: ./bld compile test run: ./bld compile test

View file

@ -2,12 +2,12 @@
<library name="bld"> <library name="bld">
<CLASSES> <CLASSES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-2.2.0.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-2.2.1.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-2.2.0-sources.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-2.2.1-sources.jar!/" />
</SOURCES> </SOURCES>
<excluded> <excluded>
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" /> <root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />

2
.idea/misc.xml generated
View file

@ -3,7 +3,7 @@
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<pattern value="rife.bld.extension.DetektOperationBuild" method="pmd" /> <pattern value="rife.bld.extension.DetektOperationBuild" method="pmd" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build" /> <output url="file://$PROJECT_DIR$/build" />
</component> </component>
</project> </project>

View file

@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Tests" type="Application" factoryName="Application" nameIsGenerated="true"> <configuration default="false" name="DetektOperationTests" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="rife.bld.extension.DetektOperationTest" /> <option name="MAIN_CLASS_NAME" value="rife.bld.extension.DetektOperationTests" />
<module name="app" /> <module name="app" />
<method v="2"> <method v="2">
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />

View file

@ -9,7 +9,7 @@
], ],
"java.configuration.updateBuildConfiguration": "automatic", "java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [ "java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-2.2.0.jar", "${HOME}/.bld/dist/bld-2.2.1.jar",
"lib/**/*.jar" "lib/**/*.jar"
] ]
} }

View file

@ -3,12 +3,20 @@
[![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) [![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
[![bld](https://img.shields.io/badge/2.2.0-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) [![bld](https://img.shields.io/badge/2.2.1-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld)
[![Release](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/releases/com/uwyn/rife2/bld-detekt/maven-metadata.xml?color=blue)](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-detekt) [![Release](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/releases/com/uwyn/rife2/bld-detekt/maven-metadata.xml?color=blue)](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-detekt)
[![Snapshot](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/snapshots/com/uwyn/rife2/bld-detekt/maven-metadata.xml?label=snapshot)](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-detekt) [![Snapshot](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/snapshots/com/uwyn/rife2/bld-detekt/maven-metadata.xml?label=snapshot)](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-detekt)
[![GitHub CI](https://github.com/rife2/bld-detekt/actions/workflows/bld.yml/badge.svg)](https://github.com/rife2/bld-detekt/actions/workflows/bld.yml) [![GitHub CI](https://github.com/rife2/bld-detekt/actions/workflows/bld.yml/badge.svg)](https://github.com/rife2/bld-detekt/actions/workflows/bld.yml)
To install, please refer to the [extensions documentation](https://github.com/rife2/bld/wiki/Extensions). To install the latest version, add the following to the `lib/bld/bld-wrapper.properties` file:
```properties
bld.extension-detekt=com.uwyn.rife2:bld-detekt
```
For more information, please refer to the [extensions](https://github.com/rife2/bld/wiki/Extensions) documentation.
## Check Source Code with Detekt
To check all Kotlin source code located in the project, add the following to your build file: To check all Kotlin source code located in the project, add the following to your build file:
```java ```java

6
examples/.idea/bld.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BldConfiguration">
<events />
</component>
</project>

View file

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Kotlin2JsCompilerArguments">
<option name="moduleKind" value="plain" />
</component>
<component name="Kotlin2JvmCompilerArguments"> <component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="1.8" /> <option name="jvmTarget" value="17" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="2.1" />
<option name="languageVersion" value="2.1" />
</component> </component>
</project> </project>

View file

@ -2,12 +2,12 @@
<library name="bld"> <library name="bld">
<CLASSES> <CLASSES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-2.2.0.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-2.2.1.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-2.2.0-sources.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-2.2.1-sources.jar!/" />
</SOURCES> </SOURCES>
<excluded> <excluded>
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" /> <root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />

View file

@ -10,6 +10,7 @@
<pattern value="com.example.ExampleBuild" method="detektBaseline" /> <pattern value="com.example.ExampleBuild" method="detektBaseline" />
<pattern value="com.example.ExampleBuild" method="detektMain" /> <pattern value="com.example.ExampleBuild" method="detektMain" />
<pattern value="com.example.ExampleBuild" method="detektTest" /> <pattern value="com.example.ExampleBuild" method="detektTest" />
<pattern value="com.example.ExampleBuild" method="testCi" />
</component> </component>
<component name="PDMPlugin"> <component name="PDMPlugin">
<option name="customRuleSets"> <option name="customRuleSets">

View file

@ -9,7 +9,7 @@
], ],
"java.configuration.updateBuildConfiguration": "automatic", "java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [ "java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-2.2.0.jar", "${HOME}/.bld/dist/bld-2.2.1.jar",
"lib/**/*.jar" "lib/**/*.jar"
] ]
} }

Binary file not shown.

View file

@ -1,8 +1,8 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.downloadLocation= bld.downloadLocation=
bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.9 bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.10-SNAPSHOT
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.4 bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.1.0
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories= bld.sourceDirectories=
bld.version=2.2.0 bld.version=2.2.1

View file

@ -26,18 +26,19 @@ public class ExampleBuild extends Project {
javaRelease = 17; javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true; autoDownloadPurge = true;
downloadSources = true;
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES); repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES);
final var kotlin = version(2, 1, 10); final var kotlin = version(2, 2, 0);
scope(compile) scope(compile)
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin)); .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin));
scope(test) scope(test)
.include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin)) .include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 0))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 13, 1)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 0))); .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 13, 1)))
.include(dependency("org.junit.platform", "junit-platform-launcher", version(1, 13, 1)));
// Include the Kotlin source directory when creating or publishing sources Java Archives // Include the Kotlin source directory when creating or publishing sources Java Archives
jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin")); jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin"));
@ -45,14 +46,14 @@ public class ExampleBuild extends Project {
public static void main(String[] args) { public static void main(String[] args) {
// Enable detailed logging // Enable detailed logging
// var level = Level.ALL; var level = Level.ALL;
// var logger = Logger.getLogger("rife.bld.extension"); var logger = Logger.getLogger("rife.bld.extension");
// var consoleHandler = new ConsoleHandler(); var consoleHandler = new ConsoleHandler();
//
// consoleHandler.setLevel(level); consoleHandler.setLevel(level);
// logger.addHandler(consoleHandler); logger.addHandler(consoleHandler);
// logger.setLevel(level); logger.setLevel(level);
// logger.setUseParentHandlers(false); logger.setUseParentHandlers(false);
new ExampleBuild().start(args); new ExampleBuild().start(args);
} }
@ -100,4 +101,13 @@ public class ExampleBuild extends Project {
.input("src/test/kotlin") .input("src/test/kotlin")
.execute(); .execute();
} }
@BuildCommand(value = "test-ci", summary = "Run detekt with a test baseline")
public void testCi() throws ExitStatusException, IOException, InterruptedException {
// Run detekt with the test baseline (for CI testing)
new DetektOperation()
.fromProject(this)
.baseline("src/test/resources/detekt-baseline.xml")
.execute();
}
} }

View file

@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>EmptyIfBlock:Example.kt$Example.Companion${ }</ID>
<ID>MagicNumber:Example.kt$Example$5</ID>
<ID>NewLineAtEndOfFile:ExampleTest.kt$com.example.ExampleTest.kt</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:Example.kt$Example.Companion$IllegalStateException()</ID>
<ID>UseCheckOrError:Example.kt$Example.Companion$throw IllegalStateException()</ID>
<ID>VariableNaming:Example.kt$Example$// https://detekt.dev/docs/rules/naming#variablenaming val Message: String get() = "Hello World!"</ID>
</CurrentIssues>
</SmellBaseline>

Binary file not shown.

View file

@ -1,8 +1,8 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.downloadLocation= bld.downloadLocation=
bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.4 bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.5
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.2.0 bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.3.0
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories= bld.sourceDirectories=
bld.version=2.2.0 bld.version=2.2.1

View file

@ -22,7 +22,11 @@ import rife.bld.publish.PublishDeveloper;
import rife.bld.publish.PublishLicense; import rife.bld.publish.PublishLicense;
import rife.bld.publish.PublishScm; import rife.bld.publish.PublishScm;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.Locale;
import static rife.bld.dependencies.Repository.*; import static rife.bld.dependencies.Repository.*;
import static rife.bld.dependencies.Scope.compile; import static rife.bld.dependencies.Scope.compile;
@ -33,7 +37,7 @@ public class DetektOperationBuild extends Project {
public DetektOperationBuild() { public DetektOperationBuild() {
pkg = "rife.bld.extension"; pkg = "rife.bld.extension";
name = "DetektOperation"; name = "DetektOperation";
version = version(0, 9, 9); version = version(0, 9, 10, "SNAPSHOT");
javaRelease = 17; javaRelease = 17;
@ -43,11 +47,11 @@ public class DetektOperationBuild extends Project {
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS); repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS);
scope(compile) scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(2, 2, 0))) .include(dependency("com.uwyn.rife2", "bld", version(2, 2, 1)))
.include(dependency("io.gitlab.arturbosch.detekt", "detekt-cli", version(1, 23, 8))); .include(dependency("io.gitlab.arturbosch.detekt", "detekt-cli", version(1, 23, 8)));
scope(test) scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 0))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 13, 1)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 0))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 13, 1)))
.include(dependency("org.assertj", "assertj-core", version(3, 27, 3))); .include(dependency("org.assertj", "assertj-core", version(3, 27, 3)));
javadocOperation() javadocOperation()
.javadocOptions() .javadocOptions()
@ -97,11 +101,40 @@ public class DetektOperationBuild extends Project {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
var os = System.getProperty("os.name");
if (os != null && os.toLowerCase(Locale.US).contains("linux")) {
new ExecOperation() new ExecOperation()
.fromProject(this) .fromProject(this)
.command("scripts/cliargs.sh") .command("scripts/cliargs.sh")
.execute(); .execute();
super.test(); }
var testResultsDir = "build/test-results/test/";
var op = testOperation().fromProject(this);
op.testToolOptions().reportsDir(new File(testResultsDir));
Exception ex = null;
try {
op.execute();
} catch (Exception e) {
ex = e;
}
var xunitViewer = new File("/usr/bin/xunit-viewer");
if (xunitViewer.exists() && xunitViewer.canExecute()) {
var reportsDir = "build/reports/tests/test/";
Files.createDirectories(Path.of(reportsDir));
new ExecOperation()
.fromProject(this)
.command(xunitViewer.getPath(), "-r", testResultsDir, "-o", reportsDir + "index.html")
.execute();
}
if (ex != null) {
throw ex;
}
} }

View file

@ -51,6 +51,7 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
"kotlinx-coroutines-", "kotlinx-coroutines-",
"kotlinx-html-jvm-", "kotlinx-html-jvm-",
"kotlinx-serialization-", "kotlinx-serialization-",
"poko-annotations-jvm-",
"sarif4k-jvm-", "sarif4k-jvm-",
"snakeyaml-engine-", "snakeyaml-engine-",
"trove4j-"); "trove4j-");
@ -323,7 +324,6 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
return configStrings(List.of(configs)); return configStrings(List.of(configs));
} }
/** /**
* Paths to the config files ({@code path/to/config.yml}). * Paths to the config files ({@code path/to/config.yml}).
* *
@ -701,7 +701,7 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
} }
} }
} }
return String.join(":", jars); return String.join(File.pathSeparator, jars);
} }
/** /**

View file

@ -1,368 +0,0 @@
/*
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rife.bld.extension;
import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import rife.bld.BaseProject;
import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.extension.detekt.Report;
import rife.bld.extension.detekt.ReportId;
import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.assertj.core.api.Assertions.*;
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class DetektOperationTest {
@BeforeAll
static void beforeAll() {
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);
}
static void deleteOnExit(File folder) {
folder.deleteOnExit();
for (var f : Objects.requireNonNull(folder.listFiles())) {
if (f.isDirectory()) {
deleteOnExit(f);
} else {
f.deleteOnExit();
}
}
}
@Test
void testBasePath() {
var foo = new File("foo");
var bar = new File("bar");
var op = new DetektOperation().basePath(foo);
assertThat(op.basePath()).as("as file").isEqualTo(foo.getAbsolutePath());
op = op.basePath(bar.toPath());
assertThat(op.basePath()).as("as path").isEqualTo(bar.getAbsolutePath());
op = op.basePath("foo");
assertThat(op.basePath()).as("as string").isEqualTo("foo");
}
@Test
void testBaseline() {
var foo = new File("foo");
var bar = new File("bar");
var op = new DetektOperation().baseline(foo);
assertThat(op.baseline()).as("as file").isEqualTo(foo.getAbsolutePath());
op = op.baseline(bar.toPath());
assertThat(op.baseline()).as("as path").isEqualTo(bar.getAbsolutePath());
op = op.baseline("foo");
assertThat(op.baseline()).as("as string").isEqualTo("foo");
}
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
void testCheckAllParameters() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "detekt-args.txt"));
assertThat(args).isNotEmpty();
var op = new DetektOperation()
.fromProject(new BaseProject())
.allRules(true)
.autoCorrect(true)
.basePath("basePath")
.basePath(new File("basePath"))
.baseline("baseline")
.buildUponDefaultConfig(true)
.classPath(new File("path1"))
.classPath("path2", "path3")
.classPath(List.of(new File("path4"), new File("path5")))
.config(new File("config1"))
.config("config2", "config3")
.config(List.of(new File("config4"), new File("config5")))
.configResource("configResource")
.configResource(new File("configResource"))
.createBaseline(true)
.debug(true)
.disableDefaultRuleSets(true)
.excludes(List.of("excludes1", "excludes2"))
.excludes("excludes3", "excludes4")
.generateConfig(true)
.includes(List.of("includes1", "includes2"))
.includes("includes3", "includes4", "includes5")
.input(new File("input1"))
.input("input2", "input3")
.input(List.of(new File("input4"), new File("input5")))
.jdkHome("jdkHome")
.jvmTarget("jvmTarget")
.languageVersion("languageVersion")
.maxIssues(10)
.parallel(true)
.plugins(new File("jar1"))
.plugins("jar2", "jar3")
.plugins(List.of(new File("jar4"), new File("jar5")))
.report(new Report(ReportId.HTML, "reports"));
assertThat(op.excludes()).as("excludes[]").containsExactly(".*/build/.*", ".*/resources/.*",
"excludes1", "excludes2", "excludes3", "excludes4");
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));
}
var params = op.executeConstructProcessCommandList();
try (var softly = new AutoCloseableSoftAssertions()) {
for (var p : args) {
var found = false;
for (var a : params) {
if (a.startsWith(p)) {
found = true;
break;
}
}
softly.assertThat(found).as(p + " not found.").isTrue();
}
}
}
@Test
void testClassPath() {
var foo = new File("foo");
var bar = new File("bar");
var op = new DetektOperation().classPath("foo", "bar");
assertThat(op.classPath()).as("String...").contains(foo, bar);
op.classPath().clear();
op = op.classPath(foo, bar);
assertThat(op.classPath()).as("File...").contains(foo, bar);
op.classPath().clear();
op = op.classPath(foo.toPath(), bar.toPath());
assertThat(op.classPath()).as("Path...").contains(foo, bar);
op.classPath().clear();
op = op.classPathStrings(List.of("foo", "bar"));
assertThat(op.classPath()).as("List(String...)").contains(foo, bar);
op.classPath().clear();
op = op.classPath(List.of(foo, bar));
assertThat(op.classPath()).as("File...").contains(foo, bar);
op.classPath().clear();
op = op.classPathPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.classPath()).as("Path...").contains(foo, bar);
op.classPath().clear();
}
@Test
void testConfig() {
var foo = new File("foo");
var bar = new File("bar");
var op = new DetektOperation().config("foo", "bar");
assertThat(op.config()).as("String...").contains(foo, bar);
op.config().clear();
op = op.config(foo, bar);
assertThat(op.config()).as("File...").contains(foo, bar);
op.config().clear();
op = op.config(foo.toPath(), bar.toPath());
assertThat(op.config()).as("Path...").contains(foo, bar);
op.config().clear();
op = op.configStrings(List.of("foo", "bar"));
assertThat(op.config()).as("List(String...)").contains(foo, bar);
op.config().clear();
op = op.config(List.of(foo, bar));
assertThat(op.config()).as("File...").contains(foo, bar);
op.config().clear();
op = op.configPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.config()).as("Path...").contains(foo, bar);
op.config().clear();
}
@Test
void testConfigResource() {
var foo = new File("foo");
var bar = new File("bar");
var op = new DetektOperation().configResource(foo);
assertThat(op.configResource()).as("as file").isEqualTo(foo.getAbsolutePath());
op = op.configResource(bar.toPath());
assertThat(op.configResource()).as("as path").isEqualTo(bar.getAbsolutePath());
op = new DetektOperation().configResource("foo");
assertThat(op.configResource()).as("as string").isEqualTo("foo");
}
@Test
void testExampleBaseline() throws IOException, ExitStatusException, InterruptedException {
var tmpDir = Files.createTempDirectory("bld-detekt-").toFile();
var baseline = new File(tmpDir, "detekt-baseline.xml");
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"example", "Example"))
.baseline(baseline)
.createBaseline(true);
op.execute();
deleteOnExit(tmpDir);
assertThat(baseline).exists();
}
@Test
void testExampleMaxIssues() {
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"example", "Example"))
.maxIssues(8);
assertThatNoException().isThrownBy(op::execute);
}
@Test
void testExampleReports() throws IOException {
var tmpDir = Files.createTempDirectory("bld-detekt-").toFile();
var html = new File(tmpDir, "report.html");
var xml = new File(tmpDir, "report.xml");
var txt = new File(tmpDir, "report.txt");
var md = new File(tmpDir, "report.md");
var sarif = new File(tmpDir, "report.sarif");
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"example", "Example"))
.report(new Report(ReportId.HTML, html.getAbsolutePath()))
.report(new Report(ReportId.XML, xml.getAbsolutePath()))
.report(new Report(ReportId.TXT, txt.getAbsolutePath()))
.report(new Report(ReportId.MD, md.getAbsolutePath()))
.report(new Report(ReportId.SARIF, sarif.getAbsolutePath()));
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
deleteOnExit(tmpDir);
List.of(html, xml, txt, md, sarif).forEach(it -> assertThat(it).exists());
}
@Test
void testExamplesExecute() {
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"example", "Example"))
.debug(true);
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
}
@Test
void testExecuteNoProject() {
var op = new DetektOperation();
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
}
@Test
void testInput() {
var foo = new File("foo");
var bar = new File("bar");
var op = new DetektOperation().input("foo", "bar");
assertThat(op.input()).as("String...").contains(foo, bar);
op.input().clear();
op = op.input(foo, bar);
assertThat(op.input()).as("File...").contains(foo, bar);
op.input().clear();
op = op.input(foo.toPath(), bar.toPath());
assertThat(op.input()).as("Path...").contains(foo, bar);
op.input().clear();
op = op.inputStrings(List.of("foo", "bar"));
assertThat(op.input()).as("List(String...)").contains(foo, bar);
op.input().clear();
op = op.input(List.of(foo, bar));
assertThat(op.input()).as("File...").contains(foo, bar);
op.input().clear();
op = op.inputPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.input()).as("Path...").contains(foo, bar);
op.input().clear();
}
@Test
void testPlugins() {
var foo = new File("foo");
var bar = new File("bar");
var op = new DetektOperation().plugins("foo", "bar");
assertThat(op.plugins()).as("String...").contains(foo, bar);
op.plugins().clear();
op = op.plugins(foo, bar);
assertThat(op.plugins()).as("File...").contains(foo, bar);
op.plugins().clear();
op = op.plugins(foo.toPath(), bar.toPath());
assertThat(op.plugins()).as("Path...").contains(foo, bar);
op.plugins().clear();
op = op.pluginsStrings(List.of("foo", "bar"));
assertThat(op.plugins()).as("List(String...)").contains(foo, bar);
op.plugins().clear();
op = op.plugins(List.of(foo, bar));
assertThat(op.plugins()).as("File...").contains(foo, bar);
op.plugins().clear();
op = op.pluginsPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.plugins()).as("Path...").contains(foo, bar);
op.plugins().clear();
}
}

View file

@ -0,0 +1,471 @@
/*
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rife.bld.extension;
import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import rife.bld.BaseProject;
import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.extension.detekt.Report;
import rife.bld.extension.detekt.ReportId;
import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.assertj.core.api.Assertions.*;
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class DetektOperationTests {
@BeforeAll
static void beforeAll() {
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);
}
static void deleteOnExit(File folder) {
folder.deleteOnExit();
for (var f : Objects.requireNonNull(folder.listFiles())) {
if (f.isDirectory()) {
deleteOnExit(f);
} else {
f.deleteOnExit();
}
}
}
@Test
void executeNoProject() {
var op = new DetektOperation();
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
}
@Nested
@DisplayName("Config Tests")
class ConfigTests {
private final File bar = new File("bar");
private final File foo = new File("foo");
private final DetektOperation op = new DetektOperation();
@Test
void configAsFileArray() {
op.config().clear();
op.config(foo, bar);
assertThat(op.config()).contains(foo, bar);
}
@Test
void configAsFileList() {
op.config().clear();
op.config(List.of(foo, bar));
assertThat(op.config()).contains(foo, bar);
}
@Test
void configAsPathArray() {
var op = new DetektOperation();
op.config().clear();
op = op.config(foo.toPath(), bar.toPath());
assertThat(op.config()).contains(foo, bar);
}
@Test
void configAsPathList() {
op.config().clear();
op.configPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.config()).as("Path...").contains(foo, bar);
}
@Test
void configAsStringArray() {
op.config().clear();
op.config("foo", "bar");
assertThat(op.config()).contains(foo, bar);
}
@Test
void configAsStringList() {
op.config().clear();
op.configStrings(List.of("foo", "bar"));
assertThat(op.config()).contains(foo, bar);
}
@Test
void configResourceAsFile() {
op.configResource(foo);
assertThat(op.configResource()).isEqualTo(foo.getAbsolutePath());
}
@Test
void configResourceAsPath() {
var op = new DetektOperation();
op = op.configResource(bar.toPath());
assertThat(op.configResource()).isEqualTo(bar.getAbsolutePath());
}
@Test
void configResourceAsString() {
op.configResource("foo");
assertThat(op.configResource()).isEqualTo("foo");
}
}
@Nested
@DisplayName("Example Tests")
class ExampleTests {
@Test
void exampleBaseline() throws IOException, ExitStatusException, InterruptedException {
var tmpDir = Files.createTempDirectory("bld-detekt-").toFile();
var baseline = new File(tmpDir, "examples/src/test/resources/detekt-baseline.xml");
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"example", "Example"))
.baseline(baseline)
.createBaseline(true);
op.execute();
deleteOnExit(tmpDir);
assertThat(baseline).exists();
}
@Test
void exampleMaxIssues() {
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"example", "Example"))
.maxIssues(8);
assertThatNoException().isThrownBy(op::execute);
}
@Test
void exampleReports() throws IOException {
var tmpDir = Files.createTempDirectory("bld-detekt-").toFile();
var html = new File(tmpDir, "report.html");
var xml = new File(tmpDir, "report.xml");
var txt = new File(tmpDir, "report.txt");
var md = new File(tmpDir, "report.md");
var sarif = new File(tmpDir, "report.sarif");
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"example", "Example"))
.report(new Report(ReportId.HTML, html.getAbsolutePath()))
.report(new Report(ReportId.XML, xml.getAbsolutePath()))
.report(new Report(ReportId.TXT, txt.getAbsolutePath()))
.report(new Report(ReportId.MD, md.getAbsolutePath()))
.report(new Report(ReportId.SARIF, sarif.getAbsolutePath()));
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
deleteOnExit(tmpDir);
List.of(html, xml, txt, md, sarif).forEach(it -> assertThat(it).exists());
}
@Test
void examplesExecute() {
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"example", "Example"))
.debug(true);
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
}
}
@Nested
@DisplayName("Options Tests")
class OptionsTests {
private final File bar = new File("bar");
private final File foo = new File("foo");
private final DetektOperation op = new DetektOperation();
@Test
@EnabledOnOs(OS.LINUX)
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
void checkAllParameters() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "detekt-args.txt"));
assertThat(args).isNotEmpty();
var op = new DetektOperation()
.fromProject(new BaseProject())
.allRules(true)
.autoCorrect(true)
.basePath("basePath")
.basePath(new File("basePath"))
.baseline("baseline")
.buildUponDefaultConfig(true)
.classPath(new File("path1"))
.classPath("path2", "path3")
.classPath(List.of(new File("path4"), new File("path5")))
.config(new File("config1"))
.config("config2", "config3")
.config(List.of(new File("config4"), new File("config5")))
.configResource("configResource")
.configResource(new File("configResource"))
.createBaseline(true)
.debug(true)
.disableDefaultRuleSets(true)
.excludes(List.of("excludes1", "excludes2"))
.excludes("excludes3", "excludes4")
.generateConfig(true)
.includes(List.of("includes1", "includes2"))
.includes("includes3", "includes4", "includes5")
.input(new File("input1"))
.input("input2", "input3")
.input(List.of(new File("input4"), new File("input5")))
.jdkHome("jdkHome")
.jvmTarget("jvmTarget")
.languageVersion("languageVersion")
.maxIssues(10)
.parallel(true)
.plugins(new File("jar1"))
.plugins("jar2", "jar3")
.plugins(List.of(new File("jar4"), new File("jar5")))
.report(new Report(ReportId.HTML, "reports"));
assertThat(op.excludes()).as("excludes[]").containsExactly(".*/build/.*", ".*/resources/.*",
"excludes1", "excludes2", "excludes3", "excludes4");
for (var i = 1; i < 6; i++) {
assertThat(op.classPath()).as("classPath[%s]", i).hasSize(5).contains(new File("path" + i));
assertThat(op.config()).as("config[%s]", i).hasSize(5).contains(new File("config" + i));
assertThat(op.includes()).as("includes[%s]", i).hasSize(5).contains("includes" + i);
assertThat(op.input()).as("input[%s]", i).hasSize(5).contains(new File("input" + i));
assertThat(op.plugins()).as("plugins[%s]", i).hasSize(5).contains(new File("jar" + i));
}
var params = op.executeConstructProcessCommandList();
try (var softly = new AutoCloseableSoftAssertions()) {
for (var p : args) {
var found = false;
for (var a : params) {
if (a.startsWith(p)) {
found = true;
break;
}
}
softly.assertThat(found).as("%s not found.", p).isTrue();
}
}
}
@Nested
@DisplayName("Base Path Tests")
class BasePathTests {
@Test
void basePathAsFile() {
op.basePath(foo);
assertThat(op.basePath()).isEqualTo(foo.getAbsolutePath());
}
@Test
void basePathAsPath() {
var op = new DetektOperation();
op = op.basePath(bar.toPath());
assertThat(op.basePath()).isEqualTo(bar.getAbsolutePath());
}
@Test
void basePathAsString() {
op.basePath("foo");
assertThat(op.basePath()).isEqualTo("foo");
}
}
@Nested
@DisplayName("Baseline Tests")
class BaselineTests {
@Test
void baselineAsFile() {
op.baseline(foo);
assertThat(op.baseline()).isEqualTo(foo.getAbsolutePath());
}
@Test
void baselineAsPath() {
var op = new DetektOperation();
op = op.baseline(bar.toPath());
assertThat(op.baseline()).isEqualTo(bar.getAbsolutePath());
}
@Test
void baselineAsString() {
op.baseline("foo");
assertThat(op.baseline()).isEqualTo("foo");
}
}
@Nested
@DisplayName("ClassPath Tests")
class ClassPathTests {
@Test
void classPathAsFileArray() {
op.classPath().clear();
op.classPath(foo, bar);
assertThat(op.classPath()).contains(foo, bar);
}
@Test
void classPathAsFileList() {
op.classPath().clear();
op.classPath(List.of(foo, bar));
assertThat(op.classPath()).contains(foo, bar);
}
@Test
void classPathAsPathArray() {
var op = new DetektOperation();
op = op.classPath(foo.toPath(), bar.toPath());
assertThat(op.classPath()).contains(foo, bar);
}
@Test
void classPathAsPathList() {
op.classPath().clear();
op.classPathPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.classPath()).contains(foo, bar);
}
@Test
void classPathAsStingArray() {
op.classPath().clear();
op.classPath("foo", "bar");
assertThat(op.classPath()).contains(foo, bar);
}
@Test
void classPathAsStringList() {
op.classPath().clear();
op.classPathStrings(List.of("foo", "bar"));
assertThat(op.classPath()).contains(foo, bar);
}
}
@Nested
@DisplayName("Input Tests")
class InputTests {
@Test
void inputAsFileArray() {
op.input().clear();
op.input(foo, bar);
assertThat(op.input()).contains(foo, bar);
}
@Test
void inputAsFileList() {
op.input().clear();
op.input(List.of(foo, bar));
assertThat(op.input()).contains(foo, bar);
}
@Test
void inputAsPathArray() {
var op = new DetektOperation();
op = op.input(foo.toPath(), bar.toPath());
assertThat(op.input()).contains(foo, bar);
}
@Test
void inputAsPathList() {
op.input().clear();
op.inputPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.input()).contains(foo, bar);
op.input().clear();
}
@Test
void inputAsStringArray() {
op.input().clear();
op.input("foo", "bar");
assertThat(op.input()).contains(foo, bar);
}
@Test
void inputAsStringList() {
op.input().clear();
op.inputStrings(List.of("foo", "bar"));
assertThat(op.input()).contains(foo, bar);
}
}
@Nested
@DisplayName("Plugins Tests")
class PluginsTests {
@Test
void pluginsAsFileArray() {
op.plugins().clear();
op.plugins(foo, bar);
assertThat(op.plugins()).contains(foo, bar);
}
@Test
void pluginsAsFileList() {
op.plugins().clear();
op.plugins(List.of(foo, bar));
assertThat(op.plugins()).contains(foo, bar);
}
@Test
void pluginsAsPathArray() {
var op = new DetektOperation();
op = op.plugins(foo.toPath(), bar.toPath());
assertThat(op.plugins()).contains(foo, bar);
}
@Test
void pluginsAsPathList() {
op.plugins().clear();
op.pluginsPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.plugins()).contains(foo, bar);
op.plugins().clear();
}
@Test
void pluginsAsStringArray() {
op.plugins().clear();
op.plugins("foo", "bar");
assertThat(op.plugins()).contains(foo, bar);
}
@Test
void pluginsAsStringList() {
op.plugins().clear();
op.pluginsStrings(List.of("foo", "bar"));
assertThat(op.plugins()).contains(foo, bar);
}
}
}
}