From 7f57b5b89c568ac1521921eba9e86321a2a5c4b0 Mon Sep 17 00:00:00 2001 From: Les Vogel Date: Wed, 31 Aug 2016 15:15:54 -0700 Subject: [PATCH 1/3] update hello world for new gradle & maven plugins --- managed_vms/helloworld/README.md | 36 +++- managed_vms/helloworld/build.gradle | 69 +++++++ .../gradle/wrapper/gradle-wrapper.properties | 6 + managed_vms/helloworld/gradlew | 169 ++++++++++++++++++ managed_vms/helloworld/gradlew.bat | 84 +++++++++ managed_vms/helloworld/pom.xml | 23 +-- .../helloworld/HelloServlet.java | 4 +- 7 files changed, 373 insertions(+), 18 deletions(-) create mode 100644 managed_vms/helloworld/build.gradle create mode 100644 managed_vms/helloworld/gradle/wrapper/gradle-wrapper.properties create mode 100755 managed_vms/helloworld/gradlew create mode 100644 managed_vms/helloworld/gradlew.bat rename managed_vms/helloworld/src/main/java/com/example/{managedvms => flexible}/helloworld/HelloServlet.java (92%) diff --git a/managed_vms/helloworld/README.md b/managed_vms/helloworld/README.md index 2f3da6f4144..c80bb2e51f6 100644 --- a/managed_vms/helloworld/README.md +++ b/managed_vms/helloworld/README.md @@ -1,8 +1,32 @@ -# Appengine Helloworld sample for Google App Engine -This sample demonstrates how to deploy an application on Google App Engine +# Appengine Helloworld sample for Google App Engine Flexible -## Running locally - $ mvn jetty:run +This sample is used as part of the [Quickstart for Java in the App Engine Flexible Environment](https://cloud.google.com/java/getting-started/hello-world) -## Deploying - $ mvn gcloud:deploy +## Setup + +Use either: + +* `gcloud init` +* `gcloud beta auth application-default login` + +## Maven +### Running locally + + $ mvn clean jetty:run-exploded + +### Deploying + + $ mvn appengine:deploy + +## Gradle +### Running locally + + $ gradle jettyRun + +If you do not have gradle installed, you can run using `./gradlew appengineRun`. + +### Deploying + + $ gradle appengineDeploy + +If you do not have gradle installed, you can deploy using `./gradlew appengineDeploy`. diff --git a/managed_vms/helloworld/build.gradle b/managed_vms/helloworld/build.gradle new file mode 100644 index 00000000000..484eaa30b9b --- /dev/null +++ b/managed_vms/helloworld/build.gradle @@ -0,0 +1,69 @@ +// Copyright 2016 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. +// [START gradle] +buildscript { // Configuration for building + repositories { + jcenter() // Bintray's repository - a fast Maven Central mirror & more + mavenCentral() + } + dependencies { + classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' + classpath 'org.akhikhl.gretty:gretty:+' + } +} + +repositories { // repositories for Jar's you access in your code + jcenter() + mavenCentral() +} + +apply plugin: 'java' +apply plugin: 'war' +apply plugin: 'org.akhikhl.gretty' +apply plugin: 'com.google.cloud.tools.appengine' + +dependencies { + providedCompile 'javax.servlet:javax.servlet-api:3.1.0' + providedCompile 'com.google.appengine:appengine:+' +// Add your dependencies here. + +} + +// [START gretty] +gretty { + port = 8080 + contextPath = '/' + servletContainer = 'jetty9' // What App Engine Flexible uses +} +// [END gretty] + +// [START model] +model { + appengine { + + deploy { // deploy configuration + stopPreviousVersion = true // default - stop the current version + promote = true // default - & make this the current version + } + + } +} +// [END model] + +group = 'com.example.appengine' // Generated output GroupId +version = '1.0-SNAPSHOT' // Version in generated output + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 +// [END gradle] diff --git a/managed_vms/helloworld/gradle/wrapper/gradle-wrapper.properties b/managed_vms/helloworld/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..a9616415a55 --- /dev/null +++ b/managed_vms/helloworld/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Aug 31 15:14:13 PDT 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip diff --git a/managed_vms/helloworld/gradlew b/managed_vms/helloworld/gradlew new file mode 100755 index 00000000000..9aa616c273d --- /dev/null +++ b/managed_vms/helloworld/gradlew @@ -0,0 +1,169 @@ +#!/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" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/managed_vms/helloworld/gradlew.bat b/managed_vms/helloworld/gradlew.bat new file mode 100644 index 00000000000..e95643d6a2c --- /dev/null +++ b/managed_vms/helloworld/gradlew.bat @@ -0,0 +1,84 @@ +@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 + +: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=%* + +: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/managed_vms/helloworld/pom.xml b/managed_vms/helloworld/pom.xml index 43f0ce18a1c..aa8ef5943e7 100644 --- a/managed_vms/helloworld/pom.xml +++ b/managed_vms/helloworld/pom.xml @@ -31,12 +31,14 @@ 1.7 1.7 2.6 - 2.0.9.106.v20160420 + 0.1.1-beta 9.3.7.v20160115 + false + javax.servlet javax.servlet-api @@ -44,6 +46,7 @@ jar provided + @@ -51,24 +54,24 @@ ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + - com.google.appengine - gcloud-maven-plugin - ${gcloud-maven-plugin-version} - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin-version} + com.google.cloud.tools + appengine-maven-plugin + ${appengine.maven.plugin} - false + + true + true + org.eclipse.jetty jetty-maven-plugin ${jetty-maven-plugin-version} + diff --git a/managed_vms/helloworld/src/main/java/com/example/managedvms/helloworld/HelloServlet.java b/managed_vms/helloworld/src/main/java/com/example/flexible/helloworld/HelloServlet.java similarity index 92% rename from managed_vms/helloworld/src/main/java/com/example/managedvms/helloworld/HelloServlet.java rename to managed_vms/helloworld/src/main/java/com/example/flexible/helloworld/HelloServlet.java index 7f08b47e2b0..b332fdf88c1 100644 --- a/managed_vms/helloworld/src/main/java/com/example/managedvms/helloworld/HelloServlet.java +++ b/managed_vms/helloworld/src/main/java/com/example/flexible/helloworld/HelloServlet.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.managedvms.helloworld; +package com.example.flexible.helloworld; import java.io.IOException; import java.io.PrintWriter; @@ -32,7 +32,7 @@ public class HelloServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { PrintWriter out = resp.getWriter(); - out.println("Hello, world"); + out.println("Hello, world - App Engine Flexible"); } } // [END example] From a2d2e1b02bf28b25db256e7e7aea1201df62a71a Mon Sep 17 00:00:00 2001 From: Les Vogel Date: Wed, 31 Aug 2016 15:45:54 -0700 Subject: [PATCH 2/3] Tweak a few things... 1. add license & tags to app.yaml 2. fix some versions and naming in the pom.xml 3. add tags to pom.xml 4. remove a blank line from build.gradle --- managed_vms/helloworld/build.gradle | 1 - managed_vms/helloworld/pom.xml | 13 ++++++++----- .../helloworld/src/main/appengine/app.yaml | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/managed_vms/helloworld/build.gradle b/managed_vms/helloworld/build.gradle index 484eaa30b9b..d0651329753 100644 --- a/managed_vms/helloworld/build.gradle +++ b/managed_vms/helloworld/build.gradle @@ -56,7 +56,6 @@ model { stopPreviousVersion = true // default - stop the current version promote = true // default - & make this the current version } - } } // [END model] diff --git a/managed_vms/helloworld/pom.xml b/managed_vms/helloworld/pom.xml index aa8ef5943e7..31c366ccc02 100644 --- a/managed_vms/helloworld/pom.xml +++ b/managed_vms/helloworld/pom.xml @@ -13,12 +13,13 @@ See the License for the specific language governing permissions and limitations under the License. --> + 4.0.0 war 1.0-SNAPSHOT - com.example.managedvms - managed-vms-helloworld + com.example.flexible + flexible-helloworld doc-samples @@ -28,11 +29,12 @@ - 1.7 - 1.7 - 2.6 + 1.8 + 1.8 + 0.1.1-beta 9.3.7.v20160115 + false @@ -75,3 +77,4 @@ + diff --git a/managed_vms/helloworld/src/main/appengine/app.yaml b/managed_vms/helloworld/src/main/appengine/app.yaml index 2a659160df5..b37fa66a82e 100644 --- a/managed_vms/helloworld/src/main/appengine/app.yaml +++ b/managed_vms/helloworld/src/main/appengine/app.yaml @@ -1,3 +1,17 @@ +# Copyright 2016 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. +# [START appyaml] runtime: java vm: true @@ -5,3 +19,4 @@ handlers: - url: /.* script: this field is required, but ignored secure: always +# [END appyaml] From 5c9305fd1119c5cb8cd4c27a0fbe5414e0f09747 Mon Sep 17 00:00:00 2001 From: Les Vogel Date: Wed, 31 Aug 2016 16:02:46 -0700 Subject: [PATCH 3/3] Shutdown new plugin tests for now. --- travis.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/travis.sh b/travis.sh index a97ba058289..3abd7936047 100755 --- a/travis.sh +++ b/travis.sh @@ -40,13 +40,13 @@ for testdir in "${devserver_tests[@]}" ; do ./java-repo-tools/scripts/test-localhost.sh appengine "${testdir}" done -newplugin_std_tests=( -# appengine/helloworld-new-plugins -) -for testdir in "${newplugin_std_tests[@]}" ; do - ./java-repo-tools/scripts/test-localhost.sh standard_mvn "${testdir}" - ./java-repo-tools/scripts/test-localhost.sh standard_gradle "${testdir}" -done +# newplugin_std_tests=( +# appengine/helloworld-new-plugins +# ) +# for testdir in "${newplugin_std_tests[@]}" ; do +# ./java-repo-tools/scripts/test-localhost.sh standard_mvn "${testdir}" +# ./java-repo-tools/scripts/test-localhost.sh standard_gradle "${testdir}" +# done # Check that all shell scripts in this repo (including this one) pass the