From 912573b56f313f0c7927747191e78ee19a50c6c5 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Thu, 1 Feb 2024 16:08:45 +0100 Subject: [PATCH] Dependency upgrade process Fixes #515 --- parent-pom/pom.xml | 6 ++++ .../dependencyupdate/ChangesFileUpdater.java | 16 +++++++++ .../dependencyupdate/DependencyUpdater.java | 36 ++++++++++++++----- .../ProjectVersionIncrementor.java | 9 ++--- 4 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/ChangesFileUpdater.java diff --git a/parent-pom/pom.xml b/parent-pom/pom.xml index 6993b74f..c61362f7 100644 --- a/parent-pom/pom.xml +++ b/parent-pom/pom.xml @@ -214,6 +214,12 @@ 1.4.8 test + + org.itsallcode + hamcrest-auto-matcher + 0.6.0 + test + diff --git a/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/ChangesFileUpdater.java b/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/ChangesFileUpdater.java new file mode 100644 index 00000000..e8c2667e --- /dev/null +++ b/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/ChangesFileUpdater.java @@ -0,0 +1,16 @@ +package com.exasol.projectkeeper.dependencyupdate; + +import com.exasol.projectkeeper.validators.changesfile.ChangesFile; +import com.exasol.projectkeeper.validators.changesfile.ChangesFile.Builder; + +class ChangesFileUpdater { + ChangesFile update(final ChangesFile changesFile) { + final Builder builder = changesFile.toBuilder(); + update(builder); + return builder.build(); + } + + private void update(final Builder builder) { + + } +} diff --git a/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/DependencyUpdater.java b/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/DependencyUpdater.java index 72345744..aec19dd7 100644 --- a/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/DependencyUpdater.java +++ b/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/DependencyUpdater.java @@ -8,6 +8,8 @@ import com.exasol.projectkeeper.ProjectKeeper; import com.exasol.projectkeeper.shared.config.ProjectKeeperConfig; import com.exasol.projectkeeper.sources.analyze.generic.MavenProcessBuilder; +import com.exasol.projectkeeper.validators.changesfile.ChangesFile; +import com.exasol.projectkeeper.validators.changesfile.ChangesFileIO; /** * This class runs the dependency update process. @@ -19,13 +21,20 @@ public class DependencyUpdater { private final Logger logger; private final Path projectDir; private final ProjectVersionIncrementor projectVersionIncrementor; + private final ChangesFileIO changesFileIO; + private final String currentProjectVersion; + private final ChangesFileUpdater changesFileUpdater; DependencyUpdater(final ProjectKeeper projectKeeper, final Logger logger, final Path projectDir, - final ProjectVersionIncrementor projectVersionIncrementor) { + final String currentProjectVersion, final ProjectVersionIncrementor projectVersionIncrementor, + final ChangesFileIO changesFileIO, final ChangesFileUpdater changesFileUpdater) { this.projectKeeper = projectKeeper; this.logger = logger; this.projectDir = projectDir; + this.currentProjectVersion = currentProjectVersion; this.projectVersionIncrementor = projectVersionIncrementor; + this.changesFileIO = changesFileIO; + this.changesFileUpdater = changesFileUpdater; } /** @@ -40,8 +49,9 @@ public class DependencyUpdater { */ public static DependencyUpdater create(final ProjectKeeper projectKeeper, final ProjectKeeperConfig config, final Logger logger, final Path projectDir, final String currentProjectVersion) { - return new DependencyUpdater(projectKeeper, logger, projectDir, - new ProjectVersionIncrementor(config, logger, projectDir, currentProjectVersion)); + return new DependencyUpdater(projectKeeper, logger, projectDir, currentProjectVersion, + new ProjectVersionIncrementor(config, logger, projectDir, currentProjectVersion), new ChangesFileIO(), + new ChangesFileUpdater()); } /** @@ -56,19 +66,20 @@ public static DependencyUpdater create(final ProjectKeeper projectKeeper, final * @return {@code true} if the process succeeded. */ public boolean updateDependencies() { - incrementProjectVersion(); + final String version = incrementProjectVersion(); updateDependencyVersions(); runProjectKeeperFix(); - updateChangelog(); + updateChangelog(version); return true; } - private void incrementProjectVersion() { + private String incrementProjectVersion() { if (projectVersionIncrementor.isCurrentVersionReleased()) { logger.info("Current version was already released: increment version"); - projectVersionIncrementor.incrementProjectVersion(); + return projectVersionIncrementor.incrementProjectVersion(); } else { logger.info("Current version was not yet released: no need to increment"); + return currentProjectVersion; } } @@ -91,7 +102,14 @@ private void runProjectKeeperFix() { } } - private void updateChangelog() { - // TODO Auto-generated method stub + private void updateChangelog(final String version) { + final Path changesFilePath = getChangesFilePath(version); + final ChangesFile changesFile = changesFileIO.read(changesFilePath); + final ChangesFile updatedChanges = changesFileUpdater.update(changesFile); + changesFileIO.write(updatedChanges, changesFilePath); + } + + private Path getChangesFilePath(final String version) { + return projectDir.resolve(ChangesFile.getPathForVersion(version)); } } diff --git a/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/ProjectVersionIncrementor.java b/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/ProjectVersionIncrementor.java index 27d0209a..95f2f383 100644 --- a/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/ProjectVersionIncrementor.java +++ b/project-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/ProjectVersionIncrementor.java @@ -74,18 +74,18 @@ private LocalDate today() { return LocalDate.ofInstant(clock.instant(), UTC_ZONE); } - void incrementProjectVersion() { - + String incrementProjectVersion() { final Model pom = readPom(); if (!this.currentProjectVersion.equals(pom.getVersion())) { throw new IllegalStateException(ExaError.messageBuilder("E-PK-CORE-174").message( "Inconsistent project version {{version in pom file}} found in pom {{pom file path}}, expected {{expected version}}", pom.getVersion(), pom.getPomFile(), currentProjectVersion).ticketMitigation().toString()); } - incrementVersion(pom); + final String nextVersion = incrementVersion(pom); if (usesReferenceCheckerPlugin()) { updateReferences(); } + return nextVersion; } private boolean usesReferenceCheckerPlugin() { @@ -98,12 +98,13 @@ private void updateReferences() { .startSimpleProcess().waitUntilFinished(Duration.ofSeconds(30)); } - private void incrementVersion(final Model pom) { + private String incrementVersion(final Model pom) { final String nextVersion = getIncrementedVersion(currentProjectVersion); logger.info("Incrementing version from " + currentProjectVersion + " to " + nextVersion + " in POM " + pom.getPomFile()); pom.setVersion(nextVersion); writePom(pom); + return nextVersion; } static String getIncrementedVersion(final String version) {