Skip to content

Commit 19959f7

Browse files
authored
Merge pull request #5 from maddingo/feature/default-target-path
Use default target Path, add target path to project sources, make apiPath required
2 parents e34e7b8 + 6222bb2 commit 19959f7

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

src/main/java/io/openapiprocessor/maven/ProcessMojo.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.apache.maven.plugins.annotations.LifecyclePhase;
1111
import org.apache.maven.plugins.annotations.Mojo;
1212
import org.apache.maven.plugins.annotations.Parameter;
13+
import org.apache.maven.project.MavenProject;
1314

1415
import java.io.File;
1516
import java.nio.file.Path;
@@ -28,21 +29,21 @@ public class ProcessMojo extends AbstractMojo {
2829
@Parameter(required = true)
2930
private String id;
3031

31-
@Parameter(required = false)
32-
private String processorName;
33-
34-
@Parameter(required = false)
32+
@Parameter(required = true)
3533
private File apiPath;
3634

3735
@Parameter(required = false)
3836
private Options options;
3937

40-
@Parameter(readonly = true, required = true, defaultValue = "${project.basedir}")
41-
private File baseDir;
38+
@Parameter(required = false, defaultValue = "true")
39+
private boolean addSourceRoot;
40+
41+
@Parameter(readonly = true, required = true, defaultValue = "${project}")
42+
private MavenProject project;
4243

4344
@Override
4445
public void execute () throws MojoExecutionException {
45-
String processor = String.format ("openapi-processor-%s", processorName == null ? id : processorName);
46+
String processor = String.format ("openapi-processor-%s", id);
4647

4748
try {
4849
getLog().info(String.format ("%10s - %s", "processor", processor));
@@ -51,11 +52,16 @@ public void execute () throws MojoExecutionException {
5152

5253
File source = apiPath.getParentFile ();
5354
String relativeSource = stripBaseDir (source.getAbsolutePath ());
54-
getLog().info(String.format ("%10s - ${project.basedir}/%s", "apiPath", relativeSource));
55+
getLog().info(String.format ("%10s - ${project.basedir}%s%s", "apiPath", File.pathSeparator, relativeSource));
56+
57+
String targetDir = (String) properties.computeIfAbsent (TARGET_DIR, k -> project.getBuild().getDirectory() + File.pathSeparator + "generated-sources" + File.pathSeparator + id);
58+
59+
if (addSourceRoot) {
60+
project.addCompileSourceRoot(targetDir);
61+
}
5562

56-
String targetDir = (String) properties.get (TARGET_DIR);
5763
String relativeTargetDir = stripBaseDir (targetDir);
58-
getLog().info(String.format ("%10s - ${project.basedir}/%s", "targetDir", relativeTargetDir));
64+
getLog().info(String.format ("%10s - ${project.basedir}%s%s", "targetDir", File.pathSeparator, relativeTargetDir));
5965

6066
File targetRoot = new File(targetDir);
6167
UpToDateCheck upToDateCheck = new UpToDateCheck ();
@@ -79,7 +85,7 @@ public void execute () throws MojoExecutionException {
7985
}
8086

8187
private String stripBaseDir (String source) {
82-
Path base = Paths.get (baseDir.getAbsolutePath ());
88+
Path base = Paths.get (project.getBasedir().getAbsolutePath ());
8389
Path src = Paths.get (source);
8490
return base.relativize (src).toString ();
8591
}

0 commit comments

Comments
 (0)