Skip to content

Commit 7a54e50

Browse files
committed
Restructured JRubyJarPluginSpec
1 parent 79121f8 commit 7a54e50

File tree

6 files changed

+80
-89
lines changed

6 files changed

+80
-89
lines changed

base-plugin/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
apply plugin: TestConfigPlugin
2-
apply plugin: 'java-gradle-plugin'
3-
apply from: "${rootProject.projectDir}/gradle/integration-tests.gradle"
4-
5-
apply plugin: 'maven-publish'
61

72
// --- Could be in a separate gradle file
83
configurations {

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ buildScan {
1313
allprojects {
1414
apply plugin: 'idea'
1515

16-
group = 'com.github.jruby-gradle'
17-
version = '1.7.0'
16+
1817

1918
if (!releaseBuild) {
2019
version = "${version}-SNAPSHOT"
@@ -39,11 +38,14 @@ subprojects {
3938
}
4039

4140
if(project.name != 'docs') {
41+
apply plugin: TestConfigPlugin
42+
apply plugin: 'java-gradle-plugin'
4243
apply plugin: 'groovy'
4344
apply plugin: 'codenarc'
4445
apply plugin: 'com.jfrog.bintray'
4546
apply plugin: 'org.ysb33r.gradletest'
46-
47+
apply plugin: 'maven-publish'
48+
apply from: "${rootProject.projectDir}/gradle/integration-tests.gradle"
4749

4850
dependencies {
4951
compile localGroovy()

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
version=1.7.0
2+
group=com.github.jruby-gradle
3+
14
org.gradle.daemon=true
25
org.gradle.caching=true
36
org.gradle.parallel=false

jar-plugin/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
group = rootProject.group
2-
version = rootProject.version
31

4-
apply from: "gradle/integration-test.gradle"
2+
3+
54

65
configurations {
76
testRepo

jar-plugin/src/integTest/groovy/com/github/jrubygradle/jar/JRubyJarIntegrationSpec.groovy

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,48 @@ class JRubyJarIntegrationSpec extends Specification {
102102
config.dependencies.find { it.name == 'jruby-mains' && it.version == version }
103103
config.dependencies.findAll({ it.name == 'jruby-mains' }).size() == 1
104104
}
105+
106+
/*
107+
@Ignore('should be an integration test since we add jar-dependencies')
108+
def "prepareTask should have its configuration lazily set"() {
109+
given:
110+
Task prepareTask = jarTask.dependsOn.find { it instanceof JRubyPrepare }
111+
112+
when:
113+
project.evaluate()
114+
115+
then:
116+
prepareTask.dependencies.find { (it instanceof Configuration) && (it.name == jarTask.configuration) }
117+
}
118+
119+
def "Adding a default main class"() {
120+
when: "Setting a default main class"
121+
project.configure(jarTask) {
122+
defaultMainClass()
123+
}
124+
jarTask.addJRubyDependency()
125+
jarTask.applyConfig()
126+
127+
then: "Then the attribute should be set to the default in the manifest"
128+
jarTask.manifest.attributes.'Main-Class' == DEFAULT_MAIN_CLASS
129+
}
130+
131+
@Ignore('should be an integration test since we add jar-dependencies')
132+
@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/115')
133+
def "jrubyVersion is lazily evaluated"() {
134+
given:
135+
final String version = '1.7.11'
136+
137+
when:
138+
project.jruby {
139+
defaultVersion version
140+
}
141+
project.evaluate()
142+
143+
then:
144+
project.tasks.findByName('jrubyJar').jrubyVersion == version
145+
}
146+
147+
*/
105148
}
106149

Lines changed: 27 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.github.jrubygradle.jar
22

3-
import com.github.jrubygradle.JRubyPlugin
43
import com.github.jrubygradle.JRubyPrepare
54
import org.gradle.api.InvalidUserDataException
65
import org.gradle.api.Project
76
import org.gradle.api.Task
8-
import org.gradle.api.artifacts.Configuration
97
import org.gradle.api.file.FileCollection
108
import org.gradle.testfixtures.ProjectBuilder
11-
import spock.lang.*
9+
import spock.lang.Specification
1210

13-
import static org.gradle.api.logging.LogLevel.LIFECYCLE
11+
import static com.github.jrubygradle.jar.JRubyJar.DEFAULT_MAIN_CLASS
1412

1513
/**
1614
* @author R. Tyler Croy
@@ -19,8 +17,6 @@ import static org.gradle.api.logging.LogLevel.LIFECYCLE
1917
*
2018
*/
2119
class JRubyJarPluginSpec extends Specification {
22-
static final File TESTROOT = new File("${System.getProperty('TESTROOT') ?: 'build/tmp/test/unittests'}/jrjps")
23-
static final File TESTREPO_LOCATION = new File("${System.getProperty('TESTREPO_LOCATION') ?: 'build/tmp/test/repo'}")
2420

2521
Project project
2622
JRubyJar jarTask
@@ -36,18 +32,15 @@ class JRubyJarPluginSpec extends Specification {
3632
static Project setupProject() {
3733
Project project = ProjectBuilder.builder().build()
3834
project.gradle.startParameter.offline = true
39-
File repo = project.file("${TESTREPO_LOCATION}/../../../../../jruby-gradle-base-plugin/src/integTest/mavenrepo")
40-
41-
project.buildDir = TESTROOT
4235

4336
project.with {
4437
apply plugin: 'com.github.jruby-gradle.jar'
4538
jruby.defaultRepositories = false
4639

4740
repositories {
48-
flatDir dirs : TESTREPO_LOCATION.absolutePath
41+
flatDir dirs: project.file('fakerepo')
4942
maven {
50-
url "file://" + repo.absolutePath
43+
url "file://" + project.file('fakerepo').absolutePath
5144
}
5245
}
5346
}
@@ -56,30 +49,26 @@ class JRubyJarPluginSpec extends Specification {
5649
}
5750

5851
void setup() {
59-
if (TESTROOT.exists()) {
60-
TESTROOT.deleteDir()
61-
}
62-
TESTROOT.mkdirs()
63-
6452
project = setupProject()
6553
jarTask = project.tasks.getByName('jrubyJar')
6654
}
6755

68-
def 'Checking tasks exist'() {
56+
void 'Checking tasks exist'() {
6957
expect:
7058
project.tasks.getByName('jrubyJar')
7159
}
7260

73-
def 'Checking appendix'() {
61+
void 'Checking appendix'() {
7462
expect:
7563
project.tasks.getByName('jrubyJar').appendix == 'jruby'
7664
}
7765

78-
def "Fails on adding non-existing initScript"() {
66+
void "Fails on adding non-existing initScript"() {
7967
given:
68+
def TESTROOT = new File(project.projectDir, 'fake')
8069
project.jruby.gemInstallDir = TESTROOT.absolutePath
81-
new File(TESTROOT,'gems').mkdirs()
82-
new File(TESTROOT,'gems/fake.txt').text = 'fake.content'
70+
new File(TESTROOT, 'gems').mkdirs()
71+
new File(TESTROOT, 'gems/fake.txt').text = 'fake.content'
8372

8473
when: "Setting a default main class"
8574
project.configure(jarTask) {
@@ -91,19 +80,7 @@ class JRubyJarPluginSpec extends Specification {
9180
thrown(InvalidUserDataException)
9281
}
9382

94-
def "Adding a default main class"() {
95-
when: "Setting a default main class"
96-
project.configure(jarTask) {
97-
defaultMainClass()
98-
}
99-
jarTask.addJRubyDependency()
100-
jarTask.applyConfig()
101-
102-
then: "Then the attribute should be set to the default in the manifest"
103-
jarTask.manifest.attributes.'Main-Class' == JRubyJar.DEFAULT_MAIN_CLASS
104-
}
105-
106-
def "Adding a default extracting main class"() {
83+
void "Adding a default extracting main class"() {
10784
when: "Setting a default extracting main class"
10885
project.configure(jarTask) {
10986
extractingMainClass()
@@ -114,7 +91,7 @@ class JRubyJarPluginSpec extends Specification {
11491
jarTask.manifest.attributes.'Main-Class' == JRubyJar.EXTRACTING_MAIN_CLASS
11592
}
11693

117-
def "Adding a custom main class"() {
94+
void "Adding a custom main class"() {
11895
when: "Setting a default main class"
11996
project.configure(jarTask) {
12097
mainClass 'org.scooby.doo.snackMain'
@@ -125,7 +102,7 @@ class JRubyJarPluginSpec extends Specification {
125102
jarTask.manifest.attributes.'Main-Class' == 'org.scooby.doo.snackMain'
126103
}
127104

128-
def "Adding a main class and additional manifest attributes"() {
105+
void "Adding a main class and additional manifest attributes"() {
129106
when: "Setting a main class"
130107
project.configure(jarTask) {
131108
mainClass 'org.scooby.doo.snackMain'
@@ -137,14 +114,15 @@ class JRubyJarPluginSpec extends Specification {
137114
jarTask.manifest.attributes.'Class-Path' == 'gangway.jar zoinks.jar'
138115
}
139116

140-
def "Setting up a java project"() {
117+
void "Setting up a java project"() {
141118
given: "All jar, java plugins have been applied"
119+
def TESTROOT = new File(project.projectDir, 'TESTROOT')
142120
project = setupProject()
143-
project.apply plugin : 'java'
121+
project.apply plugin: 'java'
144122
Task jar = project.tasks.getByName('jrubyJar')
145123

146124
and: "A local repository"
147-
File expectedDir= new File(TESTROOT,'libs/')
125+
File expectedDir = new File(TESTROOT, 'libs/')
148126
expectedDir.mkdirs()
149127
project.configure(jar) {
150128
initScript library()
@@ -155,19 +133,19 @@ class JRubyJarPluginSpec extends Specification {
155133
jar.taskDependencies.getDependencies(jar).contains(project.tasks.getByName('prepareJRubyJar'))
156134
}
157135

158-
def 'Checking setting no mainClass'() {
136+
void 'Checking setting no mainClass'() {
159137
when:
160-
project.file( 'app.rb') << ''
138+
project.file('app.rb') << ''
161139
jarTask.initScript('app.rb')
162140
jarTask.applyConfig()
163141

164142
then:
165-
jarTask.manifest.attributes['Main-Class'] == JRubyJar.DEFAULT_MAIN_CLASS
143+
jarTask.manifest.attributes['Main-Class'] == DEFAULT_MAIN_CLASS
166144
}
167145

168-
def 'Checking setting of mainClass once'() {
146+
void 'Checking setting of mainClass once'() {
169147
when:
170-
project.file( 'app.rb') << ''
148+
project.file('app.rb') << ''
171149
jarTask.initScript('app.rb')
172150
jarTask.mainClass('org.example.Main')
173151
jarTask.applyConfig()
@@ -176,7 +154,7 @@ class JRubyJarPluginSpec extends Specification {
176154
jarTask.manifest.attributes['Main-Class'] == 'org.example.Main'
177155
}
178156

179-
def 'Checking setup runnable jrubyJar task'() {
157+
void 'Checking setup runnable jrubyJar task'() {
180158
when:
181159
jarTask.initScript(jarTask.runnable())
182160
jarTask.applyConfig()
@@ -185,7 +163,7 @@ class JRubyJarPluginSpec extends Specification {
185163
jarTask.manifest.attributes.containsKey('Main-Class')
186164
}
187165

188-
def 'Checking valid library config'() {
166+
void 'Checking valid library config'() {
189167
when:
190168
jarTask.initScript(jarTask.library())
191169
jarTask.applyConfig()
@@ -194,7 +172,7 @@ class JRubyJarPluginSpec extends Specification {
194172
!jarTask.manifest.attributes.containsKey('Main-Class')
195173
}
196174

197-
def 'Checking invalid library config'() {
175+
void 'Checking invalid library config'() {
198176
when:
199177
jarTask.initScript(jarTask.library())
200178
jarTask.extractingMainClass()
@@ -205,37 +183,8 @@ class JRubyJarPluginSpec extends Specification {
205183
e.message == 'can not have mainClass for library'
206184
}
207185

208-
@Ignore('should be an integration test since we add jar-dependencies')
209-
@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/115')
210-
def "jrubyVersion is lazily evaluated"() {
211-
given:
212-
final String version = '1.7.11'
213-
214-
when:
215-
project.jruby {
216-
defaultVersion version
217-
}
218-
project.evaluate()
219-
220-
then:
221-
project.tasks.findByName('jrubyJar').jrubyVersion == version
222-
}
223-
224-
def "prepareTask should be an instance of JRubyPrepare"() {
186+
void "prepareTask should be an instance of JRubyPrepare"() {
225187
expect:
226188
jarTask.dependsOn.find { (it instanceof JRubyPrepare) && (it.name == 'prepareJRubyJar') }
227189
}
228-
229-
@Ignore('should be an integration test since we add jar-dependencies')
230-
def "prepareTask should have its configuration lazily set"() {
231-
given:
232-
Task prepareTask = jarTask.dependsOn.find { it instanceof JRubyPrepare }
233-
234-
when:
235-
project.evaluate()
236-
237-
then:
238-
prepareTask.dependencies.find { (it instanceof Configuration) && (it.name == jarTask.configuration) }
239-
}
240-
}
241-
190+
}

0 commit comments

Comments
 (0)