Skip to content

Commit

Permalink
Cleaned up and restructured base-plugin (jruby-gradle#366).
Browse files Browse the repository at this point in the history
- `JRubyPluginExtension`
- `JRubyExec`
- Split out `GemUtils.OverwriteAction` into its own class `GemOverwriteAction`.
- Moved `GemUtils` to `core-plugin`.
- Removed `RubygemsServlet`.
- Reworked `GemVersion` to be more Ivy-like rather than Maven-like.
- Reworked `JRubyPrepare` & `JRubyExec`.
- Extract common `JRubyPrepare` code to `AbstractJRubyPrepare`.
- Cleaned up `JRubyExec` to no longer depend on `JRubyExecTraits`.
- Cleaned up `JRubyExecDelegate` to no longer depend on `JRubyExecTraits`.
- In `JRubyPlugin`, register tasks instead of creating them if Gradle supports lazy-creation.
- Removed last usages of `jar-dependencies`.
- Cleaned up integration tests and unit tests
  • Loading branch information
ysb33r committed Jun 5, 2019
1 parent a4df54b commit ce44d67
Show file tree
Hide file tree
Showing 42 changed files with 2,138 additions and 1,911 deletions.
8 changes: 5 additions & 3 deletions base-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ ext {

dependencies {

compile project(":jruby-gradle-core-plugin")
compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
compile project(':jruby-gradle-core-plugin')
// compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
// compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
runtime('de.saumya.mojo:rubygems:0.2.3@war') {
// we just want the war file on the classloader for the application
// to find it and use the war-file from filesystem
Expand All @@ -42,10 +42,12 @@ dependencies {

testCompile(spockVersion) {
exclude module: 'groovy-all'
exclude group: 'org.codehaus.groovy'
}

integrationTestCompile(spockVersion) {
exclude module: 'groovy-all'
exclude group: 'org.codehaus.groovy'
}

// NOTE: This is used by JRubyPrepareGemsIntegrationSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {

void "Running a script that requires a jar"() {
setup:
def leadingDir = 'jrubyExec/jars/org/bouncycastle/'
def leadingDir = '.gems/jars/org/bouncycastle/'
def artifactPath = "${BCPROV_NAME}/${bcprovVer}/${BCPROV_NAME}-${bcprovVer}"
def withPattern = ~/.*\["file:.+${leadingDir}${artifactPath}\.jar"\].*/

Expand Down Expand Up @@ -86,24 +86,6 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
result.output =~ /Not valid/
}

void "Running a script that requires a gem, a separate jRuby, a separate configuration and a custom gemWorkDir"() {
setup:
final String customGemDir = 'customGemDir'
useScript(REQUIRES_GEM)
createJRubyExecProject withCreditCardValidator(), """
script '${REQUIRES_GEM}'
jrubyArgs '-T1'
gemWorkDir { new File(project.buildDir, '${customGemDir}' ) }
"""

when:
BuildResult result = build()

then:
result.output =~ /Not valid/
new File(projectDir, "build/${customGemDir}").exists()
}

void "Running a script that requires environment variables"() {
// This tests that the passthrough invocation
// happens for overloaded versions of environment
Expand Down Expand Up @@ -131,7 +113,7 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
}

private BuildResult build() {
gradleRunner(DEFAULT_TASK_NAME, '-i').build()
gradleRunner(DEFAULT_TASK_NAME, '-i', '-s').build()
}

@SuppressWarnings('BuilderMethodWithSideEffects')
Expand All @@ -152,14 +134,16 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
${jrubyexecConfig}
}
}
dependsOn jrubyPrepare
}
"""
}

private String withJarToUse(String jarFormat) {
"""
dependencies {
jrubyExec ${jarFormat}
gems ${jarFormat}
}
"""
}
Expand All @@ -172,3 +156,143 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
testProperties.bcprovVersion
}
}

/*
class JRubyExecDelegateSpec extends Specification {
static final String ABS_FILE_PREFIX = System.getProperty('os.name').toLowerCase().startsWith('windows') ? 'C:' : ''
Project project
JRubyExecDelegate jred
void setup() {
project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.base'
jred = JRubyExecDelegate.createJRubyExecDelegate(project)
}
void "When just passing script, scriptArgs, jrubyArgs, expect local properties to be updated"() {
given:
def xplatformFileName = project.file('path/to/file')
xplatformFileName.parentFile.mkdirs()
xplatformFileName.text = ''
def cl = {
script 'path/to/file'
jrubyArgs 'c', 'd', '-S'
scriptArgs '-x'
scriptArgs '-y', '-z'
jrubyArgs 'a', 'b'
gemWorkDir 'path/to/file'
}
jred.configure(cl)
expect:
jred.passthrough.size() == 0
jred.script == xplatformFileName
jred._convertScriptArgs() == ['-x', '-y', '-z']
jred._convertJrubyArgs() == ['c', 'd', '-S', 'a', 'b']
jred.buildArgs() == ['-rjars/setup', 'c', 'd', '-S', 'a', 'b', xplatformFileName.toString(), '-x', '-y', '-z']
jred._convertGemWorkDir(project) == project.file('path/to/file')
}
void "When passing absolute file and absolute file, expect check for existence to be executed"() {
given:
def cl = {
script ABS_FILE_PREFIX + '/path/to/file'
jrubyArgs 'c', 'd', '-S'
scriptArgs '-x'
scriptArgs '-y', '-z'
jrubyArgs 'a', 'b'
}
cl.delegate = jred
cl.call()
when:
jred.buildArgs()
then:
thrown(InvalidUserDataException)
}
void "When just passing arbitrary javaexec, expect them to be stored"() {
given:
def cl = {
environment 'XYZ', '123'
executable '/path/to/file'
jvmArgs '-x'
jvmArgs '-y', '-z'
}
cl.delegate = jred
cl.call()
expect:
jred.valuesAt(0) == ['XYZ', '123']
jred.valuesAt(1) == '/path/to/file'
jred.valuesAt(2) == '-x'
jred.valuesAt(3) == ['-y', '-z']
jred.keyAt(0) == 'environment'
jred.keyAt(1) == 'executable'
jred.keyAt(2) == 'jvmArgs'
jred.keyAt(3) == 'jvmArgs'
}
void "When using a conditional, expect specific calls to be passed"() {
given:
def cl = {
if (condition == 1) {
jvmArgs '-x'
} else {
jvmArgs '-y'
}
}
cl.delegate = jred
cl.call()
expect:
jred.valuesAt(0) == parameter
where:
condition | parameter
1 | '-x'
5 | '-y'
}
void "Prevent main from being called"() {
when:
def cl = {
main 'some.class'
}
cl.delegate = jred
cl.call()
then:
thrown(UnsupportedOperationException)
}
void "Prevent args from being called"() {
when:
def cl = {
args '-x', '-y'
}
cl.delegate = jred
cl.call()
then:
thrown(UnsupportedOperationException)
}
void "Prevent setArgs from being called"() {
when:
def cl = {
setArgs '-x', '-y'
}
cl.delegate = jred
cl.call()
then:
thrown(UnsupportedOperationException)
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import static com.github.jrubygradle.internal.JRubyExecUtils.DEFAULT_JRUBYEXEC_C

class JRubyExecIntegrationSpec extends IntegrationSpecification {
static final String DEFAULT_TASK_NAME = 'RubyWax'
static final String DEFAULT_JRUBYEXEC_CONFIG = JRubyPlugin.DEFAULT_CONFIGURATION

String jrubyExecConfig
String preamble
Expand All @@ -34,13 +35,13 @@ class JRubyExecIntegrationSpec extends IntegrationSpecification {

withJRubyExecConfig """
configuration '${configName}'
jrubyVersion '${altVersion}'
jruby.jrubyVersion '${altVersion}'
"""

withAdditionalContent """
task validateVersion {
doLast {
assert jruby.execVersion != '${altVersion}'
assert jruby.jrubyVersion != '${altVersion}'
}
}
Expand Down Expand Up @@ -74,8 +75,8 @@ class JRubyExecIntegrationSpec extends IntegrationSpecification {
"""
withDependencies "${altConfiguration} ${withCreditCardValidator()}"
withJRubyExecConfig """
jrubyVersion '${altVersion}'
configuration '${altConfiguration}'
jruby.jrubyVersion '${altVersion}'
jruby.gemConfiguration '${altConfiguration}'
"""

when:
Expand Down Expand Up @@ -109,34 +110,15 @@ class JRubyExecIntegrationSpec extends IntegrationSpecification {
result.output =~ /Not valid/
}

// Embedded server has never worked well - ignoring for now
@PendingFeature
@IgnoreIf({ IntegrationSpecification.OFFLINE })
void "Running a script that requires a gem using default embedded rubygems-servlets maven repo"() {
setup:
String version = '0.1.1'
useScript(REQUIRE_THE_A_GEM)
withPreamble 'repositories { rubygems() }'
withDependencies "jrubyExec 'rubygems:a:${version}'"
withJRubyExecConfig 'setEnvironment [:]'

when:
BuildResult result = build()

then:
// note this test has some error output not sure where this comes from. but the actual test passes
result.output =~ /loaded 'a' gem with version ${version}/
}

@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/77')
void "Running rspec from a script should not cause a gemWorkDir failure"() {
setup:
withPreamble "jruby.execVersion '${olderJRubyVersion}'"
withPreamble "jruby.jrubyVersion '${olderJRubyVersion}'"

withDependencies """
jrubyExec ${findDependency('', 'rspec', 'gem')}
jrubyExec ${findDependency('', 'rspec-core', 'gem')}
jrubyExec ${findDependency('', 'rspec-support', 'gem')}
${DEFAULT_JRUBYEXEC_CONFIG} ${findDependency('', 'rspec', 'gem')}
${DEFAULT_JRUBYEXEC_CONFIG} ${findDependency('', 'rspec-core', 'gem')}
${DEFAULT_JRUBYEXEC_CONFIG} ${findDependency('', 'rspec-support', 'gem')}
"""

withJRubyExecConfig """
Expand All @@ -154,25 +136,6 @@ class JRubyExecIntegrationSpec extends IntegrationSpecification {
result.output =~ /No examples found./
}

@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/73')
void "Running a script that has a custom gemdir"() {
setup:
String customGemDir = 'customGemDir'
useScript(REQUIRES_GEM)
withDependencies "${DEFAULT_JRUBYEXEC_CONFIG} ${withCreditCardValidator()}"
withJRubyExecConfig """
setEnvironment [:]
gemWorkDir '${customGemDir}'
"""

when:
BuildResult result = build()

then:
result.output =~ /Not valid/
new File(projectDir, customGemDir).exists()
}

@Override
void useScript(final String name, final String relativePath = null) {
super.useScript(name, relativePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ class JRubyGenerateGradleRbIntegrationSpec extends IntegrationSpecification {
${projectWithLocalRepo}
task ${DEFAULT_TASK_NAME} (type: GenerateGradleRb)
task ${DEFAULT_TASK_NAME} (type: GenerateGradleRb) {
gemInstallDir 'build/gems'
}
"""

def expected = new File(projectDir, 'gradle.rb')

when: "The load path file is generated "
gradleRunner(DEFAULT_TASK_NAME, '-i').build()
gradleRunner(DEFAULT_TASK_NAME, '-i', '-s').build()

then: "Expect to be in the configured destinationDir and be called gradle.rb"
expected.exists()
Expand Down
Loading

0 comments on commit ce44d67

Please sign in to comment.