Merge changes from topic 'cleanup-gerrit-common-data'

* changes:
  Make IncludedInDetail a static class of IncludedInResolver
  AccountLinkPanel: Remove unused constructor and link method
  AccountInfo: Move getName and getNameEmail to Account
  IdentifiedUser: Remove unused getName method
  gerrit-common: Remove unused ReviewResult class
  gerrit-common: Remove unused ProjectInfo class
  gerrit-common: Remove unused ChangeInfo class
  PageLinks: Remove unused toChange method
  ChangeLink: Remove unused public methods
This commit is contained in:
Edwin Kempin
2016-02-18 08:18:47 +00:00
committed by Gerrit Code Review
15 changed files with 81 additions and 426 deletions

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.common;
import com.google.gerrit.common.data.ChangeInfo;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
@@ -51,10 +50,6 @@ public class PageLinks {
public static final String MY_GROUPS = "/groups/self";
public static final String DOCUMENTATION = "/Documentation/";
public static String toChange(final ChangeInfo c) {
return toChange(c.getId());
}
public static String toChangeInEditMode(Change.Id c) {
return "/c/" + c + ",edit/";
}

View File

@@ -76,51 +76,4 @@ public class AccountInfo {
public String getUsername() {
return username;
}
/**
* Formats an account name.
* <p>
* If the account has a full name, it returns only the full name. Otherwise it
* returns a longer form that includes the email address.
*/
public String getName(String anonymousCowardName) {
if (getFullName() != null) {
return getFullName();
}
if (getPreferredEmail() != null) {
return getPreferredEmail();
}
return getNameEmail(anonymousCowardName);
}
/**
* Formats an account as a name and an email address.
* <p>
* Example output:
* <ul>
* <li>{@code A U. Thor &lt;author@example.com&gt;}: full populated</li>
* <li>{@code A U. Thor (12)}: missing email address</li>
* <li>{@code Anonymous Coward &lt;author@example.com&gt;}: missing name</li>
* <li>{@code Anonymous Coward (12)}: missing name and email address</li>
* </ul>
*/
public String getNameEmail(String anonymousCowardName) {
String name = getFullName();
if (name == null) {
name = anonymousCowardName;
}
final StringBuilder b = new StringBuilder();
b.append(name);
if (getPreferredEmail() != null) {
b.append(" <");
b.append(getPreferredEmail());
b.append(">");
} else if (getId() != null) {
b.append(" (");
b.append(getId().get());
b.append(")");
}
return b.toString();
}
}

View File

@@ -1,113 +0,0 @@
// Copyright (C) 2008 The Android Open Source Project
//
// 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.gerrit.common.data;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import java.sql.Timestamp;
public class ChangeInfo {
protected Change.Id id;
protected Change.Key key;
protected Account.Id owner;
protected String subject;
protected Change.Status status;
protected ProjectInfo project;
protected String branch;
protected String topic;
protected boolean starred;
protected Timestamp lastUpdatedOn;
protected PatchSet.Id patchSetId;
protected boolean latest;
public ChangeInfo() {
}
public ChangeInfo(final Change c, final PatchSet.Id patchId) {
set(c, patchId);
}
public void set(final Change c, final PatchSet.Id patchId) {
id = c.getId();
key = c.getKey();
owner = c.getOwner();
subject = c.getSubject();
status = c.getStatus();
project = new ProjectInfo(c.getProject());
branch = c.getDest().getShortName();
topic = c.getTopic();
lastUpdatedOn = c.getLastUpdatedOn();
patchSetId = patchId;
latest = patchSetId == null || patchSetId.equals(c.currentPatchSetId());
}
public ChangeInfo(final Change c) {
this(c, null);
}
public Change.Id getId() {
return id;
}
public Change.Key getKey() {
return key;
}
public Account.Id getOwner() {
return owner;
}
public String getSubject() {
return subject;
}
public Change.Status getStatus() {
return status;
}
public ProjectInfo getProject() {
return project;
}
public String getBranch() {
return branch;
}
public String getTopic() {
return topic;
}
public boolean isStarred() {
return starred;
}
public void setStarred(final boolean s) {
starred = s;
}
public PatchSet.Id getPatchSetId() {
return patchSetId;
}
public boolean isLatest() {
return latest;
}
public Timestamp getLastUpdatedOn() {
return lastUpdatedOn;
}
}

View File

@@ -1,44 +0,0 @@
// Copyright (C) 2010 The Android Open Source Project
//
// 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.gerrit.common.data;
import java.util.Collections;
import java.util.List;
public class IncludedInDetail {
private List<String> branches;
private List<String> tags;
public IncludedInDetail() {
}
public void setBranches(final List<String> b) {
Collections.sort(b);
branches = b;
}
public List<String> getBranches() {
return branches;
}
public void setTags(final List<String> t) {
Collections.sort(t);
tags = t;
}
public List<String> getTags() {
return tags;
}
}

View File

@@ -1,36 +0,0 @@
// Copyright (C) 2008 The Android Open Source Project
//
// 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.gerrit.common.data;
import com.google.gerrit.reviewdb.client.Project;
public class ProjectInfo {
protected Project.NameKey key;
protected ProjectInfo() {
}
public ProjectInfo(final Project.NameKey key) {
this.key = key;
}
public Project.NameKey getKey() {
return key;
}
public String getName() {
return key.get();
}
}

View File

@@ -1,134 +0,0 @@
// Copyright (C) 2011 The Android Open Source Project
//
// 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.gerrit.common.data;
import com.google.gerrit.reviewdb.client.Change;
import java.util.ArrayList;
import java.util.List;
/**
* Result from performing a review (comment, abandon, etc.)
*/
public class ReviewResult {
protected List<Error> errors;
protected Change.Id changeId;
public ReviewResult() {
errors = new ArrayList<>();
}
public void addError(final Error e) {
errors.add(e);
}
public List<Error> getErrors() {
return errors;
}
public Change.Id getChangeId() {
return changeId;
}
public void setChangeId(Change.Id changeId) {
this.changeId = changeId;
}
public static class Error {
public static enum Type {
/** Not permitted to abandon this change. */
ABANDON_NOT_PERMITTED,
/** Not permitted to restore this change. */
RESTORE_NOT_PERMITTED,
/** Not permitted to submit this change. */
SUBMIT_NOT_PERMITTED,
/** Approvals or dependencies are lacking for submission. */
SUBMIT_NOT_READY,
/** Review operation invalid because change is closed. */
CHANGE_IS_CLOSED,
/** Review operation invalid because change is not abandoned. */
CHANGE_NOT_ABANDONED,
/** Not permitted to publish this draft patch set */
PUBLISH_NOT_PERMITTED,
/** Not permitted to delete this draft patch set */
DELETE_NOT_PERMITTED,
/** Review operation not permitted by rule. */
RULE_ERROR,
/** Review operation invalid because patch set is not a draft. */
NOT_A_DRAFT,
/** Error writing change to git repository */
GIT_ERROR,
/** The destination branch does not exist */
DEST_BRANCH_NOT_FOUND,
/** Not permitted to edit the topic name */
EDIT_TOPIC_NAME_NOT_PERMITTED,
/** Not permitted to edit the hashtags */
EDIT_HASHTAGS_NOT_PERMITTED
}
protected Type type;
protected String message;
protected Error() {
}
public Error(final Type type) {
this.type = type;
this.message = null;
}
public Error(final Type type, final String message) {
this.type = type;
this.message = message;
}
public Type getType() {
return type;
}
public String getMessage() {
return message;
}
public String getMessageOrType() {
if (message != null) {
return message;
}
return "" + type;
}
@Override
public String toString() {
String ret = type + "";
if (message != null) {
ret += " " + message;
}
return ret;
}
}
}

View File

@@ -19,24 +19,12 @@ import com.google.gerrit.client.FormatUtil;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.info.AccountInfo;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.AccountInfoCache;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.UserIdentity;
import com.google.gwt.user.client.ui.FlowPanel;
/** Link to any user's account dashboard. */
public class AccountLinkPanel extends FlowPanel {
/** Create a link after locating account details from an active cache. */
public static AccountLinkPanel link(AccountInfoCache cache, Account.Id id) {
com.google.gerrit.common.data.AccountInfo ai = cache.get(id);
return ai != null ? new AccountLinkPanel(ai) : null;
}
public AccountLinkPanel(com.google.gerrit.common.data.AccountInfo ai) {
this(FormatUtil.asInfo(ai));
}
public AccountLinkPanel(UserIdentity ident) {
this(AccountInfo.create(
ident.getAccount().get(),

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.client.ui;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.ChangeInfo;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.GWT;
@@ -42,17 +41,6 @@ public class ChangeLink extends InlineHyperlink {
psid = ps;
}
public ChangeLink(final String text, final ChangeInfo info) {
super(text, getTarget(info));
cid = info.getId();
psid = info.getPatchSetId();
}
public static String getTarget(final ChangeInfo info) {
PatchSet.Id ps = info.getPatchSetId();
return (ps == null) ? PageLinks.toChange(info) : PageLinks.toChange(ps);
}
@Override
public void go() {
Gerrit.display(getTargetHistoryToken());

View File

@@ -243,6 +243,49 @@ public final class Account {
preferredEmail = addr;
}
/**
* Formats an account name.
* <p>
* If the account has a full name, it returns only the full name. Otherwise it
* returns a longer form that includes the email address.
*/
public String getName(String anonymousCowardName) {
if (fullName != null) {
return fullName;
}
if (preferredEmail != null) {
return preferredEmail;
}
return getNameEmail(anonymousCowardName);
}
/**
* Get the name and email address.
* <p>
* Example output:
* <ul>
* <li>{@code A U. Thor &lt;author@example.com&gt;}: full populated</li>
* <li>{@code A U. Thor (12)}: missing email address</li>
* <li>{@code Anonymous Coward &lt;author@example.com&gt;}: missing name</li>
* <li>{@code Anonymous Coward (12)}: missing name and email address</li>
* </ul>
*/
public String getNameEmail(String anonymousCowardName) {
String name = fullName != null ? fullName : anonymousCowardName;
StringBuilder b = new StringBuilder();
b.append(name);
if (preferredEmail != null) {
b.append(" <");
b.append(preferredEmail);
b.append(">");
} else if (accountId != null) {
b.append(" (");
b.append(accountId.get());
b.append(")");
}
return b.toString();
}
/** Get the date and time the user first registered. */
public Timestamp getRegisteredOn() {
return registeredOn;

View File

@@ -18,7 +18,6 @@ import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountProjectWatch;
import com.google.gerrit.reviewdb.client.Change;
@@ -308,12 +307,8 @@ public class IdentifiedUser extends CurrentUser {
return validEmails;
}
public String getName() {
return new AccountInfo(getAccount()).getName(anonymousCowardName);
}
public String getNameEmail() {
return new AccountInfo(getAccount()).getNameEmail(anonymousCowardName);
return getAccount().getNameEmail(anonymousCowardName);
}
@Override

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.change;
import com.google.gerrit.common.data.IncludedInDetail;
import com.google.gerrit.extensions.config.ExternalIncludedIn;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.BadRequestException;
@@ -80,7 +79,7 @@ class IncludedIn implements RestReadView<ChangeResource> {
throw new ResourceConflictException(err.getMessage());
}
IncludedInDetail d = IncludedInResolver.resolve(r, rw, rev);
IncludedInResolver.Result d = IncludedInResolver.resolve(r, rw, rev);
Map<String, Collection<String>> external = new HashMap<>();
for (DynamicMap.Entry<ExternalIncludedIn> i : includedIn) {
external.put(i.getExportName(),
@@ -96,7 +95,7 @@ class IncludedIn implements RestReadView<ChangeResource> {
Collection<String> tags;
Map<String, Collection<String>> external;
IncludedInInfo(IncludedInDetail in, Map<String, Collection<String>> e) {
IncludedInInfo(IncludedInResolver.Result in, Map<String, Collection<String>> e) {
branches = in.getBranches();
tags = in.getTags();
external = e;

View File

@@ -18,7 +18,6 @@ import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.gerrit.common.data.IncludedInDetail;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
@@ -47,7 +46,7 @@ public class IncludedInResolver {
private static final Logger log = LoggerFactory
.getLogger(IncludedInResolver.class);
public static IncludedInDetail resolve(final Repository repo,
public static Result resolve(final Repository repo,
final RevWalk rw, final RevCommit commit) throws IOException {
RevFlag flag = newFlag(rw);
try {
@@ -87,7 +86,7 @@ public class IncludedInResolver {
this.containsTarget = containsTarget;
}
private IncludedInDetail resolve() throws IOException {
private Result resolve() throws IOException {
RefDatabase refDb = repo.getRefDatabase();
Collection<Ref> tags = refDb.getRefs(Constants.R_TAGS).values();
Collection<Ref> branches = refDb.getRefs(Constants.R_HEADS).values();
@@ -98,7 +97,7 @@ public class IncludedInResolver {
parseCommits(allTagsAndBranches);
Set<String> allMatchingTagsAndBranches = includedIn(tipsByCommitTime, 0);
IncludedInDetail detail = new IncludedInDetail();
Result detail = new Result();
detail
.setBranches(getMatchingRefNames(allMatchingTagsAndBranches, branches));
detail.setTags(getMatchingRefNames(allMatchingTagsAndBranches, tags));
@@ -228,4 +227,30 @@ public class IncludedInResolver {
}
});
}
public static class Result {
private List<String> branches;
private List<String> tags;
public Result() {
}
public void setBranches(final List<String> b) {
Collections.sort(b);
branches = b;
}
public List<String> getBranches() {
return branches;
}
public void setTags(final List<String> t) {
Collections.sort(t);
tags = t;
}
public List<String> getTags() {
return tags;
}
}
}

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.server.notedb;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.primitives.Ints;
import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.RefNames;
@@ -62,7 +61,7 @@ public class ChangeNoteUtil {
public static PersonIdent newIdent(Account author, Date when,
PersonIdent serverIdent, String anonymousCowardName) {
return new PersonIdent(
new AccountInfo(author).getName(anonymousCowardName),
author.getName(anonymousCowardName),
author.getId().get() + "@" + GERRIT_PLACEHOLDER_HOST,
when, serverIdent.getTimeZone());
}

View File

@@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.primitives.Ints;
import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.CommentRange;
@@ -364,7 +363,7 @@ public class CommentsInNotesUtil {
private PersonIdent newIdent(Account author, Date when) {
return new PersonIdent(
new AccountInfo(author).getName(anonymousCowardName),
author.getName(anonymousCowardName),
author.getId().get() + "@" + GERRIT_PLACEHOLDER_HOST,
when, serverIdent.getTimeZone());
}

View File

@@ -14,8 +14,6 @@
package com.google.gerrit.server.change;
import com.google.gerrit.common.data.IncludedInDetail;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
import org.eclipse.jgit.junit.RepositoryTestCase;
@@ -138,7 +136,7 @@ public class IncludedInResolverTest extends RepositoryTestCase {
@Test
public void resolveLatestCommit() throws Exception {
// Check tip commit
IncludedInDetail detail = resolve(commit_v2_5);
IncludedInResolver.Result detail = resolve(commit_v2_5);
// Check that only tags and branches which refer the tip are returned
expTags.add(TAG_2_5);
@@ -152,7 +150,7 @@ public class IncludedInResolverTest extends RepositoryTestCase {
@Test
public void resolveFirstCommit() throws Exception {
// Check first commit
IncludedInDetail detail = resolve(commit_initial);
IncludedInResolver.Result detail = resolve(commit_initial);
// Check whether all tags and branches are returned
expTags.add(TAG_1_0);
@@ -176,7 +174,7 @@ public class IncludedInResolverTest extends RepositoryTestCase {
@Test
public void resolveBetwixtCommit() throws Exception {
// Check a commit somewhere in the middle
IncludedInDetail detail = resolve(commit_v1_3);
IncludedInResolver.Result detail = resolve(commit_v1_3);
// Check whether all succeeding tags and branches are returned
expTags.add(TAG_1_3);
@@ -190,7 +188,7 @@ public class IncludedInResolverTest extends RepositoryTestCase {
assertEquals(expBranches, detail.getBranches());
}
private IncludedInDetail resolve(RevCommit commit) throws Exception {
private IncludedInResolver.Result resolve(RevCommit commit) throws Exception {
return IncludedInResolver.resolve(db, revWalk, commit);
}