From 673ff197c77f58c6adf96d0e889d6f9679261eef Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Sat, 17 Aug 2024 15:49:14 +0200 Subject: [PATCH] #318 Migrate integration-test to this subdirectory --- .github/workflows/test-java-os-mix.yml | 6 +- build.gradle | 138 ++++++------------------- integration-test/build.gradle | 135 ++++++++++++++++++++++++ integration-test/common/build.gradle | 31 +++--- integration-test/gradle.properties | 1 + integration-test/settings.gradle | 30 ++++++ 6 files changed, 211 insertions(+), 130 deletions(-) create mode 100644 integration-test/build.gradle create mode 120000 integration-test/gradle.properties create mode 100644 integration-test/settings.gradle diff --git a/.github/workflows/test-java-os-mix.yml b/.github/workflows/test-java-os-mix.yml index 7d96bcf2..69dc22ef 100644 --- a/.github/workflows/test-java-os-mix.yml +++ b/.github/workflows/test-java-os-mix.yml @@ -44,14 +44,16 @@ jobs: if: runner.os != 'Windows' run: | uname -a - ./gradlew integrationTestOnly --scan + cd integration-test + ../gradlew integrationTest --scan - name: Execute integration tests (Windows) if: runner.os == 'Windows' shell: pwsh run: | uname -a - cmd /c "echo off && gradlew.bat integrationTestOnly --scan" + cd integration-test + cmd /c "echo off && ..\gradlew.bat integrationTest --scan" - name: Collect state upon failure (On Unix) if: failure() && runner.os != 'Windows' diff --git a/build.gradle b/build.gradle index 8a30186c..480fe10e 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,8 @@ plugins { alias(libs.plugins.sonar) alias(libs.plugins.jreleaser) + + id 'com.dorongold.task-tree' version '4.0.0' } allprojects { @@ -61,7 +63,7 @@ tasks.register("cleanMavenBuildRepo", Delete) { delete mavenBuildRepo } -task signAll() { +tasks.register('signAll') { doLast { logger.quiet("Signed all artifacts for upload with JReleaser") } @@ -171,7 +173,7 @@ configure(subprojects) { licenses { license { name = 'The Apache License, Version 2.0' - url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + url = 'https://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { @@ -277,8 +279,7 @@ sonar { tasks.register("publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository") { group("Publishing") description("Publishes all publications to the local Maven repository") -} -publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository.configure { + dependsOn(":htmlSanityCheck-core:publishMavenJavaPublicationToMyLocalRepositoryForFullIntegrationTestsRepository", ":htmlSanityCheck-gradle-plugin:publishPluginMavenPublicationToMyLocalRepositoryForFullIntegrationTestsRepository", ":htmlSanityCheck-gradle-plugin:publishHtmlSanityCheckPluginMarkerMavenPublicationToMyLocalRepositoryForFullIntegrationTestsRepository" @@ -286,130 +287,49 @@ publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository.confi } final String INTEGRATION_TEST_DIRECTORY = "integration-test" -final String INTEGRATION_TEST_DIRECTORY_CLI = "${INTEGRATION_TEST_DIRECTORY}/cli" -final String INTEGRATION_TEST_DIRECTORY_COMMON = "${INTEGRATION_TEST_DIRECTORY}/common" -final String INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN = "${INTEGRATION_TEST_DIRECTORY}/gradle-plugin" -tasks.register("integrationTestPrepare") { - group("Verification") - description("Prepare integration tests data") - - doLast { - def result = exec { - workingDir INTEGRATION_TEST_DIRECTORY_COMMON - commandLine System.getProperty("os.name") ==~ /Windows.*/ - ? "..\\..\\gradlew.bat" - : "../../gradlew", "clean", "buildReadmeAll" - } - logger.debug "Script output: $result" - } -} -tasks.register("cleanIntegrationTestCommon", Delete) { - description("Deletes the common data for integration tests") - - doLast { - delete(file(INTEGRATION_TEST_DIRECTORY_COMMON)) - } -} -//clean.dependsOn(cleanIntegrationTestCommon) -integrationTestPrepare.mustRunAfter(cleanIntegrationTestCommon) - -tasks.register("integrationTestGradlePluginOnly") { +tasks.register("integrationTestOnly") { group("Verification") - description("Run gradle-plugin integration tests (only)") - - final File testIndex = new File(file(INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN), "${Project.DEFAULT_BUILD_DIR_NAME}/reports/index.html") - outputs.file testIndex + description("Perform all Integration Tests") doLast { def result = exec { - workingDir INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN - commandLine System.getProperty("os.name") ==~ /Windows.*/ ? "..\\..\\gradlew.bat" : "../../gradlew", "clean", "htmlSanityCheck", "-PhtmlSanityCheckVersion=${project.version}" + workingDir INTEGRATION_TEST_DIRECTORY + commandLine((System.getProperty("os.name") ==~ /Windows.*/ + ? "..\\gradlew.bat" + : "../gradlew"), + "integrationTest") } - logger.debug "Script output: $result" - assert testIndex.exists() + logger.debug "Script output: ${result}" } } -integrationTestGradlePluginOnly.configure { - dependsOn(integrationTestPrepare) - mustRunAfter('publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository') -} -tasks.register("integrationTestGradlePlugin") { +tasks.register("integrationTest") { group("Verification") - description("Run overall gradle-plugin integration tests (and publish first)") + description("Run overall integration tests") } -integrationTestGradlePlugin.dependsOn('publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository', - 'integrationTestGradlePluginOnly') -tasks.register("cleanIntegrationTestGradlePlugin", Delete) { +integrationTestOnly.mustRunAfter(publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository, + ':htmlSanityCheck-cli:installDist') +integrationTest.dependsOn(publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository, + ':htmlSanityCheck-cli:installDist', + integrationTestOnly +) +tasks.register("cleanIntegrationTest", Delete) { group("Build") - description("Deletes the result directory from gradle-plugin integration tests") - - doLast { - delete(file(INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN)) - } -} - -tasks.register("integrationTestCliOnly") { - group("Verification") - description("Run CLI integration tests (only)") - - final String BUILD_REPORTS_DIRECTORY = "${Project.DEFAULT_BUILD_DIR_NAME}/reports" - final File testIndex = new File(file(INTEGRATION_TEST_DIRECTORY_CLI), "${BUILD_REPORTS_DIRECTORY}/index.html") - - outputs.file testIndex + description("Perform clean for Integration Tests") doLast { def result = exec { - workingDir INTEGRATION_TEST_DIRECTORY_CLI - file(BUILD_REPORTS_DIRECTORY).mkdirs() - String hscScriptFileName = "../../htmlSanityCheck-cli/${Project.DEFAULT_BUILD_DIR_NAME}/install/hsc/bin/hsc" - String params = "-r ${BUILD_REPORTS_DIRECTORY} ../common/${Project.DEFAULT_BUILD_DIR_NAME}/docs" - if (System.getProperty("os.name") ==~ /Windows.*/) { - commandLine 'cmd', '/c', "echo off && ${hscScriptFileName.replace('/', '\\')}.bat ${params}" - } else { - commandLine 'sh', '-c', "${hscScriptFileName} ${params}" - } + workingDir INTEGRATION_TEST_DIRECTORY + commandLine((System.getProperty("os.name") ==~ /Windows.*/ + ? "..\\gradlew.bat" + : "../gradlew"), + "clean") } logger.debug "Script output: ${result}" - assert testIndex.exists() - } -} -integrationTestCliOnly.configure { - dependsOn(integrationTestPrepare) - mustRunAfter(':htmlSanityCheck-cli:installDist') -} -tasks.register("integrationTestCli") { - group("Verification") - description("Run overall CLI integration tests (and publish first)") -} -integrationTestCli.configure { - dependsOn(':htmlSanityCheck-cli:installDist', 'integrationTestCliOnly') -} -tasks.register("cleanIntegrationTestCli", Delete) { - group("Build") - description("Deletes the result directory from CLI integration tests") - - doLast { - delete(file(INTEGRATION_TEST_DIRECTORY_CLI)) } } -tasks.register("integrationTestOnly") { - group("Verification") - description("Run overall integration tests (only)") -} -integrationTestOnly.dependsOn( - 'integrationTestGradlePluginOnly', - 'integrationTestCliOnly' -) +clean.dependsOn(cleanIntegrationTest) -tasks.register("integrationTest") { - group("Verification") - description("Run overall integration tests") -} -integrationTest.dependsOn( - 'integrationTestGradlePlugin', - 'integrationTestCli' -) /* * Copyright Gernot Starke and aim42 contributors. diff --git a/integration-test/build.gradle b/integration-test/build.gradle new file mode 100644 index 00000000..38833ee7 --- /dev/null +++ b/integration-test/build.gradle @@ -0,0 +1,135 @@ +final String BUILD_DIRECTORY = "${Project.DEFAULT_BUILD_DIR_NAME}" + +version = htmlSanityCheckVersion + +final String INTEGRATION_TEST_DIRECTORY_COMMON = "common" +final String INTEGRATION_TEST_DIRECTORY_COMMON_BUILD = "common/${BUILD_DIRECTORY}" + +final static String gradleCall() { + return System.getProperty("os.name") ==~ /Windows.*/ + ? "..\\..\\gradlew.bat" + : "../../gradlew" +} + +tasks.register("cleanIntegrationTestCommon", Delete) { + group("Build") + description("Deletes the common data for integration tests") + + def filesToDelete + = files(INTEGRATION_TEST_DIRECTORY_COMMON_BUILD) + + delete(filesToDelete) + + outputs.upToDateWhen { + !filesToDelete.files.any { it.exists() } + } +} +tasks.register("integrationTestPrepare") { + group("Verification") + description("Prepare integration tests data") + + mustRunAfter(cleanIntegrationTestCommon) + + doLast { + def result = exec { + workingDir INTEGRATION_TEST_DIRECTORY_COMMON + commandLine (gradleCall(), "clean", "buildReadmeAll") + } + logger.debug "Script output: $result" + } +} + +final String INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN = "gradle-plugin" +final String INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN_BUILD = "gradle-plugin/${BUILD_DIRECTORY}" + +tasks.register("cleanIntegrationTestGradlePlugin", Delete) { + group("Build") + description("Deletes the result directory from gradle-plugin integration tests") + + def filesToDelete + = files(INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN_BUILD) + + delete(filesToDelete) + + outputs.upToDateWhen { + !filesToDelete.files.any { it.exists() } + } +} +tasks.register("integrationTestGradlePlugin") { + group("Verification") + description("Run gradle-plugin integration tests (only)") + + final String buildReportsDirectory = "${INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN_BUILD}/reports" + final File testIndex = new File(file(buildReportsDirectory), "index.html") + outputs.file testIndex + + dependsOn(integrationTestPrepare) + mustRunAfter(cleanIntegrationTestGradlePlugin) + + doLast { + def result = exec { + workingDir INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN + commandLine (gradleCall(), "clean", "htmlSanityCheck", "-PhtmlSanityCheckVersion=${project.version}") + } + logger.debug "Script output: $result" + assert testIndex.exists() + } +} + +final String INTEGRATION_TEST_DIRECTORY_CLI = "cli" +final String INTEGRATION_TEST_DIRECTORY_CLI_BUILD = "${INTEGRATION_TEST_DIRECTORY_CLI}/${BUILD_DIRECTORY}" + +tasks.register("cleanIntegrationTestCli", Delete) { + group("Build") + description("Deletes the result directory from CLI integration tests") + + def filesToDelete + = files(INTEGRATION_TEST_DIRECTORY_CLI_BUILD) + + delete(filesToDelete) + + outputs.upToDateWhen { + !filesToDelete.files.any { it.exists() } + } +} +tasks.register("integrationTestCli") { + group("Verification") + description("Run CLI integration tests (only)") + + final File buildReportsDirectory = file("${INTEGRATION_TEST_DIRECTORY_CLI_BUILD}/reports") + final File testIndex = new File(buildReportsDirectory, "index.html") + + outputs.file testIndex + + dependsOn(integrationTestPrepare) + mustRunAfter(cleanIntegrationTestCli) + + doLast { + def result = exec { + buildReportsDirectory.mkdirs() + final String hscScriptFileName = "../htmlSanityCheck-cli/${BUILD_DIRECTORY}/install/hsc/bin/hsc" + String params = "-r ${buildReportsDirectory} ${INTEGRATION_TEST_DIRECTORY_COMMON_BUILD}/docs" + if (System.getProperty("os.name") ==~ /Windows.*/) { + commandLine 'cmd', '/c', "echo off && ${hscScriptFileName.replace('/', '\\')}.bat ${params}" + } else { + commandLine 'sh', '-c', "${hscScriptFileName} ${params}" + } + } + logger.debug "Script output: ${result}" + assert testIndex.exists() + } +} + +tasks.register("integrationTest") { + group("Verification") + description("Run all integration tests (without any installations etc.)") + + dependsOn(integrationTestGradlePlugin, integrationTestCli) +} + +tasks.register("clean", Delete) { + group("Build") + description("Deletes all builds") + + dependsOn(cleanIntegrationTestCommon, cleanIntegrationTestGradlePlugin, cleanIntegrationTestCli) +} diff --git a/integration-test/common/build.gradle b/integration-test/common/build.gradle index e9f7d078..4ddc77e7 100644 --- a/integration-test/common/build.gradle +++ b/integration-test/common/build.gradle @@ -7,27 +7,20 @@ repositories { } def projectRoot = "../.." -task copyReadmeResources(type: Copy) { +tasks.register('copyReadmeResources', Copy) { group 'Verification' description 'Copy resources of READMEs for integration test' - from projectRoot - include '*.properties' - into "${Project.DEFAULT_BUILD_DIR_NAME}/docs" - doLast { - String linkPath = "${Project.DEFAULT_BUILD_DIR_NAME}/docs/images" - java.nio.file.Path target = java.nio.file.Paths.get("../../../../src/docs/images") - File linkFile = file(linkPath) - java.nio.file.Path link = linkFile.toPath() - logger.quiet("Creating symlink from '{}' to '{}'", target, link) - if (linkFile.exists()) { - linkFile.delete() - } - java.nio.file.Files.createSymbolicLink(link, target) + from(projectRoot) { + include '*.properties' + } + from("${projectRoot}/src/docs") { + include 'images/**' } + into "${Project.DEFAULT_BUILD_DIR_NAME}/docs" } -task buildReadmeRoot(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) { +tasks.register('buildReadmeRoot', org.asciidoctor.gradle.jvm.AsciidoctorTask) { group 'Verification' description 'Convert root README for integration test' @@ -37,13 +30,13 @@ task buildReadmeRoot(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) { } baseDirFollowsSourceFile() outputDir file("${Project.DEFAULT_BUILD_DIR_NAME}/docs") - attributes ( + attributes( "imagesdir": "images" ) } buildReadmeRoot.dependsOn(copyReadmeResources) -task buildReadmeGradlePlugin(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) { +tasks.register('buildReadmeGradlePlugin', org.asciidoctor.gradle.jvm.AsciidoctorTask) { group 'Verification' description 'Convert Gradle Plugin README for integration test' @@ -53,13 +46,13 @@ task buildReadmeGradlePlugin(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) { } baseDirFollowsSourceFile() outputDir file("${Project.DEFAULT_BUILD_DIR_NAME}/docs") - attributes ( + attributes( "imagesdir": "../images" ) } buildReadmeGradlePlugin.dependsOn(buildReadmeRoot) -task buildReadmeAll() { +tasks.register('buildReadmeAll') { group 'Verification' description 'Convert all READMEs for integration test' } diff --git a/integration-test/gradle.properties b/integration-test/gradle.properties new file mode 120000 index 00000000..7677fb73 --- /dev/null +++ b/integration-test/gradle.properties @@ -0,0 +1 @@ +../gradle.properties \ No newline at end of file diff --git a/integration-test/settings.gradle b/integration-test/settings.gradle new file mode 100644 index 00000000..78756f1c --- /dev/null +++ b/integration-test/settings.gradle @@ -0,0 +1,30 @@ +rootProject.name = 'hsc-integration-test' + +/* + * Copyright Gerd Aschemann and aim42 contributors. + * + * 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 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */