Implemented validation of duplicate jar entries

This commit is contained in:
Miro Spönemann 2016-11-08 12:01:25 +01:00
parent b97a5ed574
commit be55c347df
3 changed files with 41 additions and 2 deletions

View file

@ -15,6 +15,7 @@ subprojects {
apply from: "${rootDir}/gradle/maven-deployment.gradle"
apply from: "${rootDir}/gradle/eclipse-project-layout.gradle"
apply from: "${rootDir}/gradle/manifest-gen.gradle"
apply from: "${rootDir}/gradle/validation.gradle"
group = 'org.eclipse.xtext'
}

View file

@ -8,10 +8,13 @@ def sourceDirs = ['src', 'xtend-gen', 'src-gen', 'emf-gen']
sourceSets {
configure(isTestProject? test : main) {
java.srcDirs = sourceDirs
java {
srcDirs = sourceDirs
include '**/*.java', '**/*.xtend'
}
resources {
srcDirs = sourceDirs
exclude '**/*.java', '**/*.xtendbin', '**/*.xtend', '**/*._trace'
exclude '**/*.java', '**/*.xtend', '**/*.xtendbin', '**/*._trace'
}
}
configure(isTestProject? main : test) {

35
gradle/validation.gradle Normal file
View file

@ -0,0 +1,35 @@
/*
* Validation of output artifacts to make sure they can be published.
*/
import java.util.jar.JarFile
def checkDuplicateEntries = { archive ->
def uniqueEntries = new HashSet()
def jarFile = new JarFile(archive)
def entries = jarFile.entries()
while (entries.hasMoreElements()) {
def entry = entries.nextElement()
if (!uniqueEntries.add(entry.name))
throw new GradleException("Duplicate entry ${entry} in archive ${archive.name}")
}
jarFile.close()
}
task validateJar {
dependsOn(jar)
inputs.file(jar.archivePath)
doLast {
checkDuplicateEntries(jar.archivePath)
}
}
check.dependsOn(validateJar)
task validateSourcesJar {
dependsOn(sourcesJar)
inputs.file(sourcesJar.archivePath)
doLast {
checkDuplicateEntries(sourcesJar.archivePath)
}
}
check.dependsOn(validateSourcesJar)