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;
}
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();
}
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);
}
}
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);
}
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);
}
}
Aggregations