Skip to content

Commit

Permalink
Use locker.mode instead of -Din-profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Feb 15, 2024
1 parent 72294b4 commit 60494dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ _In additon when using the locker, the number of files Maven need to download is

## Installation

### In-Profile Mode (for smaller amount of deps)
### IN_PROFILE Mode (for smaller amount of deps)

This command will modify your pom.xml with Locker dependencies directly in a new `locker` profile:
```shell
mvn io.mvnpm:locker-maven-plugin:LATEST:lock -Dlocker.in-profile
mvn io.mvnpm:locker-maven-plugin:LATEST:lock -Dlocker.mode=IN_PROFILE
```

### Locker BOM Mode
### LOCKER_BOM Mode (default)

This command will:
- create a distinct Locker BOM file (`./locker/pom.xml`)
Expand Down Expand Up @@ -54,16 +54,16 @@ To update, you need to add `-Dunlocked` alongside the `lock` goal (to disable th
mvn io.mvnpm:locker-maven-plugin:LATEST:lock -Dunlocked
```

NOTE: _You don't need to specify the mode (`-Din-profile` option) as it is auto-detected._
NOTE: _You don't need to specify the mode (`-Dlocker.mode` option) as it is auto-detected._

## Switch to Locker BOM Mode (from in-profile locker dependencies)

If the amount of dependencies in your project has grown, you may want to switch to the Locker BOM Mode (to reduce the amount of dependencies in your project pom.xml).
```shell
mvn io.mvnpm:locker-maven-plugin:LATEST:lock -Dunlocked -Dlocker.in-profile=false
mvn io.mvnpm:locker-maven-plugin:LATEST:lock -Dunlocked -Dlocker.mode=LOCKER_BOM
```

For the opposite, you can just remove the Locker BOM from your project and the locker profile and use the `in-profile` option to add the locker dependencies to your project pom.xml.
For the opposite, you can just remove the Locker BOM from your project and the locker profile and use the `-Dlocker.mode=IN_PROFILE` option to add the locker dependencies to your project pom.xml.

## Add the locker extension for Locker BOM mode (optional)

Expand Down
21 changes: 13 additions & 8 deletions src/main/java/io/mvnpm/maven/locker/mojos/LockMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static io.mvnpm.maven.locker.LockerConstants.LOCKER_PROFILE;
import static io.mvnpm.maven.locker.LockerProfile.findLockerProfile;
import static io.mvnpm.maven.locker.LockerProfile.usesLockerBom;
import static io.mvnpm.maven.locker.mojos.LockerMode.IN_PROFILE;
import static io.mvnpm.maven.locker.mojos.LockerMode.LOCKER_BOM;
import static java.util.Locale.ROOT;
import static org.apache.maven.plugins.annotations.ResolutionScope.TEST;

Expand Down Expand Up @@ -40,8 +42,8 @@ public final class LockMojo extends AbstractDependencyLockMojo {
@Parameter(property = "locker.filter", defaultValue = "org.mvnpm*,org.webjars*")
private List<String> filters;

@Parameter(property = "locker.in-profile", defaultValue = "false")
private boolean inProfile;
@Parameter(property = "locker.mode")
private LockerMode mode;

@Override
public void execute() throws MojoExecutionException {
Expand All @@ -59,12 +61,16 @@ public void execute() throws MojoExecutionException {
final Optional<Profile> existingLockerProfile = findLockerProfile(model);
final boolean alreadyConfiguredWithLockerBom = usesLockerBom(existingLockerProfile) || lockFileExists;
if (alreadyConfiguredWithLockerBom) {
getLog().info("Configured with locker BOM");
if (inProfile) {
getLog().warn("Ignoring 'locker.in-profile' parameter, locker BOM is already configured");
getLog().info("Configured with locker BOM Mode");
if (IN_PROFILE.equals(mode)) {
getLog().warn("Ignoring 'locker.mode' parameter, the project is already configured with Locker BOM Mode");
}
}
final boolean lockerBomModeEnabled = !inProfile || alreadyConfiguredWithLockerBom;

boolean lockerBomModeEnabled = LOCKER_BOM.equals(mode) || alreadyConfiguredWithLockerBom;
if (existingLockerProfile.isEmpty() && mode == null) {
lockerBomModeEnabled = true;
}
if (lockerBomModeEnabled) {
getLog().info(String.format(ROOT, "%s %s", lockFileExists ? "Updating" : "Creating", lockFile.absolutePath()));
final LockerPom lockerPom = DefaultLockerPom.from(lockFile, pomMinimums(), getLog());
Expand All @@ -84,8 +90,7 @@ public void execute() throws MojoExecutionException {
if (!lockerBomModeEnabled) {
getLog().info("Updating '" + LOCKER_PROFILE + "' profile with locked dependencies");
addLockerProfile = true;
}
if (!usesLockerBom(existingLockerProfile)) {
} else if (!usesLockerBom(existingLockerProfile)) {
addLockerProfile = true;
getLog().info("Switching to locker BOM in '" + LOCKER_PROFILE + "' profile");
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/mvnpm/maven/locker/mojos/LockerMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.mvnpm.maven.locker.mojos;

public enum LockerMode {
LOCKER_BOM,
IN_PROFILE
}

0 comments on commit 60494dd

Please sign in to comment.