use of com.google.gerrit.extensions.common.PluginDefinedInfo in project gerrit by GerritCodeReview.
the class ChangeQueryProcessor method create.
@Override
public List<PluginDefinedInfo> create(ChangeData cd) {
List<PluginDefinedInfo> plugins = new ArrayList<>(attributeFactories.plugins().size());
for (String plugin : attributeFactories.plugins()) {
for (Provider<ChangeAttributeFactory> provider : attributeFactories.byPlugin(plugin).values()) {
PluginDefinedInfo pda = null;
try {
pda = provider.get().create(cd, this, plugin);
} catch (RuntimeException e) {
/* Eat runtime exceptions so that queries don't fail. */
}
if (pda != null) {
pda.name = plugin;
plugins.add(pda);
}
}
}
if (plugins.isEmpty()) {
plugins = null;
}
return plugins;
}
use of com.google.gerrit.extensions.common.PluginDefinedInfo in project gerrit by GerritCodeReview.
the class OutputStreamQuery method buildChangeAttribute.
private ChangeAttribute buildChangeAttribute(ChangeData d, Map<Project.NameKey, Repository> repos, Map<Project.NameKey, RevWalk> revWalks) throws IOException {
LabelTypes labelTypes = d.getLabelTypes();
ChangeAttribute c = eventFactory.asChangeAttribute(d.change(), d.notes());
eventFactory.extend(c, d.change());
if (!trackingFooters.isEmpty()) {
eventFactory.addTrackingIds(c, d.trackingFooters());
}
if (includeAllReviewers) {
eventFactory.addAllReviewers(c, d.notes());
}
if (includeSubmitRecords) {
SubmitRuleOptions options = SubmitRuleOptions.builder().recomputeOnClosedChanges(true).build();
eventFactory.addSubmitRecords(c, submitRuleEvaluatorFactory.create(options).evaluate(d));
}
if (includeCommitMessage) {
eventFactory.addCommitMessage(c, d.commitMessage());
}
RevWalk rw = null;
if (includePatchSets || includeCurrentPatchSet || includeDependencies) {
Project.NameKey p = d.change().getProject();
rw = revWalks.get(p);
// Cache and reuse repos and revwalks.
if (rw == null) {
Repository repo = repoManager.openRepository(p);
checkState(repos.put(p, repo) == null);
rw = new RevWalk(repo);
revWalks.put(p, rw);
}
}
if (includePatchSets) {
eventFactory.addPatchSets(rw, c, d.patchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
}
if (includeCurrentPatchSet) {
PatchSet current = d.currentPatchSet();
if (current != null) {
c.currentPatchSet = eventFactory.asPatchSetAttribute(rw, d.change(), current);
eventFactory.addApprovals(c.currentPatchSet, d.currentApprovals(), labelTypes);
if (includeFiles) {
eventFactory.addPatchSetFileNames(c.currentPatchSet, d.change(), d.currentPatchSet());
}
if (includeComments) {
eventFactory.addPatchSetComments(c.currentPatchSet, d.publishedComments());
}
}
}
if (includeComments) {
eventFactory.addComments(c, d.messages());
if (includePatchSets) {
eventFactory.addPatchSets(rw, c, d.patchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
for (PatchSetAttribute attribute : c.patchSets) {
eventFactory.addPatchSetComments(attribute, d.publishedComments());
}
}
}
if (includeDependencies) {
eventFactory.addDependencies(rw, c, d.change(), d.currentPatchSet());
}
List<PluginDefinedInfo> pluginInfos = pluginInfosByChange.get(d.getId());
if (!pluginInfos.isEmpty()) {
c.plugins = pluginInfos;
}
return c;
}
use of com.google.gerrit.extensions.common.PluginDefinedInfo in project gerrit by GerritCodeReview.
the class PluginDefinedAttributesFactories method tryCreate.
private static void tryCreate(Collection<ChangeData> cds, BeanProvider beanProvider, String plugin, ChangePluginDefinedInfoFactory infoFactory, ImmutableListMultimap.Builder<Change.Id, PluginDefinedInfo> pluginInfosByChangeBuilder) {
try {
infoFactory.createPluginDefinedInfos(cds, beanProvider, plugin).forEach((id, pdi) -> {
if (pdi != null) {
pdi.name = plugin;
pluginInfosByChangeBuilder.put(id, pdi);
}
});
} catch (RuntimeException ex) {
/* Propagate runtime exceptions as structured API data types so that queries don't fail. */
logger.atWarning().atMostEvery(1, MINUTES).withCause(ex).log("error populating attribute on changes from plugin %s", plugin);
PluginDefinedInfo errorInfo = new PluginDefinedInfo();
errorInfo.name = plugin;
errorInfo.message = "Something went wrong in plugin: " + plugin;
cds.forEach(cd -> pluginInfosByChangeBuilder.put(cd.getId(), errorInfo));
}
}
use of com.google.gerrit.extensions.common.PluginDefinedInfo in project gerrit by GerritCodeReview.
the class ChangeJson method toChangeInfoImpl.
private ChangeInfo toChangeInfoImpl(ChangeData cd, Optional<PatchSet.Id> limitToPsId, List<PluginDefinedInfo> pluginInfos) throws PatchListNotAvailableException, GpgException, PermissionBackendException, IOException {
ChangeInfo out = new ChangeInfo();
CurrentUser user = userProvider.get();
if (has(CHECK)) {
out.problems = checkerProvider.get().check(cd.notes(), fix).problems();
// If any problems were fixed, the ChangeData needs to be reloaded.
for (ProblemInfo p : out.problems) {
if (p.status == ProblemInfo.Status.FIXED) {
cd = changeDataFactory.create(cd.project(), cd.getId());
break;
}
}
}
Change in = cd.change();
out.project = in.getProject().get();
out.branch = in.getDest().shortName();
out.topic = in.getTopic();
if (!cd.attentionSet().isEmpty()) {
out.removedFromAttentionSet = removalsOnly(cd.attentionSet()).stream().collect(toImmutableMap(a -> a.account().get(), a -> AttentionSetUtil.createAttentionSetInfo(a, accountLoader)));
out.attentionSet = // This filtering should match GetAttentionSet.
additionsOnly(cd.attentionSet()).stream().collect(toImmutableMap(a -> a.account().get(), a -> AttentionSetUtil.createAttentionSetInfo(a, accountLoader)));
}
out.assignee = in.getAssignee() != null ? accountLoader.get(in.getAssignee()) : null;
out.hashtags = cd.hashtags();
out.changeId = in.getKey().get();
if (in.isNew()) {
SubmitTypeRecord str = cd.submitTypeRecord();
if (str.isOk()) {
out.submitType = str.type;
}
if (includeMergeable) {
out.mergeable = cd.isMergeable();
}
if (has(SUBMITTABLE)) {
out.submittable = submittable(cd);
}
}
if (!has(SKIP_DIFFSTAT)) {
Optional<ChangedLines> changedLines = cd.changedLines();
if (changedLines.isPresent()) {
out.insertions = changedLines.get().insertions;
out.deletions = changedLines.get().deletions;
}
}
out.isPrivate = in.isPrivate() ? true : null;
out.workInProgress = in.isWorkInProgress() ? true : null;
out.hasReviewStarted = in.hasReviewStarted();
out.subject = in.getSubject();
out.status = in.getStatus().asChangeStatus();
out.owner = accountLoader.get(in.getOwner());
out.setCreated(in.getCreatedOn());
out.setUpdated(in.getLastUpdatedOn());
out._number = in.getId().get();
out.totalCommentCount = cd.totalCommentCount();
out.unresolvedCommentCount = cd.unresolvedCommentCount();
if (cd.getRefStates() != null) {
String metaName = RefNames.changeMetaRef(cd.getId());
Optional<RefState> metaState = cd.getRefStates().values().stream().filter(r -> r.ref().equals(metaName)).findAny();
// metaState should always be there, but it doesn't hurt to be extra careful.
metaState.ifPresent(rs -> out.metaRevId = rs.id().getName());
}
if (user.isIdentifiedUser()) {
Collection<String> stars = cd.stars(user.getAccountId());
out.starred = stars.contains(StarredChangesUtil.DEFAULT_LABEL) ? true : null;
if (!stars.isEmpty()) {
out.stars = stars;
}
}
if (in.isNew() && has(REVIEWED) && user.isIdentifiedUser()) {
out.reviewed = cd.isReviewedBy(user.getAccountId()) ? true : null;
}
out.labels = labelsJson.labelsFor(accountLoader, cd, has(LABELS), has(DETAILED_LABELS));
out.requirements = requirementsFor(cd);
out.submitRecords = submitRecordsFor(cd);
if (has(SUBMIT_REQUIREMENTS)) {
out.submitRequirements = submitRequirementsFor(cd);
}
if (out.labels != null && has(DETAILED_LABELS)) {
// list permitted labels, since users can't vote on those patch sets.
if (user.isIdentifiedUser() && (!limitToPsId.isPresent() || limitToPsId.get().equals(in.currentPatchSetId()))) {
out.permittedLabels = !cd.change().isAbandoned() ? labelsJson.permittedLabels(user.getAccountId(), cd) : ImmutableMap.of();
}
}
if (has(LABELS) || has(DETAILED_LABELS)) {
out.reviewers = reviewerMap(cd.reviewers(), cd.reviewersByEmail(), false);
out.pendingReviewers = reviewerMap(cd.pendingReviewers(), cd.pendingReviewersByEmail(), true);
out.removableReviewers = removableReviewers(cd, out);
}
setSubmitter(cd, out);
if (!pluginInfos.isEmpty()) {
out.plugins = pluginInfos;
}
out.revertOf = cd.change().getRevertOf() != null ? cd.change().getRevertOf().get() : null;
out.submissionId = cd.change().getSubmissionId();
out.cherryPickOfChange = cd.change().getCherryPickOf() != null ? cd.change().getCherryPickOf().changeId().get() : null;
out.cherryPickOfPatchSet = cd.change().getCherryPickOf() != null ? cd.change().getCherryPickOf().get() : null;
if (has(REVIEWER_UPDATES)) {
out.reviewerUpdates = reviewerUpdates(cd);
}
boolean needMessages = has(MESSAGES);
boolean needRevisions = has(ALL_REVISIONS) || has(CURRENT_REVISION) || limitToPsId.isPresent();
Map<PatchSet.Id, PatchSet> src;
if (needMessages || needRevisions) {
src = loadPatchSets(cd, limitToPsId);
} else {
src = null;
}
if (needMessages) {
out.messages = messages(cd);
}
finish(out);
// it will be passed to ActionVisitors as-is.
if (needRevisions) {
out.revisions = revisionJson.getRevisions(accountLoader, cd, src, limitToPsId, out);
if (out.revisions != null) {
for (Map.Entry<String, RevisionInfo> entry : out.revisions.entrySet()) {
if (entry.getValue().isCurrent) {
out.currentRevision = entry.getKey();
break;
}
}
}
}
if (has(CURRENT_ACTIONS) || has(CHANGE_ACTIONS)) {
actionJson.addChangeActions(out, cd);
}
if (has(TRACKING_IDS)) {
ListMultimap<String, String> set = trackingFooters.extract(cd.commitFooters());
out.trackingIds = set.entries().stream().map(e -> new TrackingIdInfo(e.getKey(), e.getValue())).collect(toList());
}
return out;
}
use of com.google.gerrit.extensions.common.PluginDefinedInfo in project gerrit by GerritCodeReview.
the class ChangeJson method format.
public List<ChangeInfo> format(Collection<ChangeData> in) throws PermissionBackendException {
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
ensureLoaded(in);
List<ChangeInfo> out = new ArrayList<>(in.size());
ImmutableListMultimap<Change.Id, PluginDefinedInfo> pluginInfosByChange = getPluginInfos(in);
for (ChangeData cd : in) {
out.add(format(cd, Optional.empty(), false, pluginInfosByChange.get(cd.getId())));
}
accountLoader.fill();
return out;
}
Aggregations