use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.
the class SetParent method apply.
public String apply(ProjectResource rsrc, Input input, boolean checkIfAdmin) throws AuthException, ResourceConflictException, ResourceNotFoundException, UnprocessableEntityException, IOException, PermissionBackendException {
ProjectControl ctl = rsrc.getControl();
String parentName = MoreObjects.firstNonNull(Strings.emptyToNull(input.parent), allProjects.get());
validateParentUpdate(ctl, parentName, checkIfAdmin);
try (MetaDataUpdate md = updateFactory.create(rsrc.getNameKey())) {
ProjectConfig config = ProjectConfig.read(md);
Project project = config.getProject();
project.setParentName(parentName);
String msg = Strings.emptyToNull(input.commitMessage);
if (msg == null) {
msg = String.format("Changed parent to %s.\n", parentName);
} else if (!msg.endsWith("\n")) {
msg += "\n";
}
md.setAuthor(ctl.getUser().asIdentifiedUser());
md.setMessage(msg);
config.commit(md);
cache.evict(ctl.getProject());
Project.NameKey parent = project.getParent(allProjects);
checkNotNull(parent);
return parent.get();
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(rsrc.getName());
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(String.format("invalid project.config: %s", e.getMessage()));
}
}
use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.
the class ProjectState method getConfig.
public ProjectLevelConfig getConfig(String fileName) {
if (configs.containsKey(fileName)) {
return configs.get(fileName);
}
ProjectLevelConfig cfg = new ProjectLevelConfig(fileName, this);
try (Repository git = gitMgr.openRepository(getProject().getNameKey())) {
cfg.load(git);
} catch (IOException | ConfigInvalidException e) {
log.warn("Failed to load " + fileName + " for " + getProject().getName(), e);
}
configs.put(fileName, cfg);
return cfg;
}
use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.
the class RefControlTest method setUp.
@Before
public void setUp() throws Exception {
repoManager = new InMemoryRepositoryManager();
projectCache = new ProjectCache() {
@Override
public ProjectState getAllProjects() {
return get(allProjectsName);
}
@Override
public ProjectState getAllUsers() {
return null;
}
@Override
public ProjectState get(Project.NameKey projectName) {
return all.get(projectName);
}
@Override
public void evict(Project p) {
}
@Override
public void remove(Project p) {
}
@Override
public Iterable<Project.NameKey> all() {
return Collections.emptySet();
}
@Override
public Iterable<Project.NameKey> byName(String prefix) {
return Collections.emptySet();
}
@Override
public void onCreateProject(Project.NameKey newProjectName) {
}
@Override
public Set<AccountGroup.UUID> guessRelevantGroupUUIDs() {
return Collections.emptySet();
}
@Override
public ProjectState checkedGet(Project.NameKey projectName) throws IOException {
return all.get(projectName);
}
@Override
public void evict(Project.NameKey p) {
}
};
Injector injector = Guice.createInjector(new InMemoryModule());
injector.injectMembers(this);
try {
Repository repo = repoManager.createRepository(allProjectsName);
ProjectConfig allProjects = new ProjectConfig(new Project.NameKey(allProjectsName.get()));
allProjects.load(repo);
LabelType cr = Util.codeReview();
allProjects.getLabelSections().put(cr.getName(), cr);
add(allProjects);
} catch (IOException | ConfigInvalidException e) {
throw new RuntimeException(e);
}
db = schemaFactory.open();
singleVersionListener.start();
try {
schemaCreator.create(db);
} finally {
singleVersionListener.stop();
}
Cache<SectionSortCache.EntryKey, SectionSortCache.EntryVal> c = CacheBuilder.newBuilder().build();
sectionSorter = new PermissionCollection.Factory(new SectionSortCache(c));
parent = new ProjectConfig(parentKey);
parent.load(newRepository(parentKey));
add(parent);
local = new ProjectConfig(localKey);
local.load(newRepository(localKey));
add(local);
local.getProject().setParentName(parentKey);
requestContext.setContext(new RequestContext() {
@Override
public CurrentUser getUser() {
return null;
}
@Override
public Provider<ReviewDb> getReviewDbProvider() {
return Providers.of(db);
}
});
changeControlFactory = injector.getInstance(ChangeControl.Factory.class);
}
use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.
the class DeleteComment method applyImpl.
@Override
public CommentInfo applyImpl(BatchUpdate.Factory batchUpdateFactory, CommentResource rsrc, DeleteCommentInput input) throws RestApiException, IOException, ConfigInvalidException, OrmException, PermissionBackendException, UpdateException {
CurrentUser user = userProvider.get();
permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
String newMessage = getCommentNewMessage(user.asIdentifiedUser().getName(), input.reason);
DeleteCommentOp deleteCommentOp = new DeleteCommentOp(rsrc, newMessage);
try (BatchUpdate batchUpdate = batchUpdateFactory.create(dbProvider.get(), rsrc.getRevisionResource().getProject(), user, TimeUtil.nowTs())) {
batchUpdate.addOp(rsrc.getRevisionResource().getChange().getId(), deleteCommentOp).execute();
}
ChangeNotes updatedNotes = notesFactory.createChecked(rsrc.getRevisionResource().getChange().getId());
List<Comment> changeComments = commentsUtil.publishedByChange(dbProvider.get(), updatedNotes);
Optional<Comment> updatedComment = changeComments.stream().filter(c -> c.key.equals(rsrc.getComment().key)).findFirst();
if (!updatedComment.isPresent()) {
// This should not happen as this endpoint should not remove the whole comment.
throw new ResourceNotFoundException("comment not found: " + rsrc.getComment().key);
}
return commentJson.get().newCommentFormatter().format(updatedComment.get());
}
use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.
the class AbstractChangeNotes method load.
public T load() throws OrmException {
if (loaded) {
return self();
}
boolean read = args.migration.readChanges();
if (!read && primaryStorage == PrimaryStorage.NOTE_DB) {
throw new OrmException("NoteDb is required to read change " + changeId);
}
boolean readOrWrite = read || args.migration.rawWriteChangesSetting();
if (!readOrWrite && !autoRebuild) {
loadDefaults();
return self();
}
if (args.migration.failOnLoad()) {
throw new OrmException("Reading from NoteDb is disabled");
}
try (Timer1.Context timer = args.metrics.readLatency.start(CHANGES);
Repository repo = args.repoManager.openRepository(getProjectName());
// auto-rebuilding before this object may get passed to a ChangeUpdate.
LoadHandle handle = openHandle(repo)) {
if (read) {
revision = handle.id();
onLoad(handle);
} else {
loadDefaults();
}
loaded = true;
} catch (ConfigInvalidException | IOException e) {
throw new OrmException(e);
}
return self();
}
Aggregations