1
1
package com.github.jrubygradle.jar.internal
2
2
3
+ import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
4
+
3
5
/*
4
6
* This source code is derived from Apache 2.0 licensed software copyright John
5
7
* Engelman (https://github.com/johnrengelman) and was originally ported from this
6
8
* repository: https://github.com/johnrengelman/shadow
7
9
*/
8
10
9
- import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
10
11
import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker
11
12
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
12
13
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
13
14
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
14
15
import groovy.util.logging.Slf4j
15
16
import org.apache.commons.io.FilenameUtils
16
17
import org.apache.commons.io.IOUtils
17
- import shadow.org.apache.tools.zip.UnixStat
18
- import shadow.org.apache.tools.zip.Zip64RequiredException
19
- import shadow.org.apache.tools.zip.ZipEntry
20
- import shadow.org.apache.tools.zip.ZipFile
21
- import shadow.org.apache.tools.zip.ZipOutputStream
22
18
import org.gradle.api.Action
23
19
import org.gradle.api.GradleException
24
20
import org.gradle.api.UncheckedIOException
@@ -40,6 +36,11 @@ import org.objectweb.asm.ClassReader
40
36
import org.objectweb.asm.ClassVisitor
41
37
import org.objectweb.asm.ClassWriter
42
38
import org.objectweb.asm.commons.ClassRemapper
39
+ import shadow.org.apache.tools.zip.UnixStat
40
+ import shadow.org.apache.tools.zip.Zip64RequiredException
41
+ import shadow.org.apache.tools.zip.ZipEntry
42
+ import shadow.org.apache.tools.zip.ZipFile
43
+ import shadow.org.apache.tools.zip.ZipOutputStream
43
44
44
45
import java.util.zip.ZipException
45
46
@@ -58,7 +59,7 @@ import java.util.zip.ZipException
58
59
*/
59
60
@Slf4j
60
61
@SuppressWarnings ([' ParameterCount' , ' CatchException' , ' DuplicateStringLiteral' ,
61
- ' CatchThrowable' , ' VariableName' , ' UnnecessaryGString' , ' InvertedIfElse' ])
62
+ ' CatchThrowable' , ' VariableName' , ' UnnecessaryGString' , ' InvertedIfElse' ])
62
63
class JRubyJarCopyAction implements CopyAction {
63
64
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = (new GregorianCalendar (1980 , 1 , 1 , 0 , 0 , 0 )). timeInMillis
64
65
@@ -74,9 +75,9 @@ class JRubyJarCopyAction implements CopyAction {
74
75
private final UnusedTracker unusedTracker
75
76
76
77
JRubyJarCopyAction (File zipFile , ZipCompressor compressor , DocumentationRegistry documentationRegistry ,
77
- String encoding , List<Transformer > transformers , List<Relocator > relocators ,
78
- PatternSet patternSet ,
79
- boolean preserveFileTimestamps , boolean minimizeJar , UnusedTracker unusedTracker ) {
78
+ String encoding , List<Transformer > transformers , List<Relocator > relocators ,
79
+ PatternSet patternSet ,
80
+ boolean preserveFileTimestamps , boolean minimizeJar , UnusedTracker unusedTracker ) {
80
81
81
82
this . zipFile = zipFile
82
83
this . compressor = compressor
@@ -109,20 +110,13 @@ class JRubyJarCopyAction implements CopyAction {
109
110
unusedClasses = Collections . emptySet()
110
111
}
111
112
112
- final ZipOutputStream zipOutStr
113
-
114
- try {
115
- zipOutStr = compressor. createArchiveOutputStream(zipFile)
116
- } catch (Exception e) {
117
- throw new GradleException (" Could not create ZIP '${ zipFile.toString()} '" , e)
118
- }
119
-
120
113
try {
114
+ final ZipOutputStream zipOutStr = compressor. createArchiveOutputStream(zipFile)
121
115
withResource(zipOutStr, new Action<ZipOutputStream > () {
122
116
void execute (ZipOutputStream outputStream ) {
123
117
try {
124
118
stream. process(new StreamAction (outputStream, encoding, transformers, relocators, patternSet,
125
- unusedClasses))
119
+ unusedClasses))
126
120
processTransformers(outputStream)
127
121
} catch (Exception e) {
128
122
log. error(' ex' , e)
@@ -134,10 +128,12 @@ class JRubyJarCopyAction implements CopyAction {
134
128
} catch (UncheckedIOException e) {
135
129
if (e. cause instanceof Zip64RequiredException ) {
136
130
throw new Zip64RequiredException (
137
- String . format(" %s\n\n To build this archive, please enable the zip64 extension.\n See: %s" ,
138
- e. cause. message, documentationRegistry. getDslRefForProperty(Zip , " zip64" ))
131
+ String . format(" %s\n\n To build this archive, please enable the zip64 extension.\n See: %s" ,
132
+ e. cause. message, documentationRegistry. getDslRefForProperty(Zip , " zip64" ))
139
133
)
140
134
}
135
+ } catch (Exception e) {
136
+ throw new GradleException (" Could not create ZIP '${ zipFile.toString()} '" , e)
141
137
}
142
138
return WorkResults . didWork(true )
143
139
}
@@ -217,7 +213,7 @@ class JRubyJarCopyAction implements CopyAction {
217
213
private final Set<String > visitedFiles = [] as Set
218
214
219
215
StreamAction (ZipOutputStream zipOutStr , String encoding , List<Transformer > transformers ,
220
- List<Relocator > relocators , PatternSet patternSet , Set<String > unused ) {
216
+ List<Relocator > relocators , PatternSet patternSet , Set<String > unused ) {
221
217
this . zipOutStr = zipOutStr
222
218
this . transformers = transformers
223
219
this . relocators = relocators
@@ -260,7 +256,7 @@ class JRubyJarCopyAction implements CopyAction {
260
256
261
257
private boolean isUnused (String classPath ) {
262
258
final String className = FilenameUtils . removeExtension(classPath)
263
- .replace(' /' as char , ' .' as char )
259
+ .replace(' /' as char , ' .' as char )
264
260
final boolean result = unused. contains(className)
265
261
if (result) {
266
262
log. debug(" Dropping unused class: $className " )
@@ -354,11 +350,11 @@ class JRubyJarCopyAction implements CopyAction {
354
350
try {
355
351
String mappedPath = remapper. map(element. relativePath. pathString)
356
352
transformers. find { it. canTransformResource(element) }. transform(
357
- TransformerContext . builder()
358
- .path(mappedPath)
359
- .is(is)
360
- .relocators(relocators)
361
- .build()
353
+ TransformerContext . builder()
354
+ .path(mappedPath)
355
+ .is(is)
356
+ .relocators(relocators)
357
+ .build()
362
358
)
363
359
} finally {
364
360
is. close()
0 commit comments