Search in sources :

Example 1 with BlobBasedConfig

use of org.eclipse.jgit.lib.BlobBasedConfig in project gerrit by GerritCodeReview.

the class ListDashboards method scanDashboards.

private List<DashboardInfo> scanDashboards(Project definingProject, Repository git, RevWalk rw, Ref ref, String project, boolean setDefault) throws IOException {
    List<DashboardInfo> list = new ArrayList<>();
    try (TreeWalk tw = new TreeWalk(rw.getObjectReader())) {
        tw.addTree(rw.parseTree(ref.getObjectId()));
        tw.setRecursive(true);
        while (tw.next()) {
            if (tw.getFileMode(0) == FileMode.REGULAR_FILE) {
                try {
                    list.add(DashboardsCollection.parse(definingProject, ref.getName().substring(REFS_DASHBOARDS.length()), tw.getPathString(), new BlobBasedConfig(null, git, tw.getObjectId(0)), project, setDefault));
                } catch (ConfigInvalidException e) {
                    log.warn(String.format("Cannot parse dashboard %s:%s:%s: %s", definingProject.getName(), ref.getName(), tw.getPathString(), e.getMessage()));
                }
            }
        }
    }
    return list;
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ArrayList(java.util.ArrayList) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig) DashboardInfo(com.google.gerrit.server.project.DashboardsCollection.DashboardInfo)

Example 2 with BlobBasedConfig

use of org.eclipse.jgit.lib.BlobBasedConfig in project gerrit by GerritCodeReview.

the class ListDashboards method scanDashboards.

private ImmutableList<DashboardInfo> scanDashboards(Project definingProject, Repository git, RevWalk rw, Ref ref, String project, boolean setDefault) throws IOException {
    ImmutableList.Builder<DashboardInfo> list = ImmutableList.builder();
    try (TreeWalk tw = new TreeWalk(rw.getObjectReader())) {
        tw.addTree(rw.parseTree(ref.getObjectId()));
        tw.setRecursive(true);
        while (tw.next()) {
            if (tw.getFileMode(0) == FileMode.REGULAR_FILE) {
                try {
                    list.add(DashboardsCollection.parse(definingProject, ref.getName().substring(REFS_DASHBOARDS.length()), tw.getPathString(), new BlobBasedConfig(null, git, tw.getObjectId(0)), project, setDefault));
                } catch (ConfigInvalidException e) {
                    logger.atWarning().log("Cannot parse dashboard %s:%s:%s: %s", definingProject.getName(), ref.getName(), tw.getPathString(), e.getMessage());
                }
            }
        }
    }
    return list.build();
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ImmutableList(com.google.common.collect.ImmutableList) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig) DashboardInfo(com.google.gerrit.extensions.api.projects.DashboardInfo)

Example 3 with BlobBasedConfig

use of org.eclipse.jgit.lib.BlobBasedConfig in project gerrit by GerritCodeReview.

the class DashboardsCollection method parse.

private DashboardResource parse(ProjectControl ctl, String ref, String path, ProjectControl myCtl) throws ResourceNotFoundException, IOException, AmbiguousObjectException, IncorrectObjectTypeException, ConfigInvalidException {
    String id = ref + ":" + path;
    if (!ref.startsWith(REFS_DASHBOARDS)) {
        ref = REFS_DASHBOARDS + ref;
    }
    if (!Repository.isValidRefName(ref) || !ctl.controlForRef(ref).isVisible()) {
        throw new ResourceNotFoundException(id);
    }
    try (Repository git = gitManager.openRepository(ctl.getProject().getNameKey())) {
        ObjectId objId = git.resolve(ref + ":" + path);
        if (objId == null) {
            throw new ResourceNotFoundException(id);
        }
        BlobBasedConfig cfg = new BlobBasedConfig(null, git, objId);
        return new DashboardResource(myCtl, ref, path, cfg, false);
    } catch (RepositoryNotFoundException e) {
        throw new ResourceNotFoundException(id);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) IdString(com.google.gerrit.extensions.restapi.IdString) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig)

Example 4 with BlobBasedConfig

