@@ -7,17 +7,19 @@ package com.github.jrubygradle.jar.internal
7
7
*/
8
8
9
9
import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
10
+ import com.github.jengelman.gradle.plugins.shadow.internal.GradleVersionUtil
11
+ import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker
10
12
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
11
13
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
12
14
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
13
15
import groovy.util.logging.Slf4j
14
16
import org.apache.commons.io.FilenameUtils
15
17
import org.apache.commons.io.IOUtils
16
- import org.apache.tools.zip.UnixStat
17
- import org.apache.tools.zip.Zip64RequiredException
18
- import org.apache.tools.zip.ZipEntry
19
- import org.apache.tools.zip.ZipFile
20
- import org.apache.tools.zip.ZipOutputStream
18
+ import shadow. org.apache.tools.zip.UnixStat
19
+ import shadow. org.apache.tools.zip.Zip64RequiredException
20
+ import shadow. org.apache.tools.zip.ZipEntry
21
+ import shadow. org.apache.tools.zip.ZipFile
22
+ import shadow. org.apache.tools.zip.ZipOutputStream
21
23
import org.gradle.api.Action
22
24
import org.gradle.api.GradleException
23
25
import org.gradle.api.UncheckedIOException
@@ -26,10 +28,11 @@ import org.gradle.api.file.FileTreeElement
26
28
import org.gradle.api.file.RelativePath
27
29
import org.gradle.api.internal.DocumentationRegistry
28
30
import org.gradle.api.internal.file.CopyActionProcessingStreamAction
31
+ import org.gradle.api.internal.file.DefaultFileTreeElement
29
32
import org.gradle.api.internal.file.copy.CopyAction
30
33
import org.gradle.api.internal.file.copy.CopyActionProcessingStream
31
34
import org.gradle.api.internal.file.copy.FileCopyDetailsInternal
32
- import org.gradle.api.tasks.WorkResults
35
+ import org.gradle.api.specs.Spec
33
36
import org.gradle.api.tasks.WorkResult
34
37
import org.gradle.api.tasks.bundling.Zip
35
38
import org.gradle.api.tasks.util.PatternSet
@@ -46,7 +49,7 @@ import java.util.zip.ZipException
46
49
*
47
50
* This class, in its current form is really just a big copy and paste of the
48
51
* shadow plugin's <a
49
- * href="https://github.com/johnrengelman/shadow/blob/51f2b5916edd7690dca5e89e8b3a8f330d435423 /src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy">ShadowCopyAction</a>.
52
+ * href="https://github.com/johnrengelman/shadow/blob/4.0.4 /src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy">ShadowCopyAction</a>
50
53
* with one notable exception, it disables the behavior of unzipping nested
51
54
* archives when creating the resulting archive.
52
55
*
@@ -55,25 +58,26 @@ import java.util.zip.ZipException
55
58
* support the same behavior in a less hackish way.
56
59
*/
57
60
@Slf4j
58
- class ShadowCopyAction implements CopyAction {
59
- static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = (new GregorianCalendar (1980 , 1 , 1 , 0 , 0 , 0 )). getTimeInMillis()
61
+ @SuppressWarnings ([' ParameterCount' , ' CatchException' , ' DuplicateStringLiteral' ,
62
+ ' CatchThrowable' , ' VariableName' , ' UnnecessaryGString' , ' InvertedIfElse' ])
63
+ class JRubyJarCopyAction implements CopyAction {
64
+ static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = (new GregorianCalendar (1980 , 1 , 1 , 0 , 0 , 0 )). timeInMillis
60
65
61
66
private final File zipFile
62
67
private final ZipCompressor compressor
63
68
private final DocumentationRegistry documentationRegistry
64
69
private final List<Transformer > transformers
65
70
private final List<Relocator > relocators
66
71
private final PatternSet patternSet
67
- private final ShadowStats stats
68
72
private final String encoding
69
73
private final GradleVersionUtil versionUtil
70
74
private final boolean preserveFileTimestamps
71
75
private final boolean minimizeJar
72
76
private final UnusedTracker unusedTracker
73
77
74
- ShadowCopyAction (File zipFile , ZipCompressor compressor , DocumentationRegistry documentationRegistry ,
78
+ JRubyJarCopyAction (File zipFile , ZipCompressor compressor , DocumentationRegistry documentationRegistry ,
75
79
String encoding , List<Transformer > transformers , List<Relocator > relocators ,
76
- PatternSet patternSet , ShadowStats stats , GradleVersionUtil util ,
80
+ PatternSet patternSet , GradleVersionUtil util ,
77
81
boolean preserveFileTimestamps , boolean minimizeJar , UnusedTracker unusedTracker ) {
78
82
79
83
this . zipFile = zipFile
@@ -82,7 +86,6 @@ class ShadowCopyAction implements CopyAction {
82
86
this . transformers = transformers
83
87
this . relocators = relocators
84
88
this . patternSet = patternSet
85
- this . stats = stats
86
89
this . encoding = encoding
87
90
this . versionUtil = util
88
91
this . preserveFileTimestamps = preserveFileTimestamps
@@ -122,7 +125,7 @@ class ShadowCopyAction implements CopyAction {
122
125
void execute (ZipOutputStream outputStream ) {
123
126
try {
124
127
stream. process(new StreamAction (outputStream, encoding, transformers, relocators, patternSet,
125
- unusedClasses, stats ))
128
+ unusedClasses))
126
129
processTransformers(outputStream)
127
130
} catch (Exception e) {
128
131
log. error(' ex' , e)
@@ -164,11 +167,11 @@ class ShadowCopyAction implements CopyAction {
164
167
private static <T extends Closeable > void withResource (T resource , Action<? super T> action ) {
165
168
try {
166
169
action. execute(resource)
167
- } catch (Throwable t) {
170
+ } catch (Throwable t) {
168
171
try {
169
172
resource. close()
170
173
} catch (IOException e) {
171
- // Ignored
174
+ log . debug( " Dropping ignored exception ${ e } " )
172
175
}
173
176
throw UncheckedException . throwAsUncheckedException(t)
174
177
}
@@ -198,7 +201,9 @@ class ShadowCopyAction implements CopyAction {
198
201
}
199
202
}
200
203
201
- protected void visitDir (FileCopyDetails dirDetails ) {}
204
+ @SuppressWarnings ([' UnusedMethodParameter' , ' EmptyMethodInAbstractClass' ])
205
+ protected void visitDir (FileCopyDetails dirDetails ) {
206
+ }
202
207
203
208
protected abstract void visitFile (FileCopyDetails fileDetails )
204
209
}
@@ -211,21 +216,18 @@ class ShadowCopyAction implements CopyAction {
211
216
private final RelocatorRemapper remapper
212
217
private final PatternSet patternSet
213
218
private final Set<String > unused
214
- private final ShadowStats stats
215
219
216
- private Set<String > visitedFiles = new HashSet< String > ()
220
+ private final Set<String > visitedFiles = [] as Set
217
221
218
222
StreamAction (ZipOutputStream zipOutStr , String encoding , List<Transformer > transformers ,
219
- List<Relocator > relocators , PatternSet patternSet , Set<String > unused ,
220
- ShadowStats stats ) {
223
+ List<Relocator > relocators , PatternSet patternSet , Set<String > unused ) {
221
224
this . zipOutStr = zipOutStr
222
225
this . transformers = transformers
223
226
this . relocators = relocators
224
- this . remapper = new RelocatorRemapper (relocators, stats )
227
+ this . remapper = new RelocatorRemapper (relocators, null )
225
228
this . patternSet = patternSet
226
229
this . unused = unused
227
- this . stats = stats
228
- if (encoding != null ) {
230
+ if (encoding != null ) {
229
231
this . zipOutStr. setEncoding(encoding)
230
232
}
231
233
}
@@ -264,13 +266,12 @@ class ShadowCopyAction implements CopyAction {
264
266
}
265
267
266
268
private void processArchive (FileCopyDetails fileDetails ) {
267
- stats. startJar()
268
269
ZipFile archive = new ZipFile (fileDetails. file)
269
270
try {
270
271
List<ArchiveFileTreeElement > archiveElements = archive. entries. collect {
271
272
new ArchiveFileTreeElement (new RelativeArchivePath (it))
272
273
}
273
- Spec<FileTreeElement > patternSpec = patternSet. getAsSpec()
274
+ Spec<FileTreeElement > patternSpec = patternSet. asSpec
274
275
List<ArchiveFileTreeElement > filteredArchiveElements = archiveElements. findAll { ArchiveFileTreeElement archiveElement ->
275
276
patternSpec. isSatisfiedBy(archiveElement. asFileTreeElement())
276
277
}
@@ -282,7 +283,6 @@ class ShadowCopyAction implements CopyAction {
282
283
} finally {
283
284
archive. close()
284
285
}
285
- stats. finishJar()
286
286
}
287
287
288
288
private void visitArchiveDirectory (RelativeArchivePath archiveDir ) {
@@ -293,7 +293,7 @@ class ShadowCopyAction implements CopyAction {
293
293
}
294
294
295
295
private void visitArchiveFile (ArchiveFileTreeElement archiveFile , ZipFile archive ) {
296
- def archiveFilePath = archiveFile. relativePath
296
+ RelativeArchivePath archiveFilePath = archiveFile. relativePath
297
297
if (archiveFile. classFile || ! isTransformable(archiveFile)) {
298
298
if (recordVisit(archiveFilePath) && ! isUnused(archiveFilePath. entry. name)) {
299
299
if (! remapper. hasRelocators() || ! archiveFile. classFile) {
@@ -432,7 +432,6 @@ class ShadowCopyAction implements CopyAction {
432
432
.path(mappedPath)
433
433
.is(is)
434
434
.relocators(relocators)
435
- .stats(stats)
436
435
.build()
437
436
)
438
437
} finally {
@@ -462,11 +461,10 @@ class ShadowCopyAction implements CopyAction {
462
461
RelativeArchivePath getParent () {
463
462
if (! segments || segments. length == 1 ) {
464
463
return null
465
- } else {
466
- // Parent is always a directory so add / to the end of the path
467
- String path = segments[0 .. -2 ]. join(' /' ) + ' /'
468
- return new RelativeArchivePath (setArchiveTimes(new ZipEntry (path)))
469
464
}
465
+ // Parent is always a directory so add / to the end of the path
466
+ String path = segments[0 .. -2 ]. join(' /' ) + ' /'
467
+ return new RelativeArchivePath (setArchiveTimes(new ZipEntry (path)))
470
468
}
471
469
}
472
470
@@ -482,6 +480,7 @@ class ShadowCopyAction implements CopyAction {
482
480
return archivePath. classFile
483
481
}
484
482
483
+ @SuppressWarnings ([' GetterMethodCouldBeProperty' ])
485
484
@Override
486
485
File getFile () {
487
486
return null
0 commit comments