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

Commit

Permalink
v0.2.0 + remove all traces of Gradle Software Model
Browse files Browse the repository at this point in the history
It appears that the Gradle Software Model for java projects is
not moving forward. Change code back to classic plugin format -
using extensions and project callbacks.

This code change affects how to configure the plugin now,
the "appengine" configuration block is now under project, not model.

OLD :
model {
  appengine {
  }
}

NEW :
appengine {
}
  • Loading branch information
loosebazooka committed Sep 23, 2016
1 parent b9b3291 commit 61bf4dd
Show file tree
Hide file tree
Showing 31 changed files with 1,072 additions and 970 deletions.
12 changes: 2 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

group = 'com.google.cloud.tools'
version = '0.1.2-SNAPSHOT'
version = '0.2.0-SNAPSHOT'

repositories {
mavenCentral()
Expand All @@ -30,21 +30,13 @@ repositories {
dependencies {
compile localGroovy()
compile gradleApi()
compile ('com.google.cloud.tools:appengine-plugins-core:0.1.6') {
changing = true;
}
compile 'com.google.cloud.tools:appengine-plugins-core:0.1.9'

testCompile 'commons-io:commons-io:2.4'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-core:2.0.54-beta'
}

configurations.all {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}

jar {
manifest {
attributes 'Implementation-Title': project.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,23 @@

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

import com.google.cloud.tools.gradle.appengine.model.hidden.CloudSdkBuilderFactory;
import com.google.cloud.tools.gradle.appengine.model.AppEngineFlexibleModel;
import com.google.cloud.tools.gradle.appengine.model.AppEngineFlexibleExtension;
import com.google.cloud.tools.gradle.appengine.task.CloudSdkBuilderFactory;
import com.google.cloud.tools.gradle.appengine.task.DeployTask;
import com.google.cloud.tools.gradle.appengine.task.StageFlexibleTask;

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.internal.project.ProjectIdentifier;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.ExtensionContainer;
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;
import org.gradle.model.Defaults;
import org.gradle.model.Finalize;
import org.gradle.model.Model;
import org.gradle.model.ModelMap;
import org.gradle.model.Mutate;
import org.gradle.model.Path;
import org.gradle.model.RuleSource;
import org.gradle.model.internal.core.Hidden;

import java.io.File;
import java.util.Collections;
import java.util.List;

/**
* Plugin definition for App Engine flexible environments
Expand All @@ -57,99 +45,92 @@ public class AppEngineFlexiblePlugin implements Plugin<Project> {
private static final String APP_ENGINE_FLEXIBLE_TASK_GROUP = "App Engine flexible environment";
private static final String STAGED_APP_DIR_NAME = "staged-app";

private Project project;
private AppEngineFlexibleExtension extension;
private CloudSdkBuilderFactory cloudSdkBuilderFactory;

@Override
public void apply(Project project) {

// Create an extension to share data from project space to model space
final FlexibleDataExtension projectData = project.getExtensions()
.create("_internalProjectData", FlexibleDataExtension.class);
this.project = project;
createPluginExtension();

configureProjectArchive(project, projectData);
createStageTask();
createDeployTask();
}

private void configureProjectArchive(Project project, final FlexibleDataExtension projectData) {
private void createPluginExtension() {
extension = project.getExtensions().create("appengine", AppEngineFlexibleExtension.class);

extension.getStage().setStagingDirectory(new File(project.getBuildDir(), STAGED_APP_DIR_NAME));
extension.getDeploy().setDeployables(Collections
.singletonList(new File(extension.getStage().getStagingDirectory(), "app.yaml")));
extension.getStage()
.setAppEngineDirectory(new File(project.getProjectDir(), "src/main/appengine"));
File dockerDirectory = new File(project.getProjectDir(), "src/main/docker");
if (dockerDirectory.exists()) {
extension.getStage().setDockerDirectory(dockerDirectory);
}

project.afterEvaluate(new Action<Project>() {
@Override
public void execute(Project project) {
if (project.getPlugins().hasPlugin(WarPlugin.class)) {
War war = (War) project.getProperties().get("war");
projectData.setArchive(war.getArchivePath());
}
else if (project.getPlugins().hasPlugin(JavaPlugin.class)){
Jar jar = (Jar) project.getProperties().get("jar");
projectData.setArchive(jar.getArchivePath());
}
else {
throw new GradleException("Could not find JAR or WAR configuration");
// we can only set the default location of "archive" after project evaluation (callback)
if (extension.getStage().getArtifact() == null) {
if (project.getPlugins().hasPlugin(WarPlugin.class)) {
War war = (War) project.getProperties().get("war");
extension.getStage().setArtifact(war.getArchivePath());
} else if (project.getPlugins().hasPlugin(JavaPlugin.class)) {
Jar jar = (Jar) project.getProperties().get("jar");
extension.getStage().setArtifact(jar.getArchivePath());
} else {
throw new GradleException("Could not find JAR or WAR configuration");
}

// also create the sdk builder factory after we know the location of the sdk
cloudSdkBuilderFactory = new CloudSdkBuilderFactory(
extension.getTools().getCloudSdkHome());
}
}
});
}

/**
* RuleSource configuration for the plugin
*/
public static class PluginRules extends RuleSource {

@Model
public void appengine(AppEngineFlexibleModel app) {
}

@Model
@Hidden
public void cloudSdkBuilderFactory(CloudSdkBuilderFactory factory) {
}
private void createStageTask() {
project.getTasks()
.create(STAGE_TASK_NAME, StageFlexibleTask.class, new Action<StageFlexibleTask>() {
@Override
public void execute(final StageFlexibleTask stageTask) {
stageTask.setGroup(APP_ENGINE_FLEXIBLE_TASK_GROUP);
stageTask.setDescription(
"Stage an App Engine flexible environment application for deployment");
stageTask.dependsOn(BasePlugin.ASSEMBLE_TASK_NAME);

project.afterEvaluate(new Action<Project>() {
@Override
public void execute(Project project) {
stageTask.setStagingConfig(extension.getStage());
}
});
}
});
}

@Defaults
public void setDefaults(AppEngineFlexibleModel app, @Path("buildDir") File buildDir,
ProjectIdentifier project, ExtensionContainer extensions) {
app.getStage().setArtifact(extensions.getByType(FlexibleDataExtension.class).getArchive());
app.getStage().setStagingDirectory(new File(buildDir, STAGED_APP_DIR_NAME));
List<File> deployables = Collections
.singletonList(new File(app.getStage().getStagingDirectory(), "app.yaml"));
app.getDeploy().setDeployables(deployables);

// TODO : look up using the convention for sourcesets here?
File dockerDirectory = new File(project.getProjectDir(), "src/main/docker");
if (dockerDirectory.exists()) {
app.getStage().setDockerDirectory(dockerDirectory);
private void createDeployTask() {
project.getTasks().create(DEPLOY_TASK_NAME, DeployTask.class, new Action<DeployTask>() {
@Override
public void execute(final DeployTask deployTask) {
deployTask.setGroup(APP_ENGINE_FLEXIBLE_TASK_GROUP);
deployTask.setDescription("Deploy an App Engine flexible environment application");
deployTask.dependsOn(STAGE_TASK_NAME);

project.afterEvaluate(new Action<Project>() {
@Override
public void execute(Project project) {
deployTask.setDeployConfig(extension.getDeploy());
deployTask.setCloudSdkBuilderFactory(cloudSdkBuilderFactory);
}
});
}
app.getStage().setAppEngineDirectory(new File(project.getProjectDir(), "src/main/appengine"));
}

@Mutate
public void createCloudSdkBuilderFactory(final CloudSdkBuilderFactory factory,
final AppEngineFlexibleModel app) {
factory.setCloudSdkHome(app.getTools().getCloudSdkHome());
}

@Mutate
public void createStageTask(final ModelMap<Task> tasks, final AppEngineFlexibleModel app) {
tasks.create(STAGE_TASK_NAME, StageFlexibleTask.class, new Action<StageFlexibleTask>() {
@Override
public void execute(StageFlexibleTask stageTask) {
stageTask.setStagingConfig(app.getStage());
stageTask.setGroup(APP_ENGINE_FLEXIBLE_TASK_GROUP);
stageTask.setDescription("Stage an App Engine flexible environment application for deployment");
stageTask.dependsOn(BasePlugin.ASSEMBLE_TASK_NAME);
}
});
}

@Finalize
public void createDeployTask(ModelMap<Task> tasks, final AppEngineFlexibleModel app,
final CloudSdkBuilderFactory factory) {

tasks.create(DEPLOY_TASK_NAME, DeployTask.class, new Action<DeployTask>() {
@Override
public void execute(DeployTask deployTask) {
deployTask.setDeployConfig(app.getDeploy());
deployTask.setCloudSdkBuilderFactory(factory);
deployTask.setGroup(APP_ENGINE_FLEXIBLE_TASK_GROUP);
deployTask.setDescription("Deploy an App Engine flexible environment application");
deployTask.dependsOn(STAGE_TASK_NAME);
}
});
}
});
}
}
Loading

0 comments on commit 61bf4dd

Please sign in to comment.