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

Commit

Permalink
Change all Project reference in extensions to FileOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Aug 4, 2023
1 parent 5c32b51 commit 41ad87b
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.google.cloud.tools.gradle.appengine.core.InternalProperty;
import com.google.cloud.tools.gradle.appengine.core.ToolsExtension;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.plugins.ExtensionAware;

public class AppEngineAppYamlExtension implements AppEngineCoreExtensionProperties {
Expand All @@ -35,7 +35,7 @@ public class AppEngineAppYamlExtension implements AppEngineCoreExtensionProperti
@InternalProperty private StageAppYamlExtension stage;

/** Create nested configuration blocks as Extensions. */
public void createSubExtensions(Project project) {
public void createSubExtensions(FileOperations project) {
tools =
((ExtensionAware) this).getExtensions().create(TOOLS_EXT, ToolsExtension.class, project);
deploy =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
import com.google.cloud.tools.gradle.appengine.core.ToolsExtension;
import com.google.cloud.tools.gradle.appengine.util.GradleCompatibility;
import java.io.File;
import javax.inject.Inject;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.WarPlugin;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.bundling.War;

/** Plugin definition for App Engine app.yaml based projects. */
public class AppEngineAppYamlPlugin implements Plugin<Project> {
public abstract class AppEngineAppYamlPlugin implements Plugin<Project> {

public static final String APP_ENGINE_APP_YAML_TASK_GROUP = "App Engine app.yaml based projects";
private static final String STAGE_TASK_NAME = "appengineStage";
Expand All @@ -47,12 +49,15 @@ public class AppEngineAppYamlPlugin implements Plugin<Project> {
private AppEngineAppYamlExtension appengineExtension;
private StageAppYamlExtension stageExtension;

@Inject
protected abstract FileOperations getFileOperations();

@Override
public void apply(Project project) {
this.project = project;
appengineExtension =
project.getExtensions().create("appengine", AppEngineAppYamlExtension.class);
appengineExtension.createSubExtensions(project);
appengineExtension.createSubExtensions(getFileOperations());

new AppEngineCorePluginConfiguration()
.configureCoreProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
Expand All @@ -34,15 +34,15 @@
/** Extension element to define Stage configurations for app.yaml base projects. */
public class StageAppYamlExtension {

private final Project project;
private final FileOperations project;

private File appEngineDirectory;
private File dockerDirectory;
private File artifact;
private File stagingDirectory;
private List<File> extraFilesDirectories;

public StageAppYamlExtension(Project project) {
public StageAppYamlExtension(FileOperations project) {
this.project = project;
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public FileCollection getExtraFilesDirectoriesAsInputFiles() {
if (extraFilesDirectories == null) {
return null;
}
FileCollection files = project.files();
FileCollection files = project.immutableFiles();
for (File directory : extraFilesDirectories) {
files = files.plus(project.fileTree(directory));
}
Expand All @@ -103,7 +103,8 @@ public List<File> getExtraFilesDirectories() {
}

public void setExtraFilesDirectories(Object extraFilesDirectories) {
this.extraFilesDirectories = new ArrayList<>(project.files(extraFilesDirectories).getFiles());
this.extraFilesDirectories =
new ArrayList<>(project.immutableFiles(extraFilesDirectories).getFiles());
}

AppYamlProjectStageConfiguration toAppYamlProjectStageConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import java.nio.file.Path;
import java.util.List;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;

/** Extension element to define Deployable configurations for App Engine. */
public class DeployExtension {

@InternalProperty private DeployTargetResolver deployTargetResolver;

// named gradleProject to disambiguate with deploy parameter "project"
private final Project gradleProject;
private final FileOperations gradleProject;

private String bucket;
private String gcloudMode;
Expand All @@ -44,7 +44,7 @@ public class DeployExtension {
private String version;
private File appEngineDirectory;

public DeployExtension(Project gradleProject) {
public DeployExtension(FileOperations gradleProject) {
this.gradleProject = gradleProject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
package com.google.cloud.tools.gradle.appengine.core;

import java.io.File;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;

/** Extension element to define the location of cloud sdk tooling. */
public class ToolsExtension {

private final Project project;
private final FileOperations project;

private File cloudSdkHome;
private String cloudSdkVersion;
private File cloudSdkServiceAccountFile;
private String verbosity;

public ToolsExtension(Project project) {
public ToolsExtension(FileOperations project) {
this.project = project;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.google.cloud.tools.gradle.appengine.core.InternalProperty;
import com.google.cloud.tools.gradle.appengine.core.ToolsExtension;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.plugins.ExtensionAware;

public class AppEngineStandardExtension implements AppEngineCoreExtensionProperties {
Expand All @@ -37,7 +37,7 @@ public class AppEngineStandardExtension implements AppEngineCoreExtensionPropert
@InternalProperty private RunExtension run;

/** Create nested configuration blocks as Extensions. */
public void createSubExtensions(Project project) {
public void createSubExtensions(FileOperations project) {
tools =
((ExtensionAware) this).getExtensions().create(TOOLS_EXT, ToolsExtension.class, project);
deploy =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@
import com.google.cloud.tools.gradle.appengine.util.GradleCompatibility;
import com.google.common.base.Strings;
import java.io.File;
import javax.inject.Inject;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.WarPlugin;
import org.gradle.api.tasks.bundling.War;

/** Plugin definition for App Engine standard environments. */
public class AppEngineStandardPlugin implements Plugin<Project> {
public abstract class AppEngineStandardPlugin implements Plugin<Project> {

public static final String APP_ENGINE_STANDARD_TASK_GROUP = "App Engine Standard environment";
public static final String EXPLODE_WAR_TASK_NAME = "explodeWar";
Expand All @@ -59,13 +61,16 @@ public class AppEngineStandardPlugin implements Plugin<Project> {
private StageStandardExtension stageExtension;
private File explodedWarDir;

@Inject
protected abstract FileOperations getFileOperations();

@Override
public void apply(Project project) {
this.project = project;
project.getPluginManager().apply(WarPlugin.class);
appengineExtension =
project.getExtensions().create("appengine", AppEngineStandardExtension.class);
appengineExtension.createSubExtensions(project);
appengineExtension.createSubExtensions(getFileOperations());

appEngineCorePluginConfiguration = new AppEngineCorePluginConfiguration();
appEngineCorePluginConfiguration.configureCoreProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import java.util.stream.Collectors;
import org.gradle.api.Project;
import org.gradle.api.ProjectConfigurationException;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.internal.file.FileOperations;

/** Extension element to define Run configurations for App Engine Standard Environments. */
public class RunExtension {

@InternalProperty private DeployTargetResolver deployTargetResolver;

private final Project project;
private final FileOperations project;
private int startSuccessTimeout;
private String serverVersion;

Expand All @@ -55,7 +55,7 @@ public class RunExtension {
*
* @param project The gradle project.
*/
public RunExtension(Project project) {
public RunExtension(FileOperations project) {
this.project = project;
}

Expand Down Expand Up @@ -124,39 +124,41 @@ public List<File> getServices() {
}

public void setServices(Object services) {
this.services = new ArrayList<>(project.files(services).getFiles());
this.services = new ArrayList<>(project.immutableFiles(services).getFiles());
}

/**
* Returns the appengine service directory for this project and modifies the task dependencies of
* run/start to ensure {@code serviceProject} is built first.
*/
public File projectAsService(String serviceProject) {
return projectAsService(project.getRootProject().project(serviceProject));
throw new UnsupportedOperationException("Has no access to current project");
// return projectAsService(project.getRootProject().project(serviceProject));
}

/**
* Returns the appengine service directory for this project and modifies the task dependencies of
* run/start to ensure {@code serviceProject} is built first.
*/
public File projectAsService(Project serviceProject) {
if (!serviceProject.equals(project)) {
project.evaluationDependsOn(serviceProject.getPath());
}
project
.getTasks()
.findByName(AppEngineStandardPlugin.RUN_TASK_NAME)
.dependsOn(serviceProject.getTasks().findByPath(BasePlugin.ASSEMBLE_TASK_NAME));
project
.getTasks()
.findByName(AppEngineStandardPlugin.START_TASK_NAME)
.dependsOn(serviceProject.getTasks().findByPath(BasePlugin.ASSEMBLE_TASK_NAME));
return serviceProject
.getTasks()
.findByName(AppEngineStandardPlugin.EXPLODE_WAR_TASK_NAME)
.getOutputs()
.getFiles()
.getSingleFile();
throw new UnsupportedOperationException("Has no access to current project");
// if (!serviceProject.equals(project)) {
// project.evaluationDependsOn(serviceProject.getPath());
// }
// project
// .getTasks()
// .findByName(AppEngineStandardPlugin.RUN_TASK_NAME)
// .dependsOn(serviceProject.getTasks().findByPath(BasePlugin.ASSEMBLE_TASK_NAME));
// project
// .getTasks()
// .findByName(AppEngineStandardPlugin.START_TASK_NAME)
// .dependsOn(serviceProject.getTasks().findByPath(BasePlugin.ASSEMBLE_TASK_NAME));
// return serviceProject
// .getTasks()
// .findByName(AppEngineStandardPlugin.EXPLODE_WAR_TASK_NAME)
// .getOutputs()
// .getFiles()
// .getSingleFile();
}

public Map<String, String> getEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.cloud.tools.appengine.configuration.AppEngineWebXmlProjectStageConfiguration;
import com.google.cloud.tools.gradle.appengine.util.NullSafe;
import java.io.File;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.InputFile;
Expand All @@ -30,7 +30,7 @@
/** Extension element to define Stage configurations for App Engine Standard Environments. */
public class StageStandardExtension {

private final Project project;
private final FileOperations project;

private File sourceDirectory;
private File stagingDirectory;
Expand All @@ -46,7 +46,7 @@ public class StageStandardExtension {
private String runtime;

/** Constuctor. */
public StageStandardExtension(Project project) {
public StageStandardExtension(FileOperations project) {
this.project = project;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.List;
import java.util.stream.Collectors;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.testfixtures.ProjectBuilder;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
Expand Down Expand Up @@ -60,7 +62,9 @@ public void setUpFiles() throws IOException {

@Test
public void testToAppYamlProjectStageConfiguration_allValuesSet() {
StageAppYamlExtension extension = new StageAppYamlExtension(testContextProject);
FileOperations fileOperations =
((ProjectInternal) testContextProject).getServices().get(FileOperations.class);
StageAppYamlExtension extension = new StageAppYamlExtension(fileOperations);

extension.setStagingDirectory(stagingDirectory);
extension.setAppEngineDirectory(appEngineDirectory);
Expand All @@ -81,7 +85,9 @@ public void testToAppYamlProjectStageConfiguration_allValuesSet() {

@Test
public void testToAppYamlProjectStageConfiguration_nullExtraFiles() {
StageAppYamlExtension extension = new StageAppYamlExtension(testContextProject);
FileOperations fileOperations =
((ProjectInternal) testContextProject).getServices().get(FileOperations.class);
StageAppYamlExtension extension = new StageAppYamlExtension(fileOperations);

extension.setStagingDirectory(stagingDirectory);
extension.setAppEngineDirectory(appEngineDirectory);
Expand All @@ -100,7 +106,9 @@ public void testToAppYamlProjectStageConfiguration_nullExtraFiles() {

@Test
public void testToAppYamlProjectStageConfiguration_emptyExtraFiles() {
StageAppYamlExtension extension = new StageAppYamlExtension(testContextProject);
FileOperations fileOperations =
((ProjectInternal) testContextProject).getServices().get(FileOperations.class);
StageAppYamlExtension extension = new StageAppYamlExtension(fileOperations);

extension.setStagingDirectory(stagingDirectory);
extension.setAppEngineDirectory(appEngineDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.io.IOException;
import java.nio.file.Path;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -61,7 +63,9 @@ public class DeployAllTaskTest {
@Before
public void setup() throws IOException {
Project tempProject = ProjectBuilder.builder().build();
deployExtension = new DeployExtension(tempProject);
FileOperations fileOperations =
((ProjectInternal) tempProject).getServices().get(FileOperations.class);
deployExtension = new DeployExtension(fileOperations);
deployExtension.setDeployTargetResolver(deployTargetResolver);
deployCapture = ArgumentCaptor.forClass(DeployConfiguration.class);
stageDir = tempFolder.newFolder("staging");
Expand Down
Loading

0 comments on commit 41ad87b

Please sign in to comment.