use of org.eclipse.jgit.lib.BlobBasedConfig in project gerrit by GerritCodeReview.

the class ExternalIdNotes method upsert.

/**
 * Inserts or updates a new external ID and sets it in the note map.
 *
 * <p>If the external ID already exists, it is overwritten.
 */
private ExternalId upsert(RevWalk rw, ObjectInserter ins, NoteMap noteMap, ExternalId extId, Function<ExternalId, ObjectId> noteIdResolver) throws IOException, ConfigInvalidException {
    ObjectId noteId = extId.key().sha1();
    Config c = new Config();
    ObjectId resolvedNoteId = noteIdResolver.apply(extId);
    if (noteMap.contains(resolvedNoteId)) {
        noteId = resolvedNoteId;
        ObjectId noteDataId = noteMap.get(noteId);
        byte[] raw = readNoteData(rw, noteDataId);
        try {
            c = new BlobBasedConfig(null, raw);
        } catch (ConfigInvalidException e) {
            throw new ConfigInvalidException(String.format("Invalid external id config for note %s: %s", noteId, e.getMessage()));
        }
    }
    extId.writeToConfig(c);
    byte[] raw = c.toText().getBytes(UTF_8);
    ObjectId noteData = ins.insert(OBJ_BLOB, raw);
    noteMap.set(noteId, noteData);
    return externalIdFactory.create(extId, noteData);
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ObjectId(org.eclipse.jgit.lib.ObjectId) Config(org.eclipse.jgit.lib.Config) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig) AuthConfig(com.google.gerrit.server.config.AuthConfig) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig)

Example 5 with BlobBasedConfig

use of org.eclipse.jgit.lib.BlobBasedConfig in project gerrit by GerritCodeReview.

the class DashboardsCollection method parse.

private DashboardResource parse(ProjectState parent, ProjectState current, CurrentUser user, DashboardInfo info) throws ResourceNotFoundException, IOException, AmbiguousObjectException, IncorrectObjectTypeException, ConfigInvalidException, PermissionBackendException, ResourceConflictException {
    String ref = normalizeDashboardRef(info.ref);
    try {
        permissionBackend.user(user).project(parent.getNameKey()).ref(ref).check(RefPermission.READ);
    } catch (AuthException e) {
        // Don't leak the project's existence
        throw new ResourceNotFoundException(info.id, e);
    }
    if (!Repository.isValidRefName(ref)) {
        throw new ResourceNotFoundException(info.id);
    }
    current.checkStatePermitsRead();
    try (Repository git = gitManager.openRepository(parent.getNameKey())) {
        ObjectId objId = git.resolve(ref + ":" + info.path);
        if (objId == null) {
            throw new ResourceNotFoundException(info.id);
        }
        BlobBasedConfig cfg = new BlobBasedConfig(null, git, objId);
        return new DashboardResource(current, user, ref, info.path, cfg, false);
    } catch (RepositoryNotFoundException e) {
        throw new ResourceNotFoundException(info.id, e);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) AuthException(com.google.gerrit.extensions.restapi.AuthException) DashboardResource(com.google.gerrit.server.project.DashboardResource) IdString(com.google.gerrit.extensions.restapi.IdString) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig)

Aggregations

BlobBasedConfig (org.eclipse.jgit.lib.BlobBasedConfig)7 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 IdString (com.google.gerrit.extensions.restapi.IdString)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 ArrayList (java.util.ArrayList)2 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)2 Config (org.eclipse.jgit.lib.Config)2 Repository (org.eclipse.jgit.lib.Repository)2 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)2 SubmoduleModel (com.gitblit.models.SubmoduleModel)1 ImmutableList (com.google.common.collect.ImmutableList)1 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 DashboardInfo (com.google.gerrit.extensions.api.projects.DashboardInfo)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 AuthConfig (com.google.gerrit.server.config.AuthConfig)1 DashboardResource (com.google.gerrit.server.project.DashboardResource)1 DashboardInfo (com.google.gerrit.server.project.DashboardsCollection.DashboardInfo)1 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)1 PushResult (org.eclipse.jgit.transport.PushResult)1