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 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 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 cdef9ba0..9fa0cd3c 100644 --- a/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -1,20 +1,13 @@ 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.InputDirectory 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 +18,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 { @@ -66,9 +57,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 @@ -80,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() } @@ -94,7 +85,6 @@ class JRubyExec extends JavaExec { JRubyExec() { super() super.setMain 'org.jruby.Main' - setInheritRubyEnv false try { project.configurations.getByName(JRUBYEXEC_CONFIG) @@ -155,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. @@ -254,31 +243,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.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) - } - - return newEnv + JRubyExecUtils.preparedEnvironment(env,inheritRubyEnv) + [ + 'PATH' : getComputedPATH(System.env."${JRubyExecUtils.pathVar()}"), + 'GEM_HOME' : getGemWorkDir().absolutePath, + ] } private static UnsupportedOperationException notAllowed(final String msg) { diff --git a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecDelegate.groovy index e211b70e..2db18667 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 'PATH' : JRubyExecUtils.prepareWorkingPath(gemDir,System.env."${pathVar}") environment 'GEM_HOME' : gemDir.absolutePath } } diff --git a/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy b/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy index fccc9704..8228f566 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,46 @@ class JRubyExecUtils { cmdArgs.addAll(scriptArgs) 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', + '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 + + } + + /** 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 + } + }