Skip to content

Commit

Permalink
Dependency upgrade process
Browse files Browse the repository at this point in the history
Fixes #515
  • Loading branch information
kaklakariada committed Feb 1, 2024
1 parent 56ad0d2 commit 912573b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
6 changes: 6 additions & 0 deletions parent-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@
<version>1.4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.itsallcode</groupId>
<artifactId>hamcrest-auto-matcher</artifactId>
<version>0.6.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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;
}
}

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down

0 comments on commit 912573b

Please sign in to comment.