Add 'parentproject' operator that includes changes of child projects

With the 'parentproject' operator one can find all changes of a
project and its child projects. This is e.g. useful to watch a project
tree.

Change-Id: Id45e6fc391137a1830a1782fea0b1326c661afa9
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-06-28 02:05:14 +02:00
parent 93d6838485
commit 7c0eb41351
7 changed files with 97 additions and 10 deletions

View File

@@ -110,6 +110,12 @@ matches project names by regular expression. The
link:http://www.brics.dk/automaton/[dk.brics.automaton
library] is used for evaluation of such patterns.
[[parentproject]]
parentproject:'PROJECT'::
+
Changes occurring in 'PROJECT' or in one of the child projects of
'PROJECT'.
[[branch]]
branch:'BRANCH'::
+

View File

@@ -22,13 +22,13 @@ import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.TreeSet;
public class SearchSuggestOracle extends HighlightSuggestOracle {
private static final List<ParamSuggester> paramSuggester = Arrays.asList(
new ParamSuggester("project:", new ProjectNameSuggestOracle()),
new ParamSuggester(Arrays.asList("project:", "parentproject:"),
new ProjectNameSuggestOracle()),
new ParamSuggester(Arrays.asList("owner:", "reviewer:"),
new AccountSuggestOracle() {
@Override
@@ -81,6 +81,7 @@ public class SearchSuggestOracle extends HighlightSuggestOracle {
suggestions.add("commit:");
suggestions.add("comment:");
suggestions.add("project:");
suggestions.add("parentproject:");
suggestions.add("branch:");
suggestions.add("topic:");
suggestions.add("ref:");
@@ -207,11 +208,6 @@ public class SearchSuggestOracle extends HighlightSuggestOracle {
private final List<String> operators;
private final SuggestOracle parameterSuggestionOracle;
ParamSuggester(final String operator,
final SuggestOracle parameterSuggestionOracle) {
this(Collections.singletonList(operator), parameterSuggestionOracle);
}
ParamSuggester(final List<String> operators,
final SuggestOracle parameterSuggestionOracle) {
this.operators = operators;

View File

@@ -47,6 +47,10 @@ public class ListChildProjects implements RestReadView<ProjectResource> {
this.projectNodeFactory = projectNodeFactory;
}
public void setRecursive(boolean recursive) {
this.recursive = recursive;
}
@Override
public List<ProjectInfo> apply(ProjectResource rsrc) {
if (recursive) {

View File

@@ -33,8 +33,8 @@ public abstract class BasicChangeRewrites extends QueryRewriter<ChangeData> {
new ChangeQueryBuilder.Arguments( //
new InvalidProvider<ReviewDb>(), //
new InvalidProvider<ChangeQueryRewriter>(), //
null, null, null, null, null, //
null, null, null, null, null), null);
null, null, null, null, null, null, //
null, null, null, null, null, null), null);
static Schema<ChangeData> schema(@Nullable IndexCollection indexes) {
ChangeIndex index = indexes != null ? indexes.getSearchIndex() : null;

View File

@@ -37,6 +37,7 @@ import com.google.gerrit.server.index.IndexCollection;
import com.google.gerrit.server.index.Schema;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.ListChildProjects;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.query.IntPredicate;
import com.google.gerrit.server.query.Predicate;
@@ -93,6 +94,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
public static final String FIELD_MESSAGE = "message";
public static final String FIELD_OWNER = "owner";
public static final String FIELD_OWNERIN = "ownerin";
public static final String FIELD_PARENTPROJECT = "parentproject";
public static final String FIELD_PROJECT = "project";
public static final String FIELD_REF = "ref";
public static final String FIELD_REVIEWER = "reviewer";
@@ -139,6 +141,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
final Provider<ReviewDb> dbProvider;
final Provider<ChangeQueryRewriter> rewriter;
final IdentifiedUser.GenericFactory userFactory;
final Provider<CurrentUser> self;
final CapabilityControl.Factory capabilityControlFactory;
final ChangeControl.GenericFactory changeControlGenericFactory;
final AccountResolver accountResolver;
@@ -147,6 +150,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
final PatchListCache patchListCache;
final GitRepositoryManager repoManager;
final ProjectCache projectCache;
final Provider<ListChildProjects> listChildProjects;
final IndexCollection indexes;
@Inject
@@ -154,6 +158,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
public Arguments(Provider<ReviewDb> dbProvider,
Provider<ChangeQueryRewriter> rewriter,
IdentifiedUser.GenericFactory userFactory,
Provider<CurrentUser> self,
CapabilityControl.Factory capabilityControlFactory,
ChangeControl.GenericFactory changeControlGenericFactory,
AccountResolver accountResolver,
@@ -162,10 +167,12 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
PatchListCache patchListCache,
GitRepositoryManager repoManager,
ProjectCache projectCache,
Provider<ListChildProjects> listChildProjects,
IndexCollection indexes) {
this.dbProvider = dbProvider;
this.rewriter = rewriter;
this.userFactory = userFactory;
this.self = self;
this.capabilityControlFactory = capabilityControlFactory;
this.changeControlGenericFactory = changeControlGenericFactory;
this.accountResolver = accountResolver;
@@ -174,6 +181,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
this.patchListCache = patchListCache;
this.repoManager = repoManager;
this.projectCache = projectCache;
this.listChildProjects = listChildProjects;
this.indexes = indexes;
}
}
@@ -314,6 +322,12 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
return new ProjectPredicate(args.dbProvider, name);
}
@Operator
public Predicate<ChangeData> parentproject(String name) {
return new ParentProjectPredicate(args.dbProvider, args.projectCache,
args.listChildProjects, args.self, name);
}
@Operator
public Predicate<ChangeData> branch(String name) {
if (name.startsWith("^"))

View File

@@ -0,0 +1,67 @@
// Copyright (C) 2013 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.server.query.change;
import com.google.common.collect.Lists;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.project.ListChildProjects;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectJson.ProjectInfo;
import com.google.gerrit.server.project.ProjectResource;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.query.OrPredicate;
import com.google.gerrit.server.query.Predicate;
import com.google.inject.Provider;
import java.util.Collections;
import java.util.List;
class ParentProjectPredicate extends OrPredicate<ChangeData> {
private final String value;
ParentProjectPredicate(Provider<ReviewDb> dbProvider,
ProjectCache projectCache, Provider<ListChildProjects> listChildProjects,
Provider<CurrentUser> self, String value) {
super(predicates(dbProvider, projectCache, listChildProjects, self, value));
this.value = value;
}
private static List<Predicate<ChangeData>> predicates(
Provider<ReviewDb> dbProvider, ProjectCache projectCache,
Provider<ListChildProjects> listChildProjects,
Provider<CurrentUser> self, String value) {
ProjectState projectState = projectCache.get(new Project.NameKey(value));
if (projectState == null) {
return Collections.emptyList();
}
List<Predicate<ChangeData>> r = Lists.newArrayList();
r.add(new ProjectPredicate(dbProvider, projectState.getProject().getName()));
ListChildProjects children = listChildProjects.get();
children.setRecursive(true);
for (ProjectInfo p : children.apply(new ProjectResource(
projectState.controlFor(self.get())))) {
r.add(new ProjectPredicate(dbProvider, p.name));
}
return r;
}
@Override
public String toString() {
return ChangeQueryBuilder.FIELD_PARENTPROJECT + ":" + value;
}
}

View File

@@ -26,7 +26,7 @@ public class FakeQueryBuilder extends ChangeQueryBuilder {
new FakeQueryBuilder.Definition<ChangeData, FakeQueryBuilder>(
FakeQueryBuilder.class),
new ChangeQueryBuilder.Arguments(null, null, null, null, null, null,
null, null, null, null, null, indexes),
null, null, null, null, null, null, null, indexes),
null);
}