private boolean updateExistingItem(AbstractItem item, String config) { boolean created; // Leverage XMLUnit to perform diffs Diff diff; try { String oldJob = item.getConfigFile().asString(); diff = XMLUnit.compareXML(oldJob, config); if (diff.similar()) { LOGGER.log(Level.FINE, format("Item %s is identical", item.getName())); return false; } } catch (Exception e) { // It's not a big deal if we can't diff, we'll just move on LOGGER.warning(e.getMessage()); } LOGGER.log(Level.FINE, format("Updating item %s as %s", item.getName(), config)); Source streamSource = new StreamSource(new StringReader(config)); try { item.updateByXml(streamSource); created = true; } catch (IOException e) { LOGGER.log(Level.WARNING, format("Error writing updated item to file."), e); created = false; } return created; }
private String lookupJob(String path) throws IOException { LOGGER.log(Level.FINE, format("Looking up item %s", path)); AbstractItem item = lookupStrategy.getItem(build.getProject(), path, AbstractItem.class); if (item != null) { XmlFile xmlFile = item.getConfigFile(); String jobXml = xmlFile.asString(); LOGGER.log(Level.FINE, format("Looked up item with config %s", jobXml)); return jobXml; } else { LOGGER.log(Level.WARNING, format("No item called %s could be found.", path)); throw new IOException(format("No item called %s could be found.", path)); } }