1
1
package com.github.jengelman.gradle.plugins.shadow.tasks
2
2
3
+ import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin
3
4
import com.github.jengelman.gradle.plugins.shadow.ShadowStats
4
5
import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
5
6
import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker
@@ -41,6 +42,7 @@ import org.objectweb.asm.ClassVisitor
41
42
import org.objectweb.asm.ClassWriter
42
43
import org.objectweb.asm.commons.ClassRemapper
43
44
45
+ import javax.annotation.Nonnull
44
46
import javax.annotation.Nullable
45
47
import java.util.zip.ZipException
46
48
@@ -59,11 +61,13 @@ class ShadowCopyAction implements CopyAction {
59
61
private final boolean preserveFileTimestamps
60
62
private final boolean minimizeJar
61
63
private final UnusedTracker unusedTracker
64
+ private final boolean allowModuleInfos
62
65
63
66
ShadowCopyAction (File zipFile , ZipCompressor compressor , DocumentationRegistry documentationRegistry ,
64
67
String encoding , List<Transformer > transformers , List<Relocator > relocators ,
65
68
PatternSet patternSet , ShadowStats stats ,
66
- boolean preserveFileTimestamps , boolean minimizeJar , UnusedTracker unusedTracker ) {
69
+ boolean preserveFileTimestamps , boolean minimizeJar , UnusedTracker unusedTracker ,
70
+ boolean allowModuleInfos ) {
67
71
68
72
this . zipFile = zipFile
69
73
this . compressor = compressor
@@ -76,6 +80,7 @@ class ShadowCopyAction implements CopyAction {
76
80
this . preserveFileTimestamps = preserveFileTimestamps
77
81
this . minimizeJar = minimizeJar
78
82
this . unusedTracker = unusedTracker
83
+ this . allowModuleInfos = allowModuleInfos
79
84
}
80
85
81
86
@Override
@@ -201,7 +206,17 @@ class ShadowCopyAction implements CopyAction {
201
206
private final Set<String > unused
202
207
private final ShadowStats stats
203
208
204
- private Map<String , Map > visitedFiles = new HashMap<> ()
209
+ private class VisitedFileInfo {
210
+ long size
211
+ RelativePath originJar
212
+
213
+ VisitedFileInfo (long size , @Nonnull RelativePath originJar ) {
214
+ this . size = size
215
+ this . originJar = originJar
216
+ }
217
+ }
218
+
219
+ private Map<String , VisitedFileInfo > visitedFiles = new HashMap<> ()
205
220
206
221
StreamAction (ZipOutputStream zipOutStr , String encoding , List<Transformer > transformers ,
207
222
List<Relocator > relocators , PatternSet patternSet , Set<String > unused ,
@@ -235,7 +250,7 @@ class ShadowCopyAction implements CopyAction {
235
250
originJar = new RelativePath (false )
236
251
}
237
252
238
- visitedFiles. put(path. toString(), [ size : size, originJar : originJar] )
253
+ visitedFiles. put(path. toString(), new VisitedFileInfo ( size, originJar) )
239
254
return true
240
255
}
241
256
@@ -312,37 +327,7 @@ class ShadowCopyAction implements CopyAction {
312
327
if (archiveFile. classFile || ! isTransformable(archiveFile)) {
313
328
String path = archiveFilePath. toString()
314
329
315
- if (path. endsWith(" module-info.class" )) {
316
- log. warn(" module-info collision" )
317
-
318
- def moduleFileName = " module-info"
319
- def moduleFileSuffix = " .class"
320
- File disassembleModFile = File . createTempFile(moduleFileName, moduleFileSuffix)
321
-
322
- try (InputStream is = archive. getInputStream(archiveFilePath. entry)) {
323
- try (OutputStream os = new FileOutputStream (disassembleModFile)) {
324
- IOUtils . copyLarge(is, os)
325
- }
326
- }
327
-
328
- ProcessBuilder processBuilder = new ProcessBuilder (" javap" , disassembleModFile. absolutePath)
329
- processBuilder. redirectErrorStream(true )
330
- Process process = processBuilder. start()
331
- InputStream inputStream = process. getInputStream()
332
- BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream))
333
- String line
334
-
335
- while ((line = reader. readLine()) != null ) {
336
- log. warn(line)
337
- }
338
-
339
- int exitCode = process. waitFor()
340
- if (exitCode != 0 ) {
341
- log. warn(" Process exited with code " + exitCode)
342
- }
343
-
344
- log. warn(" module-info collision end" )
345
- }
330
+ listModuleInfoOnDemand(path, archive, archiveFilePath)
346
331
347
332
if (recordVisit(path, archiveFileSize, archiveFilePath) && ! isUnused(archiveFilePath. entry. name)) {
348
333
if (! remapper. hasRelocators() || ! archiveFile. classFile) {
@@ -382,6 +367,52 @@ class ShadowCopyAction implements CopyAction {
382
367
}
383
368
}
384
369
370
+ /**
371
+ Information about the 'module-info.class' if it isn't excluded. Including can be done with
372
+ <code >allowModuleInfos()</code>, like this:
373
+ <pre ><code >
374
+ shadowJar {
375
+ ...
376
+ allowModuleInfos()
377
+ }
378
+ </code></pre>
379
+ Based on the discussion in issue 710: <a href =" https://github.com/GradleUp/shadow/issues/710" >GitHub Issue #710</a>.
380
+ */
381
+ private void listModuleInfoOnDemand (String path , ZipFile archive , RelativeArchivePath archiveFilePath ) {
382
+ if (path. endsWith(ShadowJavaPlugin . MODULE_INFO_CLASS ) && allowModuleInfos) {
383
+ log. warn(" ======== Warning: {}/{} contains module-info - Listing content ========" ,
384
+ RelativePath . parse(true , archive. name). lastName, path)
385
+
386
+ def moduleFileName = " module-info"
387
+ def moduleFileSuffix = " .class"
388
+ File disassembleModFile = File . createTempFile(moduleFileName, moduleFileSuffix)
389
+
390
+ try (InputStream is = archive. getInputStream(archiveFilePath. entry)) {
391
+ try (OutputStream os = new FileOutputStream (disassembleModFile)) {
392
+ IOUtils . copyLarge(is, os)
393
+ }
394
+ }
395
+
396
+ ProcessBuilder processBuilder = new ProcessBuilder (" javap" , disassembleModFile. absolutePath)
397
+ processBuilder. redirectErrorStream(true )
398
+ Process process = processBuilder. start()
399
+ InputStream inputStream = process. getInputStream()
400
+ BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream))
401
+
402
+ String line
403
+ while ((line = reader. readLine()) != null ) {
404
+ log. warn(line)
405
+ }
406
+
407
+ int exitCode = process. waitFor()
408
+ if (exitCode != 0 ) {
409
+ log. warn(" Process exited with code " + exitCode)
410
+ }
411
+
412
+ log. warn(" ======== module-info content listing end ========" )
413
+ }
414
+ }
415
+
385
416
private void addParentDirectories (RelativeArchivePath file ) {
386
417
if (file) {
387
418
addParentDirectories(file. parent)
0 commit comments