Initial commit
This commit is contained in:
commit
b333128660
55 changed files with 1638 additions and 0 deletions
85
examples/src/bld/java/com/example/ExampleBuild.java
Normal file
85
examples/src/bld/java/com/example/ExampleBuild.java
Normal 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();
|
||||
}
|
||||
}
|
34
examples/src/main/kotlin/com/example/Example.kt
Normal file
34
examples/src/main/kotlin/com/example/Example.kt
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
examples/src/test/kotlin/com/example/ExampleTest.kt
Normal file
11
examples/src/test/kotlin/com/example/ExampleTest.kt
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue