Skip to content

Commit

Permalink
+ better log calls
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed Aug 9, 2024
1 parent 41a0a48 commit 8162008
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 44 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<groupId>io.github.q3769</groupId>
<artifactId>semver-maven-plugin</artifactId>
<version>20240116.0.20240809</version>
<version>20240116.0.2024080904</version>
<packaging>maven-plugin</packaging>

<name>semver-maven-plugin</name>
Expand Down Expand Up @@ -229,7 +229,7 @@
<plugin>
<groupId>io.github.q3769</groupId>
<artifactId>semver-maven-plugin</artifactId>
<version>20240116.0.20240809</version>
<version>20240116.0.2024080904</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/q3769/maven/plugins/semver/LabelUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,4 @@ protected Version update(Version original) {
return setLabel(original, set);
}
}

private void logInfo(String message, Object... args) {
getLog().info(String.format(message, args));
}
}
43 changes: 27 additions & 16 deletions src/main/java/q3769/maven/plugins/semver/SemverMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Updates the POM file with a new SemVer version
Expand All @@ -39,6 +41,7 @@
*/
public abstract class SemverMojo extends AbstractMojo {
private static final String FALSE = "false";
private static final Logger log = LoggerFactory.getLogger(SemverMojo.class);
/** */
@Parameter(defaultValue = "${mojoExecution}", readonly = true)
protected MojoExecution mojo;
Expand Down Expand Up @@ -80,27 +83,23 @@ public static Version requireValidSemVer(String version) {
public void execute() throws MojoExecutionException, MojoFailureException {
String projectName = project.getName();
String pomVersion = originalPomVersion();
getLog()
.info(String.format(
"Goal '%s' processing project '%s' with POM version '%s'...",
this.mojo.getGoal(), projectName, pomVersion));
logInfo(
"Goal '%s' processing project '%s' with POM version '%s'...",
this.mojo.getGoal(), projectName, pomVersion);
if (project.hasParent()) {
getLog()
.info(String.format(
"current project %s is a module of %s",
projectName, project.getParent().getName()));
logInfo(
"current project %s is a module of %s",
projectName, project.getParent().getName());
if (FALSE.equalsIgnoreCase(processModule)) {
getLog()
.warn(String.format(
"Version of module '%s' will not be processed. By default, only parent project is processed; if otherwise desired, use the `-DprocessModule` CLI flag",
projectName));
logWarn(
"Version of module '%s' will not be processed. By default, only parent project is processed; if otherwise desired, use the `-DprocessModule` CLI flag",
projectName);
return;
}
if (pomVersion == null) {
getLog()
.warn(String.format(
"Version of module '%s' is inherited to be the same as parent '%s', thus will not be processed independently",
projectName, project.getParent().getName()));
logWarn(
"Version of module '%s' is inherited to be the same as parent '%s', thus will not be processed independently",
projectName, project.getParent().getName());
return;
}
}
Expand All @@ -111,4 +110,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
protected String originalPomVersion() {
return project.getOriginalModel().getVersion();
}

protected void logWarn(String message, Object... args) {
getLog().warn(String.format(message, args));
}

protected void logInfo(String message, Object... args) {
getLog().info(String.format(message, args));
}

protected void logDebug(String message, Object... args) {
getLog().debug(String.format(message, args));
}
}
16 changes: 7 additions & 9 deletions src/main/java/q3769/maven/plugins/semver/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private Version getUpdatedVersion() throws MojoFailureException {
"snapshot labeling requested for updated semver %s but not honored, because snapshot flag only supports normal version number increments with no labels",
updatedVersion));
}
getLog().info(String.format("labeling version %s as a SNAPSHOT...", updatedVersion));
logInfo("labeling version %s as a SNAPSHOT...", updatedVersion);
return addSnapshotLabel(updatedVersion);
}

Expand All @@ -96,10 +96,9 @@ private void updatePomFile(@NonNull String newVersion) throws MojoExecutionExcep
String originalVersion = project.getVersion();
String executedGoal = mojo.getGoal();
if (newVersion.equals(originalVersion)) {
getLog()
.info(String.format(
"Original POM version: %s remains unchanged after executing goal: %s",
originalVersion, executedGoal));
logInfo(
"Original POM version: %s remains unchanged after executing goal: %s",
originalVersion, executedGoal);
return;
}
executeMojo(
Expand All @@ -109,9 +108,8 @@ private void updatePomFile(@NonNull String newVersion) throws MojoExecutionExcep
configuration(
element(name("generateBackupPoms"), "false"), element(name("newVersion"), newVersion)),
executionEnvironment(project, session, pluginManager));
getLog()
.info(String.format(
"Updated original POM version: %s into: %s after executing goal: %s",
originalVersion, newVersion, executedGoal));
logInfo(
"Updated original POM version: %s into: %s after executing goal: %s",
originalVersion, newVersion, executedGoal);
}
}
4 changes: 0 additions & 4 deletions src/main/java/q3769/maven/plugins/semver/mojos/Merge.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,4 @@ private Version increment(Version version, @NonNull SemverNormalVersion targetNo
String.format("Unexpected targetNormalVersion: %s", targetNormalVersion));
}
}

private void logDebug(String message, Object... args) {
getLog().debug(String.format(message, args));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,4 @@ protected Version update(@NonNull final Version original) throws MojoFailureExce
original, finalMergedVersion);
return finalMergedVersion;
}

private void logDebug(String message, Object... args) {
getLog().debug(String.format(message, args));
}
}
4 changes: 0 additions & 4 deletions src/main/java/q3769/maven/plugins/semver/mojos/PickNewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,4 @@ protected Version update(Version original) {
logDebug("CLI provided version %s is newer and being picked", otherSemVer);
return other;
}

private void logDebug(String message, Object... args) {
getLog().debug(String.format(message, args));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void doExecute() throws MojoFailureException {
} catch (Exception e) {
throw new MojoFailureException(String.format("Invalid SemVer '%s'", version), e);
}
getLog().info(String.format("POM version '%s' is a valid SemVer", version));
logInfo("POM version '%s' is a valid SemVer", version);
if (forceStdOut) {
System.out.println(version);
}
Expand Down

0 comments on commit 8162008

Please sign in to comment.