diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 36775c57a56..00000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "java-repo-tools"] - path = java-repo-tools - url = https://github.com/GoogleCloudPlatform/java-repo-tools.git diff --git a/google-checks.xml b/google-checks.xml new file mode 100644 index 00000000000..e567fc7f8d3 --- /dev/null +++ b/google-checks.xml @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java-repo-tools b/java-repo-tools deleted file mode 160000 index 5c9a3169e1e..00000000000 --- a/java-repo-tools +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5c9a3169e1ee8fd471c0fd7501b50e1b2bc16773 diff --git a/managed_vms/async-rest/pom.xml b/managed_vms/async-rest/pom.xml index 031efade3e6..25d44b5775f 100644 --- a/managed_vms/async-rest/pom.xml +++ b/managed_vms/async-rest/pom.xml @@ -4,14 +4,7 @@ managed-vms-async-rest 1.0.0-SNAPSHOT war - - - doc-samples - com.google.cloud - 1.0.0 - ../.. - - + Example Async Rest Webapp YOUR_PLACES_APP_KEY 9.3.7.v20160115 @@ -33,24 +26,25 @@ ${jetty.version} - + com.google.appengine.demos.asyncrest.appKey ${places.appkey} - + com.google.appengine gcloud-maven-plugin - 2.0.9.95.v20160203 + 2.0.9.96.v20160203 - debug - debug - false - remote + /usr/local/google-cloud-sdk + debug + debug + false + remote - + org.apache.maven.plugins maven-war-plugin diff --git a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java index 6d0541adceb..87012af49cd 100644 --- a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java +++ b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java @@ -1,19 +1,3 @@ -/* - * 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. - */ - package com.google.appengine.demos; import java.io.IOException; @@ -29,8 +13,9 @@ public class DumpServlet extends HttpServlet { @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); @@ -43,42 +28,19 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) out.printf("getServletContextName=%s%n", getServletContext().getServletContextName()); out.printf("virtualServerName=%s%n", getServletContext().getVirtualServerName()); out.printf("contextPath=%s%n", getServletContext().getContextPath()); - out.printf( - "version=%d.%d%n", - getServletContext().getMajorVersion(), - getServletContext().getMinorVersion()); - out.printf( - "effectiveVersion=%d.%d%n", - getServletContext().getEffectiveMajorVersion(), - getServletContext().getEffectiveMinorVersion()); + out.printf("version=%d.%d%n", getServletContext().getMajorVersion(), getServletContext().getMinorVersion()); + out.printf("effectiveVersion=%d.%d%n", getServletContext().getEffectiveMajorVersion(), getServletContext().getEffectiveMinorVersion()); out.println(""); out.println("

Request Fields:

"); out.println("
");
-    out.printf(
-        "remoteHost/Addr:port=%s/%s:%d%n",
-        request.getRemoteHost(),
-        request.getRemoteAddr(),
-        request.getRemotePort());
-    out.printf(
-        "localName/Addr:port=%s/%s:%d%n",
-        request.getLocalName(),
-        request.getLocalAddr(),
-        request.getLocalPort());
-    out.printf(
-        "scheme=%s method=%s protocol=%s%n",
-        request.getScheme(),
-        request.getMethod(),
-        request.getProtocol());
+    out.printf("remoteHost/Addr:port=%s/%s:%d%n", request.getRemoteHost(), request.getRemoteAddr(), request.getRemotePort());
+    out.printf("localName/Addr:port=%s/%s:%d%n", request.getLocalName(), request.getLocalAddr(), request.getLocalPort());
+    out.printf("scheme=%s method=%s protocol=%s%n", request.getScheme(), request.getMethod(), request.getProtocol());
     out.printf("serverName:serverPort=%s:%d%n", request.getServerName(), request.getServerPort());
     out.printf("requestURI=%s%n", request.getRequestURI());
     out.printf("requestURL=%s%n", request.getRequestURL().toString());
-    out.printf(
-        "contextPath|servletPath|pathInfo=%s|%s|%s%n",
-        request.getContextPath(),
-        request.getServletPath(),
-        request.getPathInfo());
-    out.printf(
-        "session/new=%s/%b%n", request.getSession(true).getId(), request.getSession().isNew());
+    out.printf("contextPath|servletPath|pathInfo=%s|%s|%s%n", request.getContextPath(), request.getServletPath(), request.getPathInfo());
+    out.printf("session/new=%s/%b%n", request.getSession(true).getId(), request.getSession().isNew());
     out.println("
"); out.println("

Request Headers:

"); out.println("
");
diff --git a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AbstractRestServlet.java b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AbstractRestServlet.java
index 51a3e49b096..07956c2dc3d 100644
--- a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AbstractRestServlet.java
+++ b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AbstractRestServlet.java
@@ -1,19 +1,3 @@
-/*
- * 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.
- */
-
 package com.google.appengine.demos.asyncrest;
 
 import java.io.IOException;
@@ -32,31 +16,32 @@
 import javax.servlet.http.HttpServletResponse;
 
 /**
- * Abstract base class for REST servlets.
+ * AbstractRestServlet.
+ *
  */
 public class AbstractRestServlet extends HttpServlet {
 
-  protected static final int MAX_RESULTS = 5;
+  protected final static int MAX_RESULTS = 5;
 
-  protected static final String STYLE = "";
 
-  protected static final String APPKEY = "com.google.appengine.demos.asyncrest.appKey";
-  protected static final String APPKEY_ENV = "PLACES_APPKEY";
-  protected static final String LOC_PARAM = "loc";
-  protected static final String ITEMS_PARAM = "items";
-  protected static final String LATITUDE_PARAM = "lat";
-  protected static final String LONGITUDE_PARAM = "long";
-  protected static final String RADIUS_PARAM = "radius";
+  protected final static String APPKEY = "com.google.appengine.demos.asyncrest.appKey";
+  protected final static String APPKEY_ENV = "PLACES_APPKEY";
+  protected final static String LOC_PARAM = "loc";
+  protected final static String ITEMS_PARAM = "items";
+  protected final static String LATITUDE_PARAM = "lat";
+  protected final static String LONGITUDE_PARAM = "long";
+  protected final static String RADIUS_PARAM = "radius";
   protected String key;
 
   @Override
   public void init(ServletConfig servletConfig) throws ServletException {
-    // First try the servlet context init-param.
+    //first try the servlet context init-param
     String source = "InitParameter";
     key = servletConfig.getInitParameter(APPKEY);
     if (key == null || key.startsWith("${")) {
@@ -75,19 +60,18 @@ public void init(ServletConfig servletConfig) throws ServletException {
     }
   }
 
-  public static String sanitize(String str) {
-    if (str == null) {
+  public static String sanitize(String s) {
+    if (s == null) {
       return null;
     }
-    return str.replace("<", "?").replace("&", "?").replace("\n", "?");
+    return s.replace("<", "?").replace("&", "?").replace("\n", "?");
   }
 
   protected String restQuery(String coordinates, String radius, String item) {
     try {
-      return "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=" + key
-          + "&location=" + URLEncoder.encode(coordinates, "UTF-8")
-          + "&types=" + URLEncoder.encode(item, "UTF-8")
-          + "&radius=" + URLEncoder.encode(radius, "UTF-8");
+      return "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=" + key + "&location="
+              + URLEncoder.encode(coordinates, "UTF-8") + "&types=" + URLEncoder.encode(item, "UTF-8")
+              + "&radius=" + URLEncoder.encode(radius, "UTF-8");
 
     } catch (Exception e) {
       throw new RuntimeException(e);
@@ -100,22 +84,21 @@ public String generateResults(Queue> results) {
     Iterator> itor = results.iterator();
 
     while (resultCount < MAX_RESULTS && itor.hasNext()) {
-      Map map = (Map) itor.next();
-      String name = (String) map.get("name");
-      Object[] photos = (Object[]) map.get("photos");
+      Map m = (Map) itor.next();
+      String name = (String) m.get("name");
+      Object[] photos = (Object[]) m.get("photos");
       if (photos != null && photos.length > 0) {
         resultCount++;
-        thumbs.append(
-            "");
+        thumbs.append("");
         thumbs.append(" ");
       }
     }
     return thumbs.toString();
   }
 
-  public String getPhotoUrl(String photoref) {
+  public String getPhotoURL(String photoref) {
     return "https://maps.googleapis.com/maps/api/place/photo?key=" + key + "&photoreference=" + photoref
             + "&maxheight=40";
   }
@@ -126,11 +109,11 @@ protected String ms(long nano) {
   }
 
   protected int width(long nano) {
-    int width = (int) ((nano + 999999L) / 5000000L);
-    if (width == 0) {
-      width = 2;
+    int w = (int) ((nano + 999999L) / 5000000L);
+    if (w == 0) {
+      w = 2;
     }
-    return width;
+    return w;
   }
 
   @Override
diff --git a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AsyncRestServlet.java b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AsyncRestServlet.java
index 571752ea08d..0bee71ec433 100644
--- a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AsyncRestServlet.java
+++ b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AsyncRestServlet.java
@@ -1,30 +1,5 @@
-/*
- * 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.
- */
-
 package com.google.appengine.demos.asyncrest;
 
-import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.client.api.Response;
-import org.eclipse.jetty.client.api.Result;
-import org.eclipse.jetty.http.HttpMethod;
-import org.eclipse.jetty.util.BufferUtil;
-import org.eclipse.jetty.util.Utf8StringBuilder;
-import org.eclipse.jetty.util.ajax.JSON;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.nio.ByteBuffer;
@@ -39,10 +14,17 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.api.Response;
+import org.eclipse.jetty.client.api.Result;
+import org.eclipse.jetty.http.HttpMethod;
+import org.eclipse.jetty.util.BufferUtil;
+import org.eclipse.jetty.util.Utf8StringBuilder;
+import org.eclipse.jetty.util.ajax.JSON;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
 /**
- * Servlet which makes REST calls asynchronously.
- *
- * 

May be configured with init parameters: + * AsyncRestServlet. May be configured with init parameters: *

*
appid
*
The Google app key to use
@@ -51,9 +33,9 @@ */ public class AsyncRestServlet extends AbstractRestServlet { - static final String RESULTS_ATTR = "com.google.appengine.demos.asyncrest.client"; - static final String DURATION_ATTR = "com.google.appengine.demos.asyncrest.duration"; - static final String START_ATTR = "com.google.appengine.demos.asyncrest.start"; + final static String RESULTS_ATTR = "com.google.appengine.demos.asyncrest.client"; + final static String DURATION_ATTR = "com.google.appengine.demos.asyncrest.duration"; + final static String START_ATTR = "com.google.appengine.demos.asyncrest.start"; HttpClient client; @@ -82,22 +64,22 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) Long start = System.nanoTime(); // Do we have results yet? - Queue> results = - (Queue>) request.getAttribute(RESULTS_ATTR); + Queue> results = (Queue>) request.getAttribute(RESULTS_ATTR); - // If no results, this must be the first dispatch, so send the REST request(s). + // If no results, this must be the first dispatch, so send the REST + // request(s) if (results == null) { // define results data structures final Queue> resultsQueue = new ConcurrentLinkedQueue<>(); request.setAttribute(RESULTS_ATTR, results = resultsQueue); - // Suspend the request. + // suspend the request // This is done before scheduling async handling to avoid race of // dispatch before startAsync! final AsyncContext async = request.startAsync(); async.setTimeout(30000); - // Extract keywords to search for. + // extract keywords to search for String lat = sanitize(request.getParameter(LATITUDE_PARAM)); String longitude = sanitize(request.getParameter(LONGITUDE_PARAM)); String radius = sanitize(request.getParameter(RADIUS_PARAM)); @@ -105,19 +87,17 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) final AtomicInteger outstanding = new AtomicInteger(keywords.length); - // Send request each keyword. + // Send request each keyword for (final String item : keywords) { - client.newRequest(restQuery(lat + "," + longitude, radius, item)) - .method(HttpMethod.GET) - .send( - new AsyncRestRequest() { + client.newRequest(restQuery(lat + "," + longitude, radius, item)).method(HttpMethod.GET) + .send(new AsyncRestRequest() { @Override void onLocationFound(Map result) { resultsQueue.add(result); } @Override - void doComplete() { + void onComplete() { if (outstanding.decrementAndGet() <= 0) { async.dispatch(); } @@ -151,28 +131,20 @@ void doComplete() { long thread = initial + generate; String loc = sanitize(request.getParameter(LOC_PARAM)); - out.print( - "Asynchronous: Requesting " + sanitize(request.getParameter(ITEMS_PARAM)) + " near " + out.print("Asynchronous: Requesting " + sanitize(request.getParameter(ITEMS_PARAM)) + " near " + (loc != null ? loc : "lat=" + sanitize(request.getParameter(LATITUDE_PARAM)) + " long=" + sanitize(request.getParameter(LONGITUDE_PARAM))) + "
"); out.print("Total Time: " + ms(total) + "ms
"); - out.print( - "Thread held (red): " - + ms(thread) + "ms (" + ms(initial) - + " initial + " + ms(generate) + " generate )
"); + out.print("Thread held (red): " + ms(thread) + "ms (" + ms(initial) + " initial + " + + ms(generate) + " generate )
"); out.print("Async wait (green): " + ms(total - thread) + "ms
"); - out.println( - "" - + "" - + ""); + out.println("" + + "" + + ""); out.println("
"); out.print("First 5 results of " + results.size() + ":
"); @@ -189,7 +161,7 @@ void doComplete() { private abstract class AsyncRestRequest extends Response.Listener.Adapter { - final Utf8StringBuilder utf8Content = new Utf8StringBuilder(); + final Utf8StringBuilder _content = new Utf8StringBuilder(); AsyncRestRequest() { } @@ -197,13 +169,13 @@ private abstract class AsyncRestRequest extends Response.Listener.Adapter { @Override public void onContent(Response response, ByteBuffer content) { byte[] bytes = BufferUtil.toArray(content); - utf8Content.append(bytes, 0, bytes.length); + _content.append(bytes, 0, bytes.length); } @Override public void onComplete(Result result) { - // Extract results. - Map data = (Map) JSON.parse(utf8Content.toString()); + // extract results + Map data = (Map) JSON.parse(_content.toString()); if (data != null) { Object[] results = (Object[]) data.get("results"); if (results != null) { @@ -212,13 +184,13 @@ public void onComplete(Result result) { } } } - doComplete(); + onComplete(); } abstract void onLocationFound(Map details); - abstract void doComplete(); + abstract void onComplete(); } diff --git a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/SerialRestServlet.java b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/SerialRestServlet.java index 19d3bed254b..359fd1f3ec1 100644 --- a/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/SerialRestServlet.java +++ b/managed_vms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/SerialRestServlet.java @@ -1,23 +1,5 @@ -/* - * 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. - */ - package com.google.appengine.demos.asyncrest; -import org.eclipse.jetty.util.ajax.JSON; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -29,13 +11,16 @@ import java.util.Queue; import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jetty.util.ajax.JSON; + /** - * Servlet which makes REST calls serially. + * SerialRestServlet * - *

May be configured with init parameters: + * May be configured with init parameters: *

*
appid
*
The Google app key to use
@@ -44,8 +29,7 @@ public class SerialRestServlet extends AbstractRestServlet { @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (key == null) { response.sendError(500, APPKEY + " not set"); return; @@ -60,28 +44,26 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) String[] keywords = sanitize(request.getParameter(ITEMS_PARAM)).split(","); Queue> results = new LinkedList>(); - // Make all requests serially. + // make all requests serially for (String itemName : keywords) { URL url = new URL(restQuery(lat + "," + longitude, radius, itemName)); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); - BufferedReader reader = - new BufferedReader(new InputStreamReader(connection.getInputStream())); + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - Map query = - (Map) JSON.parse(new BufferedReader(new InputStreamReader(connection.getInputStream()))); + Map query = (Map) JSON.parse(new BufferedReader(new InputStreamReader(connection.getInputStream()))); Object[] tmp = (Object[]) query.get("results"); if (tmp != null) { for (Object o : tmp) { - Map map = (Map) o; - results.add(map); + Map m = (Map) o; + results.add(m); } } } - // Generate the response. + // Generate the response String thumbs = generateResults(results); response.setContentType("text/html"); @@ -93,19 +75,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) long now = System.nanoTime(); long total = now - start; - out.print( - "Blocking: Requesting " - + sanitize(request.getParameter(ITEMS_PARAM)) - + " near " - + (loc != null ? loc : "lat=" + lat + " long=" + longitude) - + "
"); + out.print("Blocking: Requesting " + sanitize(request.getParameter(ITEMS_PARAM)) + " near " + (loc != null ? loc : "lat=" + lat + " long=" + longitude) + "
"); out.print("Total Time: " + ms(total) + "ms
"); out.print("Thread held (red): " + ms(total) + "ms
"); - out.println( - ""); + out.println(""); out.println("
"); out.print("First 5 results of " + results.size() + ":
"); @@ -120,13 +94,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) } /** - * Handle HTTP POST request. - * - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse + * response) */ @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } diff --git a/pom.xml b/pom.xml index ee71ff00948..9bc94b812dd 100644 --- a/pom.xml +++ b/pom.xml @@ -8,17 +8,10 @@ doc-samples pom - - - com.google.cloud - shared-configuration - 1.0.0 - java-repo-tools - - 1.9.32 1 + UTF-8 1.19.0 1.19.0 1.7 @@ -59,6 +52,52 @@ unittests + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + google-checks.xml + true + true + true + + + check + + + + org.eluder.coveralls + coveralls-maven-plugin + 3.1.0 + + + ${basedir}/target/coverage.xml + + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.6 + + ${basedir}/target + + xml + html + + xml + 256m + + true + + + + + +