Skip to content

Instantly share code, notes, and snippets.

@dsdstudio
Last active October 1, 2018 16:39
Show Gist options
  • Save dsdstudio/5054347 to your computer and use it in GitHub Desktop.
Save dsdstudio/5054347 to your computer and use it in GitHub Desktop.
gradle -> felix-ipojo bytecode manipulation
apply plugin: "osgi"
apply plugin: "java"
apply plugin: "maven"
version = "0.0.1"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.apache.felix:org.apache.felix.ipojo.manipulator:1.6.0"
}
}
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
repositories {
mavenCentral()
}
dependencies {
compile "org.apache.felix:org.apache.felix.main:4.2.0", "org.apache.felix:org.apache.felix.ipojo.annotations:1.6.0"
}
jar {
manifest {
instruction 'Export-Package','*'
}
}
jar.doLast {
org.apache.felix.ipojo.manipulator.Pojoization pojo = new org.apache.felix.ipojo.manipulator.Pojoization()
File jarfile = file(jar.archivePath)
File targetJarFile = file(jar.destinationDir.absolutePath +"/" + jar.baseName + "_out.jar")
if (!jarfile.exists()) throw new InvalidUserDataException("The specified bundle file does not exist: " + jarfile.absolutePath)
pojo.pojoization(jarfile, targetJarFile, (File) null)
pojo.getWarnings().each { s ->
println s
}
if (jarfile.delete()) {
if ( !targetJarFile.renameTo(jarfile) ) {
throw new InvalidUserDataException("Cannot rename the manipulated jar file");
}
}else {
throw new InvalidUserDataException("Cannot delete the input jar file")
}
}
@dsdstudio
Copy link
Author

$ gradle build 
or 
$ gradle jar 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment