Skip to content

Commit

Permalink
Merge pull request #56 from palantir/bugfix/tarname
Browse files Browse the repository at this point in the history
Ensure that the distTar artifact name is available without an afterEvaluate block
  • Loading branch information
markelliot committed Feb 20, 2016
2 parents b5d2c60 + 0850247 commit 2ddf982
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/groovy/com/palantir/gradle/javadist/DistTarTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,26 @@ import org.gradle.api.tasks.bundling.Tar

class DistTarTask extends Tar {

private DistributionExtension distributionExtension

public DistTarTask() {
// Set compression in constructor so that task output has the right name from the start.
compression = Compression.GZIP
}

public void distributionExtension(DistributionExtension ext) {
this.distributionExtension = ext
}

@Override
public String getBaseName() {
// works around a bug where something in the tar task hierarchy either resolves the wrong
// getBaseName() call or uses baseName directly.
setBaseName(distributionExtension.serviceName)
return super.getBaseName()
}

public void configure(DistributionExtension ext) {
baseName = ext.serviceName
String archiveRootDir = ext.serviceName + '-' + String.valueOf(project.version)

from("${project.projectDir}/var") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class JavaDistributionPlugin implements Plugin<Project> {
group = GROUP_NAME
description = "Creates a compressed, gzipped tar file that contains required runtime resources."
dependsOn startScripts, initScript, configScript, manifest, manifestClasspathJar
distributionExtension ext
})

RunTask run = project.tasks.create('run', RunTask, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,36 @@ class JavaDistributionPluginTests extends Specification {
.find({it.name.endsWith("-manifest-classpath-0.1.jar")})
}

def 'distTar artifact name is set during appropriate lifecycle events'() {
given:
buildFile << '''
plugins {
id 'com.palantir.java-distribution'
id 'java'
}
distribution {
serviceName "my-service"
mainClass "dummy.service.MainClass"
args "hello"
}
println "before: distTar: ${distTar.outputs.files.singleFile}"
afterEvaluate {
println "after: distTar: ${distTar.outputs.files.singleFile}"
}
'''.stripIndent()

when:
BuildResult buildResult = run('tasks').build()

then:
buildResult.task(':tasks').outcome == TaskOutcome.SUCCESS
buildResult.output =~ ('before: distTar: [A-Za-z0-9/-_]*/my-service.tgz')
buildResult.output =~ ('after: distTar: [A-Za-z0-9/-_]*/my-service.tgz')

}

private def createUntarBuildFile(buildFile) {
buildFile << '''
plugins {
Expand Down

0 comments on commit 2ddf982

Please sign in to comment.