@@ -67,7 +67,9 @@ public class InjectTransform extends Transform {
6767// Log.info("flavorAndBuildType ${flavorAndBuildType}")
6868 targetClasses = [];
6969 Map<String , List<Map<String , Object > > > modifyMatchMaps = project. hiBeaver. modifyMatchMaps;
70- targetClasses. addAll(modifyMatchMaps. keySet());
70+ if (modifyMatchMaps != null ) {
71+ targetClasses. addAll(modifyMatchMaps. keySet());
72+ }
7173 /**
7274 * 获取所有依赖的classPaths
7375 */
@@ -176,8 +178,9 @@ public class InjectTransform extends Transform {
176178 byte [] sourceClassBytes = IOUtils . toByteArray(inputStream);
177179 if (entryName. endsWith(" .class" )) {
178180 className = entryName. replace(" /" , " ." ). replace(" .class" , " " )
179- if (shouldModifyClass(className)) {
180- modifiedClassBytes = ModifyClassUtil . modifyClasses(className, sourceClassBytes, project. hiBeaver. modifyMatchMaps. get(className));
181+ def modifyMatchMaps = project. hiBeaver. modifyMatchMaps
182+ if (modifyMatchMaps != null && shouldModifyClass(className)) {
183+ modifiedClassBytes = ModifyClassUtil . modifyClasses(className, sourceClassBytes, modifyMatchMaps. get(className));
181184 }
182185 }
183186 if (modifiedClassBytes == null ) {
@@ -200,27 +203,29 @@ public class InjectTransform extends Transform {
200203 * @return
201204 */
202205 public static boolean isJarNeedModify (File jarFile ) {
203- if (jarFile) {
204- boolean modified = false ;
205- /**
206- * 读取原jar
207- */
208- def file = new JarFile (jarFile);
209- Enumeration enumeration = file. entries();
210- while (enumeration. hasMoreElements()) {
211- JarEntry jarEntry = (JarEntry ) enumeration. nextElement();
212- String entryName = jarEntry. getName();
213- String className
214- if (entryName. endsWith(" .class" )) {
215- className = entryName. replace(" /" , " ." ). replace(" .class" , " " )
216- if (shouldModifyClass(className)) {
217- modified = true ;
206+ boolean modified = false ;
207+ if (targetClasses != null && targetClasses. size() > 0 ) {
208+ if (jarFile) {
209+ /**
210+ * 读取原jar
211+ */
212+ def file = new JarFile (jarFile);
213+ Enumeration enumeration = file. entries();
214+ while (enumeration. hasMoreElements()) {
215+ JarEntry jarEntry = (JarEntry ) enumeration. nextElement();
216+ String entryName = jarEntry. getName();
217+ String className
218+ if (entryName. endsWith(" .class" )) {
219+ className = entryName. replace(" /" , " ." ). replace(" .class" , " " )
220+ if (shouldModifyClass(className)) {
221+ modified = true ;
222+ }
218223 }
219224 }
225+ file. close();
220226 }
221- file. close();
222- return modified;
223227 }
228+ return modified;
224229 }
225230
226231 private static void writeStreamWithBuffer (InputStream inputStream , OutputStream out ) {
0 commit comments