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

@@ -35,7 +35,8 @@ import com.google.gerrit.server.project.RefUtil.InvalidRevisionException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
import java.util.TimeZone;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.TagCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -48,9 +49,6 @@ import org.eclipse.jgit.revwalk.RevWalk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.TimeZone;
public class CreateTag implements RestModifyView<ProjectResource, TagInput> {
private static final Logger log = LoggerFactory.getLogger(CreateTag.class);
@@ -65,7 +63,8 @@ public class CreateTag implements RestModifyView<ProjectResource, TagInput> {
private String ref;
@Inject
CreateTag(Provider<IdentifiedUser> identifiedUser,
CreateTag(
Provider<IdentifiedUser> identifiedUser,
GitRepositoryManager repoManager,
TagCache tagCache,
GitReferenceUpdated referenceUpdated,
@@ -94,45 +93,45 @@ public class CreateTag implements RestModifyView<ProjectResource, TagInput> {
RefControl refControl = resource.getControl().controlForRef(ref);
try (Repository repo = repoManager.openRepository(resource.getNameKey())) {
ObjectId revid = RefUtil.parseBaseRevision(
repo, resource.getNameKey(), input.revision);
ObjectId revid = RefUtil.parseBaseRevision(repo, resource.getNameKey(), input.revision);
RevWalk rw = RefUtil.verifyConnected(repo, revid);
RevObject object = rw.parseAny(revid);
rw.reset();
boolean isAnnotated = Strings.emptyToNull(input.message) != null;
boolean isSigned = isAnnotated
&& input.message.contains("-----BEGIN PGP SIGNATURE-----\n");
boolean isSigned = isAnnotated && input.message.contains("-----BEGIN PGP SIGNATURE-----\n");
if (isSigned) {
throw new MethodNotAllowedException(
"Cannot create signed tag \"" + ref + "\"");
throw new MethodNotAllowedException("Cannot create signed tag \"" + ref + "\"");
} else if (isAnnotated && !refControl.canPerform(Permission.CREATE_TAG)) {
throw new AuthException("Cannot create annotated tag \"" + ref + "\"");
} else if (!refControl.canPerform(Permission.CREATE)) {
throw new AuthException("Cannot create tag \"" + ref + "\"");
}
if (repo.getRefDatabase().exactRef(ref) != null) {
throw new ResourceConflictException(
"tag \"" + ref + "\" already exists");
throw new ResourceConflictException("tag \"" + ref + "\" already exists");
}
try (Git git = new Git(repo)) {
TagCommand tag = git.tag()
.setObjectId(object)
.setName(ref.substring(R_TAGS.length()))
.setAnnotated(isAnnotated)
.setSigned(isSigned);
TagCommand tag =
git.tag()
.setObjectId(object)
.setName(ref.substring(R_TAGS.length()))
.setAnnotated(isAnnotated)
.setSigned(isSigned);
if (isAnnotated) {
tag.setMessage(input.message)
.setTagger(identifiedUser.get()
.newCommitterIdent(TimeUtil.nowTs(), TimeZone.getDefault()));
.setTagger(
identifiedUser.get().newCommitterIdent(TimeUtil.nowTs(), TimeZone.getDefault()));
}
Ref result = tag.call();
tagCache.updateFastForward(resource.getNameKey(), ref,
ObjectId.zeroId(), result.getObjectId());
referenceUpdated.fire(resource.getNameKey(), ref,
ObjectId.zeroId(), result.getObjectId(),
tagCache.updateFastForward(
resource.getNameKey(), ref, ObjectId.zeroId(), result.getObjectId());
referenceUpdated.fire(
resource.getNameKey(),
ref,
ObjectId.zeroId(),
result.getObjectId(),
identifiedUser.get().getAccount());
try (RevWalk w = new RevWalk(repo)) {
return ListTags.createTagInfo(result, w);