Skip to content

Commit

Permalink
Add a workaround to resolve conflict from Gradle distribution and rem…
Browse files Browse the repository at this point in the history
…oved testing option from TriremeNodeRunner.
  • Loading branch information
ksoichiro committed Nov 4, 2015
1 parent 130955d commit 2ee411b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
51 changes: 51 additions & 0 deletions buildSrc/src/main/groovy/GradleDist.groovy
@@ -0,0 +1,51 @@
import org.gradle.api.Project
import org.gradle.api.file.FileTree
import org.gradle.wrapper.Download
import org.gradle.wrapper.Install
import org.gradle.wrapper.Logger
import org.gradle.wrapper.PathAssembler
import org.gradle.wrapper.WrapperConfiguration

/**
* Based on a workaround reported by Abel Salgado Romero in https://issues.gradle.org/browse/GRADLE-1715
* and the codes in https://github.com/jruby-gradle/jruby-gradle-plugin.
*
* Include this in your project's buildSrc, then add a dependency to your project:
* compile new GradleDist(project, '2.6').asFileTree
*
* Code courtesy of @ajoberstar
*/
class GradleDist {
private final Project project
final String version

GradleDist(Project project, String version) {
this.project = project
this.version = version
}

String getPath() {
// We use 'all' distribution in this project, so we should specify not 'bin' but 'all'.
return "https://services.gradle.org/distributions/gradle-${version}-all.zip"
}

File getAsFile() {
return project.file(getPath())
}

URI getAsURI() {
return project.uri(getPath())
}

FileTree getAsFileTree() {
Logger logger = new Logger(true)
Install install = new Install(logger, new Download(logger, 'gradle', ''), new PathAssembler(project.gradle.gradleUserHomeDir))
WrapperConfiguration config = new WrapperConfiguration()
config.distribution = getAsURI()
File file = install.createDist(config)
// We just want JARs under 'lib' and 'lib/plugin', so replace 'file' for 'dir:' in the original source
// with new File(file, 'lib').
// Also, we should add 'excludes' parameter to exclude conflicting dependency.
project.fileTree(dir: new File(file, 'lib'), excludes: ['**/rhino-*.jar'], includes: ['**/*.jar'])
}
}
8 changes: 7 additions & 1 deletion plugin/build.gradle
Expand Up @@ -37,7 +37,13 @@ repositories {
}

dependencies {
compile gradleApi()
// Thanks to a workaround in https://issues.gradle.org/browse/GRADLE-1715,
// using additional build script to exclude Rhino that is bundled with Gradle distribution,
// we can avoid the error that occurs when executing Trireme on tests:
// java.lang.NoSuchMethodError: org.mozilla.javascript.ScriptRuntime.setObjectProp
// Gradle distribution has an older Rhino (1.7R3) and causing conflict.
// In 1.7R3, ScriptRuntime does not have setObjectProp() method, which causes the above error.
compile new GradleDist(project, '2.8').asFileTree
compile localGroovy()
compile 'io.apigee.trireme:trireme-jar:0.8.8'
compile 'org.codehaus.gpars:gpars:1.2.1'
Expand Down
Expand Up @@ -2,7 +2,6 @@ package com.github.ksoichiro.web.resource.node

import io.apigee.trireme.core.NodeEnvironment
import io.apigee.trireme.core.NodeScript
import io.apigee.trireme.core.Sandbox
import io.apigee.trireme.core.ScriptStatus

class TriremeNodeRunner {
Expand All @@ -11,26 +10,14 @@ class TriremeNodeRunner {
String scriptPath
String[] args
ScriptStatus status
boolean retrieveStatus

TriremeNodeRunner() {
retrieveStatus = true
}

public void exec() {
NodeEnvironment env = new NodeEnvironment()
File path = scriptPath ? new File(scriptPath) : new File(workingDir, scriptName)
NodeScript script = env.createScript(scriptName, path, args)
script.setWorkingDirectory(workingDir.absolutePath)
script.setNodeVersion("0.12")
if (retrieveStatus) {
def future = script.execute()
status = future.get()
} else {
// I don't know why but when testing, getting ScriptFuture#get() causes
// java.lang.NoSuchMethodError: org.mozilla.javascript.ScriptRuntime.setObjectProp
script.execute()
}
status = script.execute().get()
env.close()
}
}
Expand Up @@ -13,7 +13,6 @@ class TriremeNodeRunnerSpec extends Specification {
scriptName: "test.js",
workingDir: project.rootDir,
args: [])
runner.retrieveStatus = false

when:
runner.exec()
Expand Down

0 comments on commit 2ee411b

Please sign in to comment.