Skip to content

Commit

Permalink
Add extensions block to manifest (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
punya authored and uschi2000 committed Nov 18, 2016
1 parent f00b4d3 commit 23cdf37
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ program for a default run configuration:
mainClass 'com.palantir.foo.bar.MyServiceMainClass'
args 'server', 'var/conf/my-service.yml'
env 'KEY1': 'value1', 'KEY2': 'value1'
manifestExtensions 'KEY3': 'value2'
}

The `distribution` block offers the following options:
Expand All @@ -76,6 +77,8 @@ The `distribution` block offers the following options:
nothing in `${projectDir}/var/data` is copied.
* (optional) `javaHome` a fixed override for the `JAVA_HOME` environment variable that will
be applied when `init.sh` is run.
* (optional) `manifestExtensions` a map of extended manifest attributes, as specified in
[SLS 1.0](https://github.com/palantir/sls-spec/blob/master/manifest.md).

#### JVM Options
The list of JVM options passed to the Java processes launched through a package's start-up scripts is obtained by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DistributionExtension {
private boolean enableManifestClasspath = false
private String javaHome = null
private List<String> excludeFromVar = ['log', 'run']
private Map<String, Object> manifestExtensions = [:]

DistributionExtension(Project project) {
this.project = project
Expand Down Expand Up @@ -108,6 +109,18 @@ class DistributionExtension {
this.excludeFromVar = excludeFromVar.toList()
}

public Map<String, Object> getManifestExtensions() {
return this.manifestExtensions;
}

public void setManifestExtensions(Map<String, Object> manifestExtensions) {
this.manifestExtensions = manifestExtensions;
}

public void manifestExtensions(Map<String, Object> manifestExtensions) {
this.manifestExtensions.putAll(manifestExtensions)
}

public String getServiceName() {
return serviceName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class JavaDistributionPlugin implements Plugin<Project> {

Task manifest = project.tasks.create('createManifest', CreateManifestTask)
project.afterEvaluate {
manifest.configure(distributionExtension.serviceName, distributionExtension.serviceGroup)
manifest.configure(
distributionExtension.serviceName,
distributionExtension.serviceGroup,
distributionExtension.manifestExtensions,
)
}

Task distTar = DistTarTask.createDistTarTask(project, 'distTar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
package com.palantir.gradle.javadist.tasks

import com.palantir.gradle.javadist.JavaDistributionPlugin
import com.palantir.gradle.javadist.util.EmitFiles
import groovy.json.JsonOutput
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

import java.nio.file.Paths

class CreateManifestTask extends DefaultTask {

@Input
Expand All @@ -33,6 +31,9 @@ class CreateManifestTask extends DefaultTask {
@Input
String serviceGroup

@Input
Map<String, Object> manifestExtensions

CreateManifestTask() {
group = JavaDistributionPlugin.GROUP_NAME
description = "Generates a simple yaml file describing the package content."
Expand All @@ -50,16 +51,19 @@ class CreateManifestTask extends DefaultTask {

@TaskAction
void createManifest() {
EmitFiles.replaceVars(
CreateManifestTask.class.getResourceAsStream('/manifest.yml'),
getManifestFile().toPath(),
['@serviceGroup@' : serviceGroup,
'@serviceName@' : serviceName,
'@serviceVersion@': getProjectVersion()])
getManifestFile().setText(JsonOutput.prettyPrint(JsonOutput.toJson([
'manifest-version': '1.0',
'product-type': 'service.v1',
'product-group': serviceGroup,
'product-name': serviceName,
'product-version': projectVersion,
'extensions': manifestExtensions,
])))
}

public void configure(String serviceName, String serviceGroup) {
public void configure(String serviceName, String serviceGroup, Map<String, Object> manifestExtensions) {
this.serviceName = serviceName
this.serviceGroup = serviceGroup
this.manifestExtensions = manifestExtensions
}
}
5 changes: 0 additions & 5 deletions src/main/resources/manifest.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class DistributionExtensionTest extends Specification {

env 'a': 'b'
env 'c': 'd'

manifestExtensions 'a': 'b'
manifestExtensions 'c': 'd'
}

then:
Expand All @@ -49,6 +52,7 @@ class DistributionExtensionTest extends Specification {
ext.defaultJvmOpts == DistributionExtension.requiredJvmOpts + ['a', 'b', 'c', 'd']
ext.excludeFromVar == ['log', 'run', 'a', 'b', 'c', 'd']
ext.env == ['a': 'b', 'c': 'd']
ext.manifestExtensions == ['a': 'b', 'c': 'd']
}

def 'collection setters replace existing data'() {
Expand All @@ -67,6 +71,8 @@ class DistributionExtensionTest extends Specification {
setExcludeFromVar(['c', 'd'])
setEnv(['a': 'b', 'c': 'd'])
setEnv(['foo': 'bar'])
setManifestExtensions(['a': 'b', 'c': 'd'])
setManifestExtensions(['foo': 'bar'])
}

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class JavaDistributionPluginTests extends GradleTestSpec {

then:
String manifest = file('dist/service-name-0.1/deployment/manifest.yml', projectDir).text
manifest.contains('product-version: 0.1\n')
manifest.contains('"product-version": "0.1"')
}

def 'manifest file contains expected fields'() {
Expand All @@ -231,11 +231,12 @@ class JavaDistributionPluginTests extends GradleTestSpec {

then:
String manifest = file('dist/service-name-0.1/deployment/manifest.yml', projectDir).text
manifest.contains('manifest-version: 1.0\n')
manifest.contains('product-group: service-group\n')
manifest.contains('product-name: service-name\n')
manifest.contains('product-version: 0.1\n')
manifest.contains('product-type: service.v1\n')
manifest.contains('"manifest-version": "1.0"')
manifest.contains('"product-group": "service-group"')
manifest.contains('"product-name": "service-name"')
manifest.contains('"product-version": "0.1"')
manifest.contains('"product-type": "service.v1"')
manifest.replaceAll(/\s/, '').contains('"extensions":{"service-dependencies":{"com.palantir.compass:compass-server":["1.75.0","2.0.0"]}}')
}

def 'produce distribution bundle with files in deployment/'() {
Expand All @@ -252,7 +253,7 @@ class JavaDistributionPluginTests extends GradleTestSpec {
then:
// clobbers deployment/manifest.yml
String manifest = file('dist/service-name-0.1/deployment/manifest.yml', projectDir).text
manifest.contains('product-name: service-name\n')
manifest.contains('"product-name": "service-name"')

// check files in deployment/ copied successfully
String actualConfiguration = file('dist/service-name-0.1/deployment/configuration.yml', projectDir).text
Expand Down Expand Up @@ -459,6 +460,9 @@ class JavaDistributionPluginTests extends GradleTestSpec {
serviceName 'service-name'
mainClass 'test.Test'
defaultJvmOpts '-Xmx4M', '-Djavax.net.ssl.trustStore=truststore.jks'
manifestExtensions 'service-dependencies': [
'com.palantir.compass:compass-server': ['1.75.0', '2.0.0']
]
}
sourceCompatibility = '1.7'
Expand Down

0 comments on commit 23cdf37

Please sign in to comment.