use of hudson.BulkChange in project branch-api-plugin by jenkinsci.
the class OrganizationFolder method computeChildren.
/**
* {@inheritDoc}
*/
@Override
protected void computeChildren(final ChildObserver<MultiBranchProject<?, ?>> observer, final TaskListener listener) throws IOException, InterruptedException {
// capture the current digests to prevent unnecessary rescan if re-saving after scan
try {
navDigest = Util.getDigestOf(Items.XSTREAM2.toXML(navigators));
} catch (XStreamException e) {
navDigest = null;
}
try {
facDigest = Util.getDigestOf(Items.XSTREAM2.toXML(projectFactories));
} catch (XStreamException e) {
facDigest = null;
}
try {
bbsDigest = Util.getDigestOf(Items.XSTREAM2.toXML(buildStrategies));
} catch (XStreamException e) {
bbsDigest = null;
}
long start = System.currentTimeMillis();
listener.getLogger().format("[%tc] Starting organization scan...%n", start);
try {
listener.getLogger().format("[%tc] Updating actions...%n", System.currentTimeMillis());
Map<SCMNavigator, List<Action>> navigatorActions = new HashMap<>();
for (SCMNavigator navigator : navigators) {
List<Action> actions;
try {
actions = navigator.fetchActions(this, null, listener);
} catch (IOException e) {
printStackTrace(e, listener.error("[%tc] Could not refresh actions for navigator %s", System.currentTimeMillis(), navigator));
// preserve previous actions if we have some transient error fetching now (e.g. API rate limit)
actions = Util.fixNull(state.getActions().get(navigator));
}
navigatorActions.put(navigator, actions);
}
// update any persistent actions for the SCMNavigator
if (!navigatorActions.equals(state.getActions())) {
boolean saveProject = false;
for (List<Action> actions : navigatorActions.values()) {
for (Action a : actions) {
// undo any hacks that attached the contributed actions without attribution
saveProject = removeActions(a.getClass()) || saveProject;
}
}
BulkChange bc = new BulkChange(state);
try {
state.setActions(navigatorActions);
try {
bc.commit();
} catch (IOException | RuntimeException e) {
listener.error("[%tc] Could not persist folder level actions", System.currentTimeMillis());
throw e;
}
if (saveProject) {
try {
save();
} catch (IOException | RuntimeException e) {
listener.error("[%tc] Could not persist folder level configuration changes", System.currentTimeMillis());
throw e;
}
}
} finally {
bc.abort();
}
}
for (SCMNavigator navigator : navigators) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
listener.getLogger().format("[%tc] Consulting %s%n", System.currentTimeMillis(), navigator.getDescriptor().getDisplayName());
try {
navigator.visitSources(new SCMSourceObserverImpl(listener, observer, navigator, (SCMSourceEvent<?>) null));
} catch (IOException | InterruptedException | RuntimeException e) {
listener.error("[%tc] Could not fetch sources from navigator %s", System.currentTimeMillis(), navigator);
throw e;
}
}
} finally {
long end = System.currentTimeMillis();
listener.getLogger().format("[%tc] Finished organization scan. Scan took %s%n", end, Util.getTimeSpanString(end - start));
}
}
use of hudson.BulkChange in project branch-api-plugin by jenkinsci.
the class MultiBranchProject method computeChildren.
/**
* {@inheritDoc}
*/
@Override
protected void computeChildren(final ChildObserver<P> observer, final TaskListener listener) throws IOException, InterruptedException {
// capture the current digests to prevent unnecessary reindex if re-saving after index
try {
srcDigest = Util.getDigestOf(Items.XSTREAM2.toXML(sources));
} catch (XStreamException e) {
srcDigest = null;
}
try {
facDigest = Util.getDigestOf(Items.XSTREAM2.toXML(getProjectFactory()));
} catch (XStreamException e) {
facDigest = null;
}
long start = System.currentTimeMillis();
listener.getLogger().format("[%tc] Starting branch indexing...%n", start);
try {
final BranchProjectFactory<P, R> _factory = getProjectFactory();
List<SCMSource> scmSources = getSCMSources();
Map<String, List<Action>> sourceActions = new LinkedHashMap<>();
for (SCMSource source : scmSources) {
try {
sourceActions.put(source.getId(), source.fetchActions(null, listener));
} catch (IOException | InterruptedException | RuntimeException e) {
listener.error("[%tc] Could not update folder level actions from source %s", System.currentTimeMillis(), source.getId());
throw e;
}
}
// update any persistent actions for the SCMSource
if (!sourceActions.equals(state.sourceActions)) {
boolean saveProject = false;
for (List<Action> actions : sourceActions.values()) {
for (Action a : actions) {
// undo any hacks that attached the contributed actions without attribution
saveProject = removeActions(a.getClass()) || saveProject;
}
}
BulkChange bc = new BulkChange(state);
try {
state.sourceActions.keySet().retainAll(sourceActions.keySet());
state.sourceActions.putAll(sourceActions);
try {
bc.commit();
} catch (IOException | RuntimeException e) {
listener.error("[%tc] Could not persist folder level actions", System.currentTimeMillis());
throw e;
}
if (saveProject) {
try {
save();
} catch (IOException | RuntimeException e) {
listener.error("[%tc] Could not persist folder level configuration changes", System.currentTimeMillis());
throw e;
}
}
} finally {
bc.abort();
}
}
for (final SCMSource source : scmSources) {
try {
source.fetch(new SCMHeadObserverImpl(source, observer, listener, _factory, new IndexingCauseFactory(), null), listener);
} catch (IOException | InterruptedException | RuntimeException e) {
listener.error("[%tc] Could not fetch branches from source %s", System.currentTimeMillis(), source.getId());
throw e;
}
}
} finally {
long end = System.currentTimeMillis();
listener.getLogger().format("[%tc] Finished branch indexing. Indexing took %s%n", end, Util.getTimeSpanString(end - start));
}
}
use of hudson.BulkChange in project kubernetes-plugin by jenkinsci.
the class NamespaceAction method pop.
@Deprecated
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
public String pop() throws IOException {
if (run == null) {
LOGGER.warning("run is null, cannot pop");
return null;
}
synchronized (run) {
BulkChange bc = new BulkChange(run);
try {
NamespaceAction action = run.getAction(NamespaceAction.class);
if (action == null) {
action = new NamespaceAction(run);
run.addAction(action);
}
String namespace = action.stack.pop();
bc.commit();
return namespace;
} finally {
bc.abort();
return null;
}
}
}
Aggregations