-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6029d61
commit 92f7943
Showing
19 changed files
with
616 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...in/src/main/java/com/exasol/projectkeeper/plugin/ProjectKeeperUpdateDependenciesMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.exasol.projectkeeper.plugin; | ||
|
||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
|
||
import com.exasol.projectkeeper.ProjectKeeper; | ||
|
||
/** | ||
* Entry point for the {@code update-dependencies} goal. | ||
* <p> | ||
* Run using {@code mvn project-keeper:update-dependencies} | ||
* </p> | ||
*/ | ||
@Mojo(name = "update-dependencies") | ||
public class ProjectKeeperUpdateDependenciesMojo extends AbstractProjectKeeperMojo { | ||
|
||
@Override | ||
protected void runProjectKeeper(final ProjectKeeper projectKeeper) throws MojoFailureException { | ||
final boolean success = projectKeeper.updateDependencies(); | ||
if (!success) { | ||
throw new MojoFailureException( | ||
"project-keeper:update-dependencies failed. See log messages above for details"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ error-tags: | |
PK-CORE: | ||
packages: | ||
- com.exasol.projectkeeper | ||
highest-index: 170 | ||
highest-index: 174 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ect-keeper/src/main/java/com/exasol/projectkeeper/dependencyupdate/DependencyUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.exasol.projectkeeper.dependencyupdate; | ||
|
||
import java.nio.file.Path; | ||
|
||
import com.exasol.projectkeeper.Logger; | ||
|
||
/** | ||
* This class runs the dependency update process. | ||
*/ | ||
public class DependencyUpdater { | ||
|
||
private final Logger logger; | ||
private final ProjectVersionIncrementor projectVersionIncrementor; | ||
|
||
DependencyUpdater(final Logger logger, final ProjectVersionIncrementor projectVersionIncrementor) { | ||
this.logger = logger; | ||
this.projectVersionIncrementor = projectVersionIncrementor; | ||
|
||
} | ||
|
||
public static DependencyUpdater create(final Logger logger, final Path projectDir, | ||
final String currentProjectVersion) { | ||
return new DependencyUpdater(logger, new ProjectVersionIncrementor(logger, projectDir, currentProjectVersion)); | ||
} | ||
|
||
/** | ||
* Runs the dependency update process. This includes the following steps: | ||
* <ol> | ||
* <li>Increment project patch version if necessary</li> | ||
* <li>Update all dependencies to their latest versions</li> | ||
* <li>Run project-keeper fix</li> | ||
* <li>If available: add information about fixed vulnerabilities to changelog</li> | ||
* </ol> | ||
* | ||
* @return {@code true} if the process succeeded. | ||
*/ | ||
public boolean updateDependencies() { | ||
incrementProjectVersion(); | ||
updateDependencyVersions(); | ||
runProjectKeeperFix(); | ||
updateChangelog(); | ||
return true; | ||
} | ||
|
||
private void incrementProjectVersion() { | ||
if (projectVersionIncrementor.isCurrentVersionReleased()) { | ||
logger.info("Current version was already released: increment version"); | ||
projectVersionIncrementor.incrementProjectVersion(); | ||
} else { | ||
logger.info("Current version was not yet released: no need to increment"); | ||
} | ||
} | ||
|
||
private void updateDependencyVersions() { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
private void runProjectKeeperFix() { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
private void updateChangelog() { | ||
// TODO Auto-generated method stub | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...er/src/main/java/com/exasol/projectkeeper/dependencyupdate/ProjectVersionIncrementor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.exasol.projectkeeper.dependencyupdate; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.*; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.apache.maven.model.Model; | ||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | ||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
|
||
import com.exasol.errorreporting.ExaError; | ||
import com.exasol.projectkeeper.Logger; | ||
import com.exasol.projectkeeper.validators.changesfile.ChangesFile; | ||
import com.exasol.projectkeeper.validators.changesfile.ChangesFileIO; | ||
import com.vdurmont.semver4j.Semver; | ||
|
||
class ProjectVersionIncrementor { | ||
private static final ZoneId UTC_ZONE = ZoneId.of("UTC"); | ||
private final String currentProjectVersion; | ||
private final ChangesFileIO changesFileIO; | ||
private final Clock clock; | ||
private final Path projectDir; | ||
private final Logger logger; | ||
|
||
ProjectVersionIncrementor(final Logger logger, final Path projectDir, final String currentProjectVersion) { | ||
this(logger, projectDir, currentProjectVersion, new ChangesFileIO(), Clock.systemUTC()); | ||
} | ||
|
||
ProjectVersionIncrementor(final Logger logger, final Path projectDir, final String currentProjectVersion, | ||
final ChangesFileIO changesFileIO, final Clock clock) { | ||
this.logger = logger; | ||
this.projectDir = projectDir; | ||
this.changesFileIO = changesFileIO; | ||
this.clock = clock; | ||
this.currentProjectVersion = Objects.requireNonNull(currentProjectVersion, "currentProjectVersion"); | ||
} | ||
|
||
/** | ||
* Check if the current version was released, i.e. has a changelog release date in the past or today. | ||
* | ||
* @return {@code true} if the current version was released (i.e. has a release date) or not (i.e. has no release | ||
* date or a future date) | ||
*/ | ||
boolean isCurrentVersionReleased() { | ||
final Path changesFilePath = projectDir.resolve(ChangesFile.getPathForVersion(currentProjectVersion)); | ||
final ChangesFile changesFile = changesFileIO.read(changesFilePath); | ||
final Optional<LocalDate> releaseDate = changesFile.getParsedReleaseDate(); | ||
if (releaseDate.isEmpty()) { | ||
logger.info("Found invalid date '" + changesFile.getReleaseDate() + "' in changelog " + changesFilePath | ||
+ ": version " + currentProjectVersion + " was not yet released"); | ||
return false; | ||
} | ||
final boolean released = releaseDate.get().isBefore(today()); | ||
if (released) { | ||
logger.info("Version " + currentProjectVersion + " was released on " + changesFile.getReleaseDate() | ||
+ " according to " + changesFilePath); | ||
} | ||
return released; | ||
} | ||
|
||
private LocalDate today() { | ||
return LocalDate.ofInstant(clock.instant(), UTC_ZONE); | ||
} | ||
|
||
void incrementProjectVersion() { | ||
final Path path = getPomPath(); | ||
final Model pom = readPom(path); | ||
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(), path, currentProjectVersion).toString()); | ||
} | ||
final String nextVersion = getIncrementedVersion(currentProjectVersion); | ||
System.out.println("#### Incremeing to " + nextVersion); | ||
logger.info("Incrementing version from " + currentProjectVersion + " to " + nextVersion + " in POM " + path); | ||
pom.setVersion(nextVersion); | ||
writePom(path, pom); | ||
} | ||
|
||
static String getIncrementedVersion(final String version) { | ||
final Semver current = new Semver(version); | ||
return current.nextPatch().toString(); | ||
} | ||
|
||
private Model readPom(final Path path) { | ||
try { | ||
return new MavenXpp3Reader().read(Files.newBufferedReader(path)); | ||
} catch (IOException | XmlPullParserException exception) { | ||
throw new IllegalStateException(ExaError.messageBuilder("E-PK-CORE-172") | ||
.message("Failed to read pom {{pom file path}}", path).toString(), exception); | ||
} | ||
} | ||
|
||
private void writePom(final Path path, final Model pom) { | ||
try { | ||
new MavenXpp3Writer().write(Files.newOutputStream(getPomPath()), pom); | ||
} catch (final IOException exception) { | ||
throw new UncheckedIOException(ExaError.messageBuilder("E-PK-CORE-173") | ||
.message("Failed to write pom {{pom file path}}", path).toString(), exception); | ||
} | ||
} | ||
|
||
private Path getPomPath() { | ||
return projectDir.resolve("pom.xml"); | ||
} | ||
} |
Oops, something went wrong.