Skip to content

Commit

Permalink
add an sls configuration (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcampanini authored and uschi2000 committed Jul 20, 2016
1 parent e43924a commit 0061a7f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ As part of package creation, this plugin will create three shell scripts:
In addition to creating these scripts, this plugin will merge the entire
contents of `${projectDir}/service` and `${projectDir}/var` into the package.

The plugin also exposes the tar file as an artifact in the `sls` configuration, making it easy to
share the artifact between sibling Gradle projects. For example:

```groovy
configurations { tarballs }
dependencies {
tarballs project(path: ':other-project', configuration: 'sls')
}
```

Running with Gradle
-------------------
To run the main class using Gradle, run the `run` task.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.nio.file.Paths
class JavaDistributionPlugin implements Plugin<Project> {

private static final String GROUP_NAME = "Distribution"
private static final String SLS_CONFIGURATION_NAME = "sls"

void apply(Project project) {
// force application of java
Expand Down Expand Up @@ -147,6 +148,9 @@ class JavaDistributionPlugin implements Plugin<Project> {
it.description = "Runs the specified project using configured mainClass and with default args."
})

project.configurations.create(SLS_CONFIGURATION_NAME)
project.artifacts.add(SLS_CONFIGURATION_NAME, distTar)

project.afterEvaluate {
manifestClasspathJar.configure(ext)
startScripts.configure(ext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.palantir.gradle.javadist
import com.energizedwork.spock.extensions.TempDirectory
import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
import nebula.test.multiproject.MultiProjectIntegrationHelper
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
Expand All @@ -11,12 +12,16 @@ import spock.lang.Specification
import java.nio.file.Files

public class GradleTestSpec extends Specification {
@TempDirectory
@TempDirectory(clean = false)
File projectDir
File buildFile
File settingsFile
MultiProjectIntegrationHelper helper

def setup() {
buildFile = file("build.gradle")
settingsFile = new File(projectDir, 'settings.gradle')
helper = new MultiProjectIntegrationHelper(projectDir, settingsFile)
println("Build directory: \n" + projectDir.absolutePath)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.palantir.gradle.javadist
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome

class JavaDistributionPluginTests extends GradleTestSpec {

Expand Down Expand Up @@ -342,7 +343,47 @@ class JavaDistributionPluginTests extends GradleTestSpec {
then:
buildResult.output =~ ("before: distTar: ${projectDir}/build/distributions/my-service.tgz")
buildResult.output =~ ("after: distTar: ${projectDir}/build/distributions/my-service.tgz")
}

def 'exposes an artifact through the sls configuration'() {
given:
helper.addSubproject('parent', '''
plugins {
id 'com.palantir.java-distribution'
id 'java'
}
repositories { jcenter() }
version '0.1'
distribution {
serviceName "my-service"
mainClass "dummy.service.MainClass"
args "hello"
}
''')

helper.addSubproject('child', '''
configurations {
fromOtherProject
}
dependencies {
fromOtherProject project(path: ':parent', configuration: 'sls')
}
task untar(type: Copy) {
// ensures the artifact is built by depending on the configuration
dependsOn configurations.fromOtherProject
// copy the contents of the tarball
from tarTree(configurations.fromOtherProject.singleFile)
into 'build/exploded'
}
''')

when:
BuildResult buildResult = runSuccessfully(':child:untar')

then:
buildResult.task(':parent:distTar').outcome == TaskOutcome.SUCCESS
file('child/build/exploded/my-service-0.1/deployment/manifest.yml')
}

private static def createUntarBuildFile(buildFile) {
Expand Down

0 comments on commit 0061a7f

Please sign in to comment.