Merge branch 'stable-2.15'
* stable-2.15:
Format Java files with google-java-format 1.6
Change-Id: I03b9e1d0d78b56dc000273af7830bd482468adf4
diff --git a/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java b/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java
index 6b9e2c0..5911074 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java
@@ -23,12 +23,10 @@
import com.google.gwtexpui.server.CacheHeaders;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
-
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
@@ -39,38 +37,39 @@
@Singleton
public class GoImportFilter extends AllRequestFilter {
- private static final String PAGE_404 = "<!DOCTYPE html>\n"
- + "<html>\n"
- + "<head>\n"
- + " <title>Gerrit-Go-Import</title>\n"
- + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
- + "</head>\n"
- + "<body>\n"
- + "NOT FOUND\n"
- + "</body>\n"
- + "</html>";
+ private static final String PAGE_404 =
+ "<!DOCTYPE html>\n"
+ + "<html>\n"
+ + "<head>\n"
+ + " <title>Gerrit-Go-Import</title>\n"
+ + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
+ + "</head>\n"
+ + "<body>\n"
+ + "NOT FOUND\n"
+ + "</body>\n"
+ + "</html>";
- private static final String PAGE_200 = "<!DOCTYPE html>\n"
- + "<html>\n"
- + "<head>\n"
- + " <title>Gerrit-Go-Import</title>\n"
- + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
- + " <meta name=\"go-import\" content=\"${content}\"/>\n"
- + "</head>\n"
- + "<body>\n"
- + "<div>\n"
- + " Gerrit-Go-Import\n"
- + "</div>\n"
- + "</body>\n"
- + "</html>";
+ private static final String PAGE_200 =
+ "<!DOCTYPE html>\n"
+ + "<html>\n"
+ + "<head>\n"
+ + " <title>Gerrit-Go-Import</title>\n"
+ + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
+ + " <meta name=\"go-import\" content=\"${content}\"/>\n"
+ + "</head>\n"
+ + "<body>\n"
+ + "<div>\n"
+ + " Gerrit-Go-Import\n"
+ + "</div>\n"
+ + "</body>\n"
+ + "</html>";
private final ProjectCache projectCache;
final String webUrl;
final String projectPrefix;
@Inject
- GoImportFilter(ProjectCache projectCache,
- @CanonicalWebUrl String webUrl)
+ GoImportFilter(ProjectCache projectCache, @CanonicalWebUrl String webUrl)
throws URISyntaxException {
this.projectCache = projectCache;
this.webUrl = webUrl.replaceFirst("/?$", "/");
@@ -79,13 +78,12 @@
private String generateProjectPrefix() throws URISyntaxException {
URI uri = new URI(webUrl);
- return uri.getHost() + (uri.getPort() == -1 ? "" : ":" + uri.getPort())
- + uri.getPath();
+ return uri.getHost() + (uri.getPort() == -1 ? "" : ":" + uri.getPort()) + uri.getPath();
}
@Override
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws IOException, ServletException {
if (request instanceof HttpServletRequest) {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse rsp = (HttpServletResponse) response;
@@ -110,12 +108,12 @@
byte[] tosend = PAGE_404.getBytes();
rsp.setStatus(404);
// Start with the longest-length project name first.
- for( int length = pathParts.length; length > 0; length-- ) {
+ for (int length = pathParts.length; length > 0; length--) {
// Create a new project name of the specified length; each time that we
// go through this loop, the project name will become shorter and shorter.
projectName = "";
- for( int i = 0; i < length; i++ ) {
- if( i > 0 ) {
+ for (int i = 0; i < length; i++) {
+ if (i > 0) {
projectName += "/";
}
projectName += pathParts[i];
@@ -140,7 +138,6 @@
} else {
chain.doFilter(request, response);
}
-
}
private String getProjectName(String servletPath) {
@@ -148,7 +145,7 @@
}
private CharSequence getContent(String projectName) {
- return projectPrefix + projectName + " git " + webUrl + "a/" + projectName;
+ return projectPrefix + projectName + " git " + webUrl + "a/" + projectName;
}
private boolean projectExists(String projectName) {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/goimport/HttpModule.java b/src/main/java/com/ericsson/gerrit/plugins/goimport/HttpModule.java
index fe5114e..f9d3240 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/goimport/HttpModule.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/goimport/HttpModule.java
@@ -22,7 +22,6 @@
class HttpModule extends ServletModule {
@Override
protected void configureServlets() {
- DynamicSet.bind(binder(), AllRequestFilter.class).to(GoImportFilter.class)
- .in(Scopes.SINGLETON);
+ DynamicSet.bind(binder(), AllRequestFilter.class).to(GoImportFilter.class).in(Scopes.SINGLETON);
}
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java b/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java
index b2a015c..6f1a582 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java
@@ -18,58 +18,49 @@
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;
-import com.ericsson.gerrit.plugins.goimport.GoImportFilter;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
-
+import java.io.IOException;
+import java.net.URISyntaxException;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
@RunWith(MockitoJUnitRunner.class)
public class GoImportFilterTest {
private static final String PROD_URL = "https://gerrit-review.googlesource.com";
- private static final String PAGE_200 = "<!DOCTYPE html>\n"
- + "<html>\n"
- + "<head>\n"
- + " <title>Gerrit-Go-Import</title>\n"
- + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
- + " <meta name=\"go-import\" content=\"gerrit-review.googlesource.com/projectName git https://gerrit-review.googlesource.com/a/projectName\"/>\n"
- + "</head>\n"
- + "<body>\n"
- + "<div>\n"
- + " Gerrit-Go-Import\n"
- + "</div>\n"
- + "</body>\n"
- + "</html>";
+ private static final String PAGE_200 =
+ "<!DOCTYPE html>\n"
+ + "<html>\n"
+ + "<head>\n"
+ + " <title>Gerrit-Go-Import</title>\n"
+ + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
+ + " <meta name=\"go-import\" content=\"gerrit-review.googlesource.com/projectName git https://gerrit-review.googlesource.com/a/projectName\"/>\n"
+ + "</head>\n"
+ + "<body>\n"
+ + "<div>\n"
+ + " Gerrit-Go-Import\n"
+ + "</div>\n"
+ + "</body>\n"
+ + "</html>";
private GoImportFilter unitUnderTest;
- @Mock
- private ProjectCache mockProjectCache;
- @Mock
- private HttpServletRequest mockRequest;
- @Mock
- private HttpServletResponse mockResponse;
- @Mock
- private FilterChain mockChain;
- @Mock
- private ServletOutputStream mockOutputStream;
- @Mock
- private ProjectState mockProjectState;
+ @Mock private ProjectCache mockProjectCache;
+ @Mock private HttpServletRequest mockRequest;
+ @Mock private HttpServletResponse mockResponse;
+ @Mock private FilterChain mockChain;
+ @Mock private ServletOutputStream mockOutputStream;
+ @Mock private ProjectState mockProjectState;
@Before
public void setUp() throws Exception {
@@ -81,13 +72,13 @@
@Test
public void testConstructor() throws Exception {
assertThat(unitUnderTest.webUrl.endsWith("/")).isTrue();
- unitUnderTest = new GoImportFilter(mockProjectCache,
- "http://gerrit-review.googlesource.com:8080/");
+ unitUnderTest =
+ new GoImportFilter(mockProjectCache, "http://gerrit-review.googlesource.com:8080/");
assertThat(unitUnderTest.webUrl.endsWith("/")).isTrue();
assertThat(unitUnderTest.projectPrefix).isNotNull();
}
- @Test(expected=URISyntaxException.class)
+ @Test(expected = URISyntaxException.class)
public void testConstructorWithURISyntaxException() throws Exception {
unitUnderTest = new GoImportFilter(mockProjectCache, "\\\\");
}
@@ -162,7 +153,7 @@
try {
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
fail("IOException should occur!");
- } catch(IOException e) {
+ } catch (IOException e) {
assertThat(msg).isEqualTo(e.getMessage());
verify(mockOutputStream, times(1)).write(any(byte[].class));
}
@@ -175,7 +166,7 @@
try {
unitUnderTest.doFilter(null, null, mockChain);
fail("ServletException should occur!");
- } catch(ServletException e) {
+ } catch (ServletException e) {
assertThat(msg).isEqualTo(e.getMessage());
verify(mockChain, times(1)).doFilter(null, null);
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/goimport/HttpModuleTest.java b/src/test/java/com/ericsson/gerrit/plugins/goimport/HttpModuleTest.java
index a73da44..547c159 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/goimport/HttpModuleTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/goimport/HttpModuleTest.java
@@ -16,15 +16,12 @@
import static com.google.common.truth.Truth.assertThat;
-import com.ericsson.gerrit.plugins.goimport.GoImportFilter;
-import com.ericsson.gerrit.plugins.goimport.HttpModule;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,8 +32,7 @@
public class HttpModuleTest {
private HttpModule unitUnderTest;
- @Mock
- private ProjectCache mockProjectCache;
+ @Mock private ProjectCache mockProjectCache;
@Before
public void setUp() throws Exception {