Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Fix UP-TO-DATE annotations (#320)
Browse files Browse the repository at this point in the history
* Fix UP-TO-DATE annotations

- Input -> InputFiles on dockerFile for appengine-web.xml staging.
- InputFiles on extraFilesDirectory method renamed to an actual
  getter.
- Also renames the configuration generater to actual name.
  • Loading branch information
loosebazooka authored Jan 8, 2019
1 parent 2595772 commit 6412e8b
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;

Expand Down Expand Up @@ -85,7 +86,7 @@ public void setStagingDirectory(Object stagingDirectory) {
/** This method is purely for incremental build calculations. */
@Optional
@InputFiles
private FileCollection convertExtraFilesDirectoriesToInputFiles() {
public FileCollection getExtraFilesDirectoriesAsInputFiles() {
if (extraFilesDirectories == null) {
return null;
}
Expand All @@ -96,10 +97,7 @@ private FileCollection convertExtraFilesDirectoriesToInputFiles() {
return files;
}

/**
* extraFilesDirectory accessor, with {@code @InputFiles} for incremental builds configured on
* {@link StageAppYamlExtension#convertExtraFilesDirectoriesToInputFiles()}.
*/
@Internal("covered by getExtraFilesDirectoriesAsInputFiles")
public List<File> getExtraFilesDirectories() {
return extraFilesDirectories;
}
Expand All @@ -108,7 +106,7 @@ public void setExtraFilesDirectories(Object extraFilesDirectories) {
this.extraFilesDirectories = new ArrayList<>(project.files(extraFilesDirectories).getFiles());
}

AppYamlProjectStageConfiguration toStageArchiveConfiguration() {
AppYamlProjectStageConfiguration toAppYamlProjectStageConfiguration() {
return AppYamlProjectStageConfiguration.builder(
appEngineDirectory.toPath(), artifact.toPath(), stagingDirectory.toPath())
.dockerDirectory(NullSafe.convert(dockerDirectory, File::toPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public void stageAction() throws AppEngineException {
getProject().mkdir(appYamlExtension.getStagingDirectory().getAbsolutePath());

AppYamlProjectStaging staging = new AppYamlProjectStaging();
staging.stageArchive(appYamlExtension.toStageArchiveConfiguration());
staging.stageArchive(appYamlExtension.toAppYamlProjectStageConfiguration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.gradle.api.Project;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;

Expand Down Expand Up @@ -67,7 +68,7 @@ public void setStagingDirectory(Object stagingDirectory) {
this.stagingDirectory = project.file(stagingDirectory);
}

@Input
@InputFile
@Optional
public File getDockerfile() {
return dockerfile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public TestProject addAppYamlBuildFileWithHome() throws IOException {
return this;
}

/** Add a appyaml based appengine-gradle-plugin build file that specifies sdk home and version. */
public TestProject addAppYamlBuildFileWithExtraFilesDirectories() throws IOException {
addBuildFile("projects/AppEnginePluginTest/build-appyaml-extraFilesDirectories.gradle");
Files.createDirectories(
getProjectRoot().toPath().resolve("src").resolve("main").resolve("extras"));
return this;
}

/** Add an generic appengine-gradle-plugin build file (for auto downloading sdk cases). */
public TestProject addAutoDownloadingBuildFile() throws IOException {
addBuildFile("projects/AppEnginePluginTest/build-auto.gradle");
Expand All @@ -93,12 +101,21 @@ private void addBuildFile(String pathInResources) throws IOException {
public TestProject addAppEngineWebXml() throws IOException {
Path webInf = projectRoot.toPath().resolve("src/main/webapp/WEB-INF");
Files.createDirectories(webInf);
File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile();
Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8));
Path appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml"));
Files.write(appengineWebXml, "<appengine-web-app/>".getBytes(Charsets.UTF_8));

return this;
}

/** Add a minimal app.yaml file to the standard location. */
public TestProject addAppYaml(String runtime) throws IOException {
Path appengineDir = projectRoot.toPath().resolve("src").resolve("main").resolve("appengine");
Files.createDirectories(appengineDir);
Path appyaml = Files.createFile(appengineDir.resolve("app.yaml"));
Files.write(appyaml, ("runtime: " + runtime).getBytes(Charsets.UTF_8));
return this;
}

/** Add an empty docker directory. */
public TestProject addDockerDir() {
File dockerDir = new File(projectRoot, "src/main/docker");
Expand Down Expand Up @@ -167,4 +184,8 @@ private Project applyProjectBuilder(Class<?>... plugins) {

return p;
}

public File getProjectRoot() {
return projectRoot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
package com.google.cloud.tools.gradle.appengine.appyaml;

import com.google.cloud.tools.appengine.configuration.AppYamlProjectStageConfiguration;
import com.google.cloud.tools.gradle.appengine.TestProject;
import com.google.common.base.Charsets;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -54,7 +59,7 @@ public void setUpFiles() throws IOException {
}

@Test
public void testToStageArchiveConfiguration_allValuesSet() {
public void testToAppYamlProjectStageConfiguration_allValuesSet() {
StageAppYamlExtension extension = new StageAppYamlExtension(testContextProject);

extension.setStagingDirectory(stagingDirectory);
Expand All @@ -63,7 +68,8 @@ public void testToStageArchiveConfiguration_allValuesSet() {
extension.setDockerDirectory(dockerDirectory);
extension.setExtraFilesDirectories(extraFilesDirectories);

AppYamlProjectStageConfiguration generatedConfig = extension.toStageArchiveConfiguration();
AppYamlProjectStageConfiguration generatedConfig =
extension.toAppYamlProjectStageConfiguration();
Assert.assertEquals(appEngineDirectory.toPath(), generatedConfig.getAppEngineDirectory());
Assert.assertEquals(stagingDirectory.toPath(), generatedConfig.getStagingDirectory());
Assert.assertEquals(artifact.toPath(), generatedConfig.getArtifact());
Expand All @@ -74,7 +80,7 @@ public void testToStageArchiveConfiguration_allValuesSet() {
}

@Test
public void testToStageArchiveConfiguration_nullExtraFiles() {
public void testToAppYamlProjectStageConfiguration_nullExtraFiles() {
StageAppYamlExtension extension = new StageAppYamlExtension(testContextProject);

extension.setStagingDirectory(stagingDirectory);
Expand All @@ -83,7 +89,8 @@ public void testToStageArchiveConfiguration_nullExtraFiles() {
extension.setDockerDirectory(dockerDirectory);
// extraFilesDirectories is not set (default = null)

AppYamlProjectStageConfiguration generatedConfig = extension.toStageArchiveConfiguration();
AppYamlProjectStageConfiguration generatedConfig =
extension.toAppYamlProjectStageConfiguration();
Assert.assertEquals(appEngineDirectory.toPath(), generatedConfig.getAppEngineDirectory());
Assert.assertEquals(stagingDirectory.toPath(), generatedConfig.getStagingDirectory());
Assert.assertEquals(artifact.toPath(), generatedConfig.getArtifact());
Expand All @@ -92,7 +99,7 @@ public void testToStageArchiveConfiguration_nullExtraFiles() {
}

@Test
public void testToStageArchiveConfiguration_emptyExtraFiles() {
public void testToAppYamlProjectStageConfiguration_emptyExtraFiles() {
StageAppYamlExtension extension = new StageAppYamlExtension(testContextProject);

extension.setStagingDirectory(stagingDirectory);
Expand All @@ -101,11 +108,38 @@ public void testToStageArchiveConfiguration_emptyExtraFiles() {
extension.setDockerDirectory(dockerDirectory);
extension.setExtraFilesDirectories(Collections.emptyList());

AppYamlProjectStageConfiguration generatedConfig = extension.toStageArchiveConfiguration();
AppYamlProjectStageConfiguration generatedConfig =
extension.toAppYamlProjectStageConfiguration();
Assert.assertEquals(appEngineDirectory.toPath(), generatedConfig.getAppEngineDirectory());
Assert.assertEquals(stagingDirectory.toPath(), generatedConfig.getStagingDirectory());
Assert.assertEquals(artifact.toPath(), generatedConfig.getArtifact());
Assert.assertEquals(dockerDirectory.toPath(), generatedConfig.getDockerDirectory());
Assert.assertEquals(0, generatedConfig.getExtraFilesDirectory().size());
}

@Test
public void testGetExtraFilesDirectoriesAsInputFiles_indirectFunctional() throws IOException {
TestProject testProject =
new TestProject(testProjectDir.getRoot())
.addAppYamlBuildFileWithExtraFilesDirectories()
.addAppYaml("java11");
Files.write(
testProject.getProjectRoot().toPath().resolve("src/main/extras/test1.txt"),
"hello".getBytes(Charsets.UTF_8));

BuildResult firstRun = testProject.applyGradleRunner("appengineStage");
Assert.assertEquals(TaskOutcome.SUCCESS, firstRun.task(":appengineStage").getOutcome());

BuildResult secondRunNoChange = testProject.applyGradleRunner("appengineStage");
Assert.assertEquals(
TaskOutcome.UP_TO_DATE, secondRunNoChange.task(":appengineStage").getOutcome());

Files.write(
testProject.getProjectRoot().toPath().resolve("src/main/extras/test2.txt"),
"hello".getBytes(Charsets.UTF_8));

BuildResult runWithNewFileAdded = testProject.applyGradleRunner("appengineStage");
Assert.assertEquals(
TaskOutcome.SUCCESS, runWithNewFileAdded.task(":appengineStage").getOutcome());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019 Google LLC. All Rights 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.
*/

plugins {
id 'java'
id 'war'
id 'com.google.cloud.tools.appengine-appyaml'
}

appengine {
deploy {
projectId = "project"
version = "version"
}
stage {
extraFilesDirectories = "src/main/extras"
}
}

0 comments on commit 6412e8b

Please sign in to comment.