Skip to content

Commit 207113a

Browse files
committed
Handle JARs that are transitive dependencies of GEMs (#370)
Finalised at hack.commit.push 2019 with @ixchelruiz.
1 parent 6bab580 commit 207113a

File tree

12 files changed

+127
-9
lines changed

12 files changed

+127
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
3939
withDependencies """
4040
gems "rubygems:sinatra:1.4.5"
4141
gems "rubygems:rack:[0,)"
42-
gems "rubygems:lookout-rack-utils:3.8.0.39"
42+
gems "rubygems:lookout-rack-utils:5.0.0.49"
4343
"""
4444

4545
when:

base-plugin/src/main/groovy/com/github/jrubygradle/JRubyPluginExtension.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import java.util.concurrent.Callable
1818
import static org.ysb33r.grolifant.api.StringUtils.stringize
1919

2020
/**
21-
* Class providing the jruby{} DSL extension to the Gradle build script.
21+
* Class providing the jruby DSL extension to the Gradle build script.
2222
*
2323
* @author Schalk W. Cronjé
2424
* @author R Tyler Croy

core-plugin/src/integTest/groovy/com/github/jrubygradle/api/core/IvyXmlProxyServerIntegrationSpec.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ class IvyXmlProxyServerIntegrationSpec extends Specification {
128128
findFiles ~/^github-pages-106.gem$/
129129
}
130130

131+
void 'Resolve GEM with JAR dependencies'() {
132+
setup:
133+
withBuildFile '''
134+
repositories.jcenter()
135+
dependencies {
136+
something 'rubygems:jruby-openssl:0.10.2'
137+
}
138+
'''
139+
140+
when:
141+
build()
142+
143+
then:
144+
findFiles ~/^jruby-openssl-0.10.2-java.gem$/
145+
}
146+
131147
private List<File> findFiles(Pattern pat) {
132148
new File(projectDir, 'build/something').listFiles(new FilenameFilter() {
133149
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class RepositoryHandlerExtension {
9595
@CompileDynamic
9696
private IvyArtifactRepository createIvyRepo(URI server, URI bindAddress) {
9797
this.project.repositories.ivy {
98-
artifactPattern "${server}/downloads/[artifact]-[revision].gem"
98+
artifactPattern "${server}/downloads/[artifact]-[revision](-[classifier]).gem"
9999
ivyPattern "${bindAddress}/[organisation]/[module]/[revision]/ivy.xml"
100100
}
101101
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ public interface GemInfo {
101101
*/
102102
List<GemDependency> getDevelopmentDependencies();
103103

104+
/** Transitive JAR requirements.
105+
*
106+
* @return List of JAR requirements. Can be empty, but never {@code null}
107+
*/
108+
List<JarDependency> getJarRequirements();
109+
104110
/** Whether the GEM is still a prerelease version.
105111
*
106112
* @return {@code true} for prerelease

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class GemVersion implements Comparable<GemVersion> {
9393
private static final Pattern RANGE = ~/^(\[|\])(.+?),(.+?)(\[|\])$/
9494

9595
private static final Pattern ONLY_DIGITS = ~/^\d+$/
96+
private static final Pattern DIGITS_AND_DOTS = ~/^\d+(\.\d+){1,3}(-\p{Alnum}+)?$/
9697

9798
// GEM requirement patterns
9899
private static final Pattern GREATER_EQUAL = ~/^>=\s*(.+)/
@@ -132,13 +133,13 @@ class GemVersion implements Comparable<GemVersion> {
132133
*/
133134
static List<GemVersion> gemVersionsFromMultipleGemRequirements(String multipleRequirements) {
134135
multipleRequirements.split(/,\s*/).collect { String it ->
135-
gemVersionFromGemRequirement(it)
136+
gemVersionFromGemRequirement(it.trim())
136137
}.findAll {
137138
it != NO_VERSION
138139
}
139140
}
140141

141-
/** Takes a GEM requirement list and creates a single GEM versoin, by taking a union of
142+
/** Takes a GEM requirement list and creates a single GEM versin, by taking a union of
142143
* all requirements.
143144
*
144145
* @param multipleRequirements Comma-separated list of GEM requirements.
@@ -208,6 +209,13 @@ class GemVersion implements Comparable<GemVersion> {
208209
)
209210
} else if (singleRequirement.matches(TWIDDLE_WAKKA)) {
210211
parseTwiddleWakka(singleRequirement)
212+
} else if (singleRequirement.matches(DIGITS_AND_DOTS)) {
213+
new GemVersion(
214+
INCLUSIVE,
215+
singleRequirement,
216+
singleRequirement,
217+
INCLUSIVE
218+
)
211219
} else {
212220
throw new GemVersionException("'${singleRequirement}' does not look like a GEM version requirement")
213221
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.jrubygradle.api.gems;
2+
3+
/** JAR dependency as specified by a GEM spec.
4+
*
5+
*/
6+
public interface JarDependency extends GemDependency {
7+
/** Group/organisation that the JAR belongs to
8+
*
9+
* @return Can be {@code null} if no organisation.
10+
*/
11+
String getGroup();
12+
}

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.github.jrubygradle.internal.core
22

33
import com.github.jrubygradle.api.gems.GemInfo
4+
import com.github.jrubygradle.api.gems.JarDependency
45
import com.github.jrubygradle.internal.gems.DefaultGemDependency
56
import com.github.jrubygradle.internal.gems.DefaultGemInfo
7+
import com.github.jrubygradle.internal.gems.DefaultJarDependency
68
import groovy.transform.CompileDynamic
79
import groovy.transform.CompileStatic
810
import groovyx.net.http.HttpBuilder
@@ -141,7 +143,7 @@ class DefaultRubyGemRestApi implements com.github.jrubygradle.api.core.RubyGemQu
141143
gemUri: jsonParser.gem_uri?.toURI(),
142144
homepageUri: jsonParser.homepage_uri?.toURI(),
143145
documentationUri: jsonParser.documentation_uri?.toURI(),
144-
authors: ((String) jsonParser.authors).split(', ').toList() ?: [],
146+
authors: ((String) jsonParser.authors).split(COMMA_SPACE).toList() ?: [],
145147
prerelease: jsonParser.prerelease
146148
// licenses arrayList
147149
)
@@ -158,10 +160,36 @@ class DefaultRubyGemRestApi implements com.github.jrubygradle.api.core.RubyGemQu
158160
})
159161
}
160162

163+
if (jsonParser.requirements) {
164+
metadata.jarRequirements.addAll(findJarRequirements(jsonParser.requirements))
165+
}
166+
161167
metadata
162168
}
163169

170+
private List<JarDependency> findJarRequirements(Iterable<String> reqs) {
171+
reqs.findAll { String it ->
172+
it.startsWith('jar ')
173+
}.collect {
174+
String[] parts = ((String) it)[4..-1].split(COMMA_SPACE, 2)
175+
String[] name_parts = parts[0].split(':', 2)
176+
if (name_parts.size() == 1) {
177+
new DefaultJarDependency(
178+
name: parts[0],
179+
requirements: parts[1]
180+
)
181+
} else {
182+
new DefaultJarDependency(
183+
group: name_parts[0],
184+
name: name_parts[1],
185+
requirements: parts[1]
186+
)
187+
}
188+
} as List<JarDependency>
189+
}
190+
164191
private final HttpBuilder httpBuilder
165192
static private final String V1 = 'api/v1'
166193
static private final String V2 = 'api/v2'
194+
static private final String COMMA_SPACE = ', '
167195
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.jrubygradle.internal.gems
22

33
import com.github.jrubygradle.api.gems.GemInfo
44
import com.github.jrubygradle.api.gems.GemDependency
5+
import com.github.jrubygradle.api.gems.JarDependency
56
import groovy.transform.CompileStatic
67

78
/** An implementation of GEM metadata.
@@ -34,4 +35,5 @@ class DefaultGemInfo implements GemInfo {
3435

3536
List<GemDependency> dependencies = []
3637
List<GemDependency> developmentDependencies = []
38+
List<JarDependency> jarRequirements = []
3739
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.github.jrubygradle.internal.gems
2+
3+
import com.github.jrubygradle.api.gems.JarDependency
4+
import groovy.transform.CompileStatic
5+
6+
/** Defining a JAR dependency.
7+
*
8+
* @author Schalk W. Cronjé
9+
*
10+
* @since 2.0
11+
*/
12+
@CompileStatic
13+
class DefaultJarDependency extends DefaultGemDependency implements JarDependency {
14+
/** Name of group / organisation.
15+
*
16+
*/
17+
String group
18+
}

0 commit comments

Comments
 (0)