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

Convert to static extension building #192

Merged
merged 6 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 Google Inc. All Right Reserved.
* Copyright (c) 2018 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.
Expand All @@ -17,7 +17,8 @@

package com.google.cloud.tools.gradle.appengine.core;

/** Base Extension class for all our appengine extensions to include themselves into. */
public class AppEngineExtension {
// dynamically fill this in in AppEngineCorePlugin
public interface AppEngineCoreExtensionProperties {
ToolsExtension getTools();

DeployExtension getDeploy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@

import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.plugins.ExtensionAware;
import org.gradle.util.GradleVersion;

/**
* Core plugin for App Engine, contains common tasks like deploy and show configuration Also
* instantiates the "tools" extension to specify the cloud sdk path.
*/
public class AppEngineCorePlugin implements Plugin<Project> {
public class AppEngineCorePluginConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APP_ENGINE_TASK_GROUP seems to be unused now.


public static final GradleVersion GRADLE_MIN_VERSION = GradleVersion.version("3.4.1");

Expand All @@ -45,21 +42,25 @@ public class AppEngineCorePlugin implements Plugin<Project> {
public static final String SHOW_CONFIG_TASK_NAME = "appengineShowConfiguration";

public static final String APPENGINE_EXTENSION = "appengine";
public static final String DEPLOY_EXTENSION = "deploy";
public static final String TOOLS_EXTENSION = "tools";

private Project project;
private AppEngineExtension extension;
private DeployExtension deployExtension;
private ToolsExtension toolsExtension;
private CloudSdkBuilderFactory cloudSdkBuilderFactory;
private String taskGroup;

@Override
public void apply(Project project) {
/** Configure core tasks for appengine flexible and standard project plugins. */
public void configureCoreProperties(
Project project,
AppEngineCoreExtensionProperties appEngineCoreExtensionProperties,
String taskGroup) {
checkGradleVersion(project);

this.project = project;
createExtensions();
this.taskGroup = taskGroup;
this.toolsExtension = appEngineCoreExtensionProperties.getTools();
this.deployExtension = appEngineCoreExtensionProperties.getDeploy();
configureCloudSdkBuilderFactory();

createDeployTask();
createDeployCronTask();
Expand All @@ -70,17 +71,7 @@ public void apply(Project project) {
createShowConfigurationTask();
}

private void createExtensions() {
extension = project.getExtensions().create(APPENGINE_EXTENSION, AppEngineExtension.class);
deployExtension =
((ExtensionAware) extension)
.getExtensions()
.create(DEPLOY_EXTENSION, DeployExtension.class, project);
toolsExtension =
((ExtensionAware) extension)
.getExtensions()
.create(TOOLS_EXTENSION, ToolsExtension.class, project);

private void configureCloudSdkBuilderFactory() {
project.afterEvaluate(
new Action<Project>() {
@Override
Expand All @@ -100,7 +91,7 @@ private void createDeployTask() {
new Action<DeployTask>() {
@Override
public void execute(final DeployTask deployTask) {
deployTask.setGroup(APP_ENGINE_TASK_GROUP);
deployTask.setGroup(taskGroup);
deployTask.setDescription("Deploy an App Engine application");

project.afterEvaluate(
Expand All @@ -124,7 +115,7 @@ private void createDeployCronTask() {
new Action<DeployCronTask>() {
@Override
public void execute(final DeployCronTask deployTask) {
deployTask.setGroup(APP_ENGINE_TASK_GROUP);
deployTask.setGroup(taskGroup);
deployTask.setDescription("Deploy Cron configuration");

project.afterEvaluate(
Expand All @@ -148,7 +139,7 @@ private void createDeployDispatchTask() {
new Action<DeployDispatchTask>() {
@Override
public void execute(final DeployDispatchTask deployTask) {
deployTask.setGroup(APP_ENGINE_TASK_GROUP);
deployTask.setGroup(taskGroup);
deployTask.setDescription("Deploy Dispatch configuration");

project.afterEvaluate(
Expand All @@ -172,7 +163,7 @@ private void createDeployDosTask() {
new Action<DeployDosTask>() {
@Override
public void execute(final DeployDosTask deployTask) {
deployTask.setGroup(APP_ENGINE_TASK_GROUP);
deployTask.setGroup(taskGroup);
deployTask.setDescription("Deploy Dos configuration");

project.afterEvaluate(
Expand All @@ -196,7 +187,7 @@ private void createDeployIndexTask() {
new Action<DeployIndexTask>() {
@Override
public void execute(final DeployIndexTask deployTask) {
deployTask.setGroup(APP_ENGINE_TASK_GROUP);
deployTask.setGroup(taskGroup);
deployTask.setDescription("Deploy Index configuration");

project.afterEvaluate(
Expand All @@ -220,7 +211,7 @@ private void createDeployQueueTask() {
new Action<DeployQueueTask>() {
@Override
public void execute(final DeployQueueTask deployTask) {
deployTask.setGroup(APP_ENGINE_TASK_GROUP);
deployTask.setGroup(taskGroup);
deployTask.setDescription("Deploy Queue configuration");

project.afterEvaluate(
Expand All @@ -244,7 +235,7 @@ private void createShowConfigurationTask() {
new Action<ShowConfigurationTask>() {
@Override
public void execute(final ShowConfigurationTask showConfigurationTask) {
showConfigurationTask.setGroup(APP_ENGINE_TASK_GROUP);
showConfigurationTask.setGroup(taskGroup);
showConfigurationTask.setDescription(
"Show current App Engine plugin configuration");

Expand All @@ -253,23 +244,6 @@ public void execute(final ShowConfigurationTask showConfigurationTask) {
});
}

/** Override the default task group of tasks from this plugin. */
public static void overrideCoreTasksGroup(Project project, final String overrideGroup) {
project
.getTasks()
.all(
new Action<Task>() {
@Override
public void execute(Task task) {
String oldGroup = task.getGroup();
if (oldGroup != null
&& oldGroup.equals(AppEngineCorePlugin.APP_ENGINE_TASK_GROUP)) {
task.setGroup(overrideGroup);
}
}
});
}

private void checkGradleVersion(Project project) {
if (GRADLE_MIN_VERSION.compareTo(GradleVersion.current()) > 0) {
throw new GradleException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.gradle.api.Project;

/** Extension element to define Deployable configurations for App Engine. */
Expand All @@ -41,6 +42,7 @@ public class DeployExtension
private String version;
private File appEngineDirectory;

@Inject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this @Inject do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah I accidentally left that in there, with new versions of gradle, if you created an extension from the root, gradle would ask you to inject the params instead of passing them in.

public DeployExtension(Project gradleProject) {
this.gradleProject = gradleProject;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public class ShowConfigurationTask extends DefaultTask {

private String extensionId;
private String allowedNestedPackageSearchPath;

@Input
public String getExtensionId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.google.cloud.tools.gradle.appengine.core;

import java.io.File;
import javax.inject.Inject;
import org.gradle.api.Project;

/** Extension element to define the location of cloud sdk tooling. */
Expand All @@ -27,6 +28,7 @@ public class ToolsExtension {

private File cloudSdkHome;

@Inject
public ToolsExtension(Project project) {
this.project = project;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2018 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.flexible;

import com.google.cloud.tools.gradle.appengine.core.AppEngineCoreExtensionProperties;
import com.google.cloud.tools.gradle.appengine.core.DeployExtension;
import com.google.cloud.tools.gradle.appengine.core.ToolsExtension;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.plugins.ExtensionAware;

public class AppEngineFlexibleExtension implements AppEngineCoreExtensionProperties {
private ToolsExtension tools;
private DeployExtension deploy;
private StageFlexibleExtension stage;

/** Create nested configuration blocks as Extensions. */
public void createSubExtensions(Project project) {
tools = ((ExtensionAware) this).getExtensions().create("tools", ToolsExtension.class, project);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to place "tools", "deploy", and "stage" in constants.

deploy =
((ExtensionAware) this).getExtensions().create("deploy", DeployExtension.class, project);
stage =
((ExtensionAware) this)
.getExtensions()
.create("stage", StageFlexibleExtension.class, project);
}

public void tools(Action<? super ToolsExtension> action) {
action.execute(tools);
}

public void deploy(Action<? super DeployExtension> action) {
action.execute(deploy);
}

public void stage(Action<? super StageFlexibleExtension> action) {
action.execute(stage);
}

@Override
public ToolsExtension getTools() {
return tools;
}

@Override
public DeployExtension getDeploy() {
return deploy;
}

public StageFlexibleExtension getStage() {
return stage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@

package com.google.cloud.tools.gradle.appengine.flexible;

import com.google.cloud.tools.gradle.appengine.core.AppEngineCorePlugin;
import com.google.cloud.tools.gradle.appengine.core.AppEngineCorePluginConfiguration;
import com.google.cloud.tools.gradle.appengine.core.DeployExtension;
import com.google.cloud.tools.gradle.appengine.util.ExtensionUtil;
import java.io.File;
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.ExtensionAware;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.WarPlugin;
import org.gradle.api.tasks.bundling.Jar;
Expand All @@ -42,27 +40,27 @@ public class AppEngineFlexiblePlugin implements Plugin<Project> {
public static final String STAGE_EXTENSION = "stage";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STAGE_EXTENSION seems to be unused now.


private Project project;
private AppEngineFlexibleExtension appengineExtension;
private StageFlexibleExtension stageExtension;

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

new AppEngineCorePluginConfiguration()
.configureCoreProperties(project, appengineExtension, APP_ENGINE_FLEXIBLE_TASK_GROUP);

configureExtensions();
createStageTask();

AppEngineCorePlugin.overrideCoreTasksGroup(project, APP_ENGINE_FLEXIBLE_TASK_GROUP);
}

private void configureExtensions() {
// obtain extensions defined by core plugin.
ExtensionAware appengine =
new ExtensionUtil(project).get(AppEngineCorePlugin.APPENGINE_EXTENSION);

// create the flexible stage extension and set defaults.
stageExtension =
appengine.getExtensions().create(STAGE_EXTENSION, StageFlexibleExtension.class, project);
stageExtension = appengineExtension.getStage();
File defaultStagedAppDir = new File(project.getBuildDir(), STAGED_APP_DIR_NAME);
stageExtension.setStagingDirectory(defaultStagedAppDir);
stageExtension.setAppEngineDirectory(new File(project.getProjectDir(), "src/main/appengine"));
Expand All @@ -73,7 +71,7 @@ private void configureExtensions() {
}

// obtain deploy extension set defaults
DeployExtension deploy = new ExtensionUtil(appengine).get(AppEngineCorePlugin.DEPLOY_EXTENSION);
DeployExtension deploy = appengineExtension.getDeploy();
deploy.setDeployables(new File(defaultStagedAppDir, "app.yaml"));
// grab default project configuration from staging default
deploy.setAppEngineDirectory(stageExtension.getAppEngineDirectory());
Expand Down Expand Up @@ -122,6 +120,9 @@ public void execute(Project project) {
});
}
});
project.getTasks().getByName(AppEngineCorePlugin.DEPLOY_TASK_NAME).dependsOn(stageTask);
project
.getTasks()
.getByName(AppEngineCorePluginConfiguration.DEPLOY_TASK_NAME)
.dependsOn(stageTask);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.google.cloud.tools.gradle.appengine.sourcecontext;

import com.google.cloud.tools.gradle.appengine.core.AppEngineCorePlugin;
import com.google.cloud.tools.gradle.appengine.core.AppEngineCoreExtensionProperties;
import com.google.cloud.tools.gradle.appengine.core.CloudSdkBuilderFactory;
import com.google.cloud.tools.gradle.appengine.core.ToolsExtension;
import com.google.cloud.tools.gradle.appengine.util.ExtensionUtil;
Expand Down Expand Up @@ -50,10 +50,8 @@ public void apply(Project project) {

private void createExtension() {
// obtain extensions defined by core plugin.
ExtensionAware appengine =
new ExtensionUtil(project).get(AppEngineCorePlugin.APPENGINE_EXTENSION);
final ToolsExtension tools =
new ExtensionUtil(appengine).get(AppEngineCorePlugin.TOOLS_EXTENSION);
ExtensionAware appengine = new ExtensionUtil(project).get("appengine");
final ToolsExtension tools = ((AppEngineCoreExtensionProperties) appengine).getTools();

// create source context extension and set defaults
extension =
Expand Down
Loading