Skip to content
This repository was archived by the owner on May 19, 2019. It is now read-only.

Commit be27986

Browse files
committed
Merge pull request #7 from ysb33r/master
Added additional unit tests. .
2 parents d54b46c + a3339d7 commit be27986

File tree

3 files changed

+138
-1
lines changed

3 files changed

+138
-1
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ apply plugin: 'groovy'
22
apply plugin: 'maven'
33
apply plugin: 'com.jfrog.bintray'
44

5+
56
buildscript {
67
repositories { jcenter() }
78
dependencies { classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.5' }
89
}
910

1011
group = 'com.github.jruby-gradle'
1112
version = '0.1.1'
13+
archivesBaseName = 'jruby-gradle-jar-plugin'
1214

1315
if (System.env.RELEASE != '1') {
1416
version = "${version}-SNAPSHOT"

src/main/groovy/com/github/jrubygradle/jar/JRubyJarConfigurator.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class JRubyJarConfigurator {
112112
*/
113113
@Incubating
114114
void configuration(String name) {
115-
this.configurations.add(archive.project.configurations.getByName(name))
115+
this.configuration(archive.project.configurations.getByName(name))
116116
}
117117

118118
/** Adds a configuration to the list of dependencies that will be packed when creating an executable jar
@@ -122,6 +122,9 @@ class JRubyJarConfigurator {
122122
*/
123123
@Incubating
124124
void configuration(Configuration config) {
125+
if(this.configurations==null) {
126+
this.configurations = []
127+
}
125128
this.configurations.add(config)
126129
}
127130

src/test/groovy/com/github/jrubygradle/jar/JRubyJarPluginSpec.groovy

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.jrubygradle.jar
22

3+
import org.gradle.api.Task
34
import org.gradle.api.file.FileCollection
45
import org.gradle.api.tasks.bundling.Jar
56
import org.gradle.testfixtures.ProjectBuilder
@@ -190,4 +191,135 @@ class JRubyJarPluginSpec extends Specification {
190191
jarTask.manifest.effectiveManifest.attributes['Class-Path']?.contains("lib/jruby-complete-${jrubyTestVersion}.jar".toString())
191192

192193
}
194+
195+
def "Building a Jar with a custom configuration"() {
196+
given: "A local repository"
197+
final String jrubyTestVersion = '1.7.15'
198+
File expectedDir= new File(TESTROOT,'libs/')
199+
expectedDir.mkdirs()
200+
File expectedJar= new File(expectedDir,'test.jar')
201+
project.jruby.gemInstallDir = new File(TESTROOT,'fakeGemDir').absolutePath
202+
203+
new File(project.jruby.gemInstallDir,'gems').mkdirs()
204+
new File(project.jruby.gemInstallDir,'gems/fake.txt').text = 'fake.content'
205+
206+
project.with {
207+
jruby {
208+
defaultRepositories = false
209+
warblerBootstrapVersion = '0.1.0'
210+
defaultVersion = jrubyTestVersion
211+
}
212+
repositories {
213+
ivy {
214+
url WARBLER_LOCATION
215+
layout('pattern') {
216+
artifact '[module]-[revision](.[ext])'
217+
}
218+
}
219+
}
220+
dependencies {
221+
jrubyJar 'org.spockframework:spock-core:0.7-groovy-2.0'
222+
}
223+
}
224+
225+
when: "I set the default main class"
226+
project.configure(jarTask) {
227+
archiveName = 'test.jar'
228+
destinationDir = expectedDir
229+
jruby {
230+
defaults 'gems'
231+
mainClass JRubyJarConfigurator.DEFAULT_MAIN_CLASS
232+
configuration 'jrubyJar'
233+
}
234+
235+
}
236+
project.evaluate()
237+
238+
and: "I actually build the JAR"
239+
project.tasks.getByName("${jarTask.name}ExtraManifest").execute()
240+
241+
jarTask.copy()
242+
def builtJar = fileNames(project.zipTree(expectedJar))
243+
244+
then: "I expect to see the JarMain.class embedded in the JAR"
245+
expectedJar.exists()
246+
builtJar.contains('com/lookout/jruby/JarMain.class')
247+
!builtJar.contains('com/lookout/jruby/WarMain.class')
248+
249+
and: "I expect to see jruby-complete packed in libs"
250+
builtJar.contains("META-INF/lib/jruby-complete-${jrubyTestVersion}.jar".toString())
251+
252+
and: "I expect to see manifest to include it"
253+
jarTask.manifest.effectiveManifest.attributes['Class-Path']?.contains("lib/jruby-complete-${jrubyTestVersion}.jar".toString())
254+
255+
}
256+
257+
def "Building a Jar with a custom configuration and 'java' plugin is applied"() {
258+
given: "Java plugin applied before JRuby Jar plugin"
259+
project = ProjectBuilder.builder().build()
260+
project.buildDir = TESTROOT
261+
project.logging.level = LIFECYCLE
262+
project.apply plugin : 'java'
263+
project.apply plugin: 'com.github.jruby-gradle.jar'
264+
Task jar = project.tasks.getByName('jar')
265+
266+
and: "A local repository"
267+
final String jrubyTestVersion = '1.7.15'
268+
File expectedDir= new File(TESTROOT,'libs/')
269+
expectedDir.mkdirs()
270+
File expectedJar= new File(expectedDir,'test.jar')
271+
project.jruby.gemInstallDir = new File(TESTROOT,'fakeGemDir').absolutePath
272+
273+
new File(project.jruby.gemInstallDir,'gems').mkdirs()
274+
new File(project.jruby.gemInstallDir,'gems/fake.txt').text = 'fake.content'
275+
276+
project.with {
277+
jruby {
278+
defaultRepositories = false
279+
warblerBootstrapVersion = '0.1.0'
280+
defaultVersion = jrubyTestVersion
281+
}
282+
repositories {
283+
ivy {
284+
url WARBLER_LOCATION
285+
layout('pattern') {
286+
artifact '[module]-[revision](.[ext])'
287+
}
288+
}
289+
}
290+
dependencies {
291+
jrubyJar 'org.spockframework:spock-core:0.7-groovy-2.0'
292+
}
293+
}
294+
295+
when: "I set the default main class"
296+
project.configure(jar) {
297+
archiveName = 'test.jar'
298+
destinationDir = expectedDir
299+
jruby {
300+
defaults 'gems'
301+
mainClass 'bogus.does.not.exist'
302+
configuration 'jrubyJar'
303+
}
304+
305+
}
306+
project.evaluate()
307+
308+
and: "I actually build the JAR"
309+
project.tasks.getByName("jarExtraManifest").execute()
310+
311+
jar.copy()
312+
def builtJar = fileNames(project.zipTree(expectedJar))
313+
314+
then: "I expect to see jruby-complete packed in libs"
315+
builtJar.contains("META-INF/lib/jruby-complete-${jrubyTestVersion}.jar".toString())
316+
317+
and: "I expect to see manifest to include it"
318+
jar.manifest.effectiveManifest.attributes['Class-Path']?.contains("lib/jruby-complete-${jrubyTestVersion}.jar".toString())
319+
320+
and: "I expect the new main class to be listed in the manifest"
321+
jar.manifest.effectiveManifest.attributes['Main-Class']?.contains('bogus.does.not.exist')
322+
323+
}
324+
193325
}

0 commit comments

Comments
 (0)