8000 added gradle build configuration to appengine endpoints-frameworks-v2… · ruudhaya/java-docs-samples@ca74223 · GitHub
[go: up one dir, main page]

Skip to content

Commit ca74223

Browse files
committed
added gradle build configuration to appengine endpoints-frameworks-v2 backend
1 parent c90a83d commit ca74223

File tree

5 files changed

+397
-5
lines changed

5 files changed

+397
-5
lines changed

appengine/endpoints-frameworks-v2/backend/README.md

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
This sample demonstrates how to use Google Cloud Endpoints Frameworks using
44
Java on App Engine Standard.
55

6-
## Adding the project ID to the sample API code
6+
## Build with Maven
7+
8+
### Adding the project ID to the sample API code
79

810
You must add the project ID obtained when you created your project to the
911
sample's `pom.xml` before you can deploy the code.
@@ -21,19 +23,19 @@ your project ID.
2123

2224
0. Save your changes.
2325

24-
## Building the sample project
26+
### Building the sample project
2527

2628
To build the project:
2729

2830
mvn clean package
2931

30-
## Generating the openapi.json file
32+
### Generating the openapi.json file
3133

3234
To generate the required configuration file `openapi.json`:
3335

3436
mvn exec:java -DGetSwaggerDoc
3537

36-
## Deploying the sample API to App Engine
38+
### Deploying the sample API to App Engine
3739

3840
To deploy the sample API:
3941

@@ -51,7 +53,92 @@ To deploy the sample API:
5153

5254
0. Wait for the upload to finish.
5355

54-
## Sending a request to the sample API
56+
### Sending a request to the sample API
57+
58+
After you deploy the API and its configuration file, you can send requests
59+
to the API.
60+
61+
To send a request to the API, from a command line, invoke the following `cURL`
62+
command:
63+
64+
curl \
65+
-H "Content-Type: application/json" \
66+
-X POST \
67+
-d '{"message":"echo"}' \
68+
https://$PROJECT_ID.appspot.com/_ah/api/echo/v1/echo
69+
70+
You will get a 200 response with the following data:
71+
72+
{
73+
"message": "echo"
74+
}
75+
76+
## Build with gradle
77+
78+
### Adding the project ID to the sample API code
79+
80+
0. Edit the file `build.gradle`.
81+
82+
0. For `def projectId = 'YOUR_PROJECT_ID'`, replace the value `YOUR_PROJECT_ID` with
83+
your project ID.
84+
85+
0. Edit the file `src/main/java/com/example/echo/Echo.java
86+
87+
0. Replace the value `YOUR-PROJECT-ID` with your project ID.
88+
89+
0. Save your changes.
90+
9E88
91+
### Building the sample project
92+
93+
To build the project on unix-based systems:
94+
95+
./gradlew build
96+
97+
Note for windows user: Use `gradlew.bat` instead of `./gradlew`
98+
99+
<details>
100+
<summary>more details</summary>
101+
The project contains the standard java and war plugins and in addition to that it contains the following plugins:
102+
[endpoints-framework-gradle-plugin](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin "endpoints-framework-gradle-plugin") for the endpoint related tasks and
103+
[appengine-gradle-plugin](https://github.com/GoogleCloudPlatform/app-gradle-plugin "appengine-gradle-plugin") for the appengine standard related tasks.
104+
</details>
105+
106+
### Generating the openapi.json file
107+
108+
To generate the required configuration file `openapi.json`:
109+
110+
./gradlew endpointsOpenApiDocs
111+
112+
This results in a file in build/endpointsOpenApiDocs/openapi.json
113+
114+
### Deploying the sample API to App Engine
115+
116+
To deploy the sample API:
117+
118+
0. Invoke the `gcloud` command to deploy the API configuration file:
119+
120+
gcloud service-management deploy build/endpointsOpenApiDocs/openapi.json
121+
122+
0. Deploy the API implementation code by invoking:
123+
124+
./gradlew appengineDeploy
125+
126+
The first time you upload a sample app, you may be prompted to authorize the
127+
deployment. Follow the prompts: when you are presented with a browser window
128+
containing a code, copy it to the terminal window.
129+
130+
<details>
131+
<summary>ERROR: (gcloud.app.deploy) The current Google Cloud project [...] does not contain an App Engine application.</summary>
132+
If you create a fresh cloud project that doesn't contain a appengine application you may receive this Error:
133+
134+
ERROR: (gcloud.app.deploy) The current Google Cloud project [...] does not contain an App Engine application. Use `gcloud app create` to initialize an App Engine application within the project.
135+
136+
In that case just execute `gcloud app create`, you will be asked to select a region and the app will be created. Then run gradle appengineDeploy again.
137+
</details>
138+
139+
0. Wait for the upload to finish.
140+
141+
### Sending a request to the sample API
55142

56143
After you deploy the API and its configuration file, you can send requests
57144
to the API.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import org.apache.tools.ant.filters.ReplaceTokens
2+
3+
buildscript {
4+
repositories {
5+
mavenCentral()
6+
}
7+
8+
dependencies {
9+
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.0'
10+
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.2'
11+
}
12+
}
13+
14+
repositories {
15+
maven {
16+
url 'https://maven-central.storage.googleapis.com'
17+
}
18+
jcenter()
19+
mavenCentral()
20+
}
21+
22+
task wrapper(type: Wrapper) {
23+
gradleVersion = '3.5'
24+
}
25+
26+
def projectId = 'endpointstest2'
27+
28+
apply plugin: 'java'
29+
apply plugin: 'war'
30+
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
31+
apply plugin: 'com.google.cloud.tools.appengine'
32+
33+
dependencies {
34+
compile 'com.google.endpoints:endpoints-framework:2.0.7'
35+
compile 'com.google.endpoints:endpoints-management-control-appengine:1.0.3'
36+
compile 'com.google.endpoints:endpoints-framework-auth:1.0.3'
37+
}
38+
39+
endpointsServer {
40+
// Endpoints Framework Plugin server-side configuration
41+
hostname = "echo-api.endpoints.${projectId}.cloud.goog"
42+
}
43+
44+
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
45+
targetCompatibility = 1.7 // App Engine Standard uses Java 7
46+
47+
// this replaces the ${endpoints.project.id} in appengine-web.xml and web.xml
48+
task replaceProjectId(type: Copy) {
49+
from 'src/main/webapp/WEB-INF/'
50+
include '*.xml'
51+
into 'build/exploded-backend/WEB-INF'
52+
expand(endpoints:[project:[id:projectId]])
53+
filteringCharset = 'UTF-8'
54+
}
55+
assemble.dependsOn replaceProjectId
Binary file not shown.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/usr/bin/env bash
2+
3+
##############################################################################
4+
##
5+
## Gradle start up script for UN*X
6+
##
7+
##############################################################################
8+
9+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10+
DEFAULT_JVM_OPTS=""
11+
12+
APP_NAME="Gradle"
13+
APP_BASE_NAME=`basename "$0"`
14+
15+
# Use the maximum available, or set MAX_FD != -1 to use that value.
16+
MAX_FD="maximum"
17+
18+
warn ( ) {
19+
echo "$*"
20+
}
21+
22+
die ( ) {
23+
echo
24+
echo "$*"
25+
echo
26+
exit 1
27+
}
28+
29+
# OS specific support (must be 'true' or 'false').
30+
cygwin=false
31+
msys=false
32+
darwin=false
33+
case "`uname`" in
34+
CYGWIN* )
35+
cygwin=true
36+
;;
37+
Darwin* )
38+
darwin=true
39+
;;
40+
MINGW* )
41+
msys=true
42+
;;
43+
esac
44+
45+
# Attempt to set APP_HOME
46+
# Resolve links: $0 may be a link
47+
PRG="$0"
48+
# Need this for relative symlinks.
49+
while [ -h "$PRG" ] ; do
50+
ls=`ls -ld "$PRG"`
51+
link=`expr "$ls" : '.*-> \(.*\)$'`
52+
if expr "$link" : '/.*' > /dev/null; then
53+
PRG="$link"
54+
else
55+
PRG=`dirname "$PRG"`"/$link"
56+
fi
57+
done
58+
SAVED="`pwd`"
59+
cd "`dirname \"$PRG\"`/" >/dev/null
60+
APP_HOME="`pwd -P`"
61+
cd "$SAVED" >/dev/null
62+
63+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64+
65+
# Determine the Java command to use to start the JVM.
66+
if [ -n "$JAVA_HOME" ] ; then
67+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68+
# IBM's JDK on AIX uses strange locations for the executables
69+
JAVACMD="$JAVA_HOME/jre/sh/java"
70+
else
71+
JAVACMD="$JAVA_HOME/bin/java"
72+
fi
73+
if [ ! -x "$JAVACMD" ] ; then
74+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75+
76+
Please set the JAVA_HOME variable in your environment to match the
77+
location of your Java installation."
78+
fi
79+
else
80+
JAVACMD="java"
81+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82+
83+
Please set the JAVA_HOME variable in your environment to match the
84+
location of your Java installation."
< 10000 /td>
85+
fi
86+
87+
# Increase the maximum file descriptors if we can.
88+
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89+
MAX_FD_LIMIT=`ulimit -H -n`
90+
if [ $? -eq 0 ] ; then
91+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92+
MAX_FD="$MAX_FD_LIMIT"
93+
fi
94+
ulimit -n $MAX_FD
95+
if [ $? -ne 0 ] ; then
96+
warn "Could not set maximum file descriptor limit: $MAX_FD"
97+
fi
98+
else
99+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100+
fi
101+
fi
102+
103+
# For Darwin, add options to specify how the application appears in the dock
104+
if $darwin; then
105+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106+
fi
107+
108+
# For Cygwin, switch paths to Windows format before running java
109+
if $cygwin ; then
110+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112+
JAVACMD=`cygpath --unix "$JAVACMD"`
113+
114+
# We build the pattern for arguments to be converted via cygpath
115+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116+
SEP=""
117+
for dir in $ROOTDIRSRAW ; do
118+
ROOTDIRS="$ROOTDIRS$SEP$dir"
119+
SEP="|"
120+
done
121+
OURCYGPATTERN="(^($ROOTDIRS))"
122+
# Add a user-defined pattern to the cygpath arguments
123+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125+
fi
126+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
127+
i=0
128+
for arg in "$@" ; do
129+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131+
132+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134+
else
135+
eval `echo args$i`="\"$arg\""
136+
fi
137+
i=$((i+1))
138+
done
139+
case $i in
140+
(0) set -- ;;
141+
(1) set -- "$args0" ;;
142+
(2) set -- "$args0" "$args1" ;;
143+
(3) set -- "$args0" "$args1" "$args2" ;;
144+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150+
esac
151+
fi
152+
153+
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154+
function splitJvmOpts() {
155+
JVM_OPTS=("$@")
156+
}
157+
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158+
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159+
160+
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

0 commit comments

Comments
 (0)
0