Search in sources :

Example 11 with ProjectResource

use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.

the class ListTags method apply.

@Override
public Response<ImmutableList<TagInfo>> apply(ProjectResource resource) throws IOException, ResourceNotFoundException, RestApiException, PermissionBackendException {
    resource.getProjectState().checkStatePermitsRead();
    List<TagInfo> tags = new ArrayList<>();
    PermissionBackend.ForProject perm = permissionBackend.currentUser().project(resource.getNameKey());
    try (Repository repo = getRepository(resource.getNameKey());
        RevWalk rw = new RevWalk(repo)) {
        Collection<Ref> all = visibleTags(resource.getNameKey(), repo, repo.getRefDatabase().getRefsByPrefix(Constants.R_TAGS));
        for (Ref ref : all) {
            tags.add(createTagInfo(perm.ref(ref.getName()), ref, rw, resource.getProjectState(), links));
        }
    }
    tags.sort(comparing(t -> t.ref));
    return Response.ok(new RefFilter<TagInfo>(Constants.R_TAGS).start(start).limit(limit).subString(matchSubstring).regex(matchRegex).filter(tags));
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RefPermission(com.google.gerrit.server.permissions.RefPermission) RevCommit(org.eclipse.jgit.revwalk.RevCommit) IdString(com.google.gerrit.extensions.restapi.IdString) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Inject(com.google.inject.Inject) RevObject(org.eclipse.jgit.revwalk.RevObject) Response(com.google.gerrit.extensions.restapi.Response) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTag(org.eclipse.jgit.revwalk.RevTag) ImmutableList(com.google.common.collect.ImmutableList) Comparator.comparing(java.util.Comparator.comparing) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) RestReadView(com.google.gerrit.extensions.restapi.RestReadView) RefFilter(com.google.gerrit.server.project.RefFilter) Collection(java.util.Collection) RefFilterOptions(com.google.gerrit.server.permissions.PermissionBackend.RefFilterOptions) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectResource(com.google.gerrit.server.project.ProjectResource) IOException(java.io.IOException) Constants(org.eclipse.jgit.lib.Constants) Option(org.kohsuke.args4j.Option) CommonConverters(com.google.gerrit.server.CommonConverters) Instant(java.time.Instant) WebLinks(com.google.gerrit.server.WebLinks) PersonIdent(org.eclipse.jgit.lib.PersonIdent) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) List(java.util.List) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ListRefsRequest(com.google.gerrit.extensions.api.projects.ProjectApi.ListRefsRequest) Ref(org.eclipse.jgit.lib.Ref) Project(com.google.gerrit.entities.Project) RefNames.isConfigRef(com.google.gerrit.entities.RefNames.isConfigRef) Repository(org.eclipse.jgit.lib.Repository) RefFilter(com.google.gerrit.server.project.RefFilter) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RefNames.isConfigRef(com.google.gerrit.entities.RefNames.isConfigRef) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 12 with ProjectResource

use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.

the class SetParentCommand method getChildrenForReparenting.

/**
 * Returns the children of the specified parent project that should be reparented. The returned
 * list of child projects does not contain projects that were specified to be excluded from
 * reparenting.
 */
private List<Project.NameKey> getChildrenForReparenting(ProjectState parent) throws Exception {
    final List<Project.NameKey> childProjects = new ArrayList<>();
    final List<Project.NameKey> excluded = new ArrayList<>(excludedChildren.size());
    for (ProjectState excludedChild : excludedChildren) {
        excluded.add(excludedChild.getProject().getNameKey());
    }
    final List<Project.NameKey> automaticallyExcluded = new ArrayList<>(excludedChildren.size());
    if (newParentKey != null) {
        automaticallyExcluded.addAll(getAllParents(newParentKey));
    }
    for (ProjectInfo child : listChildProjects.apply(new ProjectResource(parent, user)).value()) {
        final Project.NameKey childName = Project.nameKey(child.name);
        if (!excluded.contains(childName)) {
            if (!automaticallyExcluded.contains(childName)) {
                childProjects.add(childName);
            } else {
                stdout.println("Automatically excluded '" + childName + "' " + "from reparenting because it is in the parent " + "line of the new parent '" + newParentKey + "'.");
            }
        }
    }
    return childProjects;
}
Also used : Project(com.google.gerrit.entities.Project) ArrayList(java.util.ArrayList) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectResource(com.google.gerrit.server.project.ProjectResource)

Example 13 with ProjectResource

use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.

the class SetProjectCommand method run.

@Override
protected void run() throws Failure {
    enableGracefulStop();
    ConfigInput configInput = new ConfigInput();
    configInput.requireChangeId = requireChangeID;
    configInput.submitType = submitType;
    configInput.useContentMerge = contentMerge;
    configInput.useContributorAgreements = contributorAgreements;
    configInput.useSignedOffBy = signedOffBy;
    configInput.state = state;
    configInput.maxObjectSizeLimit = maxObjectSizeLimit;
    // keeping the existing description, it would delete it.
    if (Strings.emptyToNull(projectDescription) != null) {
        configInput.description = projectDescription;
    } else {
        configInput.description = projectState.getProject().getDescription();
    }
    try {
        putConfig.apply(new ProjectResource(projectState, user), configInput);
    } catch (RestApiException | PermissionBackendException e) {
        throw die(e);
    }
}
Also used : ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) ProjectResource(com.google.gerrit.server.project.ProjectResource) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 14 with ProjectResource

