@@ -30,7 +30,6 @@ class JarTransformTask(
30
30
private val tag = " JarTransformTask"
31
31
override fun compute (): Boolean {
32
32
jarInputList.forEach { jarInput ->
33
-
34
33
val md5 = DigestUtils .md5Hex(jarInput.file.absolutePath)
35
34
val out = outputProvider.getContentLocation(
36
35
md5, jarInput.contentTypes, jarInput.scopes, Format .JAR
@@ -50,36 +49,11 @@ class JarTransformTask(
50
49
while (entry != null ) {
51
50
val outEntry: ZipEntry = copyEntry(entry)
52
51
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 )
80
53
val bytes = IOUtils .toByteArray(jar)
81
54
try {
82
- val changedBytes = transForm.transformClass(transformClassInfo, bytes)
55
+ val changedBytes =
56
+ transForm.transformClass(transformClassInfo, bytes)
83
57
if (changedBytes == null ) {
84
58
outJar.putNextEntry(outEntry)
85
59
IOUtils .write(bytes, outJar)
@@ -107,6 +81,40 @@ class JarTransformTask(
107
81
return true
108
82
}
109
83
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
+
110
118
private fun copyEntry (entry : ZipEntry ): ZipEntry {
111
119
val newEntry = ZipEntry (entry.name)
112
120
newEntry.comment = entry.comment
0 commit comments