Skip to content

Commit

Permalink
Merge branch 'feature/custom_cf_tasks'
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldju committed Apr 10, 2017
2 parents cb648b6 + 9b54fa9 commit 1d5dd39
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.amazonaws.waiters.Waiter
import com.amazonaws.waiters.WaiterParameters
import com.fieldju.gradle.plugins.lambdasam.AwsSamDeployerPlugin
import groovy.util.logging.Slf4j
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.After
import org.junit.Before
Expand Down Expand Up @@ -81,7 +82,7 @@ class DeploySamTaskIntegrationTest {
Files.copy(samTemplateSource, samTemplateDest)
Files.copy(fatJarSource, fatJarDest)

def project = ProjectBuilder.builder().withName('DeploySamTaskIntegrationTest').withProjectDir(temp).build()
Project project = ProjectBuilder.builder().withName('DeploySamTaskIntegrationTest').withProjectDir(temp).build()
AwsSamDeployerPlugin plugin = new AwsSamDeployerPlugin()
plugin.apply(project)
project.'aws-sam-deployer' {
Expand All @@ -99,6 +100,7 @@ class DeploySamTaskIntegrationTest {
forceUploads = true
}

project.evaluate()
// run the package sam task, since deploy depends on it
def packageSameTask = project.tasks.getByName(AwsSamDeployerPlugin.TaskDefinitions.PACKAGE_SAM_TASK.name as String) as PackageSamTask
packageSameTask.taskAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@ class AwsSamDeployerExtension {
Map<String, String> parameterOverrides = [:]
boolean forceUploads = false

String getSamTemplateAsString() {
String getSamTemplatePath() {
if (samTemplatePath == null || samTemplatePath == "") {
throw new GradleException("samTemplatePath is a required lambdasam extention property")
}

File samTemplate = new File(samTemplatePath)

// if the template is not a real file fail
if (! (samTemplate.exists() && samTemplate.isFile())) {
throw new GradleException("The template: ${samTemplatePath} did not exist or was not a file")
}

return samTemplate.text
return samTemplatePath
}

String getStackName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.fieldju.gradle.plugins.lambdasam

import com.fieldju.gradle.plugins.lambdasam.tasks.DeploySamTask
import com.fieldju.gradle.plugins.lambdasam.tasks.PackageSamTask
import com.fieldju.gradle.plugins.lambdasam.tasks.SamTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.Logger
Expand Down Expand Up @@ -36,22 +35,22 @@ class AwsSamDeployerPlugin implements Plugin<Project> {
}

protected void configureTasks(Project project) {
project.tasks.withType(SamTask) {
conventionMapping.region = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).region }
}
AwsSamDeployerExtension extension = project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension

project.tasks.withType(DeploySamTask) {
conventionMapping.stackName = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).stackName }
conventionMapping.parameterOverrides = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).parameterOverrides }
}
project.afterEvaluate {
DeploySamTask deploySamTask = project.tasks.getByName(TaskDefinitions.DEPLOY_SAM_TASK.name) as DeploySamTask
deploySamTask.region = extension.getRegion()
deploySamTask.stackName = extension.getStackName()
deploySamTask.parameterOverrides = extension.parameterOverrides

project.tasks.withType(PackageSamTask) {
conventionMapping.s3Bucket = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).s3Bucket }
conventionMapping.s3Prefix = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).s3Prefix }
conventionMapping.kmsKeyId = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).kmsKeyId }
conventionMapping.forceUploads = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).forceUploads }
conventionMapping.samTemplatePath = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).samTemplatePath }
conventionMapping.tokenArtifactMap = { (project.extensions.getByName(EXTENSION_NAME) as AwsSamDeployerExtension).tokenArtifactMap }
PackageSamTask packageSamTask = project.tasks.getByName(TaskDefinitions.PACKAGE_SAM_TASK.name) as PackageSamTask
packageSamTask.region = extension.getRegion()
packageSamTask.s3Bucket = extension.s3Bucket
packageSamTask.s3Prefix = extension.s3Prefix
packageSamTask.kmsKeyId = extension.kmsKeyId
packageSamTask.forceUploads = extension.forceUploads
packageSamTask.samTemplatePath = extension.getSamTemplatePath()
packageSamTask.tokenArtifactMap = extension.tokenArtifactMap
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,22 @@ class PackageSamTask extends SamTask {
File buildDir = new File("${project.getBuildDir().absolutePath}${File.separator}sam")
buildDir.mkdirs()
File dest = new File("${buildDir.absolutePath}${File.separator}sam-deploy.yaml")
dest.write(samTemplatePath)
dest.write(getSamTemplateAsString())
// replace the tokens with the s3 URIs
tokenS3UriMap.each { token, uri ->
logger.lifecycle("Injecting ${uri} into ${dest.absolutePath} for token: ${token}")
ant.replace(file: dest.absolutePath, token: token, value: uri)
}
}

private String getSamTemplateAsString() {
File samTemplate = new File(samTemplatePath)

// if the template is not a real file fail
if (! (samTemplate.exists() && samTemplate.isFile())) {
throw new GradleException("The template: ${samTemplatePath} did not exist or was not a file")
}

return samTemplate.text
}
}

0 comments on commit 1d5dd39

Please sign in to comment.