@Test public void snapshotsInDependencies() throws Exception { File pomFile = getResourceAsFile("/poms/snapshots/pom-snapshots-in-dependencies.xml"); Map<ModuleName, String> modules = Maps.newHashMap(); modules.put(new ModuleName("org.jfrog.test.nested", "nested1"), "3.6"); modules.put(new ModuleName("org.jfrog.test.nested", "nested2"), "3.6"); modules.put(new ModuleName("org.jfrog.test.nested", "four"), "3.6"); try { new PomTransformer(new ModuleName("org.jfrog.test.nested", "four"), modules, "", true).transform(pomFile); fail("Pom contains snapshot in the dependencies and should fail"); } catch (SnapshotNotAllowedException e) { String message = e.getMessage(); assertTrue(message.contains("org.jfrog.test.nested:nestedX:3.2-SNAPSHOT"), "Unexpected error message: " + message); } }
public Boolean transform(File pomFile) throws IOException { this.pomFile = pomFile; if (!pomFile.exists()) { throw new IllegalArgumentException("Couldn't find pom file: " + pomFile); } SAXBuilder saxBuilder = createSaxBuilder(); Document document; EolDetectingInputStream eolDetectingStream = null; InputStreamReader inputStreamReader = null; try { eolDetectingStream = new EolDetectingInputStream(new FileInputStream(pomFile)); inputStreamReader = new InputStreamReader(eolDetectingStream, "UTF-8"); document = saxBuilder.build(inputStreamReader); } catch (JDOMException e) { throw new IOException("Failed to parse pom: " + pomFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(inputStreamReader); IOUtils.closeQuietly(eolDetectingStream); } Element rootElement = document.getRootElement(); Namespace ns = rootElement.getNamespace(); getProperties(rootElement, ns); changeParentVersion(rootElement, ns); changeCurrentModuleVersion(rootElement, ns); changeDependencyManagementVersions(rootElement, ns); changeDependencyVersions(rootElement, ns); if (scmUrl != null) { changeScm(rootElement, ns); } if (modified && !dryRun) { FileOutputStream fileOutputStream = new FileOutputStream(pomFile); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); try { XMLOutputter outputter = new XMLOutputter(); String eol = eolDetectingStream.getEol(); if (!"".equals(eol)) { Format format = outputter.getFormat(); format.setLineSeparator(eol); format.setTextMode(Format.TextMode.PRESERVE); outputter.setFormat(format); } outputter.output(document, outputStreamWriter); } finally { IOUtils.closeQuietly(outputStreamWriter); IOUtils.closeQuietly(fileOutputStream); } } return modified; }
PomTransformer { public Boolean transform(File pomFile) throws IOException { this.pomFile = pomFile; if (!pomFile.exists()) { throw new IllegalArgumentException("Couldn't find pom file: " + pomFile); } SAXBuilder saxBuilder = createSaxBuilder(); Document document; EolDetectingInputStream eolDetectingStream = null; InputStreamReader inputStreamReader = null; try { eolDetectingStream = new EolDetectingInputStream(new FileInputStream(pomFile)); inputStreamReader = new InputStreamReader(eolDetectingStream, "UTF-8"); document = saxBuilder.build(inputStreamReader); } catch (JDOMException e) { throw new IOException("Failed to parse pom: " + pomFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(inputStreamReader); IOUtils.closeQuietly(eolDetectingStream); } Element rootElement = document.getRootElement(); Namespace ns = rootElement.getNamespace(); getProperties(rootElement, ns); changeParentVersion(rootElement, ns); changeCurrentModuleVersion(rootElement, ns); changeDependencyManagementVersions(rootElement, ns); changeDependencyVersions(rootElement, ns); if (scmUrl != null) { changeScm(rootElement, ns); } if (modified && !dryRun) { FileOutputStream fileOutputStream = new FileOutputStream(pomFile); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); try { XMLOutputter outputter = new XMLOutputter(); String eol = eolDetectingStream.getEol(); if (!"".equals(eol)) { Format format = outputter.getFormat(); format.setLineSeparator(eol); format.setTextMode(Format.TextMode.PRESERVE); outputter.setFormat(format); } outputter.output(document, outputStreamWriter); } finally { IOUtils.closeQuietly(outputStreamWriter); IOUtils.closeQuietly(fileOutputStream); } } return modified; } }
PomTransformer { public Boolean transform(File pomFile) throws IOException { this.pomFile = pomFile; if (!pomFile.exists()) { throw new IllegalArgumentException("Couldn't find pom file: " + pomFile); } SAXBuilder saxBuilder = createSaxBuilder(); Document document; EolDetectingInputStream eolDetectingStream = null; InputStreamReader inputStreamReader = null; try { eolDetectingStream = new EolDetectingInputStream(new FileInputStream(pomFile)); inputStreamReader = new InputStreamReader(eolDetectingStream, "UTF-8"); document = saxBuilder.build(inputStreamReader); } catch (JDOMException e) { throw new IOException("Failed to parse pom: " + pomFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(inputStreamReader); IOUtils.closeQuietly(eolDetectingStream); } Element rootElement = document.getRootElement(); Namespace ns = rootElement.getNamespace(); getProperties(rootElement, ns); changeParentVersion(rootElement, ns); changeCurrentModuleVersion(rootElement, ns); changeDependencyManagementVersions(rootElement, ns); changeDependencyVersions(rootElement, ns); if (scmUrl != null) { changeScm(rootElement, ns); } if (modified && !dryRun) { FileOutputStream fileOutputStream = new FileOutputStream(pomFile); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); try { XMLOutputter outputter = new XMLOutputter(); String eol = eolDetectingStream.getEol(); if (!"".equals(eol)) { Format format = outputter.getFormat(); format.setLineSeparator(eol); format.setTextMode(Format.TextMode.PRESERVE); outputter.setFormat(format); } outputter.output(document, outputStreamWriter); } finally { IOUtils.closeQuietly(outputStreamWriter); IOUtils.closeQuietly(fileOutputStream); } } return modified; } PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl);  PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl,
                          boolean failOnSnapshot);  PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl,
                          boolean failOnSnapshot, boolean dryRun); }
PomTransformer { public Boolean transform(File pomFile) throws IOException { this.pomFile = pomFile; if (!pomFile.exists()) { throw new IllegalArgumentException("Couldn't find pom file: " + pomFile); } SAXBuilder saxBuilder = createSaxBuilder(); Document document; EolDetectingInputStream eolDetectingStream = null; InputStreamReader inputStreamReader = null; try { eolDetectingStream = new EolDetectingInputStream(new FileInputStream(pomFile)); inputStreamReader = new InputStreamReader(eolDetectingStream, "UTF-8"); document = saxBuilder.build(inputStreamReader); } catch (JDOMException e) { throw new IOException("Failed to parse pom: " + pomFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(inputStreamReader); IOUtils.closeQuietly(eolDetectingStream); } Element rootElement = document.getRootElement(); Namespace ns = rootElement.getNamespace(); getProperties(rootElement, ns); changeParentVersion(rootElement, ns); changeCurrentModuleVersion(rootElement, ns); changeDependencyManagementVersions(rootElement, ns); changeDependencyVersions(rootElement, ns); if (scmUrl != null) { changeScm(rootElement, ns); } if (modified && !dryRun) { FileOutputStream fileOutputStream = new FileOutputStream(pomFile); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); try { XMLOutputter outputter = new XMLOutputter(); String eol = eolDetectingStream.getEol(); if (!"".equals(eol)) { Format format = outputter.getFormat(); format.setLineSeparator(eol); format.setTextMode(Format.TextMode.PRESERVE); outputter.setFormat(format); } outputter.output(document, outputStreamWriter); } finally { IOUtils.closeQuietly(outputStreamWriter); IOUtils.closeQuietly(fileOutputStream); } } return modified; } PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl);  PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl,
                          boolean failOnSnapshot);  PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl,
                          boolean failOnSnapshot, boolean dryRun); Boolean transform(File pomFile); }
PomTransformer { public Boolean transform(File pomFile) throws IOException { this.pomFile = pomFile; if (!pomFile.exists()) { throw new IllegalArgumentException("Couldn't find pom file: " + pomFile); } SAXBuilder saxBuilder = createSaxBuilder(); Document document; EolDetectingInputStream eolDetectingStream = null; InputStreamReader inputStreamReader = null; try { eolDetectingStream = new EolDetectingInputStream(new FileInputStream(pomFile)); inputStreamReader = new InputStreamReader(eolDetectingStream, "UTF-8"); document = saxBuilder.build(inputStreamReader); } catch (JDOMException e) { throw new IOException("Failed to parse pom: " + pomFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(inputStreamReader); IOUtils.closeQuietly(eolDetectingStream); } Element rootElement = document.getRootElement(); Namespace ns = rootElement.getNamespace(); getProperties(rootElement, ns); changeParentVersion(rootElement, ns); changeCurrentModuleVersion(rootElement, ns); changeDependencyManagementVersions(rootElement, ns); changeDependencyVersions(rootElement, ns); if (scmUrl != null) { changeScm(rootElement, ns); } if (modified && !dryRun) { FileOutputStream fileOutputStream = new FileOutputStream(pomFile); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); try { XMLOutputter outputter = new XMLOutputter(); String eol = eolDetectingStream.getEol(); if (!"".equals(eol)) { Format format = outputter.getFormat(); format.setLineSeparator(eol); format.setTextMode(Format.TextMode.PRESERVE); outputter.setFormat(format); } outputter.output(document, outputStreamWriter); } finally { IOUtils.closeQuietly(outputStreamWriter); IOUtils.closeQuietly(fileOutputStream); } } return modified; } PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl);  PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl,
                          boolean failOnSnapshot);  PomTransformer(ModuleName currentModule, Map<ModuleName, String> versionsByModule, String scmUrl,
                          boolean failOnSnapshot, boolean dryRun); Boolean transform(File pomFile);  }