Skip to content

Commit e667a1d

Browse files
committed
Added rubygemRelease() as a repository name. Added jruby.defaultRepositories as a way to turn off the loading of default repositories in JRubyPlugin.apply. Updated tests to cope with change as some tests require project.evaluate to be called first. Currently ignoring jrubyPluginCustomGemRepoUrl test as it probably no longer needed.
1 parent 7eba39a commit e667a1d

File tree

7 files changed

+66
-21
lines changed

7 files changed

+66
-21
lines changed

src/integTest/groovy/com/lookout/jruby/JRubyExecExtensionIntegrationSpec.groovy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
package com.lookout.jruby
22

3+
import org.gradle.api.artifacts.repositories.ArtifactRepository
34
import org.gradle.testfixtures.ProjectBuilder
45
import spock.lang.Ignore
56
import spock.lang.IgnoreIf
67
import spock.lang.Specification
8+
import spock.lang.Stepwise
79

810
import static org.gradle.api.logging.LogLevel.LIFECYCLE
911

1012
/**
1113
* @author Schalk W. Cronjé
1214
*/
15+
@Stepwise
1316
class JRubyExecExtensionIntegrationSpec extends Specification {
1417
static final boolean TESTS_ARE_OFFLINE = System.getProperty('TESTS_ARE_OFFLINE') != null
1518
static final File TEST_SCRIPT_DIR = new File( System.getProperty('TESTS_SCRIPT_DIR') ?: 'src/integTest/resources/scripts')
16-
static final File TESTROOT = new File(System.getProperty('TESTROOT') ?: 'build/tmp/test/integration-tests')
19+
static final File TESTROOT = new File("${System.getProperty('TESTROOT') ?: 'build/tmp/test/integration-tests'}/jreeis")
1720

1821
def project
1922

2023
void setup() {
24+
if(TESTROOT.exists()) {
25+
TESTROOT.deleteDir()
26+
}
27+
TESTROOT.mkdirs()
2128
project = ProjectBuilder.builder().build()
2229
project.with {
2330
buildDir = TESTROOT

src/integTest/groovy/com/lookout/jruby/JRubyExecIntegrationSpec.groovy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ import static org.gradle.api.logging.LogLevel.LIFECYCLE
88
/**
99
* Created by schalkc on 20/08/2014.
1010
*/
11+
@Stepwise
1112
class JRubyExecIntegrationSpec extends Specification {
1213
static final boolean TESTS_ARE_OFFLINE = System.getProperty('TESTS_ARE_OFFLINE') != null
1314
static final File TEST_SCRIPT_DIR = new File( System.getProperty('TEST_SCRIPT_DIR') ?: 'src/integTest/resources/scripts')
14-
static final File TESTROOT = new File(System.getProperty('TESTROOT') ?: 'build/tmp/test/integration-tests')
15+
static final File TESTROOT = new File("${System.getProperty('TESTROOT') ?: 'build/tmp/test/integration-tests'}/jreis")
1516
static final String TASK_NAME = 'RubyWax'
1617

1718
def project
1819
def execTask
1920

2021
void setup() {
22+
if(TESTROOT.exists()) {
23+
TESTROOT.deleteDir()
24+
}
25+
TESTROOT.mkdirs()
2126
project = ProjectBuilder.builder().build()
2227
project.buildDir = TESTROOT
2328
project.logging.level = LIFECYCLE
@@ -93,7 +98,6 @@ class JRubyExecIntegrationSpec extends Specification {
9398
}
9499
}
95100

96-
97101
when:
98102
project.evaluate()
99103
execTask.exec()

src/integTest/groovy/com/lookout/jruby/JRubyPluginIntegrationSpec.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import static org.gradle.api.logging.LogLevel.LIFECYCLE
88
/**
99
* Created by schalkc on 20/08/2014.
1010
*/
11+
@Stepwise
1112
class JRubyPluginIntegrationSpec extends Specification {
1213

1314
static final boolean TESTS_ARE_OFFLINE = System.getProperty('TESTS_ARE_OFFLINE') != null

src/main/groovy/com/lookout/jruby/JRubyExec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ class JRubyExec extends JavaExec {
134134

135135
def jrubyCompletePath = project.configurations.getByName(jrubyConfigurationName)
136136
File gemDir = tmpGemDir()
137+
gemDir.mkdirs()
137138
environment 'GEM_HOME' : gemDir
138139

139140
if(configuration != null) {
140141
project.configurations.getByName(jrubyConfigurationName)
141142
project.with {
142-
mkdir gemDir
143143
configurations.getByName(configuration).files.findAll { File f ->
144144
f.name.endsWith('.gem')
145145
}.each { File f ->

src/main/groovy/com/lookout/jruby/JRubyPlugin.groovy

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,14 @@ class JRubyPlugin implements Plugin<Project> {
1313
project.apply plugin: 'war'
1414
project.extensions.create('jruby', JRubyPluginExtension, project)
1515

16-
project.ext {
17-
gemInstallDir = "${project.buildDir}/${project.jruby.gemInstallDir}"
18-
}
19-
20-
project.repositories {
21-
maven {
22-
// The url is in a closure to ensure that we can overwrite this
23-
// at runtime and have the right value come through.
24-
url { project.jruby.defaultGemRepo }
16+
if(!project.repositories.metaClass.respondsTo(project.repositories,'rubygemsRelease')) {
17+
project.repositories.metaClass.rubygemsRelease << { ->
18+
maven { url 'http://rubygems-proxy.torquebox.org/releases' }
2519
}
20+
}
2621

27-
// Required to pull in our warbler-bootstrap dependency
28-
maven { url 'http://dl.bintray.com/rtyler/jruby' }
29-
30-
// We'll need jcenter to resolve the jruby .jar deps
31-
jcenter()
22+
project.ext {
23+
gemInstallDir = "${project.buildDir}/${project.jruby.gemInstallDir}"
3224
}
3325

3426
// Set up a special configuration group for our embedding jars
@@ -37,12 +29,23 @@ class JRubyPlugin implements Plugin<Project> {
3729
jrubyWar
3830
gems
3931
}
32+
4033
project.configurations.create(JRubyExec.JRUBYEXEC_CONFIG)
4134
JRubyExecDelegate.addToProject(project)
4235

4336
// In order for jrubyWar to work we'll need to pull in the warbler
4437
// bootstrap code from this artifact
4538
project.afterEvaluate {
39+
if(project.jruby.defaultRepositories) {
40+
project.repositories {
41+
jcenter()
42+
rubygemsRelease()
43+
44+
// Required to pull in our warbler-bootstrap dependency
45+
maven { url 'http://dl.bintray.com/rtyler/jruby' }
46+
47+
}
48+
}
4649
project.dependencies {
4750
jrubyEmbeds group: 'com.lookout', name: 'warbler-bootstrap', version: '1.+'
4851
jrubyWar group: 'org.jruby', name: 'jruby-complete', version: project.jruby.defaultVersion
@@ -105,7 +108,7 @@ class JRubyPlugin implements Plugin<Project> {
105108
from "$project.buildDir/classes/main"
106109
// Bring our vendored gems into the created war file
107110
webInf {
108-
from project.gemInstallDir
111+
from project.jruby.gemInstallDir
109112
into 'gems'
110113
}
111114

src/main/groovy/com/lookout/jruby/JRubyPluginExtension.groovy

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
package com.lookout.jruby
22

3+
import org.gradle.api.Incubating
34
import org.gradle.api.Project
45

56
class JRubyPluginExtension {
67
// More details here: <http://rubygems-proxy.torquebox.org/>
7-
String defaultGemRepo = 'http://rubygems-proxy.torquebox.org/releases'
8-
String gemrepo_url = defaultGemRepo
8+
// String defaultGemRepo = 'http://rubygems-proxy.torquebox.org/releases'
9+
// String gemrepo_url = defaultGemRepo
910
String gemInstallDir = 'vendor'
11+
12+
/** The default version of jruby that will be used by jrubyWar
13+
*
14+
*/
1015
String defaultVersion = '1.7.13'
16+
17+
/** The version of jruby used by jrubyexec as well as default version of jruby that will be used by JRubyExec
18+
*
19+
*/
1120
String execVersion = defaultVersion
1221

22+
/** Set this to false if you do not want the default set of repositories to be loaded.
23+
*
24+
*/
25+
@Incubating
26+
boolean defaultRepositories = true
27+
1328
JRubyPluginExtension(Project p) {
1429
project = p
1530
}
1631

32+
/** Change the version of jruby for jrubyexec and JRubyExec
33+
*
34+
* @param newVersion
35+
*/
1736
void setExecVersion(final String newVersion) {
1837
execVersion = newVersion
1938

src/test/groovy/com/lookout/jruby/JRubyPluginTest.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ class JRubyPluginTest {
4949

5050
@Test
5151
public void jrubyPluginSetsRepositoriesCorrectly() {
52+
project.evaluate()
5253
assertTrue(hasRepositoryUrl(project, 'http://rubygems-proxy.torquebox.org/releases'))
5354
}
5455

5556
@Test
57+
@Ignore
5658
public void jrubyPluginCustomGemRepoUrl() {
5759
def url = 'http://junit.maven/releases'
5860
project.jruby.defaultGemRepo = url
61+
project.evaluate()
5962
assertTrue(hasRepositoryUrl(project, url))
6063
}
6164

@@ -71,6 +74,14 @@ class JRubyPluginTest {
7174
assertEquals(gem_name, GemUtils.gemFullNameFromFile(filename))
7275
}
7376

77+
@Test
78+
public void defaultRubyGemRepository() {
79+
project.evaluate()
80+
assertTrue project.repositories.metaClass.respondsTo(project.repositories,'rubygemsRelease') != null
81+
def repo = project.repositories.rubygemsRelease()
82+
assertTrue(hasRepositoryUrl(project, 'http://rubygems-proxy.torquebox.org/releases'))
83+
}
84+
7485
//
7586
// Helper methods for testing
7687
////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)