diff --git a/.github/scripts/prepare-test-outputs-for-merge.sh b/.github/scripts/prepare-test-outputs-for-merge.sh index 8e27bb0c9..59a00698c 100755 --- a/.github/scripts/prepare-test-outputs-for-merge.sh +++ b/.github/scripts/prepare-test-outputs-for-merge.sh @@ -21,7 +21,8 @@ set -e -echo "Using Java ${1?Pass the Java version as the first argument to this script!}" +CI_JAVA_VERSION=${1?Pass the Java version as the first argument to this script!} +CI_OS=${2?Pass the OS name as the second argument to this script!} if ! command -v xsltproc > /dev/null 2>&1; then if [ -z ${CI+_} ]; then @@ -36,27 +37,27 @@ fi echo -e "\e[1;35mUpdating Surefire reports...\e[0m" surefire_prefix_xslt=$(mktemp --suffix=.xslt) -cat > "${surefire_prefix_xslt}" <<'EOF' - - - - - - - - - - - - - - - - +sed 's/^ //g' > "${surefire_prefix_xslt}" <<'EOF' + + + + + + + + + + + + + + + + EOF function find-all-surefire-reports() { @@ -73,8 +74,8 @@ function find-all-jacoco-reports() { for surefire_report in $(find-all-surefire-reports); do echo -e "\e[1;34mAdding Java version to test case names in ${surefire_report}...\e[0m" - new_surefire_report=${surefire_report/.xml/-java-${CI_JAVA_VERSION}.xml} - xsltproc --stringparam prefix "[Java-${CI_JAVA_VERSION}]" \ + new_surefire_report=${surefire_report/.xml/-java-${CI_JAVA_VERSION}-${CI_OS}.xml} + xsltproc --stringparam prefix "[Java-${CI_JAVA_VERSION}-${CI_OS}]" \ "${surefire_prefix_xslt}" "${surefire_report}" > "${new_surefire_report}" echo -e "\e[1;34mReplacing ${surefire_report} with ${new_surefire_report}\e[0m" rm "${surefire_report}" @@ -84,7 +85,7 @@ rm "${surefire_prefix_xslt}" echo -e "\e[1;35mUpdating Jacoco reports...\e[0m" for jacoco_report in $(find-all-jacoco-reports); do - new_jacoco_report="${jacoco_report/.xml/-java-${CI_JAVA_VERSION}.xml}" + new_jacoco_report="${jacoco_report/.xml/-java-${CI_JAVA_VERSION}-${CI_OS}.xml}" echo -e "\e[1;34mRenaming ${jacoco_report} to ${new_jacoco_report}\e[0m" mv "${jacoco_report}" "${new_jacoco_report}" done diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9855663df..e91ae2b77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,40 +35,56 @@ jobs: uses: github/codeql-action/analyze@v1 test: - name: Build and test (Java ${{ matrix.java-version }}) - runs-on: ubuntu-latest + name: Build (Java ${{ matrix.java-version }} | ${{ matrix.os }}) + runs-on: ${{ matrix.os }} strategy: matrix: + os: [ ubuntu-latest ] + build-script: [ ./mvnw ] java-version: [ 11, 12, 13, 14, 15, 16, 17, 18 ] + experimental: [ false ] + include: + - os: windows-latest + build-script: './mvnw.cmd' + java-version: 17 + experimental: true steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Initialize Java ${{ matrix.java-version }} + - name: Initialize JDK uses: actions/setup-java@v3 with: distribution: 'zulu' java-version: '${{ matrix.java-version }}' - - name: Build with Java ${{ matrix.java-version }} - run: |- - concurrency=$(($(nproc) * 10)) - ./mvnw -B -U -T${concurrency}C clean package \ - --no-transfer-progress \ - -Dcheckstyle.skip=true \ - -Dstyle.color=always \ - -Dmaven.artifact.threads=${concurrency} - - - name: Mark test and coverage reports as being for this Java version - run: ".github/scripts/prepare-test-outputs-for-merge.sh ${{ matrix.java-version }}" + - name: Compile and run tests + continue-on-error: ${{ matrix.experimental }} + run: >- + ${{ matrix.build-script }} + -B + -U + -T8C + --no-transfer-progress + '-Dcheckstyle.skip=true' + '-Dstyle.color=always' + '-Dmaven.artifact.threads=100' + clean package + + - name: Annotate test reports + if: always() + run: >- + .github/scripts/prepare-test-outputs-for-merge.sh + ${{ matrix.java-version }} + ${{ matrix.os }} - name: Archive Surefire reports uses: actions/upload-artifact@v2 if: always() with: - name: tests-java-${{ matrix.java-version }} + name: tests-java-${{ matrix.java-version }}-${{ matrix.os }} path: "**/target/surefire-reports/TEST-*.xml" retention-days: 5 @@ -85,7 +101,6 @@ jobs: needs: [ test ] runs-on: ubuntu-latest if: always() - steps: - name: Checkout repository uses: actions/checkout@v3 @@ -108,8 +123,7 @@ jobs: - name: Publish code coverage continue-on-error: true if: always() - run: >- - bash <(curl -s https://codecov.io/bash) + run: bash <(curl -s https://codecov.io/bash) checkstyle: name: Run Checkstyle @@ -125,13 +139,16 @@ jobs: java-version: '17' - name: Run Checkstyle - run: |- - concurrency=$(($(nproc) * 10)) - ./mvnw -B -U -T${concurrency}C clean package \ - --no-transfer-progress \ - -DskipTests=true \ - -Dstyle.color=always \ - -Dmaven.artifact.threads=${concurrency} + run: >- + ./mvnw + -B + -U + -T8C + --no-transfer-progress + -DskipTests=true + -Dstyle.color=always + -Dmaven.artifact.threads=100 + clean package javadoc: name: Generate JavaDocs @@ -151,14 +168,17 @@ jobs: java-version: '17' - name: Generate JavaDoc documentation - run: |- - concurrency=$(($(nproc) * 10)) - ./mvnw -B -U -T${concurrency}C clean compile javadoc:jar \ - --no-transfer-progress \ - -Dmaven.test.skip=true \ - -Dcheckstyle.skip=true \ - -Dstyle.color=always \ - -Dmaven.artifact.threads=${concurrency} + run: >- + ./mvnw + -B + -U + -T8C + --no-transfer-progress + -Dmaven.test.skip=true + -Dcheckstyle.skip=true + -Dstyle.color=always + -Dmaven.artifact.threads=100 + clean compile javadoc:jar - name: Archive JavaDoc artifacts uses: actions/upload-artifact@v2 diff --git a/.gitignore b/.gitignore index 8b9d2b6ce..9c27dd563 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# Maven Wrapper -/.mvn/wrapper/maven-wrapper.jar - # Build output build/ out/ diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 000000000..c1dd12f17 Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/examples/example-serviceloader-with-jpms/src/test/resources/logback-test.xml b/examples/example-serviceloader-with-jpms/src/test/resources/logback-test.xml index 2814f8b4b..c8a7930b6 100644 --- a/examples/example-serviceloader-with-jpms/src/test/resources/logback-test.xml +++ b/examples/example-serviceloader-with-jpms/src/test/resources/logback-test.xml @@ -7,7 +7,7 @@ - + diff --git a/examples/example-serviceloader/src/test/resources/logback-test.xml b/examples/example-serviceloader/src/test/resources/logback-test.xml index 2814f8b4b..c8a7930b6 100644 --- a/examples/example-serviceloader/src/test/resources/logback-test.xml +++ b/examples/example-serviceloader/src/test/resources/logback-test.xml @@ -7,7 +7,7 @@ - + diff --git a/java-compiler-testing/pom.xml b/java-compiler-testing/pom.xml index e2ee20008..154603050 100644 --- a/java-compiler-testing/pom.xml +++ b/java-compiler-testing/pom.xml @@ -62,12 +62,6 @@ test - - org.junit.platform - junit-platform-suite - test - - org.junit.jupiter junit-jupiter @@ -92,45 +86,10 @@ org.apache.maven.plugins maven-surefire-plugin - - - - default-test - test - - test - - - true - - - - - unit-tests - test - - test - - - - com.github.ascopes.jct.testing.UnitTestSuite - - - - - - integration-tests - test - - test - - - - com.github.ascopes.jct.testing.IntegrationTestSuite - - - - + + + true + diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/DiagnosticRepresentation.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/DiagnosticRepresentation.java index 4c3d1877a..bcbb7d29c 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/DiagnosticRepresentation.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/DiagnosticRepresentation.java @@ -182,7 +182,7 @@ private void appendPossibleUnderline(StringBuilder builder, int startOfLine, int builder .append(PADDING) .append(" ".repeat(lineNumberWidth)) - .append(" ยท "); + .append(" + "); for (int i = startOfLine; i < endOfLine; ++i) { builder.append(startOffset <= i && i <= endOffset ? '^' : ' '); diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/ParentPathLocationManager.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/ParentPathLocationManager.java index aaa6703f4..364f88f82 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/ParentPathLocationManager.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/ParentPathLocationManager.java @@ -77,7 +77,8 @@ public ModuleLocation getModuleLocationFor(String moduleName) { * @return the module location if known, or an empty optional otherwise. */ public Optional getModuleLocationFor(FileObject fileObject) { - var path = Path.of(fileObject.toUri()); + // TODO(ascopes): can we get non-path file objects here? + var path = ((PathJavaFileObject) fileObject).getPath(); return getRoots() .stream() diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/PathLocationManager.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/PathLocationManager.java index c9d4a6966..1c8525167 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/PathLocationManager.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/PathLocationManager.java @@ -229,7 +229,6 @@ public void addRamPaths(Collection paths) { */ public boolean contains(FileObject fileObject) { // TODO(ascopes): can we get non-path file objects here? - var path = ((PathJavaFileObject) fileObject).getPath(); // While we could just return `Files.isRegularFile` from the start, @@ -254,12 +253,6 @@ public boolean contains(FileObject fileObject) { * @throws IllegalArgumentException if an absolute-style path is provided. */ public Optional findFile(String path) { - var relativePath = Path.of(path); - - if (relativePath.isAbsolute()) { - throw new IllegalArgumentException("Cannot use absolute paths here"); - } - for (var root : roots) { var fullPath = root.resolve(path); diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/RamPath.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/RamPath.java index a76bd2bb3..ea0f97161 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/RamPath.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/paths/RamPath.java @@ -171,7 +171,7 @@ public RamPath createFile(Path filePath, String... lines) { * @throws UncheckedIOException if an IO error occurs */ public RamPath createFile(String fileName, byte[] content) { - return createFile(Path.of(fileName), content); + return createFile(path.resolve(fileName), content); } /** @@ -183,7 +183,7 @@ public RamPath createFile(String fileName, byte[] content) { * @throws UncheckedIOException if an IO error occurs */ public RamPath createFile(String fileName, String... lines) { - return createFile(Path.of(fileName), lines); + return createFile(path.resolve(fileName), lines); } /** @@ -249,7 +249,7 @@ public RamPath copyFromClassPath( String resource, String targetPath ) { - return copyFromClassPath(loader, resource, Path.of(targetPath)); + return copyFromClassPath(loader, resource, path.resolve(targetPath)); } /** @@ -344,7 +344,7 @@ public RamPath copyTreeFromClassPath( String packageName, String targetPath ) { - return copyTreeFromClassPath(loader, packageName, Path.of(targetPath)); + return copyTreeFromClassPath(loader, packageName, path.resolve(targetPath)); } /** @@ -372,7 +372,7 @@ public RamPath copyFrom(Path existingFile, Path targetPath) { * @throws UncheckedIOException if an IO error occurs. */ public RamPath copyFrom(Path existingFile, String targetPath) { - return copyFrom(existingFile, Path.of(targetPath)); + return copyFrom(existingFile, path.resolve(targetPath)); } /** @@ -416,7 +416,7 @@ public RamPath copyFrom(URL url, String targetPath) { * @throws UncheckedIOException if an IO error occurs. */ public RamPath copyFrom(InputStream input, String targetPath) { - return copyFrom(input, Path.of(targetPath)); + return copyFrom(input, path.resolve(targetPath)); } /** @@ -491,7 +491,7 @@ public FileVisitResult visitFile( * @throws UncheckedIOException if an IO error occurs. */ public RamPath copyTreeFrom(Path tree, String targetPath) { - return copyTreeFrom(tree, Path.of(targetPath)); + return copyTreeFrom(tree, path.resolve(targetPath)); } /** @@ -524,17 +524,17 @@ public String toString() { return uri.toString(); } - private Path makeRelativeToHere(Path path) { - // ToString is needed as JIMFS will fail on trying to make a relative path from a different - // provider. - if (path.isAbsolute()) { + private Path makeRelativeToHere(Path relativePath) { + if (relativePath.isAbsolute() && !relativePath.startsWith(path)) { throw new IllegalArgumentException( - "Cannot use absolute paths for the target path (" + path + ")"); + "Cannot use absolute paths for the target path (" + relativePath + ")"); } - return path.getFileSystem() == this.path.getFileSystem() - ? path.normalize() - : this.path.resolve(path.toString()).normalize(); + // ToString is needed as JIMFS will fail on trying to make a relative path from a different + // provider. + return relativePath.getFileSystem() == path.getFileSystem() + ? relativePath.normalize() + : path.resolve(relativePath.toString()).normalize(); } /** diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/IntegrationTestSuite.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/IntegrationTestSuite.java deleted file mode 100644 index 9767ea254..000000000 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/IntegrationTestSuite.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2022 Ashley Scopes - * - * 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 - * - * http://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 io.github.ascopes.jct.testing; - -import org.junit.platform.suite.api.SelectPackages; -import org.junit.platform.suite.api.Suite; -import org.junit.platform.suite.api.SuiteDisplayName; - -/** - * Suite to run integration tests under. - * - * @author Ashley Scopes - */ - -@SelectPackages("com.github.ascopes.jct.testing.integration") -@SuiteDisplayName("Integration Tests") -@Suite -@SuppressWarnings("NewClassNamingConvention") -class IntegrationTestSuite { -} diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/UnitTestSuite.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/UnitTestSuite.java deleted file mode 100644 index 3fa07763f..000000000 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/UnitTestSuite.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2022 Ashley Scopes - * - * 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 - * - * http://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 io.github.ascopes.jct.testing; - -import org.junit.platform.suite.api.SelectPackages; -import org.junit.platform.suite.api.Suite; -import org.junit.platform.suite.api.SuiteDisplayName; - -/** - * Suite to run unit tests under. - * - * @author Ashley Scopes - */ -@SelectPackages("com.github.ascopes.jct.testing.unit") -@SuiteDisplayName("Unit Tests") -@Suite -@SuppressWarnings("NewClassNamingConvention") -class UnitTestSuite { -} diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/integration/basic/BasicLegacyCompilationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/integration/basic/BasicLegacyCompilationTest.java index 29b4b01dd..7a18a01b0 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/integration/basic/BasicLegacyCompilationTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/testing/integration/basic/BasicLegacyCompilationTest.java @@ -45,7 +45,7 @@ void helloWorldJavac(int version) { "com/example/HelloWorld.java", "package com.example;", "public class HelloWorld {", - " public static void main(String[] args) {?", + " public static void main(String[] args) {", " System.out.println(\"Hello, World\");", " }", "}" diff --git a/java-compiler-testing/src/test/java/module-info.java b/java-compiler-testing/src/test/java/module-info.java index 496004537..8cb45d94f 100644 --- a/java-compiler-testing/src/test/java/module-info.java +++ b/java-compiler-testing/src/test/java/module-info.java @@ -25,10 +25,7 @@ requires transitive net.bytebuddy.agent; // required for mockito to work with JPMS. requires transitive org.assertj.core; requires transitive org.junit.jupiter; - requires transitive org.junit.platform.suite; requires org.mockito; requires org.mockito.junit.jupiter; requires org.slf4j; - - exports io.github.ascopes.jct.testing; } diff --git a/pom.xml b/pom.xml index 52832f21f..9b5bfeaf9 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,9 @@ 0.8.8 0.1.0 + + true +