Format all Java files with google-java-format

Having a standard tool for formatting saves reviewers' valuable time.
google-java-format is Google's standard formatter and is somewhat
inspired by gofmt[1]. This commit formats everything using
google-java-format version 1.2.

The downside of this one-off formatting is breaking blame. This can be
somewhat hacked around with a tool like git-hyper-blame[2], but it's
definitely not optimal until/unless this kind of feature makes its way
to git core.

Not in this change:
* Tool support, e.g. Eclipse. The command must be run manually [3].
* Documentation of best practice, e.g. new 100-column default.

[1] https://talks.golang.org/2015/gofmt-en.slide#3
[2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html
[3] git ls-files | grep java$ | xargs google-java-format -i

Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3
Signed-off-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
Dave Borowitz
2016-11-13 09:56:32 -08:00
committed by David Pursehouse
parent 6723b6d0fa
commit 292fa154c1
2443 changed files with 54816 additions and 57825 deletions

View File

@@ -25,8 +25,7 @@ import com.google.gerrit.server.CurrentUser;
public class AuditEvent {
public static final String UNKNOWN_SESSION_ID = "000000000000000000000000000";
protected static final ListMultimap<String, ?> EMPTY_PARAMS =
ImmutableListMultimap.of();
protected static final ListMultimap<String, ?> EMPTY_PARAMS = ImmutableListMultimap.of();
public final String sessionId;
public final CurrentUser who;
@@ -58,8 +57,13 @@ public class AuditEvent {
* @param params parameters of the event
* @param result result of the event
*/
public AuditEvent(String sessionId, CurrentUser who, String what, long when,
ListMultimap<String, ?> params, Object result) {
public AuditEvent(
String sessionId,
CurrentUser who,
String what,
long when,
ListMultimap<String, ?> params,
Object result) {
Preconditions.checkNotNull(what, "what is a mandatory not null param !");
this.sessionId = MoreObjects.firstNonNull(sessionId, UNKNOWN_SESSION_ID);
@@ -96,7 +100,8 @@ public class AuditEvent {
@Override
public String toString() {
return String.format("AuditEvent UUID:%s, SID:%s, TS:%d, who:%s, what:%s",
return String.format(
"AuditEvent UUID:%s, SID:%s, TS:%d, who:%s, what:%s",
uuid.uuid(), sessionId, when, who, what);
}
}

View File

@@ -20,5 +20,4 @@ import com.google.gerrit.extensions.annotations.ExtensionPoint;
public interface AuditListener {
void onAuditableAction(AuditEvent action);
}

View File

@@ -25,5 +25,4 @@ public class AuditModule extends AbstractModule {
DynamicSet.setOf(binder(), GroupMemberAuditListener.class);
bind(AuditService.class);
}
}

View File

@@ -20,12 +20,10 @@ import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
@Singleton
public class AuditService {
private static final Logger log = LoggerFactory.getLogger(AuditService.class);
@@ -34,7 +32,8 @@ public class AuditService {
private final DynamicSet<GroupMemberAuditListener> groupMemberAuditListeners;
@Inject
public AuditService(DynamicSet<AuditListener> auditListeners,
public AuditService(
DynamicSet<AuditListener> auditListeners,
DynamicSet<GroupMemberAuditListener> groupMemberAuditListeners) {
this.auditListeners = auditListeners;
this.groupMemberAuditListeners = groupMemberAuditListeners;
@@ -46,8 +45,7 @@ public class AuditService {
}
}
public void dispatchAddAccountsToGroup(Account.Id actor,
Collection<AccountGroupMember> added) {
public void dispatchAddAccountsToGroup(Account.Id actor, Collection<AccountGroupMember> added) {
for (GroupMemberAuditListener auditListener : groupMemberAuditListeners) {
try {
auditListener.onAddAccountsToGroup(actor, added);
@@ -57,8 +55,8 @@ public class AuditService {
}
}
public void dispatchDeleteAccountsFromGroup(Account.Id actor,
Collection<AccountGroupMember> removed) {
public void dispatchDeleteAccountsFromGroup(
Account.Id actor, Collection<AccountGroupMember> removed) {
for (GroupMemberAuditListener auditListener : groupMemberAuditListeners) {
try {
auditListener.onDeleteAccountsFromGroup(actor, removed);
@@ -68,8 +66,7 @@ public class AuditService {
}
}
public void dispatchAddGroupsToGroup(Account.Id actor,
Collection<AccountGroupById> added) {
public void dispatchAddGroupsToGroup(Account.Id actor, Collection<AccountGroupById> added) {
for (GroupMemberAuditListener auditListener : groupMemberAuditListeners) {
try {
auditListener.onAddGroupsToGroup(actor, added);
@@ -79,8 +76,8 @@ public class AuditService {
}
}
public void dispatchDeleteGroupsFromGroup(Account.Id actor,
Collection<AccountGroupById> removed) {
public void dispatchDeleteGroupsFromGroup(
Account.Id actor, Collection<AccountGroupById> removed) {
for (GroupMemberAuditListener auditListener : groupMemberAuditListeners) {
try {
auditListener.onDeleteGroupsFromGroup(actor, removed);

View File

@@ -19,12 +19,9 @@ import com.google.common.collect.ListMultimap;
import com.google.gerrit.extensions.restapi.RestResource;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.server.CurrentUser;
import javax.servlet.http.HttpServletRequest;
/**
* Extended audit event. Adds request, resource and view data to HttpAuditEvent.
*/
/** Extended audit event. Adds request, resource and view data to HttpAuditEvent. */
public class ExtendedHttpAuditEvent extends HttpAuditEvent {
public final HttpServletRequest httpRequest;
public final RestResource resource;
@@ -44,12 +41,27 @@ public class ExtendedHttpAuditEvent extends HttpAuditEvent {
* @param resource REST resource data
* @param view view rendering object
*/
public ExtendedHttpAuditEvent(String sessionId, CurrentUser who,
HttpServletRequest httpRequest, long when, ListMultimap<String, ?> params,
Object input, int status, Object result, RestResource resource,
public ExtendedHttpAuditEvent(
String sessionId,
CurrentUser who,
HttpServletRequest httpRequest,
long when,
ListMultimap<String, ?> params,
Object input,
int status,
Object result,
RestResource resource,
RestView<RestResource> view) {
super(sessionId, who, httpRequest.getRequestURI(), when, params,
httpRequest.getMethod(), input, status, result);
super(
sessionId,
who,
httpRequest.getRequestURI(),
when,
params,
httpRequest.getMethod(),
input,
status,
result);
this.httpRequest = Preconditions.checkNotNull(httpRequest);
this.resource = resource;
this.view = view;

View File

@@ -18,20 +18,16 @@ import com.google.gerrit.extensions.annotations.ExtensionPoint;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import java.util.Collection;
@ExtensionPoint
public interface GroupMemberAuditListener {
void onAddAccountsToGroup(Account.Id actor,
Collection<AccountGroupMember> added);
void onAddAccountsToGroup(Account.Id actor, Collection<AccountGroupMember> added);
void onDeleteAccountsFromGroup(Account.Id actor,
Collection<AccountGroupMember> removed);
void onDeleteAccountsFromGroup(Account.Id actor, Collection<AccountGroupMember> removed);
void onAddGroupsToGroup(Account.Id actor, Collection<AccountGroupById> added);
void onDeleteGroupsFromGroup(Account.Id actor,
Collection<AccountGroupById> deleted);
void onDeleteGroupsFromGroup(Account.Id actor, Collection<AccountGroupById> deleted);
}

View File

@@ -34,9 +34,16 @@ public class HttpAuditEvent extends AuditEvent {
* @param status HTTP status
* @param result result of the event
*/
public HttpAuditEvent(String sessionId, CurrentUser who, String what,
long when, ListMultimap<String, ?> params, String httpMethod,
Object input, int status, Object result) {
public HttpAuditEvent(
String sessionId,
CurrentUser who,
String what,
long when,
ListMultimap<String, ?> params,
String httpMethod,
Object input,
int status,
Object result) {
super(sessionId, who, what, when, params, result);
this.httpMethod = httpMethod;
this.input = input;

View File

@@ -32,9 +32,16 @@ public class RpcAuditEvent extends HttpAuditEvent {
* @param status HTTP status
* @param result result of the event
*/
public RpcAuditEvent(String sessionId, CurrentUser who, String what,
long when, ListMultimap<String, ?> params, String httpMethod,
Object input, int status, Object result) {
public RpcAuditEvent(
String sessionId,
CurrentUser who,
String what,
long when,
ListMultimap<String, ?> params,
String httpMethod,
Object input,
int status,
Object result) {
super(sessionId, who, what, when, params, httpMethod, input, status, result);
}
}

View File

@@ -19,8 +19,13 @@ import com.google.gerrit.server.CurrentUser;
public class SshAuditEvent extends AuditEvent {
public SshAuditEvent(String sessionId, CurrentUser who, String what,
long when, ListMultimap<String, ?> params, Object result) {
public SshAuditEvent(
String sessionId,
CurrentUser who,
String what,
long when,
ListMultimap<String, ?> params,
Object result) {
super(sessionId, who, what, when, params, result);
}
}