Skip to content

Commit 6fdc2e2

Browse files
committed
Do not include pre-release GEMs by default (#393)
1 parent fb47d65 commit 6fdc2e2

File tree

11 files changed

+271
-39
lines changed

11 files changed

+271
-39
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.junit.rules.TemporaryFolder
3030
import spock.lang.IgnoreIf
3131
import spock.lang.Issue
3232
import spock.lang.Specification
33+
import spock.lang.Unroll
3334

3435
import java.util.regex.Pattern
3536

@@ -185,7 +186,7 @@ class IvyXmlProxyServerIntegrationSpec extends Specification {
185186
build()
186187

187188
then:
188-
findFiles (~/^asciidoctor-pdf.*\.gem$/).size() == 3
189+
findFiles(~/^asciidoctor-pdf.*\.gem$/).size() == 3
189190
}
190191

191192
@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/380')
@@ -243,14 +244,16 @@ class IvyXmlProxyServerIntegrationSpec extends Specification {
243244
.build()
244245
}
245246

246-
private void withBuildFile(String content) {
247+
private void withBuildFile(String content, boolean prerelease = false) {
247248
buildFile.text = """
248249
plugins {
249250
id 'com.github.jruby-gradle.core'
250251
}
251252
252253
repositories {
253-
ruby.gems()
254+
ruby.gems {
255+
prerelease = ${prerelease}
256+
}
254257
}
255258
256259
configurations {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2014-2019, R. Tyler Croy <[email protected]>,
3+
* Schalk Cronje <[email protected]>, Christian Meier, Lookout, Inc.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining
6+
* a copy of this software and associated documentation files (the
7+
* "Software"), to deal in the Software without restriction, including
8+
* without limitation the rights to use, copy, modify, merge, publish,
9+
* distribute, sublicense, and/or sell copies of the Software, and to
10+
* permit persons to whom the Software is furnished to do so, subject to
11+
* the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
package com.github.jrubygradle.api.core
25+
26+
import groovy.transform.CompileStatic
27+
28+
/** Additional options for configuring a remote GEM repository
29+
*
30+
* @author Schalk W. Cronjé
31+
*
32+
* @since 2.0
33+
*/
34+
@CompileStatic
35+
class GemRepositoryConfiguration {
36+
37+
/** Set whether pre-release GEMs should be considered.
38+
*
39+
*/
40+
boolean prerelease = false
41+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/**
22
* Copyright (c) 2014-2019, R. Tyler Croy <[email protected]>,
3-
* Schalk Cronje <[email protected]>, Christian Meier, Lookout, Inc.
4-
* <p>
3+
* Schalk Cronje <[email protected]>, Christian Meier, Lookout, Inc.
4+
*
55
* Permission is hereby granted, free of charge, to any person obtaining
66
* a copy of this software and associated documentation files (the
77
* "Software"), to deal in the Software without restriction, including
88
* without limitation the rights to use, copy, modify, merge, publish,
99
* distribute, sublicense, and/or sell copies of the Software, and to
1010
* permit persons to whom the Software is furnished to do so, subject to
1111
* the following conditions:
12-
* <p>
12+
*
1313
* The above copyright notice and this permission notice shall be
1414
* included in all copies or substantial portions of the Software.
15-
* <p>
15+
*
1616
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1717
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1818
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

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

Lines changed: 104 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import org.gradle.api.Action
3131
import org.gradle.api.Project
3232
import org.gradle.api.artifacts.repositories.ArtifactRepository
3333
import org.gradle.api.artifacts.repositories.IvyArtifactRepository
34-
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
3534
import org.gradle.util.GradleVersion
35+
import org.ysb33r.grolifant.api.ClosureUtils
3636

3737
/** Extension which can be added to {@code project.repositories}.
3838
*
@@ -60,7 +60,31 @@ class RepositoryHandlerExtension {
6060
* @return Artifact repository.
6161
*/
6262
ArtifactRepository gems() {
63-
bindRepositoryToProxyServer('https://rubygems.org'.toURI(), DEFAULT_GROUP_NAME)
63+
bindRepositoryToProxyServer(
64+
RUBYGEMS_URI,
65+
DEFAULT_GROUP_NAME,
66+
new GemRepositoryConfiguration()
67+
)
68+
}
69+
70+
/** Create an artifact repository which will use {@link https://rubygems.org} and
71+
* associate group {@code rubygems} with it.
72+
*
73+
* @param cfg GEM repository configuration
74+
* @return Artifact repository.
75+
*/
76+
ArtifactRepository gems(@DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
77+
bindRepositoryToProxyServer(RUBYGEMS_URI, DEFAULT_GROUP_NAME, cfg)
78+
}
79+
80+
/** Create an artifact repository which will use {@link https://rubygems.org} and
81+
* associate group {@code rubygems} with it.
82+
*
83+
* @param cfg GEM repository configuration
84+
* @return Artifact repository.
85+
*/
86+
ArtifactRepository gems(Action<GemRepositoryConfiguration> cfg) {
87+
bindRepositoryToProxyServer(RUBYGEMS_URI, DEFAULT_GROUP_NAME, cfg)
6488
}
6589

6690
/** Create an artifact repository which will use specified URI and
@@ -72,7 +96,33 @@ class RepositoryHandlerExtension {
7296
* @return Artifact repository.
7397
*/
7498
ArtifactRepository gems(Object uri) {
75-
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME)
99+
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, new GemRepositoryConfiguration())
100+
}
101+
102+
/** Create an artifact repository which will use specified URI and
103+
* associate group {@code rubygems} with it.
104+
*
105+
* @param uri URI of remote repository that serves up Rubygems. Any object convertible
106+
* with {@code project.uri} can be provided.
107+
* @param cfg GEM repository configuration
108+
*
109+
* @return Artifact repository.
110+
*/
111+
ArtifactRepository gems(Object uri, @DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
112+
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, cfg)
113+
}
114+
115+
/** Create an artifact repository which will use specified URI and
116+
* associate group {@code rubygems} with it.
117+
*
118+
* @param uri URI of remote repository that serves up Rubygems. Any object convertible
119+
* with {@code project.uri} can be provided.
120+
* @param cfg GEM repository configuration
121+
*
122+
* @return Artifact repository.
123+
*/
124+
ArtifactRepository gems(Object uri, Action<GemRepositoryConfiguration> cfg) {
125+
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, cfg)
76126
}
77127

78128
/** Create an artifact repository which will use specified URI and
@@ -84,18 +134,65 @@ class RepositoryHandlerExtension {
84134
* @return Artifact repository.
85135
*/
86136
ArtifactRepository gems(String group, Object uri) {
87-
bindRepositoryToProxyServer(project.uri(uri), group)
137+
bindRepositoryToProxyServer(project.uri(uri), group, new GemRepositoryConfiguration())
138+
}
139+
140+
/** Create an artifact repository which will use specified URI and
141+
* associate a specified group with it.
142+
*
143+
* @param group Group to associate this server with.
144+
* @param uri URI of remote repository that serves up Rubygems. Any object convertible
145+
* with {@code project.uri} can be provided.
146+
* @param cfg GEM repository configuration
147+
* @return Artifact repository.
148+
*/
149+
ArtifactRepository gems(String group, Object uri, @DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
150+
bindRepositoryToProxyServer(project.uri(uri), group, cfg)
151+
}
152+
153+
/** Create an artifact repository which will use specified URI and
154+
* associate a specified group with it.
155+
*
156+
* @param group Group to associate this server with.
157+
* @param uri URI of remote repository that serves up Rubygems. Any object convertible
158+
* with {@code project.uri} can be provided.
159+
* @param cfg GEM repository configuration
160+
* @return Artifact repository.
161+
*/
162+
ArtifactRepository gems(String group, Object uri, Action<GemRepositoryConfiguration> cfg) {
163+
bindRepositoryToProxyServer(project.uri(uri), group, cfg)
88164
}
89165

90166
private ArtifactRepository bindRepositoryToProxyServer(
91167
URI serverUri,
92-
String group
168+
String group,
169+
GemRepositoryConfiguration cfg
93170
) {
94-
IvyXmlProxyServer proxy = ivyProxies.registerProxy(serverUri, group)
171+
IvyXmlProxyServer proxy = ivyProxies.registerProxy(serverUri, group, cfg)
95172
project.extensions.getByType(GemResolverStrategy).addGemGroup(group)
96173
restrictToGems(createIvyRepo(serverUri, proxy.bindAddress), group)
97174
}
98175

176+
private ArtifactRepository bindRepositoryToProxyServer(
177+
URI serverUri,
178+
String group,
179+
@DelegatesTo(GemRepositoryConfiguration) Closure cfg
180+
) {
181+
GemRepositoryConfiguration grc = new GemRepositoryConfiguration()
182+
ClosureUtils.configureItem(grc, cfg)
183+
bindRepositoryToProxyServer(serverUri, group, grc)
184+
}
185+
186+
private ArtifactRepository bindRepositoryToProxyServer(
187+
URI serverUri,
188+
String group,
189+
Action<GemRepositoryConfiguration> cfg
190+
) {
191+
GemRepositoryConfiguration grc = new GemRepositoryConfiguration()
192+
cfg.execute(grc)
193+
bindRepositoryToProxyServer(serverUri, group, grc)
194+
}
195+
99196
@CompileDynamic
100197
private IvyArtifactRepository createIvyRepo(URI server, URI bindAddress) {
101198
this.project.repositories.ivy {
@@ -122,4 +219,5 @@ class RepositoryHandlerExtension {
122219
private final IvyXmlGlobalProxyRegistry ivyProxies
123220
private static final boolean HAS_CONTENT_FEATURE = GradleVersion.current() >= GradleVersion.version('5.1')
124221
private static final boolean HAS_SECURE_PROTOCOL_FEATURE = GradleVersion.current() >= GradleVersion.version('6.0')
222+
private static final URI RUBYGEMS_URI = 'https://rubygems.org'.toURI()
125223
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
*
3434
* @since 2.0.
3535
*
36-
* @see https://guides.rubygems.org/rubygems-org-api
36+
* @see {@link https://guides.rubygems.org/rubygems-org-api}
3737
*/
3838
public interface RubyGemQueryRestApi {
39+
3940
/**
4041
* Return all published versions for a specific GEM
4142
*
@@ -45,6 +46,16 @@ public interface RubyGemQueryRestApi {
4546
*/
4647
List<String> allVersions(String gemName) throws ApiException;
4748

49+
/**
50+
* Return all published versions for a specific GEM
51+
*
52+
* @param gemName Name of GEM.
53+
* @param includePrelease Whether pre-release versions should be included.
54+
* @return List of versions. Can be empty if the GEM does not have any versions. Never {@code null}.
55+
* @throws {@link ApiException} if a networking or parser error occurs.
56+
*/
57+
List<String> allVersions(String gemName, boolean includePrelease) throws ApiException;
58+
4859
/**
4960
* Return latest published version of GEM.
5061
*
@@ -54,6 +65,16 @@ public interface RubyGemQueryRestApi {
5465
*/
5566
String latestVersion(String gemName) throws ApiException;
5667

68+
/**
69+
* Return latest published version of GEM.
70+
*
71+
* @param gemName Name of GEM.
72+
* @param allowPrerelease Whether a prereleased version can be considered a latest version.
73+
* @return Version of GEM
74+
* @throws {@link ApiException} if GEM does not exist.
75+
*/
76+
String latestVersion(String gemName, boolean allowPrerelease) throws ApiException;
77+
5778
/** Returns the basic metadata for a GEM.
5879
*
5980
* @param gemName Name of GEM.

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package com.github.jrubygradle.internal.core
2525

2626
import com.github.jrubygradle.api.core.ApiException
27+
import com.github.jrubygradle.api.core.GemRepositoryConfiguration
2728
import com.github.jrubygradle.api.core.IvyXmlProxyServer
2829
import com.github.jrubygradle.api.core.RubyGemQueryRestApi
2930
import com.github.jrubygradle.api.gems.GemInfo
@@ -94,12 +95,19 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
9495
* @param cache Root directory for local Ivy XML cache.
9596
* @param serverUri URI of remote Rubygems proxy.
9697
* @param group Group that will be associated with the Rubygems proxy.
98+
* @param grc Additional configuration regarding remote GEM server
9799
*/
98-
protected AbstractIvyXmlProxyServer(File cache, URI serverUri, String group) {
100+
protected AbstractIvyXmlProxyServer(
101+
File cache,
102+
URI serverUri,
103+
String group,
104+
GemRepositoryConfiguration grc
105+
) {
99106
localCachePath = cache
100107
gemToIvy = new GemToIvy(serverUri)
101108
api = new DefaultRubyGemRestApi(serverUri)
102109
this.group = group
110+
this.configuration = grc
103111
}
104112

105113
@Synchronized
@@ -170,7 +178,7 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
170178
protected String getDirectoryListing(String grp, String name) throws NotFound {
171179
if (inGroups(grp)) {
172180
debug "Request to find all versions for ${grp}:${name}"
173-
List<String> versions = api.allVersions(name)
181+
List<String> versions = api.allVersions(name, configuration.prerelease)
174182
debug "Got versions ${versions.join(', ')}"
175183
revisionsAsHtmlDirectoryListing(versions)
176184
} else {
@@ -185,7 +193,7 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
185193

186194
private String getGemQueryRevisionFromIvy(String gemName, String revisionPattern) {
187195
GemVersion version = gemVersionFromGradleIvyRequirement(revisionPattern)
188-
version.highOpenEnded ? api.latestVersion(gemName) : version.high
196+
version.highOpenEnded ? api.latestVersion(gemName, configuration.prerelease) : version.high
189197
}
190198

191199
private void debug(String text) {
@@ -203,4 +211,5 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
203211
private final GemToIvy gemToIvy
204212
private final RubyGemQueryRestApi api
205213
private final String group
214+
private final GemRepositoryConfiguration configuration
206215
}

0 commit comments

Comments
 (0)