use of hudson.model.Saveable in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecution method notifyListeners.
void notifyListeners(List<FlowNode> nodes, boolean synchronous) {
List<GraphListener> toRun = getListenersToRun();
if (!toRun.isEmpty()) {
Saveable s = Saveable.NOOP;
try {
Queue.Executable exec = owner.getExecutable();
if (exec instanceof Saveable) {
s = (Saveable) exec;
}
} catch (IOException x) {
LOGGER.log(Level.WARNING, "failed to notify listeners of changes to " + nodes + " in " + this, x);
}
BulkChange bc = new BulkChange(s);
try {
for (FlowNode node : nodes) {
for (GraphListener listener : toRun) {
if (listener instanceof GraphListener.Synchronous == synchronous) {
listener.onNewHead(node);
}
}
}
} finally {
if (synchronous) {
// hack to skip save—we are holding a lock
bc.abort();
} else {
try {
bc.commit();
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
}
}
}
}
use of hudson.model.Saveable in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecution method saveOwner.
/**
* Save the owner that holds this execution.
*/
void saveOwner() {
try {
if (this.owner.getExecutable() instanceof Saveable) {
Saveable saveable = (Saveable) (this.owner.getExecutable());
saveable.save();
}
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Error persisting Run before shutdown", ex);
persistedClean = false;
}
}
use of hudson.model.Saveable in project hudson-2.x by hudson.
the class OldDataMonitor method doUpgrade.
/**
* Save all or some of the files to persist data in the new forms.
* Remove those items from the data map.
*/
public synchronized HttpResponse doUpgrade(StaplerRequest req, StaplerResponse rsp) throws IOException {
String thruVerParam = req.getParameter("thruVer");
VersionNumber thruVer = thruVerParam.equals("all") ? null : new VersionNumber(thruVerParam);
updating = true;
for (Iterator<Map.Entry<Saveable, VersionRange>> it = data.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<Saveable, VersionRange> entry = it.next();
VersionNumber version = entry.getValue().max;
if (version != null && (thruVer == null || !version.isNewerThan(thruVer))) {
entry.getKey().save();
it.remove();
}
}
updating = false;
return HttpResponses.forwardToPreviousPage();
}
use of hudson.model.Saveable in project hudson-2.x by hudson.
the class XStream2 method unmarshal.
@Override
public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
// init() is too early to do this
// defensive because some use of XStream happens before plugins are initialized.
Hudson h = Hudson.getInstance();
if (h != null && h.pluginManager != null && h.pluginManager.uberClassLoader != null) {
setClassLoader(h.pluginManager.uberClassLoader);
}
Object o = super.unmarshal(reader, root, dataHolder);
if (oldData.get() != null) {
oldData.remove();
if (o instanceof Saveable)
OldDataMonitor.report((Saveable) o, "1.106");
}
return o;
}
use of hudson.model.Saveable in project hudson-2.x by hudson.
the class RobustReflectionConverter method doUnmarshal.
public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) {
final SeenFields seenFields = new SeenFields();
Iterator it = reader.getAttributeNames();
// Remember outermost Saveable encountered, for reporting below
if (result instanceof Saveable && context.get("Saveable") == null)
context.put("Saveable", result);
// Process attributes before recursing into child elements.
while (it.hasNext()) {
String attrAlias = (String) it.next();
String attrName = mapper.attributeForAlias(attrAlias);
Class classDefiningField = determineWhichClassDefinesField(reader);
boolean fieldExistsInClass = fieldDefinedInClass(result, attrName);
if (fieldExistsInClass) {
Field field = reflectionProvider.getField(result.getClass(), attrName);
SingleValueConverter converter = mapper.getConverterFromAttribute(field.getDeclaringClass(), attrName, field.getType());
Class type = field.getType();
if (converter == null) {
converter = mapper.getConverterFromItemType(type);
}
if (converter != null) {
Object value = converter.fromString(reader.getAttribute(attrAlias));
if (type.isPrimitive()) {
type = Primitives.box(type);
}
if (value != null && !type.isAssignableFrom(value.getClass())) {
throw new ConversionException("Cannot convert type " + value.getClass().getName() + " to type " + type.getName());
}
reflectionProvider.writeField(result, attrName, value, classDefiningField);
seenFields.add(classDefiningField, attrName);
}
}
}
Map implicitCollectionsForCurrentObject = null;
while (reader.hasMoreChildren()) {
reader.moveDown();
try {
String fieldName = mapper.realMember(result.getClass(), reader.getNodeName());
boolean implicitCollectionHasSameName = mapper.getImplicitCollectionDefForFieldName(result.getClass(), reader.getNodeName()) != null;
Class classDefiningField = determineWhichClassDefinesField(reader);
boolean fieldExistsInClass = !implicitCollectionHasSameName && fieldDefinedInClass(result, fieldName);
Class type = determineType(reader, fieldExistsInClass, result, fieldName, classDefiningField);
final Object value;
if (fieldExistsInClass) {
Field field = reflectionProvider.getField(result.getClass(), fieldName);
value = unmarshalField(context, result, type, field);
// TODO the reflection provider should have returned the proper field in first place ....
Class definedType = reflectionProvider.getFieldType(result, fieldName, classDefiningField);
if (!definedType.isPrimitive()) {
type = definedType;
}
} else {
value = context.convertAnother(result, type);
}
if (value != null && !type.isAssignableFrom(value.getClass())) {
LOGGER.warning("Cannot convert type " + value.getClass().getName() + " to type " + type.getName());
// behave as if we didn't see this element
} else {
if (fieldExistsInClass) {
reflectionProvider.writeField(result, fieldName, value, classDefiningField);
seenFields.add(classDefiningField, fieldName);
} else {
implicitCollectionsForCurrentObject = writeValueToImplicitCollection(context, value, implicitCollectionsForCurrentObject, result, fieldName);
}
}
} catch (NonExistentFieldException e) {
LOGGER.log(WARNING, "Skipping a non-existent field " + e.getFieldName());
addErrorInContext(context, e);
} catch (CannotResolveClassException e) {
LOGGER.log(WARNING, "Skipping a non-existent type " + e.getMessage());
addErrorInContext(context, e);
} catch (LinkageError e) {
LOGGER.log(WARNING, "Failed to resolve a type " + e.getMessage());
addErrorInContext(context, e);
}
reader.moveUp();
}
// Report any class/field errors in Saveable objects
if (context.get("ReadError") != null && context.get("Saveable") == result) {
OldDataMonitor.report((Saveable) result, (ArrayList<Throwable>) context.get("ReadError"));
context.put("ReadError", null);
}
return result;
}
Aggregations