use of hudson.BulkChange in project branch-api-plugin by jenkinsci.
the class BasicBranchProjectFactory method setBranch.
@Override
public FreeStyleProject setBranch(FreeStyleProject project, Branch branch) {
BulkChange bc = new BulkChange(project);
try {
BasicBranchProperty prop = project.getProperty(BasicBranchProperty.class);
if (prop == null) {
project.addProperty(new BasicBranchProperty(branch));
} else {
prop.setBranch(branch);
}
assert project.getProperty(BasicBranchProperty.class).getBranch().equals(branch);
if (branch instanceof Branch.Dead) {
if (!project.isDisabled()) {
project.disable();
}
} else {
if (project.isDisabled()) {
project.enable();
}
}
bc.commit();
} catch (IOException e) {
e.printStackTrace();
} finally {
bc.abort();
}
return project;
}
use of hudson.BulkChange in project branch-api-plugin by jenkinsci.
the class BranchProjectFactory method decorate.
/**
* Decorates the project in with all the {@link JobDecorator} instances.
* NOTE: This method should suppress saving the project and only affect the in-memory state.
* NOTE: Override if the default strategy is not appropriate for the specific project type.
*
* @param project the project.
* @return the project for nicer method chaining
*/
@SuppressWarnings({ "ConstantConditions", "unchecked" })
public P decorate(P project) {
if (!isProject(project)) {
return project;
}
Branch branch = getBranch(project);
// HACK ALERT
// ==========
// We don't want to trigger a save, so we will do some trickery to inject the new values
// it would be better if Core gave us some hooks to do this
BulkChange bc = new BulkChange(project);
try {
List<BranchProperty> properties = new ArrayList<>(branch.getProperties());
Collections.sort(properties, DescriptorOrder.reverse(BranchProperty.class));
for (BranchProperty property : properties) {
JobDecorator<P, R> decorator = property.jobDecorator((Class) project.getClass());
if (decorator != null) {
// if Project then we can feed the publishers and build wrappers
if (project instanceof Project && decorator instanceof ProjectDecorator) {
DescribableList<Publisher, Descriptor<Publisher>> publishersList = ((Project) project).getPublishersList();
DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappersList = ((Project) project).getBuildWrappersList();
List<Publisher> publishers = ((ProjectDecorator) decorator).publishers(publishersList.toList());
List<BuildWrapper> buildWrappers = ((ProjectDecorator) decorator).buildWrappers(buildWrappersList.toList());
publishersList.replaceBy(publishers);
buildWrappersList.replaceBy(buildWrappers);
}
// we can always feed the job properties... but just not as easily as we'd like
List<JobProperty<? super P>> jobProperties = decorator.jobProperties(project.getAllProperties());
// both removal and addition
for (JobProperty<? super P> p : project.getAllProperties()) {
project.removeProperty(p);
}
for (JobProperty<? super P> p : jobProperties) {
project.addProperty(p);
}
// now apply the final layer
decorator.project(project);
}
}
} catch (IOException e) {
// should be safe to ignore as the BulkChange suppresses the save operation.
} finally {
bc.abort();
}
return project;
}
use of hudson.BulkChange in project kubernetes-plugin by jenkinsci.
the class AbstractInvisibleRunAction2 method push.
protected static void push(@NonNull Run<?, ?> run, @NonNull Class<? extends AbstractInvisibleRunAction2> clazz, @NonNull String item) throws IOException {
synchronized (run) {
BulkChange bc = new BulkChange(run);
try {
AbstractInvisibleRunAction2 action = run.getAction(clazz);
if (action == null) {
action = clazz.newInstance();
run.addAction(action);
}
LOGGER.log(Level.FINEST, "Pushing item {0} to action {1} in run {2}", new Object[] { item, action, run });
action.stack.push(item);
bc.commit();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Can not instantiate class " + clazz, e);
} finally {
bc.abort();
}
}
}
use of hudson.BulkChange in project kubernetes-plugin by jenkinsci.
the class NamespaceAction method push.
@Deprecated
public void push(String namespace) throws IOException {
if (run == null) {
LOGGER.warning("run is null, cannot push");
return;
}
synchronized (run) {
BulkChange bc = new BulkChange(run);
try {
NamespaceAction action = run.getAction(NamespaceAction.class);
if (action == null) {
action = new NamespaceAction(run);
run.addAction(action);
}
action.stack.push(namespace);
bc.commit();
} finally {
bc.abort();
}
}
}
use of hudson.BulkChange in project kubernetes-plugin by jenkinsci.
the class PodTemplateAction method push.
@Deprecated
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
public void push(String template) throws IOException {
if (run == null) {
LOGGER.warning("run is null, cannot push");
return;
}
synchronized (run) {
BulkChange bc = new BulkChange(run);
try {
PodTemplateAction action = run.getAction(PodTemplateAction.class);
if (action == null) {
action = new PodTemplateAction(run);
run.addAction(action);
}
action.stack.push(template);
bc.commit();
} finally {
bc.abort();
}
}
}
Aggregations