Skip to content

Commit 814c36b

Browse files
authored
Merge pull request #400 from ysb33r/master
Do not include pre-release GEMs by the default
2 parents 7e13011 + 6fdc2e2 commit 814c36b

File tree

15 files changed

+277
-65
lines changed

15 files changed

+277
-65
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import spock.lang.Issue
3030

3131
/**
3232
* @author Schalk W. Cronjé.
33+
* @author Guillaume Grossetie
3334
*/
34-
@IgnoreIf({System.getProperty('TESTS_ARE_OFFLINE')})
35+
@IgnoreIf({ IntegrationSpecification.OFFLINE })
3536
class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
3637

3738
static final String DEFAULT_TASK_NAME = 'jrubyPrepare'
@@ -54,7 +55,6 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
5455
new File(projectDir, "gems/slim-${slimVersion}").exists()
5556
}
5657

57-
@IgnoreIf({ IntegrationSpecification.OFFLINE })
5858
void "Check if rack version gets resolved"() {
5959
setup:
6060
withPreamble """repositories.ruby.gems()
@@ -76,7 +76,6 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
7676
new File(projectDir, "gems/rack-1.6.12").exists()
7777
}
7878

79-
@IgnoreIf({ IntegrationSpecification.OFFLINE })
8079
void "Check if selenium-webdriver version gets resolved"() {
8180
setup:
8281
withPreamble """repositories.ruby.gems()
@@ -97,7 +96,6 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
9796
new File(projectDir, "gems/selenium-webdriver-3.142.6").exists()
9897
}
9998

100-
@IgnoreIf({ IntegrationSpecification.OFFLINE })
10199
void "Check that GEM dependencies are locked"() {
102100
setup:
103101
File lockFile = new File(projectDir, 'gradle/dependency-locks/gems.lockfile')
@@ -139,7 +137,6 @@ rubygems:tilt:2.0.9
139137
new File(projectDir, "gems/rack-1.6.10").exists()
140138
}
141139

142-
@IgnoreIf({ IntegrationSpecification.OFFLINE })
143140
void "Check if prerelease gem gets resolved"() {
144141
setup:
145142
withDefaultRepositories()
@@ -156,7 +153,6 @@ rubygems:tilt:2.0.9
156153
}
157154

158155
@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/341')
159-
@IgnoreIf({ IntegrationSpecification.OFFLINE })
160156
void "Make an install-time gem dependency available"() {
161157
setup:
162158
withRubyGemsRepository()

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package com.github.jrubygradle
2626
import com.github.jrubygradle.api.core.JRubyAwareTask
2727
import com.github.jrubygradle.api.core.JRubyExecSpec
2828
import com.github.jrubygradle.internal.JRubyExecUtils
29+
import groovy.transform.CompileStatic
2930
import org.gradle.api.Task
3031
import org.gradle.api.artifacts.Configuration
3132
import org.gradle.api.provider.Provider
@@ -48,6 +49,7 @@ import static org.ysb33r.grolifant.api.StringUtils.stringize
4849
* @author Christian Meier
4950
*
5051
*/
52+
@CompileStatic
5153
class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
5254

5355
public static final String MAIN_CLASS = 'org.jruby.Main'
@@ -65,13 +67,13 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
6567
super.setMain MAIN_CLASS
6668
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
6769

68-
inputs.property 'jrubyver', {
70+
inputs.property 'jrubyver', { JRubyPluginExtension jruby ->
6971
jruby.jrubyVersion
70-
}
72+
}.curry(this.jruby)
7173

72-
inputs.property 'gemConfiguration', {
74+
inputs.property 'gemConfiguration', { JRubyPluginExtension jruby ->
7375
jruby.gemConfiguration
74-
}
76+
}.curry(this.jruby)
7577

7678
if (GradleVersion.current() >= GradleVersion.version('4.10')) {
7779
dependsOn(project.provider({ JRubyPluginExtension jpe ->
@@ -85,7 +87,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
8587
}
8688

8789
/** Script to execute.
88-
* @return The path to the script (or nul if not set)
90+
* @return The path to the script (or {@code null} if not set)
8991
*/
9092
@Optional
9193
@Input
@@ -184,12 +186,12 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
184186
/** If it is required that a JRubyExec task needs to be executed with a different version of JRuby that the
185187
* globally configured one, it can be done by setting it here.
186188
*
187-
* @deprecated Use{@code jruby.getProposedJRubyVersion( )} instead.
189+
* @deprecated Use {@code jruby.getJrubyVersion( )} instead.
188190
*
189191
*/
190192
@Deprecated
191193
String getJrubyVersion() {
192-
deprecated('Use jruby.getProposedJRubyVersion() rather getProposedJRubyVersion()')
194+
deprecated('Use jruby.getJrubyVersion() rather getJrubyVersion()')
193195
jruby.jrubyVersion
194196
}
195197

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
111111
*/
112112
@Deprecated
113113
String getDefaultVersion() {
114-
deprecated('Use getProposedJRubyVersion() rather than getDefaultVersion()')
114+
deprecated('Use getJrubyVersion() rather than getDefaultVersion()')
115115
getJrubyVersion()
116116
}
117117

base-plugin/src/test/groovy/com/github/jrubygradle/JRubyExecTaskSpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ class JRubyExecTaskSpec extends Specification {
7272
when:
7373
project.configure(execTask) {
7474
jruby.gemConfiguration configurationName
75-
jruby.getProposedJRubyVersion newVersion
75+
jruby.jrubyVersion newVersion
7676
}
7777
project.evaluate()
7878

7979
then:
80-
execTask.jruby.jrubyVersion != project.jruby.getProposedJRubyVersion
80+
execTask.jruby.jrubyVersion != project.jruby.jrubyVersion
8181

8282
and: "jrubyConfigurationName must point to this new configuration"
8383
execTask.jruby.getGemConfiguration().name == configurationName

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/RepositoryHandlerExtension.groovy

Lines changed: 99 additions & 20 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,37 +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())
88138
}
89139

90-
/** Adds the legacy Torquebox Maven proxy to {@code rubygems.org}.
140+
/** Create an artifact repository which will use specified URI and
141+
* associate a specified group with it.
91142
*
92-
* Please note that this proxy is effectively unmaintained an no longer supported
93-
* by the original creators.
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.
94155
*
95-
* @return Maven artifact repository
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.
96161
*/
97-
MavenArtifactRepository torquebox() {
98-
Action mvnConfigurator = new Action<MavenArtifactRepository>() {
99-
void execute(MavenArtifactRepository mvn) {
100-
mvn.url = 'http://rubygems-proxy.torquebox.org/releases'.toURI()
101-
}
102-
}
103-
(MavenArtifactRepository) restrictToGems(
104-
this.project.repositories.maven(mvnConfigurator),
105-
DEFAULT_GROUP_NAME
106-
)
162+
ArtifactRepository gems(String group, Object uri, Action<GemRepositoryConfiguration> cfg) {
163+
bindRepositoryToProxyServer(project.uri(uri), group, cfg)
107164
}
108165

109166
private ArtifactRepository bindRepositoryToProxyServer(
110167
URI serverUri,
111-
String group
168+
String group,
169+
GemRepositoryConfiguration cfg
112170
) {
113-
IvyXmlProxyServer proxy = ivyProxies.registerProxy(serverUri, group)
171+
IvyXmlProxyServer proxy = ivyProxies.registerProxy(serverUri, group, cfg)
114172
project.extensions.getByType(GemResolverStrategy).addGemGroup(group)
115173
restrictToGems(createIvyRepo(serverUri, proxy.bindAddress), group)
116174
}
117175

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+
118196
@CompileDynamic
119197
private IvyArtifactRepository createIvyRepo(URI server, URI bindAddress) {
120198
this.project.repositories.ivy {
@@ -141,4 +219,5 @@ class RepositoryHandlerExtension {
141219
private final IvyXmlGlobalProxyRegistry ivyProxies
142220
private static final boolean HAS_CONTENT_FEATURE = GradleVersion.current() >= GradleVersion.version('5.1')
143221
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()
144223
}

0 commit comments

Comments
 (0)