Skip to content

Commit 79941dc

Browse files
committed
Upgradle to Gradle 5.4.1 (#369)
- Replace Groovy `.collect` calls with `Transform.toList`.
1 parent c72b7e4 commit 79941dc

File tree

11 files changed

+72
-37
lines changed

11 files changed

+72
-37
lines changed

base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyPrepareGemsIntegrationSpec.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
131131
tasks.addAll(moreTasks)
132132
tasks.add('-i')
133133
tasks.add('-s')
134+
tasks.add('--refresh-dependencies')
134135
writeBuildFile()
135136
gradleRunner(tasks).build()
136137
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'com.gradle.build-scan' version '1.16'
2+
id 'com.gradle.build-scan' version '2.0.2'
33
id 'org.ysb33r.gradletest' version '2.0-rc.4' apply false
44
id 'com.jfrog.bintray' version '1.8.4' apply false
55
id 'org.ajoberstar.github-pages' version '1.2.0' apply false

core-plugin/src/main/groovy/com/github/jrubygradle/api/gems/GemUtils.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class GemUtils {
134134
* See:
135135
* https://gikhub.com/jruby-gradle/jruby-gradle-plugin/issues/341
136136
*/
137-
gemsToProcess.collect { it }.reverse().each { File gem ->
137+
gemsToProcess.toList().reverse().each { File gem ->
138138
args gem
139139
}
140140

core-plugin/src/main/groovy/com/github/jrubygradle/api/gems/GemVersion.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.jrubygradle.api.gems
22

3+
import com.github.jrubygradle.internal.core.Transform
34
import groovy.transform.CompileDynamic
45
import groovy.transform.CompileStatic
56
import groovy.util.logging.Slf4j
@@ -132,14 +133,14 @@ class GemVersion implements Comparable<GemVersion> {
132133
* @return List of GEM versions. Can be empty if all requirements evaluate to {@link #NO_VERSION}.
133134
*/
134135
static List<GemVersion> gemVersionsFromMultipleGemRequirements(String multipleRequirements) {
135-
multipleRequirements.split(/,\s*/).collect { String it ->
136+
Transform.toList(multipleRequirements.split(/,\s*/)) { String it ->
136137
gemVersionFromGemRequirement(it.trim())
137138
}.findAll {
138139
it != NO_VERSION
139140
}
140141
}
141142

142-
/** Takes a GEM requirement list and creates a single GEM versin, by taking a union of
143+
/** Takes a GEM requirement list and creates a single GEM version, by taking a union of
143144
* all requirements.
144145
*
145146
* @param multipleRequirements Comma-separated list of GEM requirements.

core-plugin/src/main/groovy/com/github/jrubygradle/internal/core/AbstractIvyXmlProxyServer.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import java.time.Instant
1818

1919
import static com.github.jrubygradle.api.gems.GemVersion.gemVersionFromGradleIvyRequirement
2020
import static com.github.jrubygradle.internal.core.IvyUtils.revisionsAsHtmlDirectoryListing
21-
import static java.nio.file.Files.getLastModifiedTime
2221
import static java.nio.file.Files.move
2322
import static java.nio.file.StandardCopyOption.ATOMIC_MOVE
2423
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
@@ -110,7 +109,8 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
110109

111110
protected boolean expired(Path ivyXml) {
112111
System.currentTimeMillis()
113-
Files.notExists(ivyXml) ||
112+
Path ivyXmlSha1 = ivyXml.resolveSibling("${ivyXml.toFile().name}.sha1")
113+
Files.notExists(ivyXml) || Files.notExists(ivyXmlSha1) ||
114114
(Files.getLastModifiedTime(ivyXml).toMillis() + EXPIRY_PERIOD_MILLIS < Instant.now().toEpochMilli())
115115
}
116116

@@ -139,6 +139,8 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
139139
if (inGroups(grp)) {
140140
Path ivyXml = getIvyXml(grp, name, version)
141141
ivyXml.resolveSibling("${ivyXml.toFile().name}.sha1")
142+
} else {
143+
throw new NotFound()
142144
}
143145
}
144146

core-plugin/src/main/groovy/com/github/jrubygradle/internal/core/DefaultRubyGemRestApi.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class DefaultRubyGemRestApi implements com.github.jrubygradle.api.core.RubyGemQu
149149
)
150150

151151
if (jsonParser.dependencies?.runtime) {
152-
metadata.dependencies.addAll(jsonParser.dependencies.runtime.collect {
152+
metadata.dependencies.addAll( Transform.toList(jsonParser.dependencies.runtime) {
153153
new DefaultGemDependency(name: it.name, requirements: it.requirements)
154154
})
155155
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.jrubygradle.internal.core
2+
3+
import groovy.transform.CompileStatic
4+
5+
import java.util.function.Function
6+
import java.util.stream.Collectors
7+
8+
/** Transforms a collection to another collection.
9+
*
10+
* Deals with Groovy 2.4/2.5 backwards incompatibility.
11+
*
12+
* @author Schalk W. Cronjé
13+
*
14+
* @since 2.0
15+
*
16+
*/
17+
@CompileStatic
18+
class Transform {
19+
static <I,O> List<O> toList(final Collection<I> collection, Function<I,O> tx ) {
20+
collection.stream().map(tx).collect(Collectors.toList())
21+
}
22+
23+
static <I,O> List<O> toList(final I[] collection, Function<I,O> tx ) {
24+
collection.toList().stream().map(tx).collect(Collectors.toList())
25+
}
26+
27+
static <I,O> Set<O> toSet(final Collection<I> collection, Function<I,O> tx ) {
28+
collection.stream().map(tx).collect(Collectors.toSet())
29+
}
30+
31+
static <I,O> Set<O> toSet(final Iterable<I> collection, Function<I,O> tx ) {
32+
collection.toList().stream().map(tx).collect(Collectors.toSet())
33+
}
34+
}

gradle/wrapper/gradle-wrapper.jar

1.72 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

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

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

3+
import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
4+
35
/*
46
* This source code is derived from Apache 2.0 licensed software copyright John
57
* Engelman (https://github.com/johnrengelman) and was originally ported from this
68
* repository: https://github.com/johnrengelman/shadow
79
*/
810

9-
import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
1011
import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker
1112
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
1213
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
1314
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
1415
import groovy.util.logging.Slf4j
1516
import org.apache.commons.io.FilenameUtils
1617
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
2218
import org.gradle.api.Action
2319
import org.gradle.api.GradleException
2420
import org.gradle.api.UncheckedIOException
@@ -40,6 +36,11 @@ import org.objectweb.asm.ClassReader
4036
import org.objectweb.asm.ClassVisitor
4137
import org.objectweb.asm.ClassWriter
4238
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
4344

4445
import java.util.zip.ZipException
4546

@@ -58,7 +59,7 @@ import java.util.zip.ZipException
5859
*/
5960
@Slf4j
6061
@SuppressWarnings(['ParameterCount', 'CatchException', 'DuplicateStringLiteral',
61-
'CatchThrowable', 'VariableName', 'UnnecessaryGString', 'InvertedIfElse'])
62+
'CatchThrowable', 'VariableName', 'UnnecessaryGString', 'InvertedIfElse'])
6263
class JRubyJarCopyAction implements CopyAction {
6364
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = (new GregorianCalendar(1980, 1, 1, 0, 0, 0)).timeInMillis
6465

@@ -74,9 +75,9 @@ class JRubyJarCopyAction implements CopyAction {
7475
private final UnusedTracker unusedTracker
7576

7677
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) {
8081

8182
this.zipFile = zipFile
8283
this.compressor = compressor
@@ -109,20 +110,13 @@ class JRubyJarCopyAction implements CopyAction {
109110
unusedClasses = Collections.emptySet()
110111
}
111112

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-
120113
try {
114+
final ZipOutputStream zipOutStr = compressor.createArchiveOutputStream(zipFile)
121115
withResource(zipOutStr, new Action<ZipOutputStream>() {
122116
void execute(ZipOutputStream outputStream) {
123117
try {
124118
stream.process(new StreamAction(outputStream, encoding, transformers, relocators, patternSet,
125-
unusedClasses))
119+
unusedClasses))
126120
processTransformers(outputStream)
127121
} catch (Exception e) {
128122
log.error('ex', e)
@@ -134,10 +128,12 @@ class JRubyJarCopyAction implements CopyAction {
134128
} catch (UncheckedIOException e) {
135129
if (e.cause instanceof Zip64RequiredException) {
136130
throw new Zip64RequiredException(
137-
String.format("%s\n\nTo build this archive, please enable the zip64 extension.\nSee: %s",
138-
e.cause.message, documentationRegistry.getDslRefForProperty(Zip, "zip64"))
131+
String.format("%s\n\nTo build this archive, please enable the zip64 extension.\nSee: %s",
132+
e.cause.message, documentationRegistry.getDslRefForProperty(Zip, "zip64"))
139133
)
140134
}
135+
} catch (Exception e) {
136+
throw new GradleException("Could not create ZIP '${zipFile.toString()}'", e)
141137
}
142138
return WorkResults.didWork(true)
143139
}
@@ -217,7 +213,7 @@ class JRubyJarCopyAction implements CopyAction {
217213
private final Set<String> visitedFiles = [] as Set
218214

219215
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) {
221217
this.zipOutStr = zipOutStr
222218
this.transformers = transformers
223219
this.relocators = relocators
@@ -260,7 +256,7 @@ class JRubyJarCopyAction implements CopyAction {
260256

261257
private boolean isUnused(String classPath) {
262258
final String className = FilenameUtils.removeExtension(classPath)
263-
.replace('/' as char, '.' as char)
259+
.replace('/' as char, '.' as char)
264260
final boolean result = unused.contains(className)
265261
if (result) {
266262
log.debug("Dropping unused class: $className")
@@ -354,11 +350,11 @@ class JRubyJarCopyAction implements CopyAction {
354350
try {
355351
String mappedPath = remapper.map(element.relativePath.pathString)
356352
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()
362358
)
363359
} finally {
364360
is.close()

0 commit comments

Comments
 (0)