Exemplo n.º 1
0
    /**
     * 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
        }
    }
Exemplo n.º 2
0
 private void save(File dir) {
   File f = new File(dir, MAP_FILE);
   try {
     AtomicFileWriter w = new AtomicFileWriter(f);
     try {
       for (Map.Entry<String, Integer> entry : idToNumber.entrySet()) {
         w.write(entry.getKey() + ' ' + entry.getValue() + '\n');
       }
       w.commit();
     } finally {
       w.abort();
     }
   } catch (IOException x) {
     LOGGER.log(WARNING, "could not save changes to " + f, x);
   }
 }