2323 */
2424package q3769 .maven .plugins .semver ;
2525
26+ import static java .util .Objects .requireNonNull ;
27+
2628import com .github .zafarkhaja .semver .Version ;
27- import lombok .NonNull ;
2829import org .apache .maven .execution .MavenSession ;
2930import org .apache .maven .plugin .AbstractMojo ;
3031import org .apache .maven .plugin .MojoExecution ;
3132import org .apache .maven .plugin .MojoExecutionException ;
3233import org .apache .maven .plugin .MojoFailureException ;
3334import org .apache .maven .plugins .annotations .Parameter ;
3435import org .apache .maven .project .MavenProject ;
36+ import org .jspecify .annotations .Nullable ;
3537
3638/**
3739 * Updates the POM file with a new SemVer version
@@ -43,27 +45,27 @@ public abstract class SemverMojo extends AbstractMojo {
4345
4446 /** */
4547 @ Parameter (defaultValue = "${mojoExecution}" , readonly = true )
46- protected MojoExecution mojo ;
48+ protected @ Nullable MojoExecution mojo ;
4749
4850 /** */
4951 @ Parameter (property = "processModule" , defaultValue = FALSE )
50- protected String processModule ;
52+ protected @ Nullable String processModule ;
5153
5254 /** Current Maven POM */
5355 @ Parameter (property = "project" , defaultValue = "${project}" , readonly = true , required = true )
54- protected MavenProject project ;
56+ protected @ Nullable MavenProject project ;
5557
5658 /** Default session */
5759 @ Parameter (property = "session" , defaultValue = "${session}" , readonly = true , required = true )
58- protected MavenSession session ;
60+ protected @ Nullable MavenSession session ;
5961
6062 /**
6163 * @param version text that is supposed to be valid per SemVer spec
6264 * @return A valid SemVer
6365 */
64- public static @ NonNull Version requireValidSemVer (String version ) {
66+ public static Version requireValidSemVer (@ Nullable String version ) {
6567 try {
66- return Version .parse (version );
68+ return Version .parse (requireNonNull ( version ) );
6769 } catch (Exception ex ) {
6870 throw new IllegalArgumentException ("Error parsing '" + version + "' as a SemVer" , ex );
6971 }
@@ -83,53 +85,38 @@ public abstract class SemverMojo extends AbstractMojo {
8385 */
8486 @ Override
8587 public void execute () throws MojoExecutionException , MojoFailureException {
88+ requireNonNull (project );
8689 String projectName = project .getName ();
8790 String pomVersion = originalPomVersion ();
88- logInfo (
89- "Goal '%s' processing project '%s' with POM version '%s'..." ,
90- this .mojo .getGoal (), projectName , pomVersion );
91+ getLog ()
92+ .info (String .format (
93+ "Goal '%s' processing project '%s' with POM version '%s'..." ,
94+ requireNonNull (this .mojo ).getGoal (), projectName , pomVersion ));
9195 if (project .hasParent ()) {
92- logInfo (
93- "current project %s is a module of %s" ,
94- projectName , project .getParent ().getName ());
96+ getLog ()
97+ .info (String .format (
98+ "current project %s is a module of %s" ,
99+ projectName , project .getParent ().getName ()));
95100 if (FALSE .equalsIgnoreCase (processModule )) {
96- logWarn (
97- "Version of module '%s' will not be processed. By default, only parent project is processed; if otherwise desired, use the `-DprocessModule` CLI flag" ,
98- projectName );
101+ getLog ()
102+ .warn (String .format (
103+ "Version of module '%s' will not be processed. By default, only parent project is processed; if otherwise desired, use the `-DprocessModule` CLI flag" ,
104+ projectName ));
99105 return ;
100106 }
101107 if (pomVersion == null ) {
102- logWarn (
103- "Version of module '%s' is inherited to be the same as parent '%s', thus will not be processed independently" ,
104- projectName , project .getParent ().getName ());
108+ getLog ()
109+ .warn (String .format (
110+ "Version of module '%s' is inherited to be the same as parent '%s', thus will not be processed independently" ,
111+ projectName , project .getParent ().getName ()));
105112 return ;
106113 }
107114 }
108115 doExecute ();
109116 }
110117
111118 /** @return original version in pom.xml */
112- protected String originalPomVersion () {
113- return project .getModel ().getVersion ();
114- }
115-
116- protected void logError (String message , Object ... args ) {
117- getLog ().error (String .format (message , args ));
118- }
119-
120- protected void logError (Throwable t , String message , Object ... args ) {
121- getLog ().error (String .format (message , args ), t );
122- }
123-
124- protected void logWarn (String message , Object ... args ) {
125- getLog ().warn (String .format (message , args ));
126- }
127-
128- protected void logInfo (String message , Object ... args ) {
129- getLog ().info (String .format (message , args ));
130- }
131-
132- protected void logDebug (String message , Object ... args ) {
133- getLog ().debug (String .format (message , args ));
119+ protected @ Nullable String originalPomVersion () {
120+ return requireNonNull (project ).getModel ().getVersion ();
134121 }
135122}
0 commit comments