diff --git a/src/integration-test/groovy/com/fieldju/gradle/plugins/lambdasam/tasks/DeploySamTaskIntegrationTest.groovy b/src/integration-test/groovy/com/fieldju/gradle/plugins/lambdasam/tasks/DeploySamTaskIntegrationTest.groovy index cb9d3ba..da206c2 100644 --- a/src/integration-test/groovy/com/fieldju/gradle/plugins/lambdasam/tasks/DeploySamTaskIntegrationTest.groovy +++ b/src/integration-test/groovy/com/fieldju/gradle/plugins/lambdasam/tasks/DeploySamTaskIntegrationTest.groovy @@ -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 @@ -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' { @@ -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() diff --git a/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/AwsSamDeployerExtension.groovy b/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/AwsSamDeployerExtension.groovy index ce54614..f063e0a 100644 --- a/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/AwsSamDeployerExtension.groovy +++ b/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/AwsSamDeployerExtension.groovy @@ -14,19 +14,11 @@ class AwsSamDeployerExtension { Map 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() { diff --git a/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/AwsSamDeployerPlugin.groovy b/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/AwsSamDeployerPlugin.groovy index 63f93a9..039a582 100644 --- a/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/AwsSamDeployerPlugin.groovy +++ b/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/AwsSamDeployerPlugin.groovy @@ -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 @@ -36,22 +35,22 @@ class AwsSamDeployerPlugin implements Plugin { } 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 } } diff --git a/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/tasks/PackageSamTask.groovy b/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/tasks/PackageSamTask.groovy index 9185a90..89d235c 100644 --- a/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/tasks/PackageSamTask.groovy +++ b/src/main/groovy/com/fieldju/gradle/plugins/lambdasam/tasks/PackageSamTask.groovy @@ -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 + } }