Compare commits

..

No commits in common. "a13a2b814b3361e5515ff959029a2e0f6b653601" and "b33312866097377621e5482e4ee8e63edd91eefa" have entirely different histories.

11 changed files with 35 additions and 176 deletions

3
.idea/misc.xml generated
View file

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<pattern value="rife.bld.extension.DetektOperationBuild" method="pmd" />
</component>
<component name="PDMPlugin">
<option name="skipTestSources" value="false" />
</component>

View file

@ -13,7 +13,7 @@ To install, please refer to the [extensions documentation](https://github.com/ri
To check all Kotlin source code located `src/main/kotlin` and `src/test/kotlin`, add the following to your build file
```java
@BuildCommand(summary = "Checks source with Detekt")
@BuildCommand(summary = "Check source with Detekt")
public void detekt() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
@ -25,12 +25,10 @@ public void detekt() throws ExitStatusException, IOException, InterruptedExcepti
./bld compile detekt
```
- [View Examples Project](https://github.com/rife2/bld-detekt/tree/main/examples)
To generate a Detekt baseline, add the following to your build file:
```java
@BuildCommand(value = "detekt-baseline", summary = "Creates the Detekt baseline")
@BuildCommand(value = "detekt-baseline", summary = "Creates a Detekt baseline")
public void detektBaseline() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
@ -43,6 +41,5 @@ public void detektBaseline() throws ExitStatusException, IOException, Interrupte
```console
./bld compile detekt-baseline
```
- [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.

View file

@ -1,110 +0,0 @@
<?xml version="1.0"?>
<ruleset name="erik"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Erik's Ruleset</description>
<!-- BEST PRACTICES -->
<rule ref="category/java/bestpractices.xml">
<exclude name="AvoidPrintStackTrace"/>
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
<exclude name="JUnitTestContainsTooManyAsserts"/>
<exclude name="GuardLogStatement"/>
</rule>
<rule ref="category/java/bestpractices.xml/MissingOverride">
<properties>
<property name="violationSuppressXPath"
value="//MethodDeclaration[@Name='hashCode' or @Name='equals' or @Name='toString']"/>
</properties>
</rule>
<!-- CODE STYLE -->
<rule ref="category/java/codestyle.xml">
<exclude name="AtLeastOneConstructor"/>
<exclude name="ClassNamingConventions"/>
<exclude name="ConfusingTernary"/>
<exclude name="CommentDefaultAccessModifier"/>
<exclude name="FieldNamingConventions"/>
<exclude name="LocalVariableCouldBeFinal"/>
<exclude name="LocalVariableNamingConventions"/>
<exclude name="LongVariable"/>
<exclude name="MethodArgumentCouldBeFinal"/>
<exclude name="OnlyOneReturn"/>
<exclude name="PackageCase"/>
<exclude name="ShortClassName"/>
<exclude name="ShortMethodName"/>
<exclude name="ShortVariable"/>
<exclude name="UselessParentheses"/>
<exclude name="UseUnderscoresInNumericLiterals"/>
</rule>
<rule ref="category/java/codestyle.xml/UnnecessaryImport">
<properties>
<property name="violationSuppressRegex" value="Unused (static|.*\.\*).*"/>
</properties>
</rule>
<!-- DESIGN -->
<rule ref="category/java/design.xml">
<exclude name="AvoidCatchingGenericException"/>
<exclude name="AvoidDeeplyNestedIfStmts"/>
<exclude name="AvoidUncheckedExceptionsInSignatures"/>
<exclude name="CognitiveComplexity"/>
<exclude name="CyclomaticComplexity"/>
<exclude name="ExcessiveClassLength"/>
<exclude name="ExcessiveMethodLength"/>
<exclude name="ExcessiveParameterList"/>
<exclude name="ExcessivePublicCount"/>
<exclude name="GodClass"/>
<exclude name="LawOfDemeter"/>
<exclude name="LoosePackageCoupling"/>
<exclude name="NPathComplexity"/>
<exclude name="NcssCount"/>
<exclude name="TooManyFields"/>
<exclude name="TooManyMethods"/>
<exclude name="UseObjectForClearerAPI"/>
</rule>
<!-- DOCUMENTATION -->
<rule ref="category/java/documentation.xml">
<exclude name="CommentRequired"/>
<exclude name="CommentSize"/>
</rule>
<!-- ERROR PRONE -->
<rule ref="category/java/errorprone.xml">
<exclude name="AssignmentInOperand"/>
<exclude name="AvoidCatchingNPE"/>
<exclude name="AvoidDuplicateLiterals"/>
<exclude name="AvoidFieldNameMatchingMethodName"/>
<exclude name="AvoidFieldNameMatchingTypeName"/>
<exclude name="AvoidLiteralsInIfCondition"/>
<exclude name="NullAssignment"/>
</rule>
<rule ref="category/java/errorprone.xml/AssignmentInOperand">
<properties>
<property name="allowWhile" value="true"/>
<property name="allowFor" value="true"/>
<property name="allowIf" value="true"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml/AvoidDuplicateLiterals">
<properties>
<property name="skipAnnotations" value="true"/>
</properties>
</rule>
<!-- MULTITHREADING -->
<rule ref="category/java/multithreading.xml">
</rule>
<!-- PERFORMANCE -->
<rule ref="category/java/performance.xml">
</rule>
<!-- SECURITY -->
<rule ref="category/java/security.xml">
</rule>
</ruleset>

View file

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

View file

@ -1,4 +1,4 @@
## Compile the Kotlin Example
j## Compile the Kotlin Example
```console
./bld compile
@ -8,9 +8,6 @@
```console
./bld detekt
./bld detekt-main
./bld detekt-test
```
## Generate Detekt baseline
@ -19,4 +16,4 @@
./bld detekt-baseline
```
The `detekt-baseline.xml` file will be created in the project's root directory.
The `detekt-baseline.xml` will be created in the project's root directory.

View file

@ -4,10 +4,14 @@ import rife.bld.BuildCommand;
import rife.bld.Project;
import rife.bld.extension.CompileKotlinOperation;
import rife.bld.extension.DetektOperation;
import rife.bld.extension.dokka.DokkaOperation;
import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat;
import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
@ -45,7 +49,7 @@ public class ExampleBuild extends Project {
var logger = Logger.getLogger("rife.bld.extension");
var consoleHandler = new ConsoleHandler();
// Enable detailed logging
// Enable detailed logging for the Kotlin extension
consoleHandler.setLevel(level);
logger.addHandler(consoleHandler);
logger.setLevel(level);
@ -54,22 +58,23 @@ public class ExampleBuild extends Project {
new ExampleBuild().start(args);
}
@BuildCommand(summary = "Compiles the Kotlin project")
@BuildCommand(summary = "Compile the Kotlin project")
@Override
public void compile() throws IOException {
// The source code located in src/main/kotlin and src/test/kotlin will be compiled
new CompileKotlinOperation()
.fromProject(this)
.execute();
}
@BuildCommand(summary = "Checks source with Detekt")
@BuildCommand(summary = "Check source with Detekt")
public void detekt() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
.execute();
}
@BuildCommand(value = "detekt-baseline", summary = "Creates the Detekt baseline")
@BuildCommand(value = "detekt-baseline", summary = "Creates a Detekt baseline")
public void detektBaseline() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
@ -77,18 +82,4 @@ public class ExampleBuild extends Project {
.createBaseline(true)
.execute();
}
@BuildCommand(value = "detekt-main", summary = "Checks main source with Detekt")
public void detektMain() throws ExitStatusException, IOException, InterruptedException {
var op = new DetektOperation().fromProject(this);
op.input().clear();
op.input("src/main/kotlin").execute();
}
@BuildCommand(value = "detekt-test", summary = "Checks test source with Detekt")
public void detektTest() throws ExitStatusException, IOException, InterruptedException {
var op = new DetektOperation().fromProject(this);
op.input().clear();
op.input("src/test/kotlin").execute();
}
}

View file

@ -1,5 +1,10 @@
package com.example
import java.io.IOException
/**
* Example class.
*/
class Example {
val message: String
get() = "Hello World!"

View file

@ -1,6 +1,6 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.4
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.1
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation=
bld.sourceDirectories=

View file

@ -16,7 +16,6 @@
package rife.bld.extension;
import rife.bld.BuildCommand;
import rife.bld.Project;
import rife.bld.publish.PublishDeveloper;
import rife.bld.publish.PublishLicense;
@ -41,11 +40,13 @@ public class DetektOperationBuild extends Project {
autoDownloadPurge = true;
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
var detekt = version(1, 23, 3);
scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(1, 7, 5)))
.include(dependency("io.gitlab.arturbosch.detekt", "detekt-cli", detekt))
.include(dependency("io.gitlab.arturbosch.detekt", "detekt-tooling", detekt))
.include(dependency("io.gitlab.arturbosch.detekt", "detekt-cli", version(1, 23, 3)))
// .include(dependency("io.gitlab.arturbosch.detekt", "detekt-core", version(1, 23, 3)))
// .include(dependency("io.gitlab.arturbosch.detekt", "detekt-rules", version(1, 23, 3)))
// .include(dependency("io.gitlab.arturbosch.detekt", "detekt-utils", version(1, 23, 3)))
.include(dependency("io.gitlab.arturbosch.detekt", "detekt-tooling", version(1, 23, 3)))
.include(dependency("com.beust", "jcommander", "1.82"))
.include(dependency("com.fasterxml:aalto-xml:1.3.2"));
scope(test)
@ -92,13 +93,4 @@ public class DetektOperationBuild extends Project {
public static void main(String[] args) {
new DetektOperationBuild().start(args);
}
@BuildCommand(summary = "Check source code with PMD")
public void pmd() {
new PmdOperation()
.fromProject(this)
.ruleSets("config/pmd.xml")
.execute();
}
}

View file

@ -40,15 +40,15 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
private final Collection<String> input_ = new ArrayList<>();
private final Collection<String> plugins_ = new ArrayList<>();
private final Collection<DetektReport> report_ = new ArrayList<>();
private boolean allRules_;
private boolean autoCorrect_;
private boolean allRules_ = false;
private boolean autoCorrect_ = false;
private String basePath_;
private String baseline_;
private boolean buildUponDefaultConfig_;
private String configResource_;
private boolean createBaseline_;
private boolean debug_;
private boolean disableDefaultRuleSets_;
private boolean debug_ = false;
private boolean disableDefaultRuleSets_ = false;
private String excludes_;
private boolean generateConfig_;
private String includes_;
@ -448,15 +448,6 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
return this;
}
/**
* Returns the input paths to analyze.
*
* @return the input paths
*/
public Collection<String> input() {
return input_;
}
/**
* EXPERIMENTAL: Use a custom JDK home directory to include into the
* classpath.
@ -523,7 +514,9 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
}
/**
* Extra paths to plugin jars.
* Enables parallel compilation and analysis of source files. Do some
* benchmarks first before enabling this flag. Heuristics show performance
* benefits starting from 2000 lines of Kotlin code.
*
* @param jars one or more jars
* @return this operation instance
@ -534,7 +527,9 @@ public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
}
/**
* Extra paths to plugin jars.
* Enables parallel compilation and analysis of source files. Do some
* benchmarks first before enabling this flag. Heuristics show performance
* benefits starting from 2000 lines of Kotlin code.
*
* @param jars the list of jars
* @return this operation instance

View file

@ -29,10 +29,9 @@ import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.assertj.core.api.Assertions.*; // NOPMD
import static org.assertj.core.api.Assertions.*;
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class DetektOperationTest {
@BeforeAll
static void beforeAll() {