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

Commit

Permalink
Builder model for external tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
loosebazooka committed May 9, 2014
1 parent bc7931d commit 36dabb8
Show file tree
Hide file tree
Showing 20 changed files with 531 additions and 28 deletions.
Empty file modified README.md
100755 → 100644
Empty file.
9 changes: 6 additions & 3 deletions build.gradle
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'nexus'

apply from: 'builder-model-impl.gradle'

def compatibilityVersion = 1.7
sourceCompatibility = compatibilityVersion
targetCompatibility = compatibilityVersion
Expand Down Expand Up @@ -29,6 +31,7 @@ repositories {
dependencies {
compile localGroovy()
compile gradleApi()
compile project(':builder-model')
compile "com.google.appengine:appengine-local-endpoints:${version}"
compile 'com.google.guava:guava:16.0'
testCompile 'org.spockframework:spock-core:0.6-groovy-1.8'
Expand All @@ -46,7 +49,7 @@ jar {
}

idea.project {
jdkName = '1.6'
jdkName = '1.7'

ipr.withXml { provider ->
def node = provider.asNode()
Expand All @@ -62,7 +65,7 @@ idea.project {
}

task wrapper(type: Wrapper) {
gradleVersion = '1.10'
gradleVersion = '1.11'
}

modifyPom {
Expand Down Expand Up @@ -116,7 +119,7 @@ task snapshot << {
test {
systemProperty "appengine.version", "${version}"
systemProperty "appengine.pluginversion", "${version}"
}.dependsOn install
}.dependsOn install, ':builder-model:install'

import org.gradle.plugins.signing.Sign

Expand Down
25 changes: 25 additions & 0 deletions builder-model-impl.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// set up the build for the model implementation because it needs to be compiled
// separately to use java6 instead of java7 like the main so the builder model can
// be intergrated with tools that use java6

apply from: 'java6-mode.gradle'

sourceSets {
model
main {
compileClasspath += model.output
runtimeClasspath += model.output
}
}

setJava6Mode(compileModelJava)

dependencies {
modelCompile project(':builder-model')
}

jar {
from {
sourceSets.model.output
}
}
20 changes: 20 additions & 0 deletions builder-model/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apply plugin: 'maven'
apply plugin: 'java'

apply from: '../java6-mode.gradle'

archivesBaseName = 'gradle-appengine-builder-model'
group = 'com.google.appengine'
version = '0.1.0'

setJava6Mode(compileJava)

jar {
manifest {
attributes 'Implementation-Title': 'Gradle App Engine Tooling Model',
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2014 the original author or authors.
*
* 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.appengine.gradle.model;

/**
* Interface for the App Config Options in an App Engine gradle project
* NOTE: If you change this, update the builder model version
*/
public interface AppCfgOptions {
public String getEmail();
public String getServer();
public String getHost();
public Boolean isNoCookies();
public Boolean isPassIn();
public String getPassword();
public String getHttpProxy();
public String getHttpsProxy();
public Boolean isOauth2();
public Boolean isUseJava7();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2014 the original author or authors.
*
* 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.appengine.gradle.model;

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

/**
* Interface for the AppEngine Model
* NOTE: If you change this, update the builder model version
*/
public interface AppEngineModel {
public String getModelVersion();
public String getHttpAddress();
public Integer getHttpPort();
public Boolean isDisableUpdateCheck();
public String getEnhancerVersion();
public String getEnhancerApi();
public List<String> getJvmFlags();
public File getWarDir();
public File getWebAppDir();
public String getAppEngineSdkRoot();
public AppCfgOptions getAppCfgOptions();
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Feb 19 08:54:57 EST 2014
#Thu May 01 15:19:26 EDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip
13 changes: 13 additions & 0 deletions java6-mode.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Allows a compileJavaTask to run in Java6 mode.
// Setting the system property "jdk6.home" to a JDK6 installation links the
// compatibility libraries for the task, otherwise gradle throws a warning

ext.setJava6Mode = { compileJavaTask ->
compileJavaTask.sourceCompatibility = 1.6
compileJavaTask.targetCompatibility = 1.6
// if jdk6.home is defined use it
def jdk6Home = System.properties['jdk6.home']
if(jdk6Home) {
compileJavaTask.options.bootClasspath = (new File(jdk6Home,"/jre/lib/rt.jar")).canonicalPath
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ":builder-model"
29 changes: 20 additions & 9 deletions src/main/groovy/com/google/appengine/AppEnginePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.appengine

import com.google.appengine.tooling.AppEngineToolingBuilderModel
import com.google.appengine.task.DownloadSdkTask
import com.google.appengine.task.EnhanceTask
import com.google.appengine.task.ExplodeAppTask
Expand Down Expand Up @@ -45,6 +46,9 @@ import org.gradle.api.tasks.testing.Test
import org.gradle.plugins.ear.EarPluginConvention
import org.gradle.plugins.ide.eclipse.EclipsePlugin
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry

import javax.inject.Inject

import static org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME

Expand Down Expand Up @@ -102,8 +106,15 @@ class AppEnginePlugin implements Plugin<Project> {
static final String FUNCTIONAL_TEST_RUNTIME_CONFIGURATION = 'functionalTestRuntime'
static final String FUNCTIONAL_TEST_SOURCE_SET = 'functionalTest'

private final ToolingModelBuilderRegistry registry;
@Inject
public AppEnginePlugin(ToolingModelBuilderRegistry registry) {
this.registry = registry;
}

@Override
void apply(Project project) {
registry.register(new AppEngineToolingBuilderModel());
project.configurations.create(APPENGINE_SDK_CONFIGURATION_NAME).setVisible(false).setTransitive(true)
.setDescription('The Google App Engine SDK to be downloaded and used for this project.')

Expand Down Expand Up @@ -149,35 +160,35 @@ class AppEnginePlugin implements Plugin<Project> {
configureFunctionalTest(project, appenginePluginConvention)
}

private File getExplodedSdkDirectory(Project project) {
static File getExplodedSdkDirectory(Project project) {
new File(project.gradle.gradleUserHomeDir, 'appengine-sdk')
}

private File getExplodedAppDirectory(Project project) {
static File getExplodedAppDirectory(Project project) {
getBuildSubDirectory(project, 'exploded-app')
}

private File getDownloadedAppDirectory(Project project) {
static File getDownloadedAppDirectory(Project project) {
getBuildSubDirectory(project, 'downloaded-app')
}

private File getDiscoveryDocDirectory(Project project) {
static File getDiscoveryDocDirectory(Project project) {
getBuildSubDirectory(project, 'discovery-docs')
}

private File getEndpointsClientLibDirectory(Project project) {
static File getEndpointsClientLibDirectory(Project project) {
getBuildSubDirectory(project, 'client-libs')
}

private File getGenDir(Project project) {
static File getGenDir(Project project) {
getBuildSubDirectory(project, 'generated-source')
}

private File getEndpointsExpandedSrcDir(Project project) {
static File getEndpointsExpandedSrcDir(Project project) {
new File(getGenDir(project),'endpoints/java')
}

private File getBuildSubDirectory(Project project, String subDirectory) {
static File getBuildSubDirectory(Project project, String subDirectory) {
def subDir = new StringBuilder()
subDir <<= project.buildDir
subDir <<= System.getProperty('file.separator')
Expand Down Expand Up @@ -633,7 +644,7 @@ class AppEnginePlugin implements Plugin<Project> {
}
}

private File getAppDir(Project project) {
static File getAppDir(Project project) {
if(project.hasProperty('ear')) {
return new File(project.projectDir, project.convention.getPlugin(EarPluginConvention).appDirName)
} else if(project.hasProperty('war')) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/groovy/com/google/appengine/task/DownloadSdkTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ class DownloadSdkTask extends DefaultTask {
}
}

if(!new File(getDownloadedSdkRoot()).exists()) {
if(!new File(getDownloadedSdkRoot(getAppengineSdkZipFile(), getExplodedSdkDirectory())).exists()) {
ant.unzip(src: getAppengineSdkZipFile(), dest: getExplodedSdkDirectory())
}

System.setProperty(AbstractTask.APPENGINE_SDK_ROOT_SYS_PROP_KEY, getDownloadedSdkRoot())
System.setProperty(AbstractTask.APPENGINE_SDK_ROOT_SYS_PROP_KEY, getDownloadedSdkRoot(getAppengineSdkZipFile(), getExplodedSdkDirectory()))
}

private String getDownloadedSdkRoot() {
String filename = getAppengineSdkZipFile().name.substring(0, getAppengineSdkZipFile().name.lastIndexOf('.'))
getExplodedSdkDirectory().canonicalPath + System.getProperty('file.separator') + filename
static String getDownloadedSdkRoot(File zipFile, File explodedSdkDir) {
String filename = zipFile.name.substring(0, zipFile.name.lastIndexOf('.'))
explodedSdkDir.canonicalPath + System.getProperty('file.separator') + filename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2014 the original author or authors.
*
* 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.appengine.tooling

import com.google.appengine.AppEnginePlugin
import com.google.appengine.AppEnginePluginConvention
import com.google.appengine.task.AbstractTask
import com.google.appengine.task.DownloadSdkTask
import com.google.appengine.task.appcfg.AppConfigConvention;
import com.google.appengine.gradle.model.AppCfgOptions
import com.google.appengine.gradle.model.AppEngineModel
import com.google.appengine.gradle.model.impl.DefaultAppCfgOptions;
import com.google.appengine.gradle.model.impl.DefaultAppEngineModel;

import org.gradle.api.Project
import org.gradle.api.artifacts.UnknownConfigurationException
import org.gradle.tooling.provider.model.ToolingModelBuilder;

/**
* AppEngine implementation of ToolingModelBuilder, populates the AppEngineModel
*/
public class AppEngineToolingBuilderModel implements ToolingModelBuilder {
@Override
public boolean canBuild(String modelName) {
return modelName.equals(AppEngineModel.class.getName());
}

@Override
public Object buildAll(String modelName, Project project) {
AppEnginePluginConvention conf = project.convention.plugins.appengine
AppConfigConvention appCfg = conf.getAppCfg()

AppCfgOptions appCfgOptions = new DefaultAppCfgOptions(appCfg.email,
appCfg.server,
appCfg.host,
appCfg.noCookies,
appCfg.passIn,
appCfg.password,
appCfg.httpProxy,
appCfg.httpsProxy,
appCfg.oauth2,
appCfg.update.useJava7)
return new DefaultAppEngineModel(conf.httpAddress,
conf.httpPort,
conf.disableUpdateCheck,
conf.enhancerVersion,
conf.enhancerApi,
conf.jvmFlags,
conf.warDir ?: AppEnginePlugin.getExplodedAppDirectory(project),
AppEnginePlugin.getAppDir(project),
getSdkLocation(conf, project),
appCfgOptions)

}

/**
* Determine the App Engine SDK location
* @return SDK location or null otherwise
*/
static String getSdkLocation(AppEnginePluginConvention conf, Project project) {
if(conf.downloadSdk) {
try {
def explodedSdkDir = AppEnginePlugin.getExplodedSdkDirectory(project)
def zipFile = project.configurations.getByName(AppEnginePlugin.APPENGINE_SDK_CONFIGURATION_NAME).singleFile
return DownloadSdkTask.getDownloadedSdkRoot(zipFile, explodedSdkDir)
} catch (UnknownConfigurationException e) {
// couldn't find download sdk config, try other methods
}
}
String sdkRoot = System.getProperty(AbstractTask.APPENGINE_SDK_ROOT_SYS_PROP_KEY);
if(!sdkRoot) {
sdkRoot = System.getenv(AbstractTask.APPENGINE_HOME_ENV_PROP_KEY)
}
sdkRoot
}
}
Loading

0 comments on commit 36dabb8

Please sign in to comment.