Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/main/java/io/openapiprocessor/maven/ProcessMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

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

@Parameter(required = false)
private String processorName;

@Parameter(required = false)
@Parameter(required = true)
private File apiPath;

@Parameter(required = false)
private Options options;

@Parameter(readonly = true, required = true, defaultValue = "${project.basedir}")
private File baseDir;
@Parameter(required = false, defaultValue = "true")
private boolean addSourceRoot;

@Parameter(readonly = true, required = true, defaultValue = "${project}")
private MavenProject project;

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

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

File source = apiPath.getParentFile ();
String relativeSource = stripBaseDir (source.getAbsolutePath ());
getLog().info(String.format ("%10s - ${project.basedir}/%s", "apiPath", relativeSource));
getLog().info(String.format ("%10s - ${project.basedir}%s%s", "apiPath", File.pathSeparator, relativeSource));

String targetDir = (String) properties.computeIfAbsent (TARGET_DIR, k -> project.getBuild().getDirectory() + File.pathSeparator + "generated-sources" + File.pathSeparator + id);

if (addSourceRoot) {
project.addCompileSourceRoot(targetDir);
}

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

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

private String stripBaseDir (String source) {
Path base = Paths.get (baseDir.getAbsolutePath ());
Path base = Paths.get (project.getBasedir().getAbsolutePath ());
Path src = Paths.get (source);
return base.relativize (src).toString ();
}
Expand Down