This is an automated email from the ASF dual-hosted git repository.

enorman pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new c07c13a  SLING-10069 The generated features target dir is created in 
the wrong place (#67)
c07c13a is described below

commit c07c13af614d5043bacd24a8c55ca8891cb60460
Author: Eric Norman <[email protected]>
AuthorDate: Thu Jan 21 16:20:34 2021 -0800

    SLING-10069 The generated features target dir is created in the wrong place 
(#67)
---
 .../sling/feature/maven/mojos/AbstractFeatureMojo.java  | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
index e0e7aa4..e135b0e 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
 import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -241,12 +243,21 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
     private void handleGeneratedFeatures() throws MojoExecutionException {
         final File dir;
         if (this.generatedFeatures == null) {
-            final File targetDir = new File(this.project.getBasedir(), 
this.project.getBuild().getDirectory());
+            Path targetPath = null;
+            File basedir = this.project.getBasedir();
+            if (basedir == null) {
+                // no basedir? use the build directory instead.
+                targetPath = Paths.get(this.project.getBuild().getDirectory());
+            } else {
+                // resolve build directory relative to the basedir path
+                targetPath = 
basedir.toPath().resolve(this.project.getBuild().getDirectory());
+            }
+            final File targetDir = targetPath == null ? null : 
targetPath.toFile();
             final File genDir = new File(targetDir, "generated-features");
             if (genDir.exists()) {
                 dir = genDir;
             } else {
-                if(genDir.mkdirs()) {
+                if (genDir.mkdirs()) {
                     dir = genDir;
                 } else {
                     dir = null;
@@ -257,7 +268,7 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
         }
         if (dir != null) {
             if (!dir.exists()) {
-                if(!dir.mkdirs()) {
+                if (!dir.mkdirs()) {
                     throw new MojoExecutionException("Directory does not 
exists: " + dir);
                 }
             }

Reply via email to