From f006d98c87e5867862a46971d05de3e8b3801ada Mon Sep 17 00:00:00 2001 From: Appu Goundan Date: Thu, 14 Sep 2017 09:49:47 -0400 Subject: [PATCH] preserve datastore-indexes-auto across non-clean rebuilds (#164) * preserve datastore-indexes-auto across non-clean rebuilds --- .../appengine/standard/ExplodeWarTask.java | 21 ++++++ .../standard/ExplodeWarTaskTest.java | 68 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 app-gradle-plugin/src/test/java/com/google/cloud/tools/gradle/appengine/standard/ExplodeWarTaskTest.java diff --git a/app-gradle-plugin/src/main/java/com/google/cloud/tools/gradle/appengine/standard/ExplodeWarTask.java b/app-gradle-plugin/src/main/java/com/google/cloud/tools/gradle/appengine/standard/ExplodeWarTask.java index 3b5f03529..c823da656 100644 --- a/app-gradle-plugin/src/main/java/com/google/cloud/tools/gradle/appengine/standard/ExplodeWarTask.java +++ b/app-gradle-plugin/src/main/java/com/google/cloud/tools/gradle/appengine/standard/ExplodeWarTask.java @@ -18,15 +18,36 @@ package com.google.cloud.tools.gradle.appengine.standard; import java.io.File; +import org.gradle.api.Action; import org.gradle.api.tasks.Sync; +import org.gradle.api.tasks.util.PatternFilterable; /** Expand a war. */ public class ExplodeWarTask extends Sync { + + private File explodedAppDirectory; + public void setWarFile(File warFile) { from(getProject().zipTree(warFile)); } + /** + * Sets the output directory of Sync Task and preserves the setting so it can be recovered later + * via getter. + */ public void setExplodedAppDirectory(File explodedAppDirectory) { + this.explodedAppDirectory = explodedAppDirectory; into(explodedAppDirectory); + preserve( + new Action() { + @Override + public void execute(PatternFilterable patternFilterable) { + patternFilterable.include("WEB-INF/appengine-generated/datastore-indexes-auto.xml"); + } + }); + } + + public File getExplodedAppDirectory() { + return explodedAppDirectory; } } diff --git a/app-gradle-plugin/src/test/java/com/google/cloud/tools/gradle/appengine/standard/ExplodeWarTaskTest.java b/app-gradle-plugin/src/test/java/com/google/cloud/tools/gradle/appengine/standard/ExplodeWarTaskTest.java new file mode 100644 index 000000000..46c8a8e43 --- /dev/null +++ b/app-gradle-plugin/src/test/java/com/google/cloud/tools/gradle/appengine/standard/ExplodeWarTaskTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 Google Inc. All Right Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.google.cloud.tools.gradle.appengine.standard; + +import com.google.cloud.tools.gradle.appengine.TestProject; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import org.gradle.testkit.runner.BuildResult; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +public class ExplodeWarTaskTest { + + @Rule public final TemporaryFolder testProjectDir = new TemporaryFolder(); + + @Test + public void testSyncTask() throws IOException { + BuildResult buildResult = + new TestProject(testProjectDir.getRoot()) + .addStandardBuildFile() + .addAppEngineWebXml() + .applyGradleRunner("explodeWar"); + + Path explodedApp = + testProjectDir + .getRoot() + .toPath() + .resolve("build") + .resolve("exploded-" + testProjectDir.getRoot().getName()); + Path appengineGenerated = explodedApp.resolve("WEB-INF").resolve("appengine-generated"); + Path junkXml = appengineGenerated.resolve("junk.xml"); + Path datastoreIndexesAutoXml = appengineGenerated.resolve("datastore-indexes-auto.xml"); + + Assert.assertTrue(Files.isDirectory(explodedApp)); + Assert.assertFalse(Files.isRegularFile(datastoreIndexesAutoXml)); + Assert.assertFalse(Files.isRegularFile(junkXml)); + + // creates files that we will test persistence on + Files.createDirectory(appengineGenerated); + Files.createFile(junkXml); + Files.createFile(datastoreIndexesAutoXml); + + // run explodeWar again to see if we preserve datastore-indexes-auto and remove junk, force + // it to skip UP-TO-DATE checks + new TestProject(testProjectDir.getRoot()).applyGradleRunner("explodeWar", "--rerun-tasks"); + + Assert.assertTrue(Files.isRegularFile(datastoreIndexesAutoXml)); + Assert.assertFalse(Files.isRegularFile(junkXml)); + } +}