Refine search
/** * {@link NodeMonitor}s are persisted in this file. */ private static XmlFile getConfigFile() { return new XmlFile(new File(Jenkins.getInstance().getRootDir(),"nodeMonitors.xml")); }
/** * {@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); } }
@Override public synchronized void load() { // for backward compatibility, if we don't have our own data yet, then // load from Mailer. XmlFile file = getConfigFile(); if(!file.exists()) { XStream2 xs = new XStream2(); xs.addCompatibilityAlias("hudson.tasks.Mailer$DescriptorImpl",JenkinsLocationConfiguration.class); file = new XmlFile(xs,new File(Jenkins.get().getRootDir(),"hudson.tasks.Mailer.xml")); if (file.exists()) { try { file.unmarshal(this); if (jenkinsUrl==null) jenkinsUrl = hudsonUrl; } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to load "+file, e); } } } else { super.load(); } updateSecureSessionFlag(); }
private void loadConfig() throws IOException { XmlFile cfg = getConfigFile(); if (cfg.exists()) { // reset some data that may not exist in the disk file // so that we can take a proper compensation action later. primaryView = null; views.clear(); // load from disk cfg.unmarshal(Jenkins.this); } try { checkRawBuildsDir(buildsDir); setBuildsAndWorkspacesDir(); } catch (InvalidBuildsDir invalidBuildsDir) { throw new IOException(invalidBuildsDir); } }
try (BufferedReader in = Files.newBufferedReader(Util.fileToPath(queueFile), Charset.defaultCharset())) { String line; while ((line = in.readLine()) != null) { AbstractProject j = Jenkins.getInstance().getItemByFullName(line, AbstractProject.class); if (j != null) j.scheduleBuild(); queueFile = getXMLQueueFile(); if (queueFile.exists()) { Object unmarshaledObj = new XmlFile(XSTREAM, queueFile).read(); List items;
/*package*/ XmlFile getConfigFile() { return new XmlFile(XSTREAM, new File(Jenkins.getInstance().root, "labels/"+name+".xml")); }
checkPermission(CONFIGURE); XmlFile configXmlFile = getConfigFile(); final AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile()); try { try { Object o = new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshalNullingOut(this); if (o!=this) { Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable<Void,IOException>() { @Override public Void call() throws IOException { onLoad(getParent(), getRootDir().getName()); Jenkins.getInstance().rebuildDependencyGraphAsync(); SaveableListener.fireOnChange(this, getConfigFile());
public synchronized TopLevelItem createProjectFromXML(String name, InputStream xml) throws IOException { acl.checkPermission(Item.CREATE); Jenkins.getInstance().getProjectNamingStrategy().checkName(name); Items.verifyItemDoesNotAlreadyExist(parent, name, null); File configXml = Items.getConfigFile(getRootDirFor(name)).getFile(); final File dir = configXml.getParentFile(); dir.mkdirs(); TopLevelItem result = Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable<TopLevelItem,IOException>() { @Override public TopLevelItem call() throws IOException { return (TopLevelItem) Items.load(parent, dir); success = acl.getACL().hasCreatePermission(Jenkins.getAuthentication(), parent, result.getDescriptor()) && result.getDescriptor().isApplicableIn(parent); if (!success) { Util.deleteRecursive(dir);
acl.checkPermission(Item.CREATE); src.checkPermission(Item.EXTENDED_READ); XmlFile srcConfigFile = Items.getConfigFile(src); if (!src.hasPermission(Item.CONFIGURE)) { Matcher matcher = AbstractItem.SECRET_PATTERN.matcher(srcConfigFile.asString()); while (matcher.find()) { if (Secret.decrypt(matcher.group(1)) != null) { throw new AccessDeniedException(Messages.ItemGroupMixIn_may_not_copy_as_it_contains_secrets_and_(src.getFullName(), Jenkins.getAuthentication().getName(), Item.PERMISSIONS.title, Item.EXTENDED_READ.name, Item.CONFIGURE.name)); Files.copy(Util.fileToPath(srcConfigFile.getFile()), Util.fileToPath(Items.getConfigFile(result).getFile()), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); result = Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable<T,IOException>() { @Override public T call() throws IOException { return (T) Items.load(parent, rootDir); Jenkins.getInstance().rebuildDependencyGraphAsync();
/** * Reloads this job from the disk. * * Exposed through CLI as well. * * TODO: think about exposing this to UI * * @since 1.556 */ @RequirePOST public void doReload() throws IOException { checkPermission(CONFIGURE); // try to reflect the changes by reloading getConfigFile().unmarshal(this); Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable<Void, IOException>() { @Override public Void call() throws IOException { onLoad(getParent(), getRootDir().getName()); return null; } }); Jenkins.getInstance().rebuildDependencyGraphAsync(); SaveableListener.fireOnChange(this, getConfigFile()); }
public void save() throws IOException { if(BulkChange.contains(this)) return; XmlFile config = getXmlFile(); config.write(this); SaveableListener.fireOnChange(this, config); }
/** * 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); } jenkins.getQueue().scheduleMaintenance(); }
/** @see ItemGroupMixIn#createProjectFromXML */ public PromotionProcess createProcessFromXml(final String name, InputStream xml) throws IOException { owner.checkPermission(Item.CONFIGURE); // CREATE is ItemGroup-scoped and owner is not an ItemGroup Jenkins.getInstance().getProjectNamingStrategy().checkName(name); if (getItem(name) != null) { throw new IllegalArgumentException(owner.getDisplayName() + " already contains an item '" + name + "'"); } File configXml = Items.getConfigFile(getRootDirFor(name)).getFile(); File dir = configXml.getParentFile(); if (!dir.mkdirs()) { throw new IOException("Cannot create directories for "+dir); } try { IOUtils.copy(xml, configXml); PromotionProcess result = Items.whileUpdatingByXml(new MasterToSlaveCallable<PromotionProcess, IOException>() { @Override public PromotionProcess call() throws IOException { setOwner(owner); return getItem(name); } }); if (result == null) { throw new IOException("failed to load from " + configXml); } ItemListener.fireOnCreated(result); return result; } catch (IOException e) { Util.deleteRecursive(dir); throw e; } }
/** * The file we save our configuration. */ private static @Nonnull XmlFile getConfigFile(@Nonnull File file) { return new XmlFile(XSTREAM,file); }
public synchronized TopLevelItem createProjectFromXML(String name, InputStream xml) throws IOException { acl.checkPermission(Job.CREATE); // place it as config.xml File configXml = Items.getConfigFile(getRootDirFor(name)).getFile(); configXml.getParentFile().mkdirs(); try { IOUtils.copy(xml,configXml); // load it TopLevelItem result = (TopLevelItem)Items.load(parent,configXml.getParentFile()); add(result); ItemListener.fireOnCreated(result); Hudson.getInstance().rebuildDependencyGraph(); return result; } catch (IOException e) { // if anything fails, delete the config file to avoid further confusion Util.deleteRecursive(configXml.getParentFile()); throw e; } }