Skip to content

Commit

Permalink
#318 WIP Use common directory for all integration tests
Browse files Browse the repository at this point in the history
and improve clean tasks (align with Gradle good practices)
  • Loading branch information
ascheman committed Aug 21, 2024
1 parent 802fac2 commit ba6d701
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 85 deletions.
47 changes: 32 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ File baseBuildDir = file("${project.rootDir}/build")
File mavenBuildRepo = new File(baseBuildDir, "maven-repo")
// end::mavenBuildRepo[]

tasks.register("cleanMavenBuildRepo", Delete) {
description "Clean intermediate Maven Repository '${mavenBuildRepo}'"
delete mavenBuildRepo
}

task signAll() {
doLast {
logger.quiet("Signed all artifacts for upload with JReleaser")
Expand Down Expand Up @@ -282,19 +287,33 @@ publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository.confi
}

final String INTEGRATION_TEST_DIRECTORY = "integration-test"
final String INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN = "${INTEGRATION_TEST_DIRECTORY}/gradle-plugin"
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"

static void cleanBuild(final File baseDirectory) {
File integrationTestBuildDir = new File(baseDirectory, "${Project.DEFAULT_BUILD_DIR_NAME}")
if (integrationTestBuildDir.exists()) {
integrationTestBuildDir.eachFileRecurse { file ->
file.delete()
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"
}
integrationTestBuildDir.deleteDir()
logger.debug "Script output: $result"
}
}
tasks.register("cleanIntegrationTestCommon", Delete) {
description("Deletes the common data for integration tests")

doLast {
delete(file(INTEGRATION_TEST_DIRECTORY_COMMON))
}
assert !integrationTestBuildDir.exists()
}
//clean.dependsOn(cleanIntegrationTestCommon)
integrationTestPrepare.mustRunAfter(cleanIntegrationTestCommon)

tasks.register("integrationTestGradlePluginOnly") {
group("Verification")
Expand All @@ -313,6 +332,7 @@ tasks.register("integrationTestGradlePluginOnly") {
}
}
integrationTestGradlePluginOnly.configure {
dependsOn(integrationTestPrepare)
mustRunAfter('publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository')
}
tasks.register("integrationTestGradlePlugin") {
Expand All @@ -326,10 +346,9 @@ tasks.register("cleanIntegrationTestGradlePlugin", Delete) {
description("Deletes the result directory from gradle-plugin integration tests")

doLast {
cleanBuild file(INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN)
delete(file(INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN))
}
}
clean.dependsOn cleanIntegrationTestGradlePlugin

tasks.register("integrationTestCliOnly") {
group("Verification")
Expand All @@ -345,7 +364,7 @@ tasks.register("integrationTestCliOnly") {
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/src/test/resources"
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 {
Expand All @@ -357,6 +376,7 @@ tasks.register("integrationTestCliOnly") {
}
}
integrationTestCliOnly.configure {
dependsOn(integrationTestPrepare)
mustRunAfter(':htmlSanityCheck-cli:installDist')
}
tasks.register("integrationTestCli") {
Expand All @@ -371,12 +391,9 @@ tasks.register("cleanIntegrationTestCli", Delete) {
description("Deletes the result directory from CLI integration tests")

doLast {
cleanBuild file(INTEGRATION_TEST_DIRECTORY_CLI)
delete(file(INTEGRATION_TEST_DIRECTORY_CLI))
}
}
//noinspection GroovyAssignabilityCheck
clean.dependsOn cleanIntegrationTestCli
//integrationTestCli.dependsOn cleanIntegrationTestCli
tasks.register("integrationTestOnly") {
group("Verification")
description("Run overall integration tests (only)")
Expand Down
96 changes: 96 additions & 0 deletions integration-test/common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
plugins {
id 'org.asciidoctor.jvm.convert' version '4.0.3'
}

repositories {
mavenCentral()
}

def projectRoot = "../.."
task copyReadmeResources(type: 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)
}
}

task buildReadmeRoot(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) {
group 'Verification'
description 'Convert root README for integration test'

sourceDir projectRoot
sources {
include 'README.adoc'
}
baseDirFollowsSourceFile()
outputDir file("${Project.DEFAULT_BUILD_DIR_NAME}/docs")
attributes (
"imagesdir": "images"
)
}
buildReadmeRoot.dependsOn(copyReadmeResources)

task buildReadmeGradlePlugin(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) {
group 'Verification'
description 'Convert Gradle Plugin README for integration test'

sourceDir projectRoot
sources {
include 'htmlSanityCheck-gradle-plugin/README.adoc'
}
baseDirFollowsSourceFile()
outputDir file("${Project.DEFAULT_BUILD_DIR_NAME}/docs")
attributes (
"imagesdir": "../images"
)
}
buildReadmeGradlePlugin.dependsOn(buildReadmeRoot)

task buildReadmeAll() {
group 'Verification'
description 'Convert all READMEs for integration test'
}
buildReadmeAll.dependsOn(buildReadmeRoot, buildReadmeGradlePlugin)
build.dependsOn(buildReadmeAll)

/*
* 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.
*
*/
30 changes: 30 additions & 0 deletions integration-test/common/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
rootProject.name = 'hsc-integration-test-common'

/*
* 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.
*
*/
Empty file.

This file was deleted.

Empty file.
76 changes: 10 additions & 66 deletions integration-test/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,85 +1,29 @@
plugins {
id 'org.aim42.htmlSanityCheck' version "${htmlSanityCheckVersion}"
id 'org.asciidoctor.jvm.convert' version '4.0.3'
}

repositories {
mavenCentral()
}

def projectRoot = "../.."
def sourceDirectory = "src/test/resources"
task copyReadmeResources(type: Copy) {
from projectRoot
include '*.properties'
into "build/docs"
doLast {
String linkPath = "build/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)
}
}

task buildDocs(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) {
sourceDir sourceDirectory
sources { include '*.adoc' }
baseDirFollowsSourceFile()
outputDir file("build/docs")

forkOptions JavaVersion.current() >= JavaVersion.VERSION_1_9
? { jvmArgs '--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED',
'--add-opens', 'java.base/java.io=ALL-UNNAMED'
}
: {}
}

task buildReadmeRoot(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) {
sourceDir projectRoot
sources {
include 'README.adoc'
}
baseDirFollowsSourceFile()
outputDir file("build/docs")
attributes (
"imagesdir": "images"
)
}
buildReadmeRoot.dependsOn(copyReadmeResources)
buildReadmeRoot.dependsOn(buildDocs)

task buildReadmeGradlePlugin(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) {
sourceDir projectRoot
sources {
include 'htmlSanityCheck-gradle-plugin/README.adoc'
}
baseDirFollowsSourceFile()
outputDir file("build/docs")
attributes (
"imagesdir": "../images"
)
}
buildReadmeGradlePlugin.dependsOn(buildReadmeRoot)
//buildReadmeGradlePlugin.dependsOn(copyReadmeResources)

File reports = file("${Project.DEFAULT_BUILD_DIR_NAME}/reports")
htmlSanityCheck {
sourceDir = file("../common/src/test/resources")
sourceDir = file("../common/${Project.DEFAULT_BUILD_DIR_NAME}/docs")

checkingResultsDir = file("build/reports")
checkingResultsDir = reports
failOnErrors = true

logger.quiet "HSC version: ${htmlSanityCheckVersion}"
logger.quiet "HSC sourceDir: ${sourceDir.absolutePath}"
logger.quiet "HSC checkingResultsDir: ${checkingResultsDir.absolutePath}"
}
htmlSanityCheck.dependsOn(buildDocs)
htmlSanityCheck.dependsOn(buildReadmeRoot)
htmlSanityCheck.dependsOn(buildReadmeGradlePlugin)

task clean() {
description "Clean (${reports}"
group 'CleanUp'
reports.deleteDir()
file('${Project.DEFAULT_BUILD_DIR_NAME}/test-results').deleteDir()
}

/*
* Copyright Gerd Aschemann and aim42 contributors.
Expand Down

0 comments on commit ba6d701

Please sign in to comment.