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 (#62)
Browse files Browse the repository at this point in the history
* v0.2.0 + remove all traces of Gradle Software Model

minor fixes
- Fix incompatibilities with gradle 3.0+ for maven upload.
- Signing is handled by the nexus plugin
- Make sure you run --no-daemon when doing an upload
- update integTest for java8 runnability


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 authored Sep 26, 2016
1 parent b9b3291 commit 910e21c
Show file tree
Hide file tree
Showing 34 changed files with 1,082 additions and 988 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
20 changes: 7 additions & 13 deletions scripts/publishing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,11 @@ extraArchive {
}

gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.allTasks.any { it instanceof Sign } &&
taskGraph.allTasks.any { it.name.equals(project.nexus.getUploadTaskName()) }) {
Console console = System.console()
console.printf "\n\nPGP credentials required to sign artifacts.\n\n"

def id = readPropCmdLine(console, "signing.keyId", "", "PGP Key Id")
def file = readPropCmdLine(console, "signing.secretKeyRingFile", "${System.getProperty("user.home")}/.gnupg/secring.gpg", "PGP Secret Key Ring File (absolute path)")
def password = console.readPassword("PGP Private Key Password: ")

project.ext."signing.keyId" = id
project.ext."signing.secretKeyRingFile" = file
project.ext."signing.password" = password
console.printf "\n\nOSS Sonatype Credential required to upload.\n\n"
if (taskGraph.allTasks.any { it.name.equals(project.nexus.getUploadTaskName()) }) {
java.io.Console console = System.console()
// something about the gradle cmdline output messed with the output ordering
// so sleep a little so we appear after [building x%]
sleep(200)

def nexusUsername = readPropCmdLine(console, "nexus.username", "", "Sonatype Username")
def nexusPassword = console.readPassword("Sonatype Password: ")
Expand All @@ -60,6 +52,8 @@ gradle.taskGraph.whenReady { taskGraph ->
}
}

// if you see a weird error pointing here, make sure you run upload with --no-daemon
// so stdin is good to go
def readPropCmdLine(console, property, defaultValue, msg) {
def value = System.getProperty(property) ?: defaultValue
value = console.readLine("$msg [${value}]:") ?: value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
*/
public class AppEngineStandardPluginIntegrationTest {

@BeforeClass
public static void assertEnvironment() {
Assert.assertThat(System.getProperty("java.version"), CoreMatchers.startsWith("1.7"));
}

@Rule
public Timeout globalTimeout = Timeout.seconds(180);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ repositories {
dependencies {
compile "javax.servlet:servlet-api:2.5"
}

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
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 910e21c

Please sign in to comment.