Skip to content

Commit f69840d

Browse files
committed
Pin to the shadow plugin 4.0.4 and pull in enough internal classes to compile and run
There are some object/class conflicts between the "stock" commons compression code, and the vendored under shadow.* For simplicity's sake, just taking everything from the shadow. namespace instead of fighting these silly objects
1 parent 235124e commit f69840d

File tree

4 files changed

+48
-47
lines changed

4 files changed

+48
-47
lines changed

jar-plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies {
2020
/*
2121
* NOTE: version 5.0.0 of the shadow plugin supports only Gradle 5.x and later
2222
*/
23-
compile 'com.github.jengelman.gradle.plugins:shadow:[4.0.2,5.0)'
23+
compile 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
2424
compile 'org.codehaus.plexus:plexus-utils:[3.2.0,3.3)'
2525
compile 'org.apache.commons:commons-io:1.3.2'
2626
compile 'org.ow2.asm:asm-commons:[6.1,6.99)'

jar-plugin/src/main/groovy/com/github/jrubygradle/jar/JRubyJar.groovy

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.github.jrubygradle.jar
22

3-
import com.github.jengelman.gradle.plugins.shadow.internal.DefaultZipCompressor
3+
import com.github.jengelman.gradle.plugins.shadow.internal.GradleVersionUtil
44
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
55
import com.github.jrubygradle.JRubyPrepare
66
import com.github.jrubygradle.jar.internal.JRubyDirInfoTransformer
77
import com.github.jrubygradle.jar.internal.JRubyJarCopyAction
88
import groovy.transform.PackageScope
9-
import org.apache.tools.zip.ZipOutputStream
109
import org.gradle.api.InvalidUserDataException
1110
import org.gradle.api.artifacts.Configuration
1211
import org.gradle.api.file.DuplicatesStrategy
1312
import org.gradle.api.internal.file.copy.CopyAction
1413
import org.gradle.api.tasks.Input
14+
import org.gradle.api.tasks.Internal
1515
import org.gradle.api.tasks.Optional
1616
import org.gradle.api.tasks.StopExecutionException
1717
import org.gradle.api.tasks.bundling.Jar
18-
import org.gradle.api.tasks.bundling.ZipEntryCompression
1918

2019
/**
2120
* JRubyJar creates a Java Archive with Ruby code packed inside of it.
@@ -241,6 +240,7 @@ class JRubyJar extends Jar {
241240
appendix = 'jruby'
242241
/* Make sure our default configuration is present regardless of whether we use it or not */
243242
prepareTask = project.task("prepare${prepareNameForSuffix(name)}", type: JRubyPrepare)
243+
versionUtil = new GradleVersionUtil(getProject().getGradle().getGradleVersion())
244244
dependsOn prepareTask
245245

246246
// TODO get rid of this and try to adjust the CopySpec for the gems
@@ -293,20 +293,21 @@ class JRubyJar extends Jar {
293293
return new JRubyJarCopyAction(getArchivePath(),
294294
getInternalCompressor(),
295295
null, /* DocumentationRegistry */
296+
'utf-8', /* encoding */
296297
[new JRubyDirInfoTransformer()], /* transformers */
297298
[], /* relocators */
298-
mainSpec.buildRootResolver().getPatternSet())
299+
mainSpec.buildRootResolver().getPatternSet(), /* patternSet */
300+
versionUtil, /* util */
301+
false, /* preserveFileTimestamps */
302+
false, /* minimizeJar */
303+
null /* unusedTracker */
304+
)
305+
299306
}
300307

308+
@Internal
301309
protected ZipCompressor getInternalCompressor() {
302-
switch (entryCompression) {
303-
case ZipEntryCompression.DEFLATED:
304-
return new DefaultZipCompressor(this.zip64, ZipOutputStream.DEFLATED)
305-
case ZipEntryCompression.STORED:
306-
return new DefaultZipCompressor(this.zip64, ZipOutputStream.STORED)
307-
default:
308-
throw new IllegalArgumentException(String.format('Unknown Compression type %s', entryCompression))
309-
}
310+
return versionUtil.getInternalCompressor(getEntryCompression(), this)
310311
}
311312

312313
/**
@@ -328,4 +329,5 @@ class JRubyJar extends Jar {
328329
protected String embeddedJRubyMainsVersion = DEFAULT_JRUBY_MAINS
329330
protected String jarConfiguration = DEFAULT_JRUBYJAR_CONFIG
330331
protected String jarMainClass
332+
protected GradleVersionUtil versionUtil
331333
}

jar-plugin/src/main/groovy/com/github/jrubygradle/jar/internal/JRubyDirInfoTransformer.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.nio.file.Files
44
import java.nio.file.Path
55
import java.nio.file.Paths
66

7-
import org.apache.tools.zip.ZipEntry
7+
import shadow.org.apache.tools.zip.ZipEntry
88
import org.codehaus.plexus.util.IOUtil
99
import org.gradle.api.file.FileTreeElement
1010

jar-plugin/src/main/groovy/com/github/jrubygradle/jar/internal/JRubyJarCopyAction.groovy

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ package com.github.jrubygradle.jar.internal
77
*/
88

99
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
1012
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
1113
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
1214
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
1315
import groovy.util.logging.Slf4j
1416
import org.apache.commons.io.FilenameUtils
1517
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
2123
import org.gradle.api.Action
2224
import org.gradle.api.GradleException
2325
import org.gradle.api.UncheckedIOException
@@ -26,10 +28,11 @@ import org.gradle.api.file.FileTreeElement
2628
import org.gradle.api.file.RelativePath
2729
import org.gradle.api.internal.DocumentationRegistry
2830
import org.gradle.api.internal.file.CopyActionProcessingStreamAction
31+
import org.gradle.api.internal.file.DefaultFileTreeElement
2932
import org.gradle.api.internal.file.copy.CopyAction
3033
import org.gradle.api.internal.file.copy.CopyActionProcessingStream
3134
import org.gradle.api.internal.file.copy.FileCopyDetailsInternal
32-
import org.gradle.api.tasks.WorkResults
35+
import org.gradle.api.specs.Spec
3336
import org.gradle.api.tasks.WorkResult
3437
import org.gradle.api.tasks.bundling.Zip
3538
import org.gradle.api.tasks.util.PatternSet
@@ -46,7 +49,7 @@ import java.util.zip.ZipException
4649
*
4750
* This class, in its current form is really just a big copy and paste of the
4851
* 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>
5053
* with one notable exception, it disables the behavior of unzipping nested
5154
* archives when creating the resulting archive.
5255
*
@@ -55,25 +58,26 @@ import java.util.zip.ZipException
5558
* support the same behavior in a less hackish way.
5659
*/
5760
@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
6065

6166
private final File zipFile
6267
private final ZipCompressor compressor
6368
private final DocumentationRegistry documentationRegistry
6469
private final List<Transformer> transformers
6570
private final List<Relocator> relocators
6671
private final PatternSet patternSet
67-
private final ShadowStats stats
6872
private final String encoding
6973
private final GradleVersionUtil versionUtil
7074
private final boolean preserveFileTimestamps
7175
private final boolean minimizeJar
7276
private final UnusedTracker unusedTracker
7377

74-
ShadowCopyAction(File zipFile, ZipCompressor compressor, DocumentationRegistry documentationRegistry,
78+
JRubyJarCopyAction(File zipFile, ZipCompressor compressor, DocumentationRegistry documentationRegistry,
7579
String encoding, List<Transformer> transformers, List<Relocator> relocators,
76-
PatternSet patternSet, ShadowStats stats, GradleVersionUtil util,
80+
PatternSet patternSet, GradleVersionUtil util,
7781
boolean preserveFileTimestamps, boolean minimizeJar, UnusedTracker unusedTracker) {
7882

7983
this.zipFile = zipFile
@@ -82,7 +86,6 @@ class ShadowCopyAction implements CopyAction {
8286
this.transformers = transformers
8387
this.relocators = relocators
8488
this.patternSet = patternSet
85-
this.stats = stats
8689
this.encoding = encoding
8790
this.versionUtil = util
8891
this.preserveFileTimestamps = preserveFileTimestamps
@@ -122,7 +125,7 @@ class ShadowCopyAction implements CopyAction {
122125
void execute(ZipOutputStream outputStream) {
123126
try {
124127
stream.process(new StreamAction(outputStream, encoding, transformers, relocators, patternSet,
125-
unusedClasses, stats))
128+
unusedClasses))
126129
processTransformers(outputStream)
127130
} catch (Exception e) {
128131
log.error('ex', e)
@@ -164,11 +167,11 @@ class ShadowCopyAction implements CopyAction {
164167
private static <T extends Closeable> void withResource(T resource, Action<? super T> action) {
165168
try {
166169
action.execute(resource)
167-
} catch(Throwable t) {
170+
} catch (Throwable t) {
168171
try {
169172
resource.close()
170173
} catch (IOException e) {
171-
// Ignored
174+
log.debug("Dropping ignored exception ${e}")
172175
}
173176
throw UncheckedException.throwAsUncheckedException(t)
174177
}
@@ -198,7 +201,9 @@ class ShadowCopyAction implements CopyAction {
198201
}
199202
}
200203

201-
protected void visitDir(FileCopyDetails dirDetails) {}
204+
@SuppressWarnings(['UnusedMethodParameter', 'EmptyMethodInAbstractClass'])
205+
protected void visitDir(FileCopyDetails dirDetails) {
206+
}
202207

203208
protected abstract void visitFile(FileCopyDetails fileDetails)
204209
}
@@ -211,21 +216,18 @@ class ShadowCopyAction implements CopyAction {
211216
private final RelocatorRemapper remapper
212217
private final PatternSet patternSet
213218
private final Set<String> unused
214-
private final ShadowStats stats
215219

216-
private Set<String> visitedFiles = new HashSet<String>()
220+
private final Set<String> visitedFiles = [] as Set
217221

218222
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) {
221224
this.zipOutStr = zipOutStr
222225
this.transformers = transformers
223226
this.relocators = relocators
224-
this.remapper = new RelocatorRemapper(relocators, stats)
227+
this.remapper = new RelocatorRemapper(relocators, null)
225228
this.patternSet = patternSet
226229
this.unused = unused
227-
this.stats = stats
228-
if(encoding != null) {
230+
if (encoding != null) {
229231
this.zipOutStr.setEncoding(encoding)
230232
}
231233
}
@@ -264,13 +266,12 @@ class ShadowCopyAction implements CopyAction {
264266
}
265267

266268
private void processArchive(FileCopyDetails fileDetails) {
267-
stats.startJar()
268269
ZipFile archive = new ZipFile(fileDetails.file)
269270
try {
270271
List<ArchiveFileTreeElement> archiveElements = archive.entries.collect {
271272
new ArchiveFileTreeElement(new RelativeArchivePath(it))
272273
}
273-
Spec<FileTreeElement> patternSpec = patternSet.getAsSpec()
274+
Spec<FileTreeElement> patternSpec = patternSet.asSpec
274275
List<ArchiveFileTreeElement> filteredArchiveElements = archiveElements.findAll { ArchiveFileTreeElement archiveElement ->
275276
patternSpec.isSatisfiedBy(archiveElement.asFileTreeElement())
276277
}
@@ -282,7 +283,6 @@ class ShadowCopyAction implements CopyAction {
282283
} finally {
283284
archive.close()
284285
}
285-
stats.finishJar()
286286
}
287287

288288
private void visitArchiveDirectory(RelativeArchivePath archiveDir) {
@@ -293,7 +293,7 @@ class ShadowCopyAction implements CopyAction {
293293
}
294294

295295
private void visitArchiveFile(ArchiveFileTreeElement archiveFile, ZipFile archive) {
296-
def archiveFilePath = archiveFile.relativePath
296+
RelativeArchivePath archiveFilePath = archiveFile.relativePath
297297
if (archiveFile.classFile || !isTransformable(archiveFile)) {
298298
if (recordVisit(archiveFilePath) && !isUnused(archiveFilePath.entry.name)) {
299299
if (!remapper.hasRelocators() || !archiveFile.classFile) {
@@ -432,7 +432,6 @@ class ShadowCopyAction implements CopyAction {
432432
.path(mappedPath)
433433
.is(is)
434434
.relocators(relocators)
435-
.stats(stats)
436435
.build()
437436
)
438437
} finally {
@@ -462,11 +461,10 @@ class ShadowCopyAction implements CopyAction {
462461
RelativeArchivePath getParent() {
463462
if (!segments || segments.length == 1) {
464463
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)))
469464
}
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)))
470468
}
471469
}
472470

@@ -482,6 +480,7 @@ class ShadowCopyAction implements CopyAction {
482480
return archivePath.classFile
483481
}
484482

483+
@SuppressWarnings(['GetterMethodCouldBeProperty'])
485484
@Override
486485
File getFile() {
487486
return null

0 commit comments

Comments
 (0)