/** {@inheritDoc} */ @Override public void save() throws IOException { if (BulkChange.contains(this)) { return; } final File nodesDir = getNodesDir(); final Set<String> existing = new HashSet<String>(); for (Node n : nodes.values()) { if (n instanceof EphemeralNode) { continue; } existing.add(n.getNodeName()); XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM, new File(new File(nodesDir, n.getNodeName()), "config.xml")); xmlFile.write(n); SaveableListener.fireOnChange(this, xmlFile); } for (File forDeletion : nodesDir.listFiles( new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !existing.contains(pathname.getName()); } })) { Util.deleteRecursive(forDeletion); } }
/** * Updates Job by its XML definition. * @since 1.473 */ public void updateByXml(Source source) throws IOException { checkPermission(CONFIGURE); XmlFile configXmlFile = getConfigFile(); AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile()); try { try { // this allows us to use UTF-8 for storing data, // plus it checks any well-formedness issue in the submitted // data Transformer t = TransformerFactory.newInstance() .newTransformer(); t.transform(source, new StreamResult(out)); out.close(); } catch (TransformerException e) { throw new IOException("Failed to persist config.xml", e); } // try to reflect the changes by reloading new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshal(this); Items.whileUpdatingByXml(new Callable<Void,IOException>() { @Override public Void call() throws IOException { onLoad(getParent(), getRootDir().getName()); return null; } }); Jenkins.getInstance().rebuildDependencyGraphAsync(); // if everything went well, commit this new version out.commit(); SaveableListener.fireOnChange(this, getConfigFile()); } finally { out.abort(); // don't leave anything behind } }
public void save() throws IOException { if (BulkChange.contains(this)) return; try { getConfigFile().write(this); SaveableListener.fireOnChange(this, getConfigFile()); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to save " + getConfigFile(), e); } }
/** * Actually persists a node on disk. * * @param node the node to be persisted. * @throws IOException if the node could not be persisted. */ private void persistNode(final @Nonnull Node node) throws IOException { // no need for a full save() so we just do the minimum if (node instanceof EphemeralNode) { Util.deleteRecursive(new File(getNodesDir(), node.getNodeName())); } else { XmlFile xmlFile = new XmlFile( Jenkins.XSTREAM, new File(new File(getNodesDir(), node.getNodeName()), "config.xml")); xmlFile.write(node); SaveableListener.fireOnChange(this, xmlFile); } }
public synchronized void save() throws IOException { IS_SAVING.set(Boolean.TRUE); try { if (!credentials.isEmpty()) { XmlFile xmlFile = getXmlFile(project); xmlFile.write(this); SaveableListener.fireOnChange(this, xmlFile); } } finally { IS_SAVING.remove(); } }
/** Save the settings to a file. */ public synchronized void save() throws IOException { if (BulkChange.contains(this)) return; long start = 0; if (logger.isLoggable(Level.FINE)) start = System.currentTimeMillis(); File file = getFingerprintFile(md5sum); save(file); SaveableListener.fireOnChange(this, getConfigFile(file)); if (logger.isLoggable(Level.FINE)) logger.fine( "Saving fingerprint " + file + " took " + (System.currentTimeMillis() - start) + "ms"); }
/** Fires the {@link #onChange} event. */ public static void fireOnChange(Saveable o, XmlFile file) { for (SaveableListener l : all()) { l.onChange(o, file); } }
/** Save the settings to a file. */ public synchronized void save() throws IOException { if (BulkChange.contains(this)) return; getConfigFile().write(this); SaveableListener.fireOnChange(this, getConfigFile()); }