Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass of many formatting fixes #820

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=false
indent_style=space
indent_size=2

[{*.gson,*.gradle,*.groovy,*.gant,*.gdsl,*.gy}]
indent_style=space
indent_size=4

[{*.xjsp,*.tag,*.jsf,*.jsp,*.jspf,*.tagf}]
indent_style=space
indent_size=4

[{*.yml,*.yaml}]
indent_style=space
indent_size=2

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.appengine.analytics;

import com.google.appengine.api.urlfetch.URLFetchService;
Expand All @@ -30,9 +31,9 @@
@SuppressWarnings("serial")
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
@WebServlet(
name = "analytics",
description = "Analytics: Send Analytics Event to Google Analytics",
urlPatterns = "/analytics"
name = "analytics",
description = "Analytics: Send Analytics Event to Google Analytics",
urlPatterns = "/analytics"
)
public class AnalyticsServlet extends HttpServlet {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
package com.example.appengine.appidentity;

import com.google.apphosting.api.ApiProxy;

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
@WebServlet(name = "appidentity", description = "AppIdentity: Get the Host Name",
urlPatterns = "/appidentity/identity")
@WebServlet(
name = "appidentity",
description = "AppIdentity: Get the Host Name",
urlPatterns = "/appidentity/identity"
)
public class IdentityServlet extends HttpServlet {

// [START versioned_hostnames]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.appengine.api.appidentity.AppIdentityService;
import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
import com.google.appengine.api.appidentity.PublicCertificate;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -35,17 +34,20 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
@WebServlet(name = "signforapp", description = "AppIdentity: Sign 'abcdefg'",
urlPatterns = "/appidentity/sign")
@WebServlet(
name = "signforapp",
description = "AppIdentity: Sign 'abcdefg'",
urlPatterns = "/appidentity/sign"
)
public class SignForAppServlet extends HttpServlet {

private final AppIdentityService appIdentity;

public SignForAppServlet() {
Expand Down Expand Up @@ -98,10 +100,7 @@ private String simulateIdentityAssertion()

return String.format(
"isValid=%b for message: %s\n\tsignature: %s\n\tpublic cert: %s",
isValid,
message,
Arrays.toString(blobSignature),
Arrays.toString(publicCert));
isValid, message, Arrays.toString(blobSignature), Arrays.toString(publicCert));
}
// [END asserting_identity_to_other_services]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@
import com.google.appengine.api.appidentity.AppIdentityService;
import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
import com.google.common.io.CharStreams;

import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import org.json.JSONObject;
import org.json.JSONTokener;

@SuppressWarnings("serial")
class UrlShortener {
// [START asserting_identity_to_Google_APIs]

/**
* Returns a shortened URL by calling the Google URL Shortener API.
*
Expand Down Expand Up @@ -68,11 +67,10 @@ public String createShortUrl(String longUrl) throws Exception {
} else {
try (InputStream s = connection.getErrorStream();
InputStreamReader r = new InputStreamReader(s, StandardCharsets.UTF_8)) {
throw new RuntimeException(String.format(
"got error (%d) response %s from %s",
connection.getResponseCode(),
CharStreams.toString(r),
connection.toString()));
throw new RuntimeException(
String.format(
"got error (%d) response %s from %s",
connection.getResponseCode(), CharStreams.toString(r), connection.toString()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
@WebServlet(name = "UrlShortener", description = "AppIdentity: Url Shortener",
urlPatterns = "/appidentity/shorten")
@WebServlet(
name = "UrlShortener",
description = "AppIdentity: Url Shortener",
urlPatterns = "/appidentity/shorten"
)
public class UrlShortenerServlet extends HttpServlet {

private final UrlShortener shortener;

public UrlShortenerServlet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import static org.mockito.Mockito.when;

import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -29,12 +32,6 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.io.PrintWriter;
import java.io.StringWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Unit tests for {@link IdentityServlet}.
*/
Expand All @@ -44,8 +41,10 @@ public class IdentityServletTest {
// Set up a helper so that the ApiProxy returns a valid environment for local testing.
private final LocalServiceTestHelper helper = new LocalServiceTestHelper();

@Mock private HttpServletRequest mockRequest;
@Mock private HttpServletResponse mockResponse;
@Mock
private HttpServletRequest mockRequest;
@Mock
private HttpServletResponse mockResponse;
private StringWriter responseWriter;
private IdentityServlet servletUnderTest;

Expand All @@ -61,7 +60,8 @@ public void setUp() throws Exception {
servletUnderTest = new IdentityServlet();
}

@After public void tearDown() {
@After
public void tearDown() {
helper.tearDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import static org.mockito.Mockito.when;

import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -29,12 +32,6 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.io.PrintWriter;
import java.io.StringWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Unit tests for {@link SignForAppServlet}.
*/
Expand All @@ -43,12 +40,15 @@ public class SignForAppServletTest {

private final LocalServiceTestHelper helper = new LocalServiceTestHelper();

@Mock private HttpServletRequest mockRequest;
@Mock private HttpServletResponse mockResponse;
@Mock
private HttpServletRequest mockRequest;
@Mock
private HttpServletResponse mockResponse;
private StringWriter responseWriter;
private SignForAppServlet servletUnderTest;

@Before public void setUp() throws Exception {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
helper.setUp();

Expand All @@ -59,11 +59,13 @@ public class SignForAppServletTest {
servletUnderTest = new SignForAppServlet();
}

@After public void tearDown() {
@After
public void tearDown() {
helper.tearDown();
}

@Test public void doGet_defaultEnvironment_successfullyVerifiesSignature() throws Exception {
@Test
public void doGet_defaultEnvironment_successfullyVerifiesSignature() throws Exception {
servletUnderTest.doGet(mockRequest, mockResponse);

assertThat(responseWriter.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.example.bigtable;

import java.io.IOException;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -28,12 +29,11 @@
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
// [START example]

/**
* A minimal application that connects to Cloud Bigtable using the native HBase API
* and performs some basic operations.
* A minimal application that connects to Cloud Bigtable using the native HBase API and performs
* some basic operations.
*/
public class BigtableHelloWorld {

Expand All @@ -43,13 +43,18 @@ public class BigtableHelloWorld {
private static final byte[] COLUMN_NAME = Bytes.toBytes("greeting");

// Write some friendly greetings to Cloud Bigtable
private static final String[] GREETINGS =
{ "Hello World!", "Hello Cloud Bigtable!", "Hello HBase!" };

private static final String[] GREETINGS = {
"Hello World!", "Hello Cloud Bigtable!", "Hello HBase!"
};

/**
* Create a table -- first time only.
* @param connection to Bigtable
* @return the status
*/
public static String create(Connection connection) {
try {
// The admin API lets us create, manage and delete tables
// The admin API lets us create, manage and delete tables
Admin admin = connection.getAdmin();
// [END connecting_to_bigtable]

Expand All @@ -66,9 +71,7 @@ public static String create(Connection connection) {
return "Create table " + Bytes.toString(TABLE_NAME);
}

/**
* Connects to Cloud Bigtable, runs some basic operations and prints the results.
*/
/** Connects to Cloud Bigtable, runs some basic operations and prints the results. */
public static String doHelloWorld() {

StringBuilder result = new StringBuilder();
Expand Down Expand Up @@ -141,7 +144,5 @@ public static String doHelloWorld() {

return result.toString();
}


}
// [END example]
Loading