-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! add test for Java modules compatibility of JUnit 5 support
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
- Loading branch information
1 parent
606b737
commit 8a8d599
Showing
2 changed files
with
95 additions
and
90 deletions.
There are no files selected for viewing
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) |
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