Skip to content

Commit

Permalink
Merge pull request #400 from ysb33r/master
Browse files Browse the repository at this point in the history
Do not include pre-release GEMs by the default
  • Loading branch information
ysb33r authored Dec 25, 2019
2 parents 7e13011 + 6fdc2e2 commit 814c36b
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import spock.lang.Issue

/**
* @author Schalk W. Cronjé.
* @author Guillaume Grossetie
*/
@IgnoreIf({System.getProperty('TESTS_ARE_OFFLINE')})
@IgnoreIf({ IntegrationSpecification.OFFLINE })
class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {

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

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

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

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

@IgnoreIf({ IntegrationSpecification.OFFLINE })
void "Check if prerelease gem gets resolved"() {
setup:
withDefaultRepositories()
Expand All @@ -156,7 +153,6 @@ rubygems:tilt:2.0.9
}

@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/341')
@IgnoreIf({ IntegrationSpecification.OFFLINE })
void "Make an install-time gem dependency available"() {
setup:
withRubyGemsRepository()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package com.github.jrubygradle
import com.github.jrubygradle.api.core.JRubyAwareTask
import com.github.jrubygradle.api.core.JRubyExecSpec
import com.github.jrubygradle.internal.JRubyExecUtils
import groovy.transform.CompileStatic
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.provider.Provider
Expand All @@ -48,6 +49,7 @@ import static org.ysb33r.grolifant.api.StringUtils.stringize
* @author Christian Meier
*
*/
@CompileStatic
class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {

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

inputs.property 'jrubyver', {
inputs.property 'jrubyver', { JRubyPluginExtension jruby ->
jruby.jrubyVersion
}
}.curry(this.jruby)

inputs.property 'gemConfiguration', {
inputs.property 'gemConfiguration', { JRubyPluginExtension jruby ->
jruby.gemConfiguration
}
}.curry(this.jruby)

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

/** Script to execute.
* @return The path to the script (or nul if not set)
* @return The path to the script (or {@code null} if not set)
*/
@Optional
@Input
Expand Down Expand Up @@ -184,12 +186,12 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
/** If it is required that a JRubyExec task needs to be executed with a different version of JRuby that the
* globally configured one, it can be done by setting it here.
*
* @deprecated Use{@code jruby.getProposedJRubyVersion( )} instead.
* @deprecated Use {@code jruby.getJrubyVersion( )} instead.
*
*/
@Deprecated
String getJrubyVersion() {
deprecated('Use jruby.getProposedJRubyVersion() rather getProposedJRubyVersion()')
deprecated('Use jruby.getJrubyVersion() rather getJrubyVersion()')
jruby.jrubyVersion
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
*/
@Deprecated
String getDefaultVersion() {
deprecated('Use getProposedJRubyVersion() rather than getDefaultVersion()')
deprecated('Use getJrubyVersion() rather than getDefaultVersion()')
getJrubyVersion()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ class JRubyExecTaskSpec extends Specification {
when:
project.configure(execTask) {
jruby.gemConfiguration configurationName
jruby.getProposedJRubyVersion newVersion
jruby.jrubyVersion newVersion
}
project.evaluate()

then:
execTask.jruby.jrubyVersion != project.jruby.getProposedJRubyVersion
execTask.jruby.jrubyVersion != project.jruby.jrubyVersion

and: "jrubyConfigurationName must point to this new configuration"
execTask.jruby.getGemConfiguration().name == configurationName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.junit.rules.TemporaryFolder
import spock.lang.IgnoreIf
import spock.lang.Issue
import spock.lang.Specification
import spock.lang.Unroll

import java.util.regex.Pattern

Expand Down Expand Up @@ -185,7 +186,7 @@ class IvyXmlProxyServerIntegrationSpec extends Specification {
build()

then:
findFiles (~/^asciidoctor-pdf.*\.gem$/).size() == 3
findFiles(~/^asciidoctor-pdf.*\.gem$/).size() == 3
}

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

private void withBuildFile(String content) {
private void withBuildFile(String content, boolean prerelease = false) {
buildFile.text = """
plugins {
id 'com.github.jruby-gradle.core'
}
repositories {
ruby.gems()
ruby.gems {
prerelease = ${prerelease}
}
}
configurations {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2014-2019, R. Tyler Croy <[email protected]>,
* Schalk Cronje <[email protected]>, Christian Meier, Lookout, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.github.jrubygradle.api.core

import groovy.transform.CompileStatic

/** Additional options for configuring a remote GEM repository
*
* @author Schalk W. Cronjé
*
* @since 2.0
*/
@CompileStatic
class GemRepositoryConfiguration {

/** Set whether pre-release GEMs should be considered.
*
*/
boolean prerelease = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.ArtifactRepository
import org.gradle.api.artifacts.repositories.IvyArtifactRepository
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.util.GradleVersion
import org.ysb33r.grolifant.api.ClosureUtils

/** Extension which can be added to {@code project.repositories}.
*
Expand Down Expand Up @@ -60,7 +60,31 @@ class RepositoryHandlerExtension {
* @return Artifact repository.
*/
ArtifactRepository gems() {
bindRepositoryToProxyServer('https://rubygems.org'.toURI(), DEFAULT_GROUP_NAME)
bindRepositoryToProxyServer(
RUBYGEMS_URI,
DEFAULT_GROUP_NAME,
new GemRepositoryConfiguration()
)
}

/** Create an artifact repository which will use {@link https://rubygems.org} and
* associate group {@code rubygems} with it.
*
* @param cfg GEM repository configuration
* @return Artifact repository.
*/
ArtifactRepository gems(@DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
bindRepositoryToProxyServer(RUBYGEMS_URI, DEFAULT_GROUP_NAME, cfg)
}

/** Create an artifact repository which will use {@link https://rubygems.org} and
* associate group {@code rubygems} with it.
*
* @param cfg GEM repository configuration
* @return Artifact repository.
*/
ArtifactRepository gems(Action<GemRepositoryConfiguration> cfg) {
bindRepositoryToProxyServer(RUBYGEMS_URI, DEFAULT_GROUP_NAME, cfg)
}

/** Create an artifact repository which will use specified URI and
Expand All @@ -72,7 +96,33 @@ class RepositoryHandlerExtension {
* @return Artifact repository.
*/
ArtifactRepository gems(Object uri) {
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME)
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, new GemRepositoryConfiguration())
}

/** Create an artifact repository which will use specified URI and
* associate group {@code rubygems} with it.
*
* @param uri URI of remote repository that serves up Rubygems. Any object convertible
* with {@code project.uri} can be provided.
* @param cfg GEM repository configuration
*
* @return Artifact repository.
*/
ArtifactRepository gems(Object uri, @DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, cfg)
}

/** Create an artifact repository which will use specified URI and
* associate group {@code rubygems} with it.
*
* @param uri URI of remote repository that serves up Rubygems. Any object convertible
* with {@code project.uri} can be provided.
* @param cfg GEM repository configuration
*
* @return Artifact repository.
*/
ArtifactRepository gems(Object uri, Action<GemRepositoryConfiguration> cfg) {
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, cfg)
}

/** Create an artifact repository which will use specified URI and
Expand All @@ -84,37 +134,65 @@ class RepositoryHandlerExtension {
* @return Artifact repository.
*/
ArtifactRepository gems(String group, Object uri) {
bindRepositoryToProxyServer(project.uri(uri), group)
bindRepositoryToProxyServer(project.uri(uri), group, new GemRepositoryConfiguration())
}

/** Adds the legacy Torquebox Maven proxy to {@code rubygems.org}.
/** Create an artifact repository which will use specified URI and
* associate a specified group with it.
*
* Please note that this proxy is effectively unmaintained an no longer supported
* by the original creators.
* @param group Group to associate this server with.
* @param uri URI of remote repository that serves up Rubygems. Any object convertible
* with {@code project.uri} can be provided.
* @param cfg GEM repository configuration
* @return Artifact repository.
*/
ArtifactRepository gems(String group, Object uri, @DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
bindRepositoryToProxyServer(project.uri(uri), group, cfg)
}

/** Create an artifact repository which will use specified URI and
* associate a specified group with it.
*
* @return Maven artifact repository
* @param group Group to associate this server with.
* @param uri URI of remote repository that serves up Rubygems. Any object convertible
* with {@code project.uri} can be provided.
* @param cfg GEM repository configuration
* @return Artifact repository.
*/
MavenArtifactRepository torquebox() {
Action mvnConfigurator = new Action<MavenArtifactRepository>() {
void execute(MavenArtifactRepository mvn) {
mvn.url = 'http://rubygems-proxy.torquebox.org/releases'.toURI()
}
}
(MavenArtifactRepository) restrictToGems(
this.project.repositories.maven(mvnConfigurator),
DEFAULT_GROUP_NAME
)
ArtifactRepository gems(String group, Object uri, Action<GemRepositoryConfiguration> cfg) {
bindRepositoryToProxyServer(project.uri(uri), group, cfg)
}

private ArtifactRepository bindRepositoryToProxyServer(
URI serverUri,
String group
String group,
GemRepositoryConfiguration cfg
) {
IvyXmlProxyServer proxy = ivyProxies.registerProxy(serverUri, group)
IvyXmlProxyServer proxy = ivyProxies.registerProxy(serverUri, group, cfg)
project.extensions.getByType(GemResolverStrategy).addGemGroup(group)
restrictToGems(createIvyRepo(serverUri, proxy.bindAddress), group)
}

private ArtifactRepository bindRepositoryToProxyServer(
URI serverUri,
String group,
@DelegatesTo(GemRepositoryConfiguration) Closure cfg
) {
GemRepositoryConfiguration grc = new GemRepositoryConfiguration()
ClosureUtils.configureItem(grc, cfg)
bindRepositoryToProxyServer(serverUri, group, grc)
}

private ArtifactRepository bindRepositoryToProxyServer(
URI serverUri,
String group,
Action<GemRepositoryConfiguration> cfg
) {
GemRepositoryConfiguration grc = new GemRepositoryConfiguration()
cfg.execute(grc)
bindRepositoryToProxyServer(serverUri, group, grc)
}

@CompileDynamic
private IvyArtifactRepository createIvyRepo(URI server, URI bindAddress) {
this.project.repositories.ivy {
Expand All @@ -141,4 +219,5 @@ class RepositoryHandlerExtension {
private final IvyXmlGlobalProxyRegistry ivyProxies
private static final boolean HAS_CONTENT_FEATURE = GradleVersion.current() >= GradleVersion.version('5.1')
private static final boolean HAS_SECURE_PROTOCOL_FEATURE = GradleVersion.current() >= GradleVersion.version('6.0')
private static final URI RUBYGEMS_URI = 'https://rubygems.org'.toURI()
}
Loading

0 comments on commit 814c36b

Please sign in to comment.