Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,15 @@ jobs:
run: ./gradlew runMavenTest -PtestJavaVersion=${{ matrix.test_java_version }} "-Porg.gradle.java.installations.paths=${{ env.test_jdk_path }}"
env:
JAVA_HOME: ${{ env.build_jdk_path }}
- name: Upload Maven integration test verification results
id: upload-results
uses: actions/upload-artifact@v7
if: always()
with:
name: maven-test-results-${{ matrix.os }}-java${{ matrix.test_java_version }}
path: archunit-maven-test/verification-results/
if-no-files-found: ignore
- name: Report artifact location
if: always() && steps.upload-results.outputs.artifact-url
run: |
echo "::notice title=Maven test results (logs & surefire XML)::${{ steps.upload-results.outputs.artifact-url }}"
Comment thread
schulzjo-tng marked this conversation as resolved.
2 changes: 2 additions & 0 deletions archunit-maven-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/src
/pom.xml
93 changes: 61 additions & 32 deletions archunit-maven-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ clean {
}
}

task initializeMavenTest {
def initializeMavenTest = tasks.register('initializeMavenTest') {
doLast {
verificationResultArchivePath.with {
deleteDir()
Expand All @@ -102,16 +102,12 @@ def mavenCommand = { String... params ->
}

def addMavenTest = { IntegrationTestConfig config ->
String prepareMavenTest = "prepareMavenTest${config.suffix}"
String executeRules = "executeRules${config.suffix}"
String verifyRules = "verifyRules${config.suffix}"
String cleanUpMavenTest = "cleanUpMavenTest${config.suffix}"
String runMavenTest = "runMavenTest${config.suffix}"
def mavenSurefirePlugin = libs.mavenSurefirePlugin.get()
def mavenCompilerPlugin = libs.mavenCompilerPlugin.get()

return {
tasks.create(name: prepareMavenTest, dependsOn: initializeMavenTest) {
def prepareMavenTest = tasks.register("prepareMavenTest${config.suffix}") {
dependsOn initializeMavenTest
doLast {
mavenPom.delete()
Files.copy(mavenPomTemplate.toPath(), mavenPom.toPath())
Expand Down Expand Up @@ -156,28 +152,51 @@ def addMavenTest = { IntegrationTestConfig config ->
}
}

def mavenExec = { closure ->
return {
workingDir projectDir
environment JAVA_HOME: jdkHome
delegate.with(closure)
def executeRules = tasks.register("executeRules${config.suffix}", Exec) {
dependsOn prepareMavenTest

def logStream
doFirst {
def logPath = new File(verificationResultArchivePath, config.identifier)
assert logPath.mkdir() || logPath.directory : "Couldn't create directory $logPath"
def logFile = new File(logPath, "${name}.log")
logStream = new FileOutputStream(logFile)
standardOutput = logStream
errorOutput = logStream
Comment thread
hankem marked this conversation as resolved.
println "\$ ${commandLine.join(" ")} > ${project.relativePath(logFile)}"
}
}

tasks.create(name: executeRules, type: Exec, dependsOn: prepareMavenTest).configure mavenExec {
workingDir projectDir
environment JAVA_HOME: jdkHome
commandLine mavenCommand('clean', 'test', '-P', 'execute-rules')

doLast {
if (logStream) {
logStream.close()
}
}
}

tasks.create(name: verifyRules, type: Exec, dependsOn: executeRules).configure mavenExec {
def verifyRules = tasks.register("verifyRules${config.suffix}", Exec) {
dependsOn executeRules

doFirst {
println "\$ ${commandLine.join(" ")}"
}

workingDir projectDir
environment JAVA_HOME: jdkHome
commandLine mavenCommand('surefire:test', '-P', 'verify-rules')
}

tasks.create(name: cleanUpMavenTest) {
def cleanUpMavenTest = tasks.register("cleanUpMavenTest${config.suffix}") {
doFirst {
def archivePath = new File(verificationResultArchivePath, config.identifier)
println "Copying test results to ${project.relativePath(archivePath)}"
copy {
from verificationResultOriginPath
include '**/*.xml'
into new File(verificationResultArchivePath, "${config.identifier}")
into archivePath
}
}
doLast {
Expand All @@ -187,23 +206,27 @@ def addMavenTest = { IntegrationTestConfig config ->
}
}

// Run cleanUp even if task fails
[tasks[prepareMavenTest], tasks[verifyRules], tasks[executeRules]]*.finalizedBy tasks[cleanUpMavenTest]
[prepareMavenTest, verifyRules, executeRules].each { taskProvider ->
taskProvider.configure { finalizedBy cleanUpMavenTest }
}

tasks.create(name: runMavenTest, dependsOn: [prepareMavenTest, executeRules, verifyRules, cleanUpMavenTest])
def runMavenTest = tasks.register("runMavenTest${config.suffix}") {
dependsOn prepareMavenTest, executeRules, verifyRules, cleanUpMavenTest
}

[prepareMavenTest, executeRules, verifyRules, cleanUpMavenTest, runMavenTest].each { taskName ->
tasks[taskName].onlyIf("requires Java ${config.minimumJavaVersion} or higher") {
config.supports(integrationTestJavaVersion)
[prepareMavenTest, executeRules, verifyRules, cleanUpMavenTest, runMavenTest].each { taskProvider ->
taskProvider.configure {
onlyIf("requires Java ${config.minimumJavaVersion} or higher") {
config.supports(integrationTestJavaVersion)
}
}
}

def executeRulesTask = tasks[executeRules]
gradle.projectsEvaluated {
def publishTasks = allprojects
def publishTasks = rootProject.allprojects
.findAll { it.findProperty('isReleaseProject') }
.collectMany { [it.publish, it.publishToMavenLocal] }
executeRulesTask.mustRunAfter(*publishTasks)
executeRules.configure { mustRunAfter(*publishTasks) }
}
}
}
Expand Down Expand Up @@ -265,14 +288,20 @@ integrationTestConfigs.each { config -> project.with(addMavenTest(config)) }

def suffixes = integrationTestConfigs*.suffix.sort()
[suffixes, suffixes.tail()].transpose().each { twoConsecutiveSuffixes ->
tasks["prepareMavenTest${twoConsecutiveSuffixes[1]}"].mustRunAfter(tasks["cleanUpMavenTest${twoConsecutiveSuffixes[0]}"])
tasks.named("prepareMavenTest${twoConsecutiveSuffixes[1]}").configure {
mustRunAfter tasks.named("cleanUpMavenTest${twoConsecutiveSuffixes[0]}")
}
}

tasks.register('runMavenTest') {
dependsOn integrationTestConfigs.collect { tasks.named("runMavenTest${it.suffix}") }
}

task runMavenTest
tasks.findAll { it.name ==~ /^runMavenTest.+/ }.each { runMavenTest.dependsOn it }
tasks.findAll { it.name ==~ /.*MavenTest.+/ }.each {
it.doFirst {
println "Running Maven Integration Test with JDK ${integrationTestJavaVersion} located at ${jdkHome}"
tasks.configureEach {
if (name ==~ /.*MavenTest.+/) {
doFirst {
println "Running Maven Integration Test with JDK ${integrationTestJavaVersion} located at ${jdkHome}"
}
}
}

Expand Down
15 changes: 1 addition & 14 deletions archunit-maven-test/verification/TestResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,7 @@ private void validateAllArchitectureFailures(Match testCaseTags) {
}

void assertMatchWith(GivenTestClasses givenTestClasses) {
Set<SingleTest> onlyGiven = difference(givenTestClasses.tests, failedArchitectureTests);
assertThat(onlyGiven).as("Tests that were expected to fail, but didn't").isEmpty();
Set<SingleTest> onlyFailed = difference(failedArchitectureTests, givenTestClasses.tests);
assertThat(onlyFailed).as("Tests that unexpectedly failed").isEmpty();
}

private <T> Set<T> difference(Set<T> set, Set<T> toSubtract) {
Set<T> result = new HashSet<>();
for (T elem : set) {
if (!toSubtract.contains(elem)) {
result.add(elem);
}
}
return result;
assertThat(failedArchitectureTests).as("actual failures").hasSameElementsAs(givenTestClasses.tests);
Comment thread
hankem marked this conversation as resolved.
}

void markProcessed(List<File> testReports) {
Expand Down
Loading