From 573681ea6c55d55d7a21771b6729246ae4048f7d Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 4 Nov 2023 02:00:42 -0700 Subject: [PATCH] Added tests --- .github/workflows/bld.yml | 38 +++++++++ .github/workflows/pages.yml | 57 +++++++++++++ .../CompileKotlinOperationBuild.java | 2 - .../bld/extension/CompileKotlinOperation.java | 9 ++- .../extension/CompileKotlinOperationTest.java | 81 ++++++++++++++++--- 5 files changed, 173 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/bld.yml create mode 100644 .github/workflows/pages.yml diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml new file mode 100644 index 0000000..d5d3f40 --- /dev/null +++ b/.github/workflows/bld.yml @@ -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 diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..2120d4c --- /dev/null +++ b/.github/workflows/pages.yml @@ -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 \ No newline at end of file diff --git a/src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java b/src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java index 4766ce6..4ef448a 100644 --- a/src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java +++ b/src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java @@ -70,8 +70,6 @@ public class CompileKotlinOperationBuild extends Project { .url("https://github.com/rife2/bld-kotlin")) .signKey(property("sign.key")) .signPassphrase(property("sign.passphrase")); - - testOperation().mainClass("rife.bld.extension.CompileKotlinOperationTest"); } public static void main(String[] args) { diff --git a/src/main/java/rife/bld/extension/CompileKotlinOperation.java b/src/main/java/rife/bld/extension/CompileKotlinOperation.java index 030b6d1..8d17f11 100644 --- a/src/main/java/rife/bld/extension/CompileKotlinOperation.java +++ b/src/main/java/rife/bld/extension/CompileKotlinOperation.java @@ -37,8 +37,8 @@ import java.util.regex.Pattern; public class CompileKotlinOperation extends AbstractOperation { public static final Pattern KOTLIN_FILE_PATTERN = Pattern.compile("^.*\\.kt$"); private static final Logger LOGGER = Logger.getLogger(CompileKotlinOperation.class.getName()); - public final Collection compileOptions_ = new ArrayList<>(); private final Collection compileMainClasspath_ = new ArrayList<>(); + private final Collection compileOptions_ = new ArrayList<>(); private final Collection compileTestClasspath_ = new ArrayList<>(); private final Collection mainSourceDirectories_ = new ArrayList<>(); private final Collection mainSourceFiles_ = new ArrayList<>(); @@ -50,6 +50,11 @@ public class CompileKotlinOperation extends AbstractOperation getKotlinFileList(File directory) { if (directory == null) { return Collections.emptyList(); + } else if (!directory.exists()) { + if (LOGGER.isLoggable(Level.WARNING)) { + LOGGER.warning("Directory not found: " + directory.getAbsolutePath()); + } + return Collections.emptyList(); } else { var dir_abs = directory.getAbsoluteFile(); return FileUtils.getFileList(dir_abs, KOTLIN_FILE_PATTERN, null).stream().map((file) -> @@ -114,7 +119,7 @@ public class CompileKotlinOperation extends AbstractOperation classpath) { + public CompileKotlinOperation compileMainClasspath(Collection classpath) { compileMainClasspath_.addAll(classpath); return this; } diff --git a/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java b/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java index 0b2ba0b..8acc57e 100644 --- a/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java +++ b/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java @@ -16,17 +16,78 @@ package rife.bld.extension; -@SuppressWarnings({"PMD.TestClassWithoutTestCases", "PMD.SystemPrintln"}) -public class CompileKotlinOperationTest { - void verifyHello() { - if (!"Hello World!".equals(new CompileKotlinOperation().getMessage())) { - throw new AssertionError(); - } else { - System.out.println("Succeeded"); - } +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import rife.tools.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +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.assertThat; + +class CompileKotlinOperationTest { + + @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); } - public static void main(String[] args) { - new CompileKotlinOperationTest().verifyHello(); + @Test + void testExecute() throws IOException { + var tmpDir = Files.createTempDirectory("bld-kotlin").toFile(); + + try { + var buildDir = new File(tmpDir, "build"); + var mainDir = new File(buildDir, "main"); + var testDir = new File(buildDir, "test"); + + assertThat(mainDir.mkdirs()).isTrue(); + assertThat(testDir.mkdirs()).isTrue(); + + var compileJars = new ArrayList(); + for (var f : Objects.requireNonNull(new File("examples/lib/compile").listFiles())) { + compileJars.add(f.getAbsolutePath()); + } + + var testJars = new ArrayList(); + for (var f : Objects.requireNonNull(new File("examples/lib/test").listFiles())) { + testJars.add(f.getAbsolutePath()); + } + + var op = new CompileKotlinOperation() + .compileOptions("-verbose") + .buildMainDirectory(mainDir) + .buildTestDirectory(testDir) + .compileMainClasspath(compileJars) + .compileTestClasspath(testJars) + .compileTestClasspath(compileJars) + .compileTestClasspath(mainDir.getAbsolutePath()) + .mainSourceFiles(CompileKotlinOperation.getKotlinFileList(new File("examples/src/main/kotlin"))) + .testSourceFiles(CompileKotlinOperation.getKotlinFileList(new File("examples/src/test/kotlin"))); + + op.execute(); + + assertThat(tmpDir).isNotEmptyDirectory(); + assertThat(mainDir).isNotEmptyDirectory(); + assertThat(testDir).isNotEmptyDirectory(); + + var exampleClass = Path.of(mainDir.getAbsolutePath(), "com", "example", "Example.class").toFile(); + assertThat(exampleClass).exists(); + } finally { + FileUtils.deleteDirectory(tmpDir); + } } } \ No newline at end of file