Skip to content

Commit

Permalink
Merge pull request #95 from ysb33r/master
Browse files Browse the repository at this point in the history
FIXED #83, #92, #93
  • Loading branch information
ysb33r committed Dec 21, 2014
2 parents 3147226 + fee2e4b commit aec3391
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 42 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/main/groovy/com/github/jrubygradle/GemUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
Expand Down
50 changes: 9 additions & 41 deletions src/main/groovy/com/github/jrubygradle/JRubyExec.groovy
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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()
}
Expand All @@ -94,7 +85,6 @@ class JRubyExec extends JavaExec {
JRubyExec() {
super()
super.setMain 'org.jruby.Main'
setInheritRubyEnv false

try {
project.configurations.getByName(JRUBYEXEC_CONFIG)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -254,31 +243,10 @@ class JRubyExec extends JavaExec {
}

Map getPreparedEnvironment(Map env) {
Map<String, Object> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 ->
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,4 +78,46 @@ class JRubyExecUtils {
cmdArgs.addAll(scriptArgs)
cmdArgs as List<String>
}

/** 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<String, Object> preparedEnvironment(Map<String, Object> env,boolean inheritRubyEnv) {
Map<String, Object> newEnv = [
'JARS_NO_REQUIRE' : 'true',
'JBUNDLE_SKIP' : 'true',
'JARS_SKIP' : 'true',
] as Map<String, Object>

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
}

}

0 comments on commit aec3391

Please sign in to comment.