From 386f2d09e525384c49b4e08c4ce61b549d1c88b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 18:05:37 +0000 Subject: [PATCH 1/9] Refactored the way environment is prepared in JRubyExec (to less lines of code) --- .../com/github/jrubygradle/JRubyExec.groovy | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy index cdef9ba0..d21121b3 100644 --- a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -264,21 +264,10 @@ class JRubyExec extends JavaExec { 'JARS_SKIP' : 'true', ] - env.each { key, value -> - /* Filter all out all the undesirable environment variables to - * propogate into the child process' environment - */ - if (!inheritRubyEnv) { - if ( (key in FILTER_ENV_KEYS) || - (key.startsWith('rvm')) || - (key in newEnv)) { - return - } - } - newEnv.put(key, value) - } + env.findAll { String key,Object value -> + inheritRubyEnv || !(key in FILTER_ENV_KEYS || key.toLowerCase().startsWith('rvm')) + } + newEnv - return newEnv } private static UnsupportedOperationException notAllowed(final String msg) { From 9b139e636ca1e5a402f89f98527c7e9499ae8c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 20:46:02 +0000 Subject: [PATCH 2/9] Address path variable in a platform-sensitive manner when preparing the JRubyExec environment --- .../com/github/jrubygradle/JRubyExec.groovy | 28 +++---------------- .../internal/JRubyExecUtils.groovy | 19 +++++++++++++ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy index d21121b3..84a91b86 100644 --- a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -1,20 +1,12 @@ package com.github.jrubygradle import com.github.jrubygradle.internal.JRubyExecUtils -import org.gradle.api.InvalidUserDataException import org.gradle.api.Project -import org.gradle.api.artifacts.Configuration -import org.gradle.api.file.FileCollection import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskInstantiationException import org.gradle.internal.FileUtils -import org.gradle.process.ExecResult import org.gradle.process.JavaExecSpec import org.gradle.util.CollectionUtils @@ -25,8 +17,6 @@ import org.gradle.util.CollectionUtils class JRubyExec extends JavaExec { static final String JRUBYEXEC_CONFIG = 'jrubyExec' - // Names of environment variables that we can/should filter out - static final List FILTER_ENV_KEYS = ['GEM_PATH', 'RUBY_VERSION', 'GEM_HOME'] static void updateJRubyDependencies(Project proj) { proj.dependencies { @@ -254,20 +244,10 @@ class JRubyExec extends JavaExec { } Map getPreparedEnvironment(Map env) { - Map newEnv = [ - 'PATH' : getComputedPATH(System.env.PATH), - 'GEM_HOME' : getGemWorkDir().absoluteFile, - // Skip all the default behaviors that the - // jar-dependencies and jbundler might attempt at runtime - 'JARS_NO_REQUIRE' : 'true', - 'JBUNDLE_SKIP' : 'true', - 'JARS_SKIP' : 'true', - ] - - env.findAll { String key,Object value -> - inheritRubyEnv || !(key in FILTER_ENV_KEYS || key.toLowerCase().startsWith('rvm')) - } + newEnv - + JRubyExecUtils.preparedEnvironment(env,inheritRubyEnv) + [ + (JRubyExecUtils.pathVar()) : getComputedPATH(System.env."${JRubyExecUtils.pathVar()}"), + 'GEM_HOME' : getGemWorkDir().absoluteFile, + ] } private static UnsupportedOperationException notAllowed(final String msg) { diff --git a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy index fccc9704..df19eff5 100644 --- a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy +++ b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy @@ -14,6 +14,8 @@ import java.util.regex.Matcher @CompileStatic class JRubyExecUtils { + static final List FILTER_ENV_KEYS = ['GEM_PATH', 'RUBY_VERSION', 'GEM_HOME'] + /** Extract a list of files from a configuration that is suitable for a jruby classpath * * @param cfg Configuration to use @@ -76,4 +78,21 @@ class JRubyExecUtils { cmdArgs.addAll(scriptArgs) cmdArgs as List } + + static Map preparedEnvironment(Map env,boolean inheritRubyEnv) { + Map newEnv = [ + 'JARS_NO_REQUIRE' : 'true', + 'JBUNDLE_SKIP' : 'true', + 'JARS_SKIP' : 'true', + ] as Map + + env.findAll { String key,Object value -> + inheritRubyEnv || !(key in FILTER_ENV_KEYS || key.toLowerCase().startsWith('rvm')) + } + newEnv + + } + + static String pathVar() { + org.gradle.internal.os.OperatingSystem.current().pathVar + } } From f56b269b3f0cbde65e951fa470d8a2bc4419c124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 21:05:44 +0000 Subject: [PATCH 3/9] Refactored computation of a working search path when using GEMs so that it works properly in a cross-platform manner --- .../com/github/jrubygradle/JRubyExec.groovy | 3 +-- .../internal/JRubyExecUtils.groovy | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy index 84a91b86..916e279c 100644 --- a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -145,8 +145,7 @@ class JRubyExec extends JavaExec { * */ String getComputedPATH(String originalPath) { - File path = new File(getGemWorkDir(), 'bin') - return path.absolutePath + File.pathSeparatorChar + originalPath + JRubyExecUtils.prepareWorkingPath(getGemWorkDir(),originalPath) } /** Setting the {@code jruby-complete} version allows for tasks to be run using different versions of JRuby. diff --git a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy index df19eff5..8228f566 100644 --- a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy +++ b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy @@ -79,6 +79,13 @@ class JRubyExecUtils { cmdArgs as List } + /** Prepare a basic environment for usage with an external JRuby environment + * + * @param env Environment to start from + * @param inheritRubyEnv Set to {@code true} is the global RUby environment should be inherited + * @return Map of environmental variables + * @since 0.1.11 + */ static Map preparedEnvironment(Map env,boolean inheritRubyEnv) { Map newEnv = [ 'JARS_NO_REQUIRE' : 'true', @@ -92,7 +99,25 @@ class JRubyExecUtils { } + /** Get the name of the system search path environmental variable + * + * @return Name of variable + * @since 0.1.11 + */ static String pathVar() { org.gradle.internal.os.OperatingSystem.current().pathVar } + + /** Create a search path that includes the GEM working directory + * + * @param gemWorkDir GEM work dir instance + * @param originalPath The original platform-specific search path + * @return A search suitable for the specific operating system the job will run on + * @since 0.1.11 + */ + static String prepareWorkingPath(File gemWorkDir, String originalPath) { + File path = new File(gemWorkDir, 'bin') + return path.absolutePath + File.pathSeparatorChar + originalPath + } + } From 49eb69412f42d62d35a046e11ff3c05de791f175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 21:33:00 +0000 Subject: [PATCH 4/9] project.jrubyexec now uses the same environment preparation as JRubyExec --- .../groovy/com/github/jrubygradle/JRubyExec.groovy | 5 ++--- .../jrubygradle/internal/JRubyExecDelegate.groovy | 11 ++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy index 916e279c..751a831c 100644 --- a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -56,9 +56,8 @@ class JRubyExec extends JavaExec { * * @since 0.1.10 */ - @Optional @Input - Boolean inheritRubyEnv + Boolean inheritRubyEnv = false /** Directory to use for unpacking GEMs. * This is optional. If not set, then an internal generated folder will be used. In general the latter behaviour @@ -245,7 +244,7 @@ class JRubyExec extends JavaExec { Map getPreparedEnvironment(Map env) { JRubyExecUtils.preparedEnvironment(env,inheritRubyEnv) + [ (JRubyExecUtils.pathVar()) : getComputedPATH(System.env."${JRubyExecUtils.pathVar()}"), - 'GEM_HOME' : getGemWorkDir().absoluteFile, + 'GEM_HOME' : getGemWorkDir().absolutePath, ] } diff --git a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy index e211b70e..963c647c 100644 --- a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy +++ b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy @@ -100,6 +100,12 @@ class JRubyExecDelegate { JRubyExecUtils.buildArgs(jrubyArgs,script,scriptArgs) } + /** Allow jrubyexec to inherit a Ruby env from the shell (e.g. RVM) + * + * @since 0.1.11 + */ + boolean inheritRubyEnv = false + @PackageScope def keyAt(Integer index) { passthrough[index].keySet()[0] @@ -133,7 +139,7 @@ class JRubyExecDelegate { GemUtils.OverwriteAction overwrite = project.gradle.startParameter.refreshDependencies ? GemUtils.OverwriteAction.OVERWRITE : GemUtils.OverwriteAction.SKIP project.mkdir gemDir GemUtils.extractGems(project,config,config,gemDir,overwrite) - + String pathVar = JRubyExecUtils.pathVar() project.javaexec { classpath JRubyExecUtils.classpathFromConfiguration(config) proxy.passthrough.each { item -> @@ -145,6 +151,9 @@ class JRubyExecDelegate { proxy.buildArgs().each { item -> args item.toString() } + + setEnvironment JRubyExecUtils.preparedEnvironment(getEnvironment(),proxy.inheritRubyEnv) + environment pathVar , JRubyExecUtils.prepareWorkingPath(gemDir,System.env."${pathVar}") environment 'GEM_HOME' : gemDir.absolutePath } } From 15829f84757285e3c089f42bf550e36264db8c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 21:59:34 +0000 Subject: [PATCH 5/9] Made sure that if getGemWorkDir changes value, that JRubyExec will rebuild --- src/main/groovy/com/github/jrubygradle/JRubyExec.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy index 751a831c..255fb1df 100644 --- a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -3,6 +3,7 @@ package com.github.jrubygradle import com.github.jrubygradle.internal.JRubyExecUtils import org.gradle.api.Project import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputDirectory import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.Optional import org.gradle.api.tasks.TaskInstantiationException @@ -69,12 +70,13 @@ class JRubyExec extends JavaExec { */ Object gemWorkDir - /** Returns the directory that will be used to unapck GEMs in. + /** Returns the directory that will be used to unpack GEMs in. * * @return Target directory * @since 0.1.9 */ @Optional + @Input File getGemWorkDir() { gemWorkDir ? project.file(gemWorkDir) : tmpGemDir() } @@ -83,7 +85,6 @@ class JRubyExec extends JavaExec { JRubyExec() { super() super.setMain 'org.jruby.Main' - setInheritRubyEnv false try { project.configurations.getByName(JRUBYEXEC_CONFIG) From 7f57b69f96294b6f684431278d6b1777045c5ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 23:02:57 +0000 Subject: [PATCH 6/9] Stop Appveyour CI if one of the matrix builds fail --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index dc36509e..26cf3727 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,3 +21,5 @@ environment: - JAVA_HOME: C:\Program Files (x86)\Java\jdk1.7.0 - JAVA_HOME: C:\Program Files (x86)\Java\jdk1.8.0 +matrix: + fast_finish: true From 22fed4239e80a10fce3cea04da605f2370ca6780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 23:08:09 +0000 Subject: [PATCH 7/9] Looks like the previous fix for handling search path in a cross-platform way was broken --- src/main/groovy/com/github/jrubygradle/GemUtils.groovy | 2 ++ src/main/groovy/com/github/jrubygradle/JRubyExec.groovy | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/github/jrubygradle/GemUtils.groovy b/src/main/groovy/com/github/jrubygradle/GemUtils.groovy index cc950e36..4074ffba 100644 --- a/src/main/groovy/com/github/jrubygradle/GemUtils.groovy +++ b/src/main/groovy/com/github/jrubygradle/GemUtils.groovy @@ -109,6 +109,8 @@ class GemUtils { if(System.getProperty('os.name').toLowerCase().startsWith('windows')) { environment 'TMP' : System.env.TMP, 'TEMP' : System.env.TEMP } + + systemProperties 'file.encoding' : 'utf-8' } } } diff --git a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy index 255fb1df..964cb769 100644 --- a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -244,7 +244,8 @@ class JRubyExec extends JavaExec { Map getPreparedEnvironment(Map env) { JRubyExecUtils.preparedEnvironment(env,inheritRubyEnv) + [ - (JRubyExecUtils.pathVar()) : getComputedPATH(System.env."${JRubyExecUtils.pathVar()}"), + //(JRubyExecUtils.pathVar()) : getComputedPATH(System.env."${JRubyExecUtils.pathVar()}"), + 'PATH' : getComputedPATH(System.env."${JRubyExecUtils.pathVar()}"), 'GEM_HOME' : getGemWorkDir().absolutePath, ] } From c5f8ee3738459b199561ae38299cabf071cd55f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 23:31:07 +0000 Subject: [PATCH 8/9] Clean up some bits after confirming that system search path works cross-platform --- src/main/groovy/com/github/jrubygradle/JRubyExec.groovy | 1 - .../com/github/jrubygradle/internal/JRubyExecDelegate.groovy | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy index 964cb769..9fa0cd3c 100644 --- a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -244,7 +244,6 @@ class JRubyExec extends JavaExec { Map getPreparedEnvironment(Map env) { JRubyExecUtils.preparedEnvironment(env,inheritRubyEnv) + [ - //(JRubyExecUtils.pathVar()) : getComputedPATH(System.env."${JRubyExecUtils.pathVar()}"), 'PATH' : getComputedPATH(System.env."${JRubyExecUtils.pathVar()}"), 'GEM_HOME' : getGemWorkDir().absolutePath, ] diff --git a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy index 963c647c..2db18667 100644 --- a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy +++ b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy @@ -153,7 +153,7 @@ class JRubyExecDelegate { } setEnvironment JRubyExecUtils.preparedEnvironment(getEnvironment(),proxy.inheritRubyEnv) - environment pathVar , JRubyExecUtils.prepareWorkingPath(gemDir,System.env."${pathVar}") + environment 'PATH' : JRubyExecUtils.prepareWorkingPath(gemDir,System.env."${pathVar}") environment 'GEM_HOME' : gemDir.absolutePath } } From fee2e4b9720ff3f8cd762d4601af570501d669f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 21 Dec 2014 23:49:45 +0000 Subject: [PATCH 9/9] Updated CHANGELOG in preparation for upcoming 0.1.11 release --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 096415ee..390a6406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## 0.1.11 - Roadmap + +### Features + +* [#29](https://github.com/jruby-gradle/jruby-gradle-plugin/issues/29) - Ability to generate a gradle.rb file + +### Bugfixes + +* [#83](https://github.com/jruby-gradle/jruby-gradle-plugin/issues/83) - Installing GEMs + on Windows +* [#93](https://github.com/jruby-gradle/jruby-gradle-plugin/issues/93) - More consistency + between `JRubyExec` and `project.jrubyexec` in the way the execution environment is prepared + way + +### Improvements + +* [#92](https://github.com/jruby-gradle/jruby-gradle-plugin/issues/92) - Support for building + and testing Windows environments on Appveyor ## 0.1.10