From 615f44a06c62ceedd8019dc1046e072d84dd830e Mon Sep 17 00:00:00 2001 From: Les Vogel Date: Thu, 11 Aug 2016 09:29:37 -0700 Subject: [PATCH 1/2] New Plugins --- .gitignore | 3 + appengine/helloworld-new-plugins/README.md | 59 +++++++ appengine/helloworld-new-plugins/build.gradle | 52 ++++++ .../gradle/wrapper/gradle-wrapper.properties | 6 + appengine/helloworld-new-plugins/gradlew | 164 ++++++++++++++++++ appengine/helloworld-new-plugins/gradlew.bat | 90 ++++++++++ appengine/helloworld-new-plugins/pom.xml | 74 ++++++++ .../helloworld-new-plugins/settings.gradle | 1 + .../appengine/helloworld/HelloServlet.java | 36 ++++ .../src/main/webapp/WEB-INF/appengine-web.xml | 20 +++ .../src/main/webapp/WEB-INF/web.xml | 14 ++ pom.xml | 1 + 12 files changed, 520 insertions(+) create mode 100644 appengine/helloworld-new-plugins/README.md create mode 100644 appengine/helloworld-new-plugins/build.gradle create mode 100644 appengine/helloworld-new-plugins/gradle/wrapper/gradle-wrapper.properties create mode 100755 appengine/helloworld-new-plugins/gradlew create mode 100644 appengine/helloworld-new-plugins/gradlew.bat create mode 100644 appengine/helloworld-new-plugins/pom.xml create mode 100644 appengine/helloworld-new-plugins/settings.gradle create mode 100644 appengine/helloworld-new-plugins/src/main/java/com/example/appengine/helloworld/HelloServlet.java create mode 100644 appengine/helloworld-new-plugins/src/main/webapp/WEB-INF/appengine-web.xml create mode 100644 appengine/helloworld-new-plugins/src/main/webapp/WEB-INF/web.xml diff --git a/.gitignore b/.gitignore index 76b065e85ba..8e171704c09 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ Session.vim .netrwhist *~ tags + +# Gradle +out/ diff --git a/appengine/helloworld-new-plugins/README.md b/appengine/helloworld-new-plugins/README.md new file mode 100644 index 00000000000..80b1c6fcff7 --- /dev/null +++ b/appengine/helloworld-new-plugins/README.md @@ -0,0 +1,59 @@ +# Google App Engine Standard Environment Hello World Sample + +This sample demonstrates how to deploy an application on Google App Engine. + +See the [Google App Engine standard environment documentation][ae-docs] for more +detailed instructions. + +[ae-docs]: https://cloud.google.com/appengine/docs/java/ + +## Setup + +Use either: + +* `gcloud init` +* `gcloud beta auth application-default login` + +## Maven +### Running locally + + $ mvn appengine:run + +### Deploying + + $ mvn appengine:deploy + +## Gradle +### Running locally + + $ ./gradlew appengineRun + +### Deploying + + $ ./gradlew appengineDeploy + + diff --git a/appengine/helloworld-new-plugins/build.gradle b/appengine/helloworld-new-plugins/build.gradle new file mode 100644 index 00000000000..30ce87b8f80 --- /dev/null +++ b/appengine/helloworld-new-plugins/build.gradle @@ -0,0 +1,52 @@ +buildscript { + repositories { + jcenter() // Bintray's repository - a fast Maven Central mirror & more + mavenCentral() + } + dependencies { + classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle plugin + } +} + +repositories { + maven { + url 'https://maven-central.storage.googleapis.com' // Google's mirror of Maven Central +// url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT Reposiotry + } + jcenter() + mavenCentral() +} + +apply plugin: 'java' +apply plugin: 'war' +apply plugin: 'com.google.cloud.tools.appengine' + +dependencies { // Servlet for App Engine Standard +// providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5' + providedCompile 'javax.servlet:javax.servlet-api:3.1.0' // if beta-quickstart in appengine-web.xml +} + +task wrapper(type: Wrapper) { // use the gradle wrapper "./gradlew.sh ..." + gradleVersion = '2.14' // "gradle wrapper --gradle-version 2.14" (to create files and directories) +} + +model { + appengine { + run { // dev appserver configuration (standard environments only) + jvmFlags = ['-Dappengine.user.timezone=UTC'] + host = '127.0.0.1' + port = 8080 + } + + deploy { // deploy configuration + promote = true + stopPreviousVersion = true + } + } +} + +group = 'com.example.appengine' +version = '1.0-SNAPSHOT' + +sourceCompatibility = JavaVersion.VERSION_1_7 +targetCompatibility = JavaVersion.VERSION_1_7 diff --git a/appengine/helloworld-new-plugins/gradle/wrapper/gradle-wrapper.properties b/appengine/helloworld-new-plugins/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..399d9f7ee28 --- /dev/null +++ b/appengine/helloworld-new-plugins/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Aug 04 16:12:44 PDT 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip diff --git a/appengine/helloworld-new-plugins/gradlew b/appengine/helloworld-new-plugins/gradlew new file mode 100755 index 00000000000..27309d92314 --- /dev/null +++ b/appengine/helloworld-new-plugins/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/appengine/helloworld-new-plugins/gradlew.bat b/appengine/helloworld-new-plugins/gradlew.bat new file mode 100644 index 00000000000..f6d5974e72f --- /dev/null +++ b/appengine/helloworld-new-plugins/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/appengine/helloworld-new-plugins/pom.xml b/appengine/helloworld-new-plugins/pom.xml new file mode 100644 index 00000000000..4efb8a8e5b7 --- /dev/null +++ b/appengine/helloworld-new-plugins/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + war + 1.0-SNAPSHOT + com.example.appengine + appengine-helloworld + + + 1.7 + 1.7 + + + + com.google.cloud + doc-samples + 1.0.0 + ../.. + + + + javax.servlet + servlet-api + jar + provided + + + + + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + + + + com.google.cloud.tools + appengine-maven-plugin + 0.1.1-beta + + + + + + + + + true + true + + + + + + diff --git a/appengine/helloworld-new-plugins/settings.gradle b/appengine/helloworld-new-plugins/settings.gradle new file mode 100644 index 00000000000..3c0d21f2018 --- /dev/null +++ b/appengine/helloworld-new-plugins/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'appengine-helloworld' diff --git a/appengine/helloworld-new-plugins/src/main/java/com/example/appengine/helloworld/HelloServlet.java b/appengine/helloworld-new-plugins/src/main/java/com/example/appengine/helloworld/HelloServlet.java new file mode 100644 index 00000000000..d9135a0ce63 --- /dev/null +++ b/appengine/helloworld-new-plugins/src/main/java/com/example/appengine/helloworld/HelloServlet.java @@ -0,0 +1,36 @@ +/** + * Copyright 2015 Google Inc. All Rights 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.example.appengine.helloworld; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +// [START example] +@SuppressWarnings("serial") +public class HelloServlet extends HttpServlet { + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + PrintWriter out = resp.getWriter(); + out.println("Hello, world"); + } +} +// [END example] diff --git a/appengine/helloworld-new-plugins/src/main/webapp/WEB-INF/appengine-web.xml b/appengine/helloworld-new-plugins/src/main/webapp/WEB-INF/appengine-web.xml new file mode 100644 index 00000000000..3ee2fa64c4e --- /dev/null +++ b/appengine/helloworld-new-plugins/src/main/webapp/WEB-INF/appengine-web.xml @@ -0,0 +1,20 @@ + + + + + your-project-id + 1 + true + + diff --git a/appengine/helloworld-new-plugins/src/main/webapp/WEB-INF/web.xml b/appengine/helloworld-new-plugins/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..1a1704104a2 --- /dev/null +++ b/appengine/helloworld-new-plugins/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,14 @@ + + + + hello + com.example.appengine.helloworld.HelloServlet + + + hello + / + + diff --git a/pom.xml b/pom.xml index faaab723c76..5d383b8ded0 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,7 @@ appengine/firebase-event-proxy/gae-firebase-event-proxy appengine/guestbook-objectify appengine/helloworld + appengine/helloworld-new-plugins appengine/images appengine/logs appengine/mailgun From c2b02b721a15b5e32467526ca2511abf9442cdbc Mon Sep 17 00:00:00 2001 From: Les Vogel Date: Mon, 15 Aug 2016 15:09:43 -0700 Subject: [PATCH 2/2] Fixes for Tim --- appengine/helloworld-new-plugins/README.md | 8 ++++++-- appengine/helloworld-new-plugins/build.gradle | 3 ++- appengine/helloworld-new-plugins/pom.xml | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/appengine/helloworld-new-plugins/README.md b/appengine/helloworld-new-plugins/README.md index 80b1c6fcff7..fe76dd711f2 100644 --- a/appengine/helloworld-new-plugins/README.md +++ b/appengine/helloworld-new-plugins/README.md @@ -26,11 +26,15 @@ Use either: ## Gradle ### Running locally - $ ./gradlew appengineRun + $ gradle appengineRun + +If you do not have gradle installed, you can run using `./gradlew appengineRun`. ### Deploying - $ ./gradlew appengineDeploy + $ gradle appengineDeploy + +If you do not have gradle installed, you can deploy using `./gradlew appengineDeploy`.