jarTransformer

Read and Transform the contents of jar file entry in the jar file.

License

License

Categories

Categories

ORM Data
GroupId

GroupId

cn.nikeo.jar-transformer
ArtifactId

ArtifactId

jar-transformer
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

jarTransformer
Read and Transform the contents of jar file entry in the jar file.
Project URL

Project URL

https://github.com/nikeorever/jarTransformer
Source Code Management

Source Code Management

https://github.com/nikeorever/jarTransformer

Download jar-transformer

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.10

Project Modules

There are no modules declared in this project.

jarTransformer

Maven Central

Read and Transform the contents of jar file entry in the jar file.

Sample

 transformJar(File("input.jar"), File("output.jar")) { inputJarEntry, outputJarEntryInputStream ->
      when {
          inputJarEntry.isClassFile() -> {
              // handle class file
              val clazz = ClassPool().makeClass(outputJarEntryInputStream)
              // modify bytecode
              if (clazz.name == "androidx.activity.R") {
                  clazz.addField(CtField(CtClass.intType, "generated_int_field", clazz), "100")
              }
              clazz.toBytecode()
          }
          inputJarEntry.isDirectory -> {
              outputJarEntryInputStream.readBytes()
          }
          else -> {
              outputJarEntryInputStream.readBytes()
          }
      }
 }

Or Use DSL API:

 transformJarDsl(File("input.jar"), File("output.jar")) {
      handleClassEntry { outputJarEntryInputStream ->
          // handle class file
          val clazz = ClassPool().makeClass(outputJarEntryInputStream)
          // modify bytecode
          if (clazz.name == "androidx.activity.R") {
              clazz.addField(CtField(CtClass.intType, "generated_int_field", clazz), "100")
          }
          clazz.toBytecode()
      }
 }

Download

Gradle Kotlin Script

repositories {
    mavenCentral()
}

dependencies {
    implementation("cn.nikeo.jar-transformer:jar-transformer:1.0.0")
}

Maven

<dependency>
  <groupId>cn.nikeo.jar-transformer</groupId>
  <artifactId>jar-transformer</artifactId>
  <version>1.0.0</version>
</dependency>

License

Apache License, Version 2.0, (LICENSE or https://www.apache.org/licenses/LICENSE-2.0)

Versions

Version
1.0.0