use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.
the class CreateProjectIT method createProject.
@Test
public void createProject() throws Exception {
String newProjectName = name("newProject");
ProjectInfo p = gApi.projects().create(newProjectName).get();
assertThat(p.name).isEqualTo(newProjectName);
Optional<ProjectState> projectState = projectCache.get(Project.nameKey(newProjectName));
assertThat(projectState).isPresent();
assertProjectInfo(projectState.get().getProject(), p);
assertHead(newProjectName, "refs/heads/master");
assertThat(readProjectConfig(newProjectName)).hasValue("[access]\n\tinheritFrom = All-Projects\n[submit]\n\taction = inherit\n");
}
use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.
the class QueryProjects method apply.
public List<ProjectInfo> apply() throws BadRequestException, MethodNotAllowedException {
if (Strings.isNullOrEmpty(query)) {
throw new BadRequestException("missing query field");
}
ProjectIndex searchIndex = indexes.getSearchIndex();
if (searchIndex == null) {
throw new MethodNotAllowedException("no project index");
}
ProjectQueryProcessor queryProcessor = queryProcessorProvider.get();
if (start != 0) {
queryProcessor.setStart(start);
}
if (limit != 0) {
queryProcessor.setUserProvidedLimit(limit);
}
try {
QueryResult<ProjectData> result = queryProcessor.query(queryBuilder.parse(query));
List<ProjectData> pds = result.entities();
ArrayList<ProjectInfo> projectInfos = Lists.newArrayListWithCapacity(pds.size());
for (ProjectData pd : pds) {
projectInfos.add(json.format(pd.getProject()));
}
return projectInfos;
} catch (QueryParseException e) {
throw new BadRequestException(e.getMessage());
}
}
use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.
the class ListProjects method display.
@Nullable
public SortedMap<String, ProjectInfo> display(@Nullable PrintWriter stdout) throws BadRequestException, PermissionBackendException {
if (all && state != null) {
throw new BadRequestException("'all' and 'state' may not be used together");
}
if (groupUuid != null) {
try {
if (!groupControlFactory.controlFor(groupUuid).isVisible()) {
return Collections.emptySortedMap();
}
} catch (NoSuchGroupException ex) {
return Collections.emptySortedMap();
}
}
int foundIndex = 0;
int found = 0;
TreeMap<String, ProjectInfo> output = new TreeMap<>();
Map<String, String> hiddenNames = new HashMap<>();
Map<Project.NameKey, Boolean> accessibleParents = new HashMap<>();
PermissionBackend.WithUser perm = permissionBackend.user(currentUser);
final TreeMap<Project.NameKey, ProjectNode> treeMap = new TreeMap<>();
try {
Iterator<ProjectState> projectStatesIt = filter(perm).iterator();
while (projectStatesIt.hasNext()) {
ProjectState e = projectStatesIt.next();
Project.NameKey projectName = e.getNameKey();
if (e.getProject().getState() == HIDDEN && !all && state != HIDDEN) {
// If state HIDDEN wasn't selected, and it's HIDDEN, pretend it's not present.
continue;
}
if (state != null && e.getProject().getState() != state) {
continue;
}
if (groupUuid != null && !e.getLocalGroups().contains(GroupReference.forGroup(groupResolver.parseId(groupUuid.get())))) {
continue;
}
if (showTree && !format.isJson()) {
treeMap.put(projectName, projectNodeFactory.create(e.getProject(), true));
continue;
}
if (foundIndex++ < start) {
continue;
}
if (limit > 0 && ++found > limit) {
break;
}
ProjectInfo info = new ProjectInfo();
info.name = projectName.get();
if (showTree && format.isJson()) {
addParentProjectInfo(hiddenNames, accessibleParents, perm, e, info);
}
if (showDescription) {
info.description = emptyToNull(e.getProject().getDescription());
}
info.state = e.getProject().getState();
try {
if (!showBranch.isEmpty()) {
try (Repository git = repoManager.openRepository(projectName)) {
if (!type.matches(git)) {
continue;
}
List<Ref> refs = retrieveBranchRefs(e, git);
if (!hasValidRef(refs)) {
continue;
}
addProjectBranchesInfo(info, refs);
}
} else if (!showTree && type.useMatch()) {
try (Repository git = repoManager.openRepository(projectName)) {
if (!type.matches(git)) {
continue;
}
}
}
} catch (RepositoryNotFoundException err) {
// If the Git repository is gone, the project doesn't actually exist anymore.
continue;
} catch (IOException err) {
logger.atWarning().withCause(err).log("Unexpected error reading %s", projectName);
continue;
}
ImmutableList<WebLinkInfo> links = webLinks.getProjectLinks(projectName.get());
info.webLinks = links.isEmpty() ? null : links;
if (stdout == null || format.isJson()) {
output.put(info.name, info);
continue;
}
if (!showBranch.isEmpty()) {
printProjectBranches(stdout, info);
}
stdout.print(info.name);
if (info.description != null) {
// We still want to list every project as one-liners, hence escaping \n.
stdout.print(" - " + StringUtil.escapeString(info.description));
}
stdout.print('\n');
}
for (ProjectInfo info : output.values()) {
info.id = Url.encode(info.name);
info.name = null;
}
if (stdout == null) {
return output;
} else if (format.isJson()) {
format.newGson().toJson(output, new TypeToken<Map<String, ProjectInfo>>() {
}.getType(), stdout);
stdout.print('\n');
} else if (showTree && treeMap.size() > 0) {
printProjectTree(stdout, treeMap);
}
return null;
} finally {
if (stdout != null) {
stdout.flush();
}
}
}
use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.
the class AbstractQueryProjectsTest method byDescription.
@Test
public void byDescription() throws Exception {
ProjectInfo project1 = createProjectWithDescription(name("project1"), "This is a test project.");
ProjectInfo project2 = createProjectWithDescription(name("project2"), "ANOTHER TEST PROJECT.");
createProjectWithDescription(name("project3"), "Maintainers of project foo.");
assertQuery("description:test", project1, project2);
assertQuery("description:non-existing");
BadRequestException thrown = assertThrows(BadRequestException.class, () -> assertQuery("description:\"\""));
assertThat(thrown).hasMessageThat().contains("description operator requires a value");
}
use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.
the class AbstractQueryProjectsTest method byDefaultField.
@Test
public void byDefaultField() throws Exception {
ProjectInfo project1 = createProject(name("foo-project"));
ProjectInfo project2 = createProject(name("project2"));
ProjectInfo project3 = createProjectWithDescription(name("project3"), "decription that contains foo and the UUID of project2: " + project2.id);
assertQuery("non-existing");
assertQuery("foo", project1, project3);
assertQuery(project2.id, project2, project3);
}
Aggregations