Skip to content

Commit

Permalink
Merge pull request #13 from mvnpm/use-unlocked
Browse files Browse the repository at this point in the history
Use negated properties instead of activeByDefault for locker profile
  • Loading branch information
ia3andy authored Jan 8, 2024
2 parents f97484e + 039169f commit 8d0e473
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/io/mvnpm/maven/locker/mojos/LockMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public void execute() throws MojoExecutionException {
final Model model = project.getModel();
final Optional<Profile> existingLockerProfile = model.getProfiles().stream()
.filter(p -> p.getId().equals(LOCKER_PROFILE)).findFirst();
final boolean hasActiveByDefaultProfiles = model.getProfiles().stream()
.anyMatch(p -> p.getActivation().isActiveByDefault());
if (hasActiveByDefaultProfiles) {
getLog().warn(
"\n\nThe locker profile uses a NEGATED PROPERTY '!unlocked'. This OVERRIDES the 'activeByDefault' option in other profiles.\n\n"
+
"Your pom.xml contains profiles with 'activeByDefault=true'.\n" +
"For CONSISTENT BEHAVIOR, consider REMOVING 'activeByDefault=true' from your profiles or use NEGATED PROPERTIES instead.\n\n");
}
if (existingLockerProfile.isEmpty()) {
getLog().info(
"Adding '" + LOCKER_PROFILE + "' profile to the pom.xml...");
Expand Down Expand Up @@ -105,6 +114,7 @@ private String getLockerProfile() throws IOException {
final String tpl = Resources.toString(Resources.getResource(LockMojo.class, "locker-profile.xml"),
StandardCharsets.UTF_8);
final Map<String, Object> data = Map.of(
"useNegatedProp", true,
"lockerProfile", LOCKER_PROFILE,
"groupId", project.getGroupId(),
"artifactId", project.getArtifactId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
<profile>
<id>{lockerProfile}</id>
<activation>
{#if useNegatedProp}
<property>
<name>!unlocked</name>
</property>
{#else}
<activeByDefault>true</activeByDefault>
{/if}
</activation>
<dependencyManagement>
<dependencies>
Expand Down

0 comments on commit 8d0e473

Please sign in to comment.