Initial commit

This commit is contained in:
Erik C. Thauvin 2023-11-25 14:41:22 -08:00
commit b333128660
55 changed files with 1638 additions and 0 deletions

38
.github/workflows/bld.yml vendored Normal file
View file

@ -0,0 +1,38 @@
name: bld-ci
on: [ push, pull_request, workflow_dispatch ]
jobs:
build-bld-project:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [ 17, 20 ]
steps:
- name: Checkout source repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ matrix.java-version }}
- name: Grant execute permission for bld
run: chmod +x bld
- name: Download the dependencies
run: ./bld download
- name: Download the examples dependencies
run: |
cd examples
chmod +x bld
./bld download
- name: Run tests with bld
run: ./bld compile test

57
.github/workflows/pages.yml vendored Normal file
View file

@ -0,0 +1,57 @@
name: javadocs-pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout source repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
- name: Build Javadocs
run: ./bld download clean javadoc
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload generated Javadocs repository
path: 'build/javadoc/'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1

57
.gitignore vendored Normal file
View file

@ -0,0 +1,57 @@
.gradle
.DS_Store
build
lib/bld/**
!lib/bld/bld-wrapper.jar
!lib/bld/bld-wrapper.properties
lib/compile/
lib/runtime/
lib/standalone/
lib/test/
# IDEA ignores
# User-specific
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Editor-based Rest Client
.idea/httpRequests
local.properties

3
.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

28
.idea/app.iml generated Normal file
View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/build/main" />
<output-test url="file://$MODULE_DIR$/build/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" relativeOutputPath="resources" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="RUNTIME">
<library>
<CLASSES>
<root url="file://$MODULE_DIR$/src/main/resources/templates" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="compile" level="project" />
<orderEntry type="library" scope="RUNTIME" name="runtime" level="project" />
<orderEntry type="library" scope="TEST" name="test" level="project" />
</component>
</module>

14
.idea/bld.iml generated Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/build/bld" />
<output-test url="file://$MODULE_DIR$/build/bld" />
<exclude-output />
<content url="file://$MODULE_DIR$/src/bld">
<sourceFolder url="file://$MODULE_DIR$/src/bld/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="bld" level="project" />
</component>
</module>

6
.idea/copyright/Apache_License.xml generated Normal file
View file

@ -0,0 +1,6 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="Copyright &amp;#36;today.year the original author or authors.&#10; &#10;Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);&#10;you may not use this file except in compliance with the License.&#10;You may obtain a copy of the License at&#10;&#10; https://www.apache.org/licenses/LICENSE-2.0&#10;&#10;Unless required by applicable law or agreed to in writing, software&#10;distributed under the License is distributed on an &quot;AS IS&quot; BASIS,&#10;WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&#10;See the License for the specific language governing permissions and&#10;limitations under the License." />
<option name="myName" value="Apache License" />
</copyright>
</component>

3
.idea/copyright/profiles_settings.xml generated Normal file
View file

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="Apache License" />
</component>

View file

@ -0,0 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ADDITIONAL_TAGS" value="created" />
</inspection_tool>
</profile>
</component>

18
.idea/libraries/bld.xml generated Normal file
View file

@ -0,0 +1,18 @@
<component name="libraryTable">
<library name="bld">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
</SOURCES>
<excluded>
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
</excluded>
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
</library>
</component>

13
.idea/libraries/compile.xml generated Normal file
View file

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="compile">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/compile" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/compile" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" type="SOURCES" />
</library>
</component>

14
.idea/libraries/runtime.xml generated Normal file
View file

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="runtime">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/runtime" />
<root url="file://$PROJECT_DIR$/src/main/resources" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/runtime" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="false" type="SOURCES" />
</library>
</component>

14
.idea/libraries/test.xml generated Normal file
View file

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="test">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/test" />
<root url="file://$PROJECT_DIR$/src/test/resources" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/test" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" type="SOURCES" />
</library>
</component>

9
.idea/misc.xml generated Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PDMPlugin">
<option name="skipTestSources" value="false" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build" />
</component>
</project>

9
.idea/modules.xml generated Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/app.iml" filepath="$PROJECT_DIR$/.idea/app.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/bld.iml" filepath="$PROJECT_DIR$/.idea/bld.iml" />
</modules>
</component>
</project>

9
.idea/runConfigurations/Run Tests.xml generated Normal file
View file

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

6
.idea/vcs.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

11
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Run Tests",
"request": "launch",
"mainClass": "rife.bld.extension.DetektOperationTest"
}
]
}

15
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,15 @@
{
"java.project.sourcePaths": [
"src/main/java",
"src/main/resources",
"src/test/java",
"src/bld/java"
],
"java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-1.7.5.jar",
"lib/compile/*.jar",
"lib/runtime/*.jar",
"lib/test/*.jar"
]
}

45
README.md Executable file
View file

@ -0,0 +1,45 @@
# [bld](https://rife2.com/bld) Extension to Perform Static Code Analysis with [Detekt](https://detekt.dev/) for [Kotlin](https://kotlinlang.org/)
[![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)
[![bld](https://img.shields.io/badge/1.7.3-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)
[![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)
To install, please refer to the [extensions documentation](https://github.com/rife2/bld/wiki/Extensions).
To check all Kotlin source code located `src/main/kotlin` and `src/test/kotlin`, add the following to your build file
```java
@BuildCommand(summary = "Check source with Detekt")
public void detekt() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
.execute();
}
```
```console
./bld compile detekt
```
To generate a Detekt baseline, add the following to your build file:
```java
@BuildCommand(value = "detekt-baseline", summary = "Creates a Detekt baseline")
public void detektBaseline() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
.baseline("detekt-baseline.xml")
.createBaseline(true)
.execute();
}
```
```console
./bld compile detekt-baseline
```
Please check the [DetektOperation documentation](https://rife2.github.io/bld-detekt/rife/bld/extension/DetektOperation.html#method-summary) for all available configuration options.

2
bld Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env sh
java -jar "$(dirname "$0")/lib/bld/bld-wrapper.jar" "$0" --build rife.bld.extension.DetektOperationBuild "$@"

4
bld.bat Normal file
View file

@ -0,0 +1,4 @@
@echo off
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
java -jar "%DIRNAME%/lib/bld/bld-wrapper.jar" "%0" --build rife.bld.extension.DetektOperationBuild %*

57
examples/.gitignore vendored Normal file
View file

@ -0,0 +1,57 @@
.gradle
.DS_Store
build
lib/bld/**
!lib/bld/bld-wrapper.jar
!lib/bld/bld-wrapper.properties
lib/compile/
lib/runtime/
lib/standalone/
lib/test/
# IDEA ignores
# User-specific
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Editor-based Rest Client
.idea/httpRequests
detekt-baseline.xml

3
examples/.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

1
examples/.idea/.name generated Normal file
View file

@ -0,0 +1 @@
bld-detekt-examples

29
examples/.idea/app.iml generated Normal file
View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/build/main" />
<output-test url="file://$MODULE_DIR$/build/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" relativeOutputPath="resources" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="RUNTIME">
<library>
<CLASSES>
<root url="file://$MODULE_DIR$/src/main/resources/templates" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="compile" level="project" />
<orderEntry type="library" scope="RUNTIME" name="runtime" level="project" />
<orderEntry type="library" scope="TEST" name="test" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>

15
examples/.idea/bld.iml generated Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/build/bld" />
<output-test url="file://$MODULE_DIR$/build/bld" />
<exclude-output />
<content url="file://$MODULE_DIR$/src/bld">
<sourceFolder url="file://$MODULE_DIR$/src/bld/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="bld" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>

View file

@ -0,0 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ADDITIONAL_TAGS" value="created" />
</inspection_tool>
</profile>
</component>

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

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="1.8" />
</component>
</project>

View file

@ -0,0 +1,23 @@
<component name="libraryTable">
<library name="KotlinJavaRuntime" type="repository">
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.20" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.20/kotlin-stdlib-jdk8-1.9.20.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.20/kotlin-stdlib-1.9.20.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.20/kotlin-stdlib-jdk7-1.9.20.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.20/kotlin-stdlib-jdk8-1.9.20-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.20/kotlin-stdlib-1.9.20-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.20/kotlin-stdlib-jdk7-1.9.20-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.20/kotlin-stdlib-jdk8-1.9.20-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.20/kotlin-stdlib-1.9.20-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.20/kotlin-stdlib-jdk7-1.9.20-sources.jar!/" />
</SOURCES>
</library>
</component>

18
examples/.idea/libraries/bld.xml generated Normal file
View file

@ -0,0 +1,18 @@
<component name="libraryTable">
<library name="bld">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
</SOURCES>
<excluded>
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
</excluded>
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
</library>
</component>

13
examples/.idea/libraries/compile.xml generated Normal file
View file

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="compile">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/compile" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/compile" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" type="SOURCES" />
</library>
</component>

14
examples/.idea/libraries/runtime.xml generated Normal file
View file

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="runtime">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/runtime" />
<root url="file://$PROJECT_DIR$/src/main/resources" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/runtime" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="false" type="SOURCES" />
</library>
</component>

14
examples/.idea/libraries/test.xml generated Normal file
View file

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="test">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/test" />
<root url="file://$PROJECT_DIR$/src/test/resources" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/test" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" type="SOURCES" />
</library>
</component>

27
examples/.idea/misc.xml generated Normal file
View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<pattern value="com.example.ExampleBuild" />
<pattern value="com.example.ExampleBuild" method="javadoc" />
<pattern value="com.example.ExampleBuild" method="dokkaHtml" />
<pattern value="com.example.ExampleBuild" method="dokkaGfm" />
<pattern value="com.example.ExampleBuild" method="dokkaJekyll" />
</component>
<component name="PDMPlugin">
<option name="customRuleSets">
<list>
<option value="K:\java\semver\config\pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-generated-version/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-pitest/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-jacoco-report/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-checkstyle/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-exec/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-testng/config/pmd.xml" />
</list>
</option>
<option name="skipTestSources" value="false" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build" />
</component>
</project>

9
examples/.idea/modules.xml generated Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/app.iml" filepath="$PROJECT_DIR$/.idea/app.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/bld.iml" filepath="$PROJECT_DIR$/.idea/bld.iml" />
</modules>
</component>
</project>

View file

@ -0,0 +1,9 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Tests" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.example.ExampleTest" />
<module name="app" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

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

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

11
examples/.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Run Tests",
"request": "launch",
"mainClass": "com.example.ExampleTest"
}
]
}

15
examples/.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,15 @@
{
"java.project.sourcePaths": [
"src/main/java",
"src/main/resources",
"src/test/java",
"src/bld/java"
],
"java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-1.7.5.jar",
"lib/compile/*.jar",
"lib/runtime/*.jar",
"lib/test/*.jar"
]
}

19
examples/README.md Normal file
View file

@ -0,0 +1,19 @@
j## Compile the Kotlin Example
```console
./bld compile
```
## Check code with Detekt
```console
./bld detekt
```
## Generate Detekt baseline
```console
./bld detekt-baseline
```
The `detekt-baseline.xml` will be created in the project's root directory.

2
examples/bld Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env sh
java -jar "$(dirname "$0")/lib/bld/bld-wrapper.jar" "$0" --build com.example.ExampleBuild "$@"

4
examples/bld.bat Normal file
View file

@ -0,0 +1,4 @@
@echo off
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
java -jar "%DIRNAME%/lib/bld/bld-wrapper.jar" "%0" --build com.example.ExampleBuild %*

Binary file not shown.

View file

@ -0,0 +1,8 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.extensions=com.uwyn.rife2:bld-kotlin:0.9.0-SNAPSHOT
bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.0-SNAPSHOT
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation=
bld.sourceDirectories=
bld.version=1.7.5

View file

@ -0,0 +1,85 @@
package com.example;
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;
import java.util.logging.Logger;
import static rife.bld.dependencies.Repository.*;
import static rife.bld.dependencies.Scope.compile;
import static rife.bld.dependencies.Scope.test;
public class ExampleBuild extends Project {
public ExampleBuild() {
pkg = "com.example";
name = "Example";
mainClass = "com.example.Example";
version = version(0, 1, 0);
javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true;
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES);
scope(compile)
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", version(1, 9, 21)));
scope(test)
.include(dependency("org.jetbrains.kotlin:kotlin-test-junit5:1.9.21"))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)));
// Include the Kotlin source directory when creating or publishing sources Java Archives
jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin"));
}
public static void main(String[] args) {
var level = Level.ALL;
var logger = Logger.getLogger("rife.bld.extension");
var consoleHandler = new ConsoleHandler();
// Enable detailed logging for the Kotlin extension
consoleHandler.setLevel(level);
logger.addHandler(consoleHandler);
logger.setLevel(level);
logger.setUseParentHandlers(false);
new ExampleBuild().start(args);
}
@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 = "Check source with Detekt")
public void detekt() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
.execute();
}
@BuildCommand(value = "detekt-baseline", summary = "Creates a Detekt baseline")
public void detektBaseline() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
.baseline("detekt-baseline.xml")
.createBaseline(true)
.execute();
}
}

View file

@ -0,0 +1,34 @@
package com.example
import java.io.IOException
/**
* Example class.
*/
class Example {
val message: String
get() = "Hello World!"
// https://detekt.dev/docs/1.22.0/rules/performance#arrayprimitive
fun returningFunction(): Array<Double> { return arrayOf() }
// https://detekt.dev/docs/1.22.0/rules/style#canbenonnullable
fun foo(a: Int?) {
val b = a!! + 2
}
companion object {
@JvmStatic
fun main(args: Array<String>) {
// https://detekt.dev/docs/1.22.0/rules/naming#booleanpropertynaming
val progressBar: Boolean = true
// https://detekt.dev/docs/1.22.0/rules/potential-bugs#avoidreferentialequality
val areEqual = "aString" === ""
println(Example().message)
if (false) {
// https://detekt.dev/docs/1.22.0/rules/exceptions#exceptionraisedinunexpectedlocation
throw IllegalStateException()
}
}
}
}

View file

@ -0,0 +1,11 @@
package com.example
import kotlin.test.Test
import kotlin.test.assertEquals
class ExampleTest {
@Test
fun verifyHello() {
assertEquals("Hello World!", Example().message)
}
} // https://detekt.dev/docs/1.22.0/rules/empty-blocks#emptyfunctionblock

BIN
lib/bld/bld-wrapper.jar Normal file

Binary file not shown.

View file

@ -0,0 +1,7 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
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=
bld.version=1.7.5

View file

@ -0,0 +1,96 @@
/*
* Copyright 2023 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 rife.bld.Project;
import rife.bld.publish.PublishDeveloper;
import rife.bld.publish.PublishLicense;
import rife.bld.publish.PublishScm;
import java.util.List;
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;
public class DetektOperationBuild extends Project {
public DetektOperationBuild() {
pkg = "rife.bld.extension";
name = "DetektOperation";
version = version(0, 9, 0, "SNAPSHOT");
javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true;
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(1, 7, 5)))
.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)
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 12, 5)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)))
.include(dependency("org.assertj", "assertj-core", version(3, 24, 2)));
javadocOperation()
.javadocOptions()
.author()
.docLint(NO_MISSING)
.link("https://rife2.github.io/bld/")
.link("https://rife2.github.io/rife2/");
publishOperation()
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
.info()
.groupId("com.uwyn.rife2")
.artifactId("bld-detekt")
.description("bld Detekt Extension")
.url("https://github.com/rife2/bld-detekt")
.developer(
new PublishDeveloper()
.id("ethauvin")
.name("Erik C. Thauvin")
.email("erik@thauvin.net")
.url("https://erik.thauvin.net/")
)
.license(
new PublishLicense()
.name("The Apache License, Version 2.0")
.url("http://www.apache.org/licenses/LICENSE-2.0.txt")
)
.scm(
new PublishScm()
.connection("scm:git:https://github.com/rife2/bld-detekt.git")
.developerConnection("scm:git:git@github.com:rife2/bld-detekt.git")
.url("https://github.com/rife2/bld-detekt")
)
.signKey(property("sign.key"))
.signPassphrase(property("sign.passphrase"));
}
public static void main(String[] args) {
new DetektOperationBuild().start(args);
}
}

View file

@ -0,0 +1,552 @@
/*
* Copyright 2023 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 rife.bld.BaseProject;
import rife.bld.operations.AbstractProcessOperation;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Performs static code analysis with <a href="https://detekt.dev/">Detekt</a>.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public class DetektOperation extends AbstractProcessOperation<DetektOperation> {
private static final Logger LOGGER = Logger.getLogger(DetektReport.class.getName());
private final Collection<String> classpath_ = new ArrayList<>();
private final Collection<String> config_ = new ArrayList<>();
private final Collection<String> input_ = new ArrayList<>();
private final Collection<String> plugins_ = new ArrayList<>();
private final Collection<DetektReport> report_ = new ArrayList<>();
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_ = false;
private boolean disableDefaultRuleSets_ = false;
private String excludes_;
private boolean generateConfig_;
private String includes_;
private String jdkHome_;
private String jvmTarget_;
private String languageVersion_;
private int maxIssues_;
private boolean parallel_;
private BaseProject project_;
/**
* Activates all available (even unstable) rules.
*
* @param allRules {@code true} or {@code false}
* @return this operation instance
*/
public DetektOperation allRules(boolean allRules) {
allRules_ = allRules;
return this;
}
/**
* Allow rules to auto correct code if they support it. The default rule
* sets do NOT support auto correcting and won't change any line in the
* users code base. However custom rules can be written to support auto
* correcting. The additional 'formatting' rule set, added with
* {@link #plugins(String...) Plugins}, does support it and needs this flag.
*
* @param autoCorrect {@code true} or {@code false}
* @return this operation instance
*/
public DetektOperation autoCorrect(boolean autoCorrect) {
autoCorrect_ = autoCorrect;
return this;
}
/**
* Specifies a directory as the base path. Currently it impacts all file
* paths in the formatted reports. File paths in console output and txt
* report are not affected and remain as absolute paths.
*
* @param path the directory path
* @return this operation instance
*/
public DetektOperation basePath(String path) {
basePath_ = path;
return this;
}
/**
* If a baseline xml file is passed in, only new code smells not in the
* baseline are printed in the console.
*
* @param baseline the baseline xml file
* @return this operation instance
*/
public DetektOperation baseline(String baseline) {
baseline_ = baseline;
return this;
}
/**
* Preconfigures detekt with a bunch of rules and some opinionated defaults
* for you. Allows additional provided configurations to override the
* defaults.
*
* @param buildUponDefaultConfig {@code true} or {@code false}
* @return this operation instance
*/
public DetektOperation buildUponDefaultConfig(boolean buildUponDefaultConfig) {
buildUponDefaultConfig_ = buildUponDefaultConfig;
return this;
}
/**
* EXPERIMENTAL: Paths where to find user class files and depending jar
* files. Used for type resolution.
*
* @param paths one or more files
* @return this operation instance
*/
public DetektOperation classPath(String... paths) {
classpath_.addAll(List.of(paths));
return this;
}
/**
* EXPERIMENTAL: Paths where to find user class files and depending jar
* files. Used for type resolution.
*
* @param paths the list of files
* @return this operation instance
*/
public DetektOperation classPath(Collection<String> paths) {
classpath_.addAll(paths);
return this;
}
/**
* Path to the config file ({@code path/to/config.yml}).
*
* @param configs one or more config files
* @return this operation instance
*/
public DetektOperation config(String... configs) {
config_.addAll(List.of(configs));
return this;
}
/**
* Path to the config file ({@code path/to/config.yml}).
*
* @param configs the list pf config files
* @return this operation instance
*/
public DetektOperation config(Collection<String> configs) {
config_.addAll(configs);
return this;
}
/**
* Path to the config resource on detekt's classpath ({@code path/to/config.yml}).
*
* @param resource the config resource path
* @return this operation instance
*/
public DetektOperation configResource(String resource) {
configResource_ = resource;
return this;
}
/**
* Treats current analysis findings as a smell baseline for future detekt
* runs.
*
* @param createBaseline {@code true} or {@code false}
* @return this operation instance
*/
public DetektOperation createBaseline(boolean createBaseline) {
createBaseline_ = createBaseline;
return this;
}
/**
* Prints extra information about configurations and extensions.
*
* @param debug {@code true} or {@code false}
* @return this operation instance
*/
public DetektOperation debug(boolean debug) {
debug_ = debug;
return this;
}
/**
* Disables default rule sets.
*
* @param disable {@code true} or {@code false}
* @return this operation instance
*/
public DetektOperation disableDefaultRuleSets(boolean disable) {
disableDefaultRuleSets_ = disable;
return this;
}
/**
* Globbing patterns describing paths to exclude from the analysis.
*
* @param patterns the patterns
* @return this operation instance
*/
public DetektOperation excludes(String patterns) {
excludes_ = patterns;
return this;
}
/**
* Part of the {@link #execute} operation, constructs the command list
* to use for building the process.
*/
@Override
protected List<String> executeConstructProcessCommandList() {
if (project_ == null) {
LOGGER.severe("A project must be specified.");
}
final List<String> args = new ArrayList<>();
args.add(javaTool());
args.add("-cp");
args.add(Path.of(project_.libBldDirectory().getAbsolutePath(), "*").toString());
args.add("io.gitlab.arturbosch.detekt.cli.Main");
// all-rules
if (allRules_) {
args.add("--all-rules");
}
// auto-correct
if (autoCorrect_) {
args.add("--auto-correct");
}
// base-path
if (basePath_ != null) {
args.add("--base-path");
args.add(basePath_);
}
// baseline
if (baseline_ != null) {
args.add("--baseline");
args.add(baseline_);
}
// 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_));
}
// config
if (!config_.isEmpty()) {
args.add("-config");
args.add(String.join(";", config_));
}
// config-resource
if (configResource_ != null) {
args.add("--config-resource");
args.add(configResource_);
}
// create-baseline
if (createBaseline_) {
args.add("--create-baseline");
}
// debug
if (debug_) {
args.add("--debug");
}
// disable-default-rulesets
if (disableDefaultRuleSets_) {
args.add("--disable-default-rulesets");
}
// excludes
if (excludes_ != null) {
args.add("--excludes");
}
// generate-config
if (generateConfig_) {
args.add("--generate-config");
}
// includes
if (includes_ != null) {
args.add("--includes");
args.add(includes_);
}
// input
if (!input_.isEmpty()) {
args.add("--input");
args.add(String.join(",", input_));
}
// jdk-home
if (jdkHome_ != null) {
args.add("--jdk-home");
args.add(jdkHome_);
}
// jvm-target
if (jvmTarget_ != null) {
args.add("--jvm-target");
args.add(jvmTarget_);
}
// language-version
if (languageVersion_ != null) {
args.add("--language-version");
args.add(languageVersion_);
}
// max-issues
if (maxIssues_ > 0) {
args.add("--max-issues");
args.add(String.valueOf(maxIssues_));
}
// parallel
if (parallel_) {
args.add("--parallel");
}
// plugins
if (!plugins_.isEmpty()) {
args.add("--plugins");
args.add(String.join(".", plugins_));
}
// report
if (!report_.isEmpty()) {
report_.forEach(it -> {
args.add("-r");
args.add(it.id().name().toLowerCase() + ":" + it.path());
});
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.join(" ", args));
}
return args;
}
/**
* Configures the operation from a {@link BaseProject}.
* <p>
* Sets the {@link #input input} to {@code src/main/kotlin}, {@code src/test/kotlin} and {@code detekt-baseline.xml}
* if they exist.
*
* @param project the project to configure the operation from
* @return this operation instance
*/
@Override
public DetektOperation fromProject(BaseProject project) {
project_ = project;
var main = new File(project.srcMainDirectory(), "kotlin");
if (main.exists()) {
input_.add(main.getAbsolutePath());
}
var test = new File(project.srcTestDirectory(), "kotlin");
if (test.exists()) {
input_.add(test.getAbsolutePath());
}
var baseline = new File(project.workDirectory(), "detekt-baseline.xml");
if (baseline.exists()) {
baseline_ = baseline.getAbsolutePath();
}
return this;
}
/**
* Export default config. Path can be specified with {@link #config config} option.
* <p>
* Default path: {@code default-detekt-config.yml}
*
* @param generate {@code true} or {@code false}
* @return this operation instance
*/
public DetektOperation generateConfig(boolean generate) {
generateConfig_ = generate;
return this;
}
/**
* Globbing patterns describing paths to include in the analysis. Useful in
* combination with {@link #excludes(String) excludes} patterns.
*
* @param patterns the patterns
* @return this operation instance
*/
public DetektOperation includes(String patterns) {
includes_ = patterns;
return this;
}
/**
* Input paths to analyze. If not specified the current working directory is used.
*
* @param paths the list of paths
* @return this operation instance
*/
public DetektOperation input(Collection<String> paths) {
input_.addAll(paths);
return this;
}
/**
* Input paths to analyze. If not specified the current working directory is used.
*
* @param paths one or more paths
* @return this operation instance
*/
public DetektOperation input(String... paths) {
input_.addAll(List.of(paths));
return this;
}
/**
* EXPERIMENTAL: Use a custom JDK home directory to include into the
* classpath.
*
* @param path the JDK home directory path
* @return this operation instance
*/
public DetektOperation jdkHome(String path) {
jdkHome_ = path;
return this;
}
/**
* EXPERIMENTAL: Target version of the generated JVM bytecode that was
* generated during compilation and is now being used for type resolution
* <p>
* Default: 1.8
*
* @param target the target version
* @return this operation instance
*/
public DetektOperation jvmTarget(String target) {
jvmTarget_ = target;
return this;
}
/**
* EXPERIMENTAL: Compatibility mode for Kotlin language version X.Y,
* reports errors for all language features that came out later.
* <p>
* Possible Values: [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1]
*
* @param version the version
* @return this operation instance
*/
public DetektOperation languageVersion(String version) {
languageVersion_ = version;
return this;
}
/**
* Return exit code 0 only when found issues count does not exceed
* specified issues count.
*
* @param max the issues code
* @return this operation instance
*/
public DetektOperation maxIssues(int max) {
maxIssues_ = max;
return this;
}
/**
* 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 parallel{@code true} or {@code false}
* @return this operation instance
*/
public DetektOperation parallel(boolean parallel) {
parallel_ = parallel;
return this;
}
/**
* 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
*/
public DetektOperation plugins(String... jars) {
plugins_.addAll(List.of(jars));
return this;
}
/**
* 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
*/
public DetektOperation plugins(Collection<String> jars) {
plugins_.addAll(jars);
return this;
}
/**
* Generates a report for given 'report-id' and stores it on given 'path'.
*
* @param reports one or more reports
* @return this operation instance
*/
public DetektOperation report(DetektReport... reports) {
report_.addAll(List.of(reports));
return this;
}
}

View file

@ -0,0 +1,28 @@
/*
* Copyright 2023 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;
/**
* Defines a report for given report-id to be stores in the given path.
*
* @param id the report-id
* @param path the given path
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public record DetektReport(DetektReportId id, String path) {
}

View file

@ -0,0 +1,27 @@
/*
* Copyright 2023 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;
/**
* The report-id values.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public enum DetektReportId {
TXT, XML, HTML, MD, SARIF
}

View file

@ -0,0 +1,104 @@
/*
* Copyright 2023 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.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.assertj.core.api.Assertions.*;
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);
}
@Test
void testExamplesExecute() {
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"Example"));
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
}
@Test
void testExampleMaxIssues() {
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"Example"))
.maxIssues(8);
assertThatNoException().isThrownBy(op::execute);
}
@Test
void testExampleReports() throws IOException {
var tmpDir = Files.createTempDirectory("bld-detekt-").toFile();
tmpDir.deleteOnExit();
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"))
.report(new DetektReport(DetektReportId.HTML, html.getAbsolutePath()))
.report(new DetektReport(DetektReportId.XML, xml.getAbsolutePath()))
.report(new DetektReport(DetektReportId.TXT, txt.getAbsolutePath()))
.report(new DetektReport(DetektReportId.MD, md.getAbsolutePath()))
.report(new DetektReport(DetektReportId.SARIF, sarif.getAbsolutePath()));
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
List.of(html, xml, txt, md, sarif).forEach(it -> assertThat(it).exists());
}
@Test
void testExampleBaseline() throws IOException, ExitStatusException, InterruptedException {
var tmpDir = Files.createTempDirectory("bld-detekt-").toFile();
tmpDir.deleteOnExit();
var baseline = new File(tmpDir, "detekt-baseline.xml");
var op = new DetektOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"Example"))
.baseline(baseline.getAbsolutePath())
.createBaseline(true);
op.execute();
assertThat(baseline).exists();
}
}