use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.

the class LabelApiImpl method create.

@Override
public LabelApi create(LabelDefinitionInput input) throws RestApiException {
    try {
        createLabel.apply(project, IdString.fromDecoded(label), input);
        // recreate project resource because project state was updated by creating the new label and
        // needs to be reloaded
        project = new ProjectResource(projectCache.get(project.getNameKey()).orElseThrow(illegalState(project.getNameKey())), project.getUser());
        return this;
    } catch (Exception e) {
        throw asRestApiException("Cannot create branch", e);
    }
}
Also used : ProjectResource(com.google.gerrit.server.project.ProjectResource) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 15 with ProjectResource

use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.

the class ConfigInfoCreator method constructInfo.

@SuppressWarnings("deprecation")
public static ConfigInfo constructInfo(boolean serverEnableSignedPush, ProjectState projectState, CurrentUser user, DynamicMap<ProjectConfigEntry> pluginConfigEntries, PluginConfigFactory cfgFactory, AllProjectsName allProjects, UiActions uiActions, DynamicMap<RestView<ProjectResource>> views) {
    ConfigInfo configInfo = new ConfigInfo();
    Project p = projectState.getProject();
    configInfo.description = Strings.emptyToNull(p.getDescription());
    ProjectState parentState = Iterables.getFirst(projectState.parents(), null);
    for (BooleanProjectConfig cfg : BooleanProjectConfig.values()) {
        InheritedBooleanInfo info = new InheritedBooleanInfo();
        info.configuredValue = p.getBooleanConfig(cfg);
        if (parentState != null) {
            info.inheritedValue = parentState.is(cfg);
        }
        BooleanProjectConfigTransformations.set(cfg, configInfo, info);
    }
    if (!serverEnableSignedPush) {
        configInfo.enableSignedPush = null;
        configInfo.requireSignedPush = null;
    }
    configInfo.maxObjectSizeLimit = getMaxObjectSizeLimit(projectState, p);
    configInfo.defaultSubmitType = new SubmitTypeInfo();
    configInfo.defaultSubmitType.value = projectState.getSubmitType();
    configInfo.defaultSubmitType.configuredValue = MoreObjects.firstNonNull(projectState.getConfig().getProject().getSubmitType(), Project.DEFAULT_SUBMIT_TYPE);
    ProjectState parent = projectState.isAllProjects() ? projectState : projectState.parents().get(0);
    configInfo.defaultSubmitType.inheritedValue = parent.getSubmitType();
    configInfo.submitType = configInfo.defaultSubmitType.value;
    configInfo.state = p.getState() != com.google.gerrit.extensions.client.ProjectState.ACTIVE ? p.getState() : null;
    configInfo.commentlinks = new LinkedHashMap<>();
    for (CommentLinkInfo cl : projectState.getCommentLinks()) {
        configInfo.commentlinks.put(cl.name, cl);
    }
    configInfo.pluginConfig = getPluginConfig(projectState, pluginConfigEntries, cfgFactory, allProjects);
    configInfo.actions = new TreeMap<>();
    for (UiAction.Description d : uiActions.from(views, new ProjectResource(projectState, user))) {
        configInfo.actions.put(d.getId(), new ActionInfo(d));
    }
    configInfo.extensionPanelNames = projectState.getConfig().getExtensionPanelSections();
    return configInfo;
}
Also used : ActionInfo(com.google.gerrit.extensions.common.ActionInfo) ConfigInfo(com.google.gerrit.extensions.api.projects.ConfigInfo) UiAction(com.google.gerrit.extensions.webui.UiAction) InheritedBooleanInfo(com.google.gerrit.extensions.api.projects.ConfigInfo.InheritedBooleanInfo) Project(com.google.gerrit.entities.Project) SubmitTypeInfo(com.google.gerrit.extensions.api.projects.ConfigInfo.SubmitTypeInfo) CommentLinkInfo(com.google.gerrit.extensions.api.projects.CommentLinkInfo) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectResource(com.google.gerrit.server.project.ProjectResource) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig)

Aggregations

ProjectResource (com.google.gerrit.server.project.ProjectResource)17 ProjectState (com.google.gerrit.server.project.ProjectState)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)5 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)5 Project (com.google.gerrit.entities.Project)4 IdString (com.google.gerrit.extensions.restapi.IdString)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)4 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)4 ArrayList (java.util.ArrayList)4 ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 Project (com.google.gerrit.reviewdb.client.Project)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)2 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)2 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)2 ImmutableList (com.google.common.collect.ImmutableList)1 Capable (com.google.gerrit.common.data.Capable)1 BooleanProjectConfig (com.google.gerrit.entities.BooleanProjectConfig)1