|
1 | 1 | package com.github.jrubygradle.jar
|
2 | 2 |
|
| 3 | +import org.gradle.api.Task |
3 | 4 | import org.gradle.api.file.FileCollection
|
4 | 5 | import org.gradle.api.tasks.bundling.Jar
|
5 | 6 | import org.gradle.testfixtures.ProjectBuilder
|
@@ -190,4 +191,135 @@ class JRubyJarPluginSpec extends Specification {
|
190 | 191 | jarTask.manifest.effectiveManifest.attributes['Class-Path']?.contains("lib/jruby-complete-${jrubyTestVersion}.jar".toString())
|
191 | 192 |
|
192 | 193 | }
|
| 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 | + |
193 | 325 | }
|
0 commit comments