Skip to content

Commit

Permalink
Merge pull request #111 from ysb33r/master
Browse files Browse the repository at this point in the history
 Resolved issues port #108 merge
  • Loading branch information
R. Tyler Croy committed Apr 22, 2015
2 parents 63f7cf2 + 15307fa commit 2c83736
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 11 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ dependencies {
compile gradleApi()
compile localGroovy()

testCompile 'junit:junit:4.+'

String spockVersion = "org.spockframework:spock-core:0.7-groovy-${gradle.gradleVersion.startsWith('1.')?'1.8':'2.0'}"
String spockVersion = "org.spockframework:spock-core:1.0-groovy-2.3"

testCompile (spockVersion) {
exclude module : 'groovy-all'
Expand Down
23 changes: 16 additions & 7 deletions src/main/groovy/com/github/jrubygradle/GemUtils.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.jrubygradle

import com.github.jrubygradle.internal.JRubyExecUtils
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.CopySpec
Expand Down Expand Up @@ -51,6 +52,8 @@ class GemUtils {
Set<File> gemsToProcess = []
Set<File> deletes = []

Map jrubyVersion = JRubyExecUtils.jrubyJarVersionTriple(jRubyClasspath)

getGems(gems).files.each { File gem ->
String gemName = gemFullNameFromFile(gem.name)
File extractDir = new File(destDir, "gems/${gemName}")
Expand Down Expand Up @@ -99,13 +102,13 @@ class GemUtils {
// is overwritten
args '--ignore-dependencies',
"--install-dir=${destDir.absolutePath}",
'--no-user-install',
'--wrappers',
'--no-user-install',
'--wrappers',
'-N',
'--platform=java'

// Workaround for bug
if(jRubyClasspath.name.contains('1.7.14')) {
if(JRubyExecUtils.jrubyJarVersion(jRubyClasspath) == '1.7.14') {
project.logger.debug "Gem installation: Working around bug in jruby 1.7.14"
environment HOME : project.gradle.gradleUserHomeDir.absolutePath
}
Expand All @@ -117,10 +120,16 @@ class GemUtils {

systemProperties 'file.encoding' : 'utf-8'
}
project.javaexec {
main 'org.jruby.Main'
classpath jRubyClasspath
args '-r', 'jruby/commands', '-e', "JRuby::Commands.generate_dir_info( '${destDir.absolutePath}' )"

if(jrubyVersion.major == 1 && jrubyVersion.minor <= 7 && jrubyVersion.patchlevel < 19) {
project.logger.warn "Not generating JRuby directory info information as current JRuby version < 1.7.19"
} else {
project.javaexec {
main 'org.jruby.Main'
classpath jRubyClasspath
args '-r', 'jruby/commands', '-e', "JRuby::Commands.generate_dir_info( '${destDir.absolutePath}' )"

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,32 @@ class JRubyExecUtils {
* @since 0.1.9
*/
@CompileDynamic
static String jrubyJarVersion(File jar) {
static String jrubyJarVersion(final File jar) {
Matcher matches = jar.name =~ /jruby-complete-(.+)\.jar/
!matches ? null : matches[0][1]
}

/** Extracts the JRuby version number as a triplet from a jruby-complete-XXX.jar filename
*
* @param jar JRuby Jar
* @return Version string map [major,minor,patchlevel] or null
*
* @since 0.1.16
*/
@CompileDynamic
static Map jrubyJarVersionTriple(final File jar) {
String version = jrubyJarVersion(jar)
if(!version) {return null}

Matcher matches = version =~ /(\d{1,2})\.(\d{1,3})\.(\d{1,3})/

(!matches.matches() || matches[0].size() != 4) ? null : [
major : matches[0][1].toInteger(),
minor : matches[0][2].toInteger(),
patchlevel : matches[0][3].toInteger()
]
}

/** Extract the jruby-complete-XXX.jar as a FileCollection
*
* @param cfg FileCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,28 @@ class JRubyExecUtilsSpec extends Specification {
cmdArgs instanceof List<String>
cmdArgs.find { it == 'spock' }
}

def "The version string in a jruby jar filename must be extracted correctly"() {

expect:
version == JRubyExecUtils.jrubyJarVersion(new File(jarName))

where:
jarName || version
'jruby-complete-1.7.14.jar' || '1.7.14'
'jruby-complete-22.999.888.jar' || '22.999.888'
'jruby-complete.jar' || null
}

def "The version information in a jruby jar filename must be extracted correctly"() {

expect:
triplet == JRubyExecUtils.jrubyJarVersionTriple(new File(jarName))

where:
jarName || triplet
'jruby-complete-1.7.14.jar' || [ major : 1, minor : 7, patchlevel : 14]
'jruby-complete-22.999.888.jar' || [ major : 22, minor : 999, patchlevel : 888 ]
'jruby-complete.jar' || null
}
}

0 comments on commit 2c83736

Please sign in to comment.