77
88import org .apache .maven .plugin .AbstractMojo ;
99import org .apache .maven .plugin .MojoExecutionException ;
10+ import org .apache .maven .plugin .logging .Log ;
1011import org .apache .maven .plugins .annotations .LifecyclePhase ;
1112import org .apache .maven .plugins .annotations .Mojo ;
1213import org .apache .maven .plugins .annotations .Parameter ;
@@ -43,42 +44,43 @@ public class ProcessMojo extends AbstractMojo {
4344
4445 @ Override
4546 public void execute () throws MojoExecutionException {
47+ Log log = getLog ();
4648 String processor = String .format ("openapi-processor-%s" , id );
4749
4850 try {
49- getLog () .info (String .format ("%10s - %s" , "processor" , processor ));
51+ log .info (String .format ("%10s - %s" , "processor" , processor ));
5052
5153 Map <String , Object > properties = createProperties ();
5254
53- File source = apiPath .getParentFile ();
55+ File source = apiPath .getAbsoluteFile ();
5456 String relativeSource = stripBaseDir (source .getAbsolutePath ());
55- getLog () .info (String .format ("%10s - ${project.basedir}%s%s " , "apiPath" , File . separator , relativeSource ));
57+ log .info (String .format ("%10s - %s " , "apiPath" , joinDirs ( "${project.basedir}" , relativeSource ) ));
5658
57- String targetDir = (String ) properties .computeIfAbsent (TARGET_DIR , k -> project .getBuild ().getDirectory () + File .separator + "generated-sources" + File .separator + id );
59+ String targetDir = (String ) properties .computeIfAbsent (TARGET_DIR , k -> joinDirs (
60+ project .getBuild ().getDirectory (),
61+ "generated-sources" ,
62+ id ));
5863
5964 if (addSourceRoot ) {
6065 project .addCompileSourceRoot (targetDir );
6166 }
6267
6368 String relativeTargetDir = stripBaseDir (targetDir );
64- getLog () .info (String .format ("%10s - ${project.basedir}%s%s " , "targetDir" , File . separator , relativeTargetDir ));
69+ log .info (String .format ("%10s - %s " , "targetDir" , joinDirs ( "${project.basedir}" , relativeTargetDir ) ));
6570
6671 File targetRoot = new File (targetDir );
6772 UpToDateCheck upToDateCheck = new UpToDateCheck ();
68- boolean upToDate = upToDateCheck .isUpToDate (source , targetRoot );
73+ boolean upToDate = upToDateCheck .isUpToDate (source . getParentFile () , targetRoot );
6974
75+ log .info ("" );
7076 if (!upToDate ) {
71- getLog ().info ("" );
72- getLog ().info ( "Changes detected - generating target files!" );
77+ log .info ("Changes detected - generating target files!" );
7378
74- new ProcessorRunner (id , properties )
75- .run ();
79+ new ProcessorRunner (id , properties ).run ();
7680
7781 } else {
78- getLog ().info ("" );
79- getLog ().info ( "Nothing to process - all generated target files are up to date." );
82+ log .info ("Nothing to process - all generated target files are up to date." );
8083 }
81-
8284 } catch (Exception e ) {
8385 throw new MojoExecutionException (String .format ("Execution failed - %s" , processor ), e );
8486 }
@@ -90,6 +92,10 @@ private String stripBaseDir (String source) {
9092 return base .relativize (src ).toString ();
9193 }
9294
95+ private String joinDirs (CharSequence ... directories ) {
96+ return String .join (File .separator , directories );
97+ }
98+
9399 private Map <String , Object > createProperties () throws MojoExecutionException {
94100 Map <String , Object > properties = new HashMap <> ();
95101
@@ -127,14 +133,8 @@ private void addNestedProperties (Nested nested, Map<String, Object> parent) {
127133 }
128134
129135 // copy common api path to openapi-processor props if not set
130- private void setApiPath (Map <String , Object > properties ) throws MojoExecutionException {
136+ private void setApiPath (Map <String , Object > properties ) {
131137 if (!properties .containsKey (API_PATH )) {
132- if (apiPath == null ) {
133- throw new MojoExecutionException (this ,
134- "'common <apiPath>' or '" + id + " <apiPath>' not set!" ,
135- "'common <apiPath>' or '" + id + " <apiPath>' not set!" );
136- }
137-
138138 properties .put (API_PATH , apiPath );
139139 } else {
140140 apiPath = new File ((String ) properties .get (API_PATH ));
0 commit comments