@Test public void testVersionReplacement() throws Exception { File outDir = Tests.copyPackageSources(getClass()); LOG.info("Updating poms in " + outDir); File[] files = outDir.listFiles(); assertNotNull("No output files!", files); assertTrue("No output files!", files.length > 0); List<PomUpdateStatus> pomsToChange = new ArrayList<>(); for (File file : files) { try { PomUpdateStatus pomUpdateStatus = PomUpdateStatus.createPomUpdateStatus(file); pomUpdateStatus.setRootPom(true); pomsToChange.add(pomUpdateStatus); } catch (Exception e) { fail("Failed to parse " + file, e); } } Map<String, String> propertyVersions = new HashMap<>(); propertyVersions.put("assertj.version", assertJVersion); propertyVersions.put("fabric8.maven.plugin.version", fmpVersion); propertyVersions.put("fabric8.version", fabric8Version); propertyVersions.put("spring-boot.version", springBootVersion); List<DependencyVersionChange> changes = new ArrayList<>(); changes.add(new MavenDependencyVersionChange("io.fabric8:fabric8-maven-plugin", fmpVersion, MavenScopes.PLUGIN, true, ElementProcessors.createFabric8MavenPluginElementProcessor())); changes.add(new DependencyVersionChange(Kind.MAVEN, "org.assertj:assertj-core", assertJVersion, MavenScopes.ARTIFACT)); changes.add(new DependencyVersionChange(Kind.MAVEN, "io.fabric8:fabric8-project-bom-with-platform-deps", fabric8Version, MavenScopes.ARTIFACT)); changes.add(new DependencyVersionChange(Kind.MAVEN, "org.springframework.boot:spring-boot-dependencies", springBootVersion, MavenScopes.ARTIFACT)); PomHelper.updatePomVersions(pomsToChange, changes); for (File file : files) { Document doc; try { doc = parseXmlFile(file); } catch (Exception e) { fail("Failed to parse " + file + " due to " + e, e); continue; } assertPropertiesValid(file, doc, propertyVersions); assertChangesValid(file, doc, changes); } }
public static boolean updatePomVersions(List<PomUpdateStatus> pomsToChange, List<DependencyVersionChange> changes) throws IOException { Map<String, String> propertyChanges = new TreeMap<>(); for (PomUpdateStatus status : pomsToChange) { status.updateVersions(changes, propertyChanges); } if (!propertyChanges.isEmpty()) { for (PomUpdateStatus status : pomsToChange) { status.updateProperties(propertyChanges); } } boolean answer = false; for (PomUpdateStatus status : pomsToChange) { if (status.saveIfChanged()) { answer = true; } } return answer; }
PomHelper { public static boolean updatePomVersions(List<PomUpdateStatus> pomsToChange, List<DependencyVersionChange> changes) throws IOException { Map<String, String> propertyChanges = new TreeMap<>(); for (PomUpdateStatus status : pomsToChange) { status.updateVersions(changes, propertyChanges); } if (!propertyChanges.isEmpty()) { for (PomUpdateStatus status : pomsToChange) { status.updateProperties(propertyChanges); } } boolean answer = false; for (PomUpdateStatus status : pomsToChange) { if (status.saveIfChanged()) { answer = true; } } return answer; } }
PomHelper { public static boolean updatePomVersions(List<PomUpdateStatus> pomsToChange, List<DependencyVersionChange> changes) throws IOException { Map<String, String> propertyChanges = new TreeMap<>(); for (PomUpdateStatus status : pomsToChange) { status.updateVersions(changes, propertyChanges); } if (!propertyChanges.isEmpty()) { for (PomUpdateStatus status : pomsToChange) { status.updateProperties(propertyChanges); } } boolean answer = false; for (PomUpdateStatus status : pomsToChange) { if (status.saveIfChanged()) { answer = true; } } return answer; }  }
PomHelper { public static boolean updatePomVersions(List<PomUpdateStatus> pomsToChange, List<DependencyVersionChange> changes) throws IOException { Map<String, String> propertyChanges = new TreeMap<>(); for (PomUpdateStatus status : pomsToChange) { status.updateVersions(changes, propertyChanges); } if (!propertyChanges.isEmpty()) { for (PomUpdateStatus status : pomsToChange) { status.updateProperties(propertyChanges); } } boolean answer = false; for (PomUpdateStatus status : pomsToChange) { if (status.saveIfChanged()) { answer = true; } } return answer; }  static boolean updatePomVersionsInPoms(File dir, List<DependencyVersionChange> changes); static boolean updatePomVersions(List<PomUpdateStatus> pomsToChange, List<DependencyVersionChange> changes); static boolean updatePluginVersion(Document doc, DependencyVersionChange change, Map<String, String> propertyChanges, boolean lazyAdd); static boolean updateDependencyVersion(Document doc, DependencyVersionChange change, Map<String, String> propertyChanges); static boolean updateProperties(Document doc, Map<String, String> propertyChanges); }
PomHelper { public static boolean updatePomVersions(List<PomUpdateStatus> pomsToChange, List<DependencyVersionChange> changes) throws IOException { Map<String, String> propertyChanges = new TreeMap<>(); for (PomUpdateStatus status : pomsToChange) { status.updateVersions(changes, propertyChanges); } if (!propertyChanges.isEmpty()) { for (PomUpdateStatus status : pomsToChange) { status.updateProperties(propertyChanges); } } boolean answer = false; for (PomUpdateStatus status : pomsToChange) { if (status.saveIfChanged()) { answer = true; } } return answer; }  static boolean updatePomVersionsInPoms(File dir, List<DependencyVersionChange> changes); static boolean updatePomVersions(List<PomUpdateStatus> pomsToChange, List<DependencyVersionChange> changes); static boolean updatePluginVersion(Document doc, DependencyVersionChange change, Map<String, String> propertyChanges, boolean lazyAdd); static boolean updateDependencyVersion(Document doc, DependencyVersionChange change, Map<String, String> propertyChanges); static boolean updateProperties(Document doc, Map<String, String> propertyChanges);  }