-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for Java modules compatibility of JUnit 5 support
Unfortunately it is not trivial to test that the final artifacts work in a Java modules project. To keep the effort low we just add a test that catches the most probable error: The dependencies change and suddenly two artifacts comprising the JUnit 5 support export the same package. To simplify this even further we can just assume that each JUnit 5 artifact exports exactly one package and by asserting that this is exactly the expected package we effectively prevent collisions. If we use automatic module names we have to assume that artifacts will export all of their packages on the module path. Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
- Loading branch information
1 parent
ba452bf
commit ff3bc43
Showing
5 changed files
with
108 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
buildSrc/src/main/groovy/archunit.java-artifact-check-conventions.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import java.time.LocalDateTime | ||
import java.util.jar.JarFile | ||
import java.util.jar.Manifest | ||
|
||
def checkThirdParty = { JarFile jarFile -> | ||
assert jarFile.getEntry('com/tngtech/archunit/thirdparty/org/objectweb/asm/ClassVisitor.class') != null: 'ASM is missing from 3rd party' | ||
assert jarFile.getEntry('com/tngtech/archunit/thirdparty/org/objectweb/asm/asm.license') != null: 'ASM license is missing from 3rd party' | ||
assert jarFile.getEntry('com/tngtech/archunit/thirdparty/com/google/common/collect/ImmutableSet.class') != null: 'Guava is missing from 3rd party' | ||
} | ||
|
||
def checkNoThirdParty = { JarFile jarFile -> | ||
assert jarFile.getEntry('com/tngtech/archunit/thirdparty') == null: 'There exists a third party folder' | ||
} | ||
|
||
def checkNoIllegalJarEntries = { JarFile jarFile -> | ||
def illegalEntries = Collections.list(jarFile.entries()).findAll { | ||
!it.name.startsWith('com/tngtech/archunit/') && | ||
it.name != 'com/' && | ||
it.name != 'com/tngtech/' && | ||
!it.name.startsWith('META-INF/') | ||
} | ||
assert illegalEntries.empty: """ | ||
|There are invalid entries contained inside of release artifact ${new File(jarFile.name).name}: | ||
|-> ${illegalEntries.join("${System.lineSeparator()}-> ")}""".stripMargin().trim() | ||
} | ||
|
||
def checkManifest = { Manifest manifest -> | ||
println "Verifying correct Manifest of ${project.name}" | ||
|
||
def checkAttributes = { expected -> | ||
expected.each { key, value -> | ||
assert manifest.mainAttributes.getValue(key) == value | ||
} | ||
} | ||
checkAttributes([ | ||
'Specification-Title' : "ArchUnit - Module '${project.name}'", | ||
'Specification-Version' : version, | ||
'Specification-Vendor' : 'TNG Technology Consulting GmbH', | ||
'Implementation-Title' : "com.tngtech.${project.name.replace('-', '.')}", | ||
'Implementation-Version': version, | ||
'Implementation-Vendor' : 'TNG Technology Consulting GmbH', | ||
'Issue-Tracker' : 'https://github.com/TNG/ArchUnit/issues', | ||
'Documentation-URL' : 'https://github.com/TNG/ArchUnit', | ||
'Copyright' : "${LocalDateTime.now().year} TNG Technology Consulting GmbH", | ||
'License' : 'The Apache Software License, Version 2.0', | ||
'Automatic-Module-Name' : "com.tngtech.${project.name.replaceFirst('-', '.').replaceFirst('-', '.').replace('-', '')}" | ||
]) | ||
} | ||
|
||
ext.checkArtifactContent = { JarFile jarFile -> | ||
checkManifest(jarFile.manifest) | ||
if (project.repackaging.repackagesAsm) { | ||
println "Artifact ${project.name} is configured to repackage 3rd party libs -> checking existence of 3rd party package..." | ||
checkThirdParty(jarFile) | ||
} else { | ||
println "Artifact ${project.name} is configured to not repackage 3rd party libs -> checking absense of 3rd party package..." | ||
checkNoThirdParty(jarFile) | ||
} | ||
checkNoIllegalJarEntries(jarFile) | ||
} | ||
|
||
task checkArtifact { | ||
dependsOn(build) | ||
|
||
doLast { | ||
def jarFile = new JarFile(jar.archiveFile.get().getAsFile()) | ||
checkArtifactContent(jarFile) | ||
} | ||
} | ||
build.finalizedBy(checkArtifact) | ||
|
||
abstract class SinglePackageExportExtension { | ||
String exportedPackage | ||
} | ||
|
||
ext.singlePackageExport = extensions.create('singlePackageExport', SinglePackageExportExtension) | ||
|
||
task checkExportedPackage { | ||
dependsOn(build) | ||
doLast { | ||
def exportedPackage = project.singlePackageExport?.exportedPackage | ||
if (exportedPackage) { | ||
def jarFile = new JarFile(jar.archiveFile.get().getAsFile()) | ||
def packageEntries = Collections.list(jarFile.entries()) | ||
.findAll { it.name.endsWith('.class') } | ||
.collect { it.name.replaceAll('/[^/]*$', '') } | ||
.collect { it.replace('/', '.') } | ||
.unique() | ||
assert packageEntries == [exportedPackage]: "Project is configured to export only single package $exportedPackage" | ||
} | ||
} | ||
} | ||
build.finalizedBy(checkExportedPackage) |
69 changes: 2 additions & 67 deletions
69
buildSrc/src/main/groovy/archunit.java-release-check-conventions.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters