Skip to content

Commit

Permalink
#515: Implement auto dependency update (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada authored Feb 22, 2024
1 parent 7b3f258 commit 93c05b0
Show file tree
Hide file tree
Showing 20 changed files with 910 additions and 69 deletions.
66 changes: 34 additions & 32 deletions dependencies.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions doc/changes/changes_4.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Code name: Automatic Security Updates

* Updated `com.exasol:project-keeper-shared-test-setup:3.0.1` to `4.0.0`
* Updated `nl.jqno.equalsverifier:equalsverifier:3.15.4` to `3.15.6`
* Added `org.junit-pioneer:junit-pioneer:2.2.0`
* Updated `org.junit.jupiter:junit-jupiter-engine:5.10.1` to `5.10.2`
* Updated `org.junit.jupiter:junit-jupiter-params:5.10.1` to `5.10.2`
* Updated `org.mockito:mockito-junit-jupiter:5.8.0` to `5.10.0`
Expand Down
14 changes: 14 additions & 0 deletions doc/user_guide/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ In addition this plugin can also fix the project structure. For that use:
mvn project-keeper:fix
```

Run the following commands to update dependencies:

```sh
mvn project-keeper:update-dependencies
```

For multi-module projects these commands may fail with the following error:

```
Expand All @@ -279,6 +285,7 @@ In this case add command line option `--projects .`:
```sh
mvn project-keeper:verify --projects .
mvn project-keeper:fix --projects .
mvn project-keeper:update-dependencies --projects .
```

You can skip the execution of project-keeper by adding `-Dproject-keeper.skip=true` to your maven command.
Expand All @@ -301,6 +308,13 @@ cd path/to/project
java -jar path/to/project-keeper-cli-2.7.1.jar fix
```

Run the following commands to update dependencies:

```sh
cd path/to/project
java -jar path/to/project-keeper-cli-2.7.1.jar update-dependencies
```

### Project Version

PK needs to know about the overall version of the project. For example for validating it in the changes file. For single source projects, PK simply takes the version from the project. For other projects you can:
Expand Down
6 changes: 6 additions & 0 deletions parent-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion project-keeper-cli/error_code_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ error-tags:
PK-CLI:
packages:
- com.exasol.projectkeeper.cli
highest-index: 4
highest-index: 5
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.*;

import com.exasol.errorreporting.ExaError;
Expand All @@ -19,6 +20,12 @@ public class ProjectKeeperLauncher {
private static final Logger LOGGER = Logger.getLogger(ProjectKeeperLauncher.class.getName());
private static final String GOAL_VERIFY = "verify";
private static final String GOAL_FIX = "fix";
private static final String GOAL_UPDATE_DEPENDENCIES = "update-dependencies";
private static final Map<String, ProjectKeeperGoal> ACCEPT_GOALS = Map.of( //
GOAL_VERIFY, ProjectKeeper::verify, //
GOAL_FIX, ProjectKeeper::fix, //
GOAL_UPDATE_DEPENDENCIES, ProjectKeeper::updateDependencies //
);

private final Path currentWorkingDir;

Expand Down Expand Up @@ -60,23 +67,36 @@ void start(final String[] args) {

private void runProjectKeeper(final String goal) {
final ProjectKeeper projectKeeper = createProjectKeeper();
final boolean success = goal.equals(GOAL_FIX) ? projectKeeper.fix() : projectKeeper.verify();
final ProjectKeeperGoal method = getProjectKeeperGoal(goal);
final boolean success = method.execute(projectKeeper);
if (!success) {
throw new IllegalStateException(
ExaError.messageBuilder("E-PK-CLI-1").message("Failed to run project keeper {{goal}}", goal)
.mitigation("See log messages above for details.").toString());
}
}

private ProjectKeeperGoal getProjectKeeperGoal(final String goal) {
final ProjectKeeperGoal failure = pk -> {
LOGGER.warning(() -> ExaError.messageBuilder("E-PK-CLI-5").message("Goal {{goal}} not supported.", goal)
.mitigation("Use one of the supported goals: {{supported goals}}", ACCEPT_GOALS.keySet())
.toString());
return false;
};
return ACCEPT_GOALS.getOrDefault(goal, failure);
}

private ProjectKeeper createProjectKeeper() {
return ProjectKeeper.createProjectKeeper(new JULLogger(), this.currentWorkingDir, null);
}

private void verifyCommandLineArguments(final String[] args) {
if ((args == null) || (args.length != 1) || !(GOAL_FIX.equals(args[0]) || GOAL_VERIFY.equals(args[0]))) {
if ((args == null) || (args.length != 1) || !(GOAL_FIX.equals(args[0]) || GOAL_VERIFY.equals(args[0])
|| GOAL_UPDATE_DEPENDENCIES.equals(args[0]))) {
throw new IllegalArgumentException(ExaError.messageBuilder("E-PK-CLI-2")
.message("Got no or invalid command line argument {{arguments}}.", Arrays.toString(args))
.mitigation("Please only specify arguments '" + GOAL_VERIFY + "' or '" + GOAL_FIX + "'.")
.mitigation("Please only specify arguments '" + GOAL_VERIFY + "', '" + GOAL_FIX + "' or '"
+ GOAL_UPDATE_DEPENDENCIES + "'.")
.toString());
}
}
Expand All @@ -97,4 +117,9 @@ public void error(final String message) {
LOGGER.severe(message);
}
}

@FunctionalInterface
private interface ProjectKeeperGoal {
boolean execute(ProjectKeeper projectKeeper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ static Stream<Arguments> invalidArguments() {
@MethodSource("invalidArguments")
void failsForWrongArguments(final String... args) throws IOException, InterruptedException {
assertProcessFails(args, "E-PK-CLI-2: Got no or invalid command line argument '" + Arrays.toString(args)
+ "'. Please only specify arguments 'verify' or 'fix'.");
+ "'. Please only specify arguments 'verify', 'fix' or 'update-dependencies'.");
}

@Test
void runMainMethodWithNullArgumentFails() throws IOException, InterruptedException {
final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> ProjectKeeperLauncher.main(null));
assertThat(exception.getMessage(), equalTo(
"E-PK-CLI-2: Got no or invalid command line argument 'null'. Please only specify arguments 'verify' or 'fix'."));
"E-PK-CLI-2: Got no or invalid command line argument 'null'. Please only specify arguments 'verify', 'fix' or 'update-dependencies'."));
}

@Test
Expand All @@ -68,6 +68,13 @@ void fixingJavaProjectSucceeds() throws InterruptedException, IOException {
assertProcessSucceeds("verify");
}

@Test
void updateDependenciesJavaProjectSucceeds() throws InterruptedException, IOException {
prepareMavenProject();
assertProcessSucceeds("fix");
assertProcessSucceeds("update-dependencies");
}

@Test
void fixingGolangProjectSucceeds() throws InterruptedException, IOException {
prepareGolangProject();
Expand Down
Loading

0 comments on commit 93c05b0

Please sign in to comment.