/** * Returns the file that records the last/current polling activity. */ public File getLogFile() { return new File(job.getRootDir(),"scm-polling.log"); }
/** * The file we save our configuration. */ public static XmlFile getConfigFile(Item item) { return getConfigFile(item.getRootDir()); }
private File expandVariablesForDirectory(String base, Item item) { return new File(expandVariablesForDirectory(base, item.getFullName(), item.getRootDir().getPath())); }
@Override public void onLocationChanged(Item item, String oldFullName, String newFullName) { final Jenkins jenkins = Jenkins.getInstance(); if (!jenkins.isDefaultBuildDir() && item instanceof Job) { File newBuildDir = ((Job)item).getBuildDir(); try { if (!Util.isDescendant(item.getRootDir(), newBuildDir)) { //OK builds are stored somewhere outside of the item's root, so none of the other move operations has probably moved it. //So let's try even though we lack some information String oldBuildsDir = Jenkins.expandVariablesForDirectory(jenkins.getRawBuildsDir(), oldFullName, "<NOPE>"); if (oldBuildsDir.contains("<NOPE>")) { LOGGER.severe(String.format("Builds directory for job %1$s appears to be outside of item root," + " but somehow still containing the item root path, which is unknown. Cannot move builds from %2$s to %1$s.", newFullName, oldFullName)); } else { File oldDir = new File(oldBuildsDir); if (oldDir.isDirectory()) { try { FileUtils.moveDirectory(oldDir, newBuildDir); } catch (IOException e) { LOGGER.log(Level.SEVERE, String.format("Failed to move %s to %s", oldBuildsDir, newBuildDir.getAbsolutePath()), e); } } } } } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to inspect " + item.getRootDir() + ". Builds might not be moved.", e); } } } }
/** * Returns the file that records the last/current polling activity. */ public File getLogFile() { return new File(job.getRootDir(),"scm-polling.log"); }
/** * The file we save our configuration. */ public static XmlFile getConfigFile(Item item) { return getConfigFile(item.getRootDir()); }
/** * The file we save our configuration. */ public static XmlFile getConfigFile(Item item) { return getConfigFile(item.getRootDir()); } /**
/** * The file we save our configuration. */ public static XmlFile getConfigFile(Item item) { return getConfigFile(item.getRootDir()); }
/** * The file we save our configuration. */ public static XmlFile getConfigFile(Item item) { return getConfigFile(item.getRootDir()); }
/** * The file we save our configuration. */ public static XmlFile getConfigFile(Item item) { return getConfigFile(item.getRootDir()); }
private File expandVariablesForDirectory(String base, Item item) { return new File(expandVariablesForDirectory(base, item.getFullName(), item.getRootDir().getPath())); }
@Override public void notifyItemUpdated(Item item, DslEnvironment dslEnvironment) { LOGGER.log(Level.INFO, String.format("Updating promotions for %s", item.getName())); @SuppressWarnings("unchecked") Set<String> newPromotions = (Set<String>) dslEnvironment.get("processNames"); File dir = new File(item.getRootDir(), "promotions/"); boolean update = false; // Delete removed promotions if (newPromotions != null) { File[] files = dir.listFiles(); if (files != null) { for (File promotion : files) { if (!newPromotions.contains(promotion.getName())) { boolean deleted = promotion.delete(); if(deleted){ LOGGER.log(Level.INFO, String.format("Deleted promotion with name %s for %s", promotion.getName(), item.getName())); update = true; } } } } } // Delegate to create-method this.notifyItemCreated(item, dslEnvironment, update); }
@Override public void onLocationChanged(Item item, String oldFullName, String newFullName) { final Jenkins jenkins = Jenkins.getInstance(); if (!jenkins.isDefaultBuildDir() && item instanceof Job) { File newBuildDir = ((Job)item).getBuildDir(); try { if (!Util.isDescendant(item.getRootDir(), newBuildDir)) { //OK builds are stored somewhere outside of the item's root, so none of the other move operations has probably moved it. //So let's try even though we lack some information String oldBuildsDir = Jenkins.expandVariablesForDirectory(jenkins.getRawBuildsDir(), oldFullName, "<NOPE>"); if (oldBuildsDir.contains("<NOPE>")) { LOGGER.severe(String.format("Builds directory for job %1$s appears to be outside of item root," + " but somehow still containing the item root path, which is unknown. Cannot move builds from %2$s to %1$s.", newFullName, oldFullName)); } else { File oldDir = new File(oldBuildsDir); if (oldDir.isDirectory()) { try { FileUtils.moveDirectory(oldDir, newBuildDir); } catch (IOException e) { LOGGER.log(Level.SEVERE, String.format("Failed to move %s to %s", oldBuildsDir, newBuildDir.getAbsolutePath()), e); } } } } } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to inspect " + item.getRootDir() + ". Builds might not be moved.", e); } } } }
XSTREAM.registerConverter(new ManualConditionConverter(XSTREAM.getMapper(), XSTREAM.getReflectionProvider())); String xml = XSTREAM.toXML(promotionProcess); File dir = new File(item.getRootDir(), "promotions/" + name); File configXml = Items.getConfigFile(dir).getFile(); boolean created = configXml.getParentFile().mkdirs();
oldDir = new File (item.getRootDir().getParentFile(), oldSimpleName); } else if (oldParent instanceof DirectlyModifiableTopLevelItemGroup && item instanceof TopLevelItem) { oldDir = ((DirectlyModifiableTopLevelItemGroup) oldParent).getRootDirFor((TopLevelItem) item); oldStrategy = plugin.getStrategyForDeletedSaveable(item, JenkinsFilesHelper.buildPathRelativeToHudsonRoot(oldDir), true); File newDir = item.getRootDir(); ScmSyncStrategy newStrategy = plugin.getStrategyForSaveable(item, newDir); ScmTransaction transaction = plugin.getTransaction();
@Override public void onDeleted(Item item) { super.onDeleted(item); ScmSyncConfigurationPlugin plugin = ScmSyncConfigurationPlugin.getInstance(); if(plugin != null){ String path = JenkinsFilesHelper.buildPathRelativeToHudsonRoot(item.getRootDir()); ScmSyncStrategy strategy = plugin.getStrategyForDeletedSaveable(item, path, true); if (strategy != null) { WeightedMessage message = strategy.getCommitMessageFactory().getMessageWhenItemDeleted(item); ScmTransaction transaction = plugin.getTransaction(); transaction.defineCommitMessage(message); transaction.registerPathForDeletion(path); } } }