@@ -30,7 +30,6 @@ class JarTransformTask(
3030 private val tag = " JarTransformTask"
3131 override fun compute (): Boolean {
3232 jarInputList.forEach { jarInput ->
33-
3433 val md5 = DigestUtils .md5Hex(jarInput.file.absolutePath)
3534 val out = outputProvider.getContentLocation(
3635 md5, jarInput.contentTypes, jarInput.scopes, Format .JAR
@@ -50,36 +49,11 @@ class JarTransformTask(
5049 while (entry != null ) {
5150 val outEntry: ZipEntry = copyEntry(entry)
5251 if (! entry.isDirectory && entry.name.endsWith(" .class" )) {
53- val name = entry.name.removeSuffix(" .class" )
54- val separatorIndex = entry.name.lastIndexOf(File .separatorChar)
55- val packageName =
56- if (separatorIndex > - 1 )
57- entry.name
58- .substring(0 , separatorIndex)
59- .removePrefix(File .separator)
60- .removeSuffix(File .separator)
61- else " "
62- val isInnerClass = entry.name.contains(" $" )
63- val className =
64- if (separatorIndex > - 1 )
65- entry.name.substring(separatorIndex + 1 )
66- .removeSuffix(" .class" )
67- else
68- entry.name.removeSuffix(" .class" )
69-
70- val transformClassInfo = TransformClassInfo (
71- name,
72- packageName,
73- className,
74- jarInput.file.absolutePath,
75- out .absolutePath,
76- jarInput,
77- true ,
78- isInnerClass
79- )
52+ val transformClassInfo = buildTransformClassInfo(entry.name, jarInput, out )
8053 val bytes = IOUtils .toByteArray(jar)
8154 try {
82- val changedBytes = transForm.transformClass(transformClassInfo, bytes)
55+ val changedBytes =
56+ transForm.transformClass(transformClassInfo, bytes)
8357 if (changedBytes == null ) {
8458 outJar.putNextEntry(outEntry)
8559 IOUtils .write(bytes, outJar)
@@ -107,6 +81,40 @@ class JarTransformTask(
10781 return true
10882 }
10983
84+ private fun buildTransformClassInfo (
85+ entryName : String ,
86+ jarInput : JarInput ,
87+ out : File
88+ ): TransformClassInfo {
89+ val name = entryName.removeSuffix(" .class" )
90+ val separatorIndex = entryName.lastIndexOf(File .separatorChar)
91+ val packageName =
92+ if (separatorIndex > - 1 )
93+ entryName
94+ .substring(0 , separatorIndex)
95+ .removePrefix(File .separator)
96+ .removeSuffix(File .separator)
97+ else " "
98+ val isInnerClass = entryName.contains(" $" )
99+ val className =
100+ if (separatorIndex > - 1 )
101+ entryName.substring(separatorIndex + 1 )
102+ .removeSuffix(" .class" )
103+ else
104+ entryName.removeSuffix(" .class" )
105+
106+ return TransformClassInfo (
107+ name,
108+ packageName,
109+ className,
110+ jarInput.file.absolutePath,
111+ out .absolutePath,
112+ jarInput,
113+ true ,
114+ isInnerClass
115+ )
116+ }
117+
110118 private fun copyEntry (entry : ZipEntry ): ZipEntry {
111119 val newEntry = ZipEntry (entry.name)
112120 newEntry.comment = entry.comment
0 commit comments