Make IncludedInDetail a static class of IncludedInResolver

IncludedInDetail is only used by the IncludedIn change REST API
endpoint and in the tests for the IncludedInResolver.

Make it a static class of IncludedInResolver and rename it to
Result which is a bit shorter.

Remove the now unused IncludedInDetail class from gerrit-common.

Change-Id: I8255dd99ead8ba4798ab1dd9a05880e2facbd249
This commit is contained in:
David Pursehouse
2016-02-18 16:00:12 +09:00
parent 3db8abaf63
commit 29d8a29f52
4 changed files with 35 additions and 57 deletions

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

@@ -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

@@ -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);
}