Skip to content

Commit

Permalink
Re-run LaunchConfigTask when classpath changes, fixes #144 (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
uschi2000 authored Dec 7, 2016
1 parent 9a9be3f commit d786e0b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.palantir.gradle.javadist.tasks.*
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.plugins.JavaPlugin

class JavaDistributionPlugin implements Plugin<Project> {

Expand Down Expand Up @@ -53,7 +54,8 @@ class JavaDistributionPlugin implements Plugin<Project> {
LaunchConfigTask launchConfig = project.tasks.create('createLaunchConfig', LaunchConfigTask)
project.afterEvaluate {
launchConfig.configure(distributionExtension.mainClass, distributionExtension.args, distributionExtension.checkArgs,
distributionExtension.defaultJvmOpts, distributionExtension.javaHome, distributionExtension.env)
distributionExtension.defaultJvmOpts, distributionExtension.javaHome, distributionExtension.env,
project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtime)
}

Task initScript = project.tasks.create('createInitScript', CreateInitScriptTask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

import java.nio.file.Files
Expand All @@ -46,11 +46,15 @@ class LaunchConfigTask extends DefaultTask {
List<String> defaultJvmOpts

@Input
Map<String,String> env
Map<String, String> env

@Input
@Optional
String javaHome

@InputFiles
FileCollection classpath

LaunchConfigTask() {
group = JavaDistributionPlugin.GROUP_NAME
description = "Generates launcher-static.yml and launcher-check.yml configurations."
Expand All @@ -67,7 +71,7 @@ class LaunchConfigTask extends DefaultTask {
List<String> classpath
List<String> jvmOpts
List<String> args
Map<String,String> env
Map<String, String> env
}

@OutputFile
Expand Down Expand Up @@ -100,8 +104,7 @@ class LaunchConfigTask extends DefaultTask {
config.mainClass = mainClass
config.javaHome = javaHome ?: ""
config.args = args
config.classpath = relativizeToServiceLibDirectory(
project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtime)
config.classpath = relativizeToServiceLibDirectory(classpath)
config.jvmOpts = defaultJvmOpts
config.env = env
return config
Expand All @@ -113,12 +116,13 @@ class LaunchConfigTask extends DefaultTask {
return output
}

public void configure(String mainClass, List<String> args, List<String> checkArgs, List<String> defaultJvmOpts, String javaHome, Map<String,String> env) {
public void configure(String mainClass, List<String> args, List<String> checkArgs, List<String> defaultJvmOpts, String javaHome, Map<String, String> env, FileCollection classpath) {
this.mainClass = mainClass
this.args = args
this.checkArgs = checkArgs
this.defaultJvmOpts = defaultJvmOpts
this.javaHome = javaHome
this.env = env
this.classpath = classpath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,46 @@ class JavaDistributionPluginTests extends GradleTestSpec {
exec('dist/service-name-0.1/service/monitoring/bin/check.sh') ==~ /(?m)Checking health of 'service-name'\.\.\.\s+Healthy.*\n/
}

def 'packaging tasks re-run after version change'() {
given:
createUntarBuildFile(buildFile)
buildFile << '''
distribution {
enableManifestClasspath true
}
task untar02 (type: Copy) {
from tarTree(resources.gzip("${buildDir}/distributions/service-name-0.2.sls.tgz"))
into "${projectDir}/dist"
dependsOn distTar
}
'''.stripIndent()
file('src/main/java/test/Test.java') << '''
package test;
public class Test {
public static void main(String[] args) {
while(true);
}
}
'''.stripIndent()

when:
runSuccessfully(':build', ':distTar', ':untar')
buildFile << '''
version '0.2'
'''.stripIndent()

then:
def version02BuildOutput = runSuccessfully(':build', ':distTar', ':untar02').output
version02BuildOutput ==~ /(?m)(?s).*^:createCheckScript UP-TO-DATE$.*/
version02BuildOutput ==~ /(?m)(?s).*^:createInitScript UP-TO-DATE$.*/
version02BuildOutput ==~ /(?m)(?s).*^:createLaunchConfig$.*/
version02BuildOutput ==~ /(?m)(?s).*^:createManifest$.*/
version02BuildOutput ==~ /(?m)(?s).*^:manifestClasspathJar$.*/
version02BuildOutput ==~ /(?m)(?s).*^:distTar$.*/
exec('dist/service-name-0.2/service/bin/init.sh', 'start') ==~ /(?m)Running 'service-name'\.\.\.\s+Started \(\d+\)\n/
exec('dist/service-name-0.2/service/bin/init.sh', 'stop') ==~ /(?m)Stopping 'service-name'\.\.\.\s+Stopped \(\d+\)\n/
}

def 'status reports when process name and id don"t match'() {
given:
createUntarBuildFile(buildFile)
Expand Down

0 comments on commit d786e0b

Please sign in to comment.