blob: b8eb387f462bb0014215a3fbbb9af48ebf2dc720 [file] [log] [blame]
import java.util.jar.JarEntry
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import java.util.zip.ZipOutputStream
dependencies {
sourceBundle group: 'org.springframework', name: 'spring-test', version: "${springframeworkVersion}"
}
task rewriteJar(dependsOn: 'bundlor') {
String jarFileName = file(buildDir.path + "/org.springframework.test-${springframeworkVersion}.jar").path
doLast() {
ZipFile jarFile = new ZipFile(jarFileName)
println "------------"
println "Cloning content of jar file ${jarFileName}:"
println "------------"
new ZipFile(jarFileName).entries().findAll{ !it.directory }.each { println it.name }
println "------------"
String cloneFileName = new File(jarFileName).path + "-clone"
FileOutputStream fos = new FileOutputStream(cloneFileName)
String manifest
jarFile.entries().findAll { it.name == "META-INF/MANIFEST.MF" }.each {
manifest = jarFile.getInputStream(it).text
}
println "------------"
println manifest
println "------------"
JarOutputStream jarOutputStream = new JarOutputStream(fos,
new java.util.jar.Manifest(new ByteArrayInputStream(manifest.getBytes(java.nio.charset.Charset.forName("UTF-8")))))
println "------------"
byte[] readBuffer = new byte[2156]
jarFile.entries().findAll { !it.directory && !(it.name == "META-INF/MANIFEST.MF") && !(it.name.contains("TransactionalTestExecutionListener")) }.each {
println "adding ${it.name} to ${cloneFileName}"
jarOutputStream.putNextEntry(new JarEntry(it.name))
jarOutputStream << jarFile.getInputStream(it)
}
jarOutputStream.finish()
println "finished writing ${cloneFileName}"
println "------------"
println "from ${cloneFileName} to ${jarFileName}"
println "within ${file(cloneFileName).parentFile.path} is ${file(cloneFileName).name}"
println "rename ${file(cloneFileName).name} -> ${file(jarFileName).name}"
delete file(jarFileName)
copy {
from file(file(cloneFileName).parentFile.path)
into file(file(cloneFileName).parentFile.path)
rename { String fileName ->
fileName.replace(file(cloneFileName).name, file(jarFileName).name)
}
}
delete file(cloneFileName)
println "------------"
println "Removed 'TransactionalTestExecutionListener' from content of jar file ${jarFileName}:"
println "------------"
new ZipFile(jarFileName).entries().findAll{ !it.directory }.each { println it.name }
println "------------"
}
}