You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2018/08/14 12:06:59 UTC

[sling-whiteboard] branch master updated: corrected scripts folder handling

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

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new a4f4a43  corrected scripts folder handling
a4f4a43 is described below

commit a4f4a439041ca81b8ec39380384c90552476f5be
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Aug 14 14:06:54 2018 +0200

    corrected scripts folder handling
---
 .../pom.xml                                          |  1 -
 .../scripting/maven/plugin/ScriptingMavenPlugin.java | 20 +++++++++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/scripting-resolver/examples/org-apache-sling-scripting-examplebundle-precompiled/pom.xml b/scripting-resolver/examples/org-apache-sling-scripting-examplebundle-precompiled/pom.xml
index 54b23be..c4be823 100644
--- a/scripting-resolver/examples/org-apache-sling-scripting-examplebundle-precompiled/pom.xml
+++ b/scripting-resolver/examples/org-apache-sling-scripting-examplebundle-precompiled/pom.xml
@@ -34,7 +34,6 @@
     <packaging>bundle</packaging>
 
     <build>
-        <sourceDirectory>src/main/scripts</sourceDirectory>
         <plugins>
             <plugin>
                 <groupId>org.apache.sling</groupId>
diff --git a/scripting-resolver/org-apache-sling-scripting-maven-plugin/src/main/java/org/apache/sling/scripting/maven/plugin/ScriptingMavenPlugin.java b/scripting-resolver/org-apache-sling-scripting-maven-plugin/src/main/java/org/apache/sling/scripting/maven/plugin/ScriptingMavenPlugin.java
index 422fa36..875133c 100644
--- a/scripting-resolver/org-apache-sling-scripting-maven-plugin/src/main/java/org/apache/sling/scripting/maven/plugin/ScriptingMavenPlugin.java
+++ b/scripting-resolver/org-apache-sling-scripting-maven-plugin/src/main/java/org/apache/sling/scripting/maven/plugin/ScriptingMavenPlugin.java
@@ -38,6 +38,7 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -59,15 +60,24 @@ public class ScriptingMavenPlugin extends AbstractMojo
 
     public void execute() throws MojoExecutionException
     {
+        File sdFile = new File(scriptsDirectory);
+        if (!sdFile.exists()) {
+            sdFile = new File(project.getBasedir(), scriptsDirectory);
+            if (!sdFile.exists()) {
+                throw new MojoExecutionException("Cannot find file " + scriptsDirectory + ".");
+            }
+        }
+        final AtomicReference<File> scriptsDirectoryReference = new AtomicReference<>();
+        scriptsDirectoryReference.set(sdFile);;
         DirectoryScanner scanner = new DirectoryScanner();
-        scanner.setBasedir(scriptsDirectory);
+        scanner.setBasedir(sdFile);
         scanner.setIncludes("**");
         scanner.setExcludes("**/*.class");
         scanner.addDefaultExcludes();
         scanner.scan();
 
-        List<String> scriptPaths = Stream.of(scanner.getIncludedFiles()).map(path -> new File(scriptsDirectory, path))
-            .map(file -> file.getPath().substring((scriptsDirectory + File.pathSeparatorChar).length()))
+        List<String> scriptPaths = Stream.of(scanner.getIncludedFiles()).map(path -> new File(scriptsDirectoryReference.get(), path))
+            .map(file -> file.getPath().substring((scriptsDirectoryReference.get().getPath() + File.pathSeparatorChar).length()))
             .collect(Collectors.toList());
 
 
@@ -90,7 +100,7 @@ public class ScriptingMavenPlugin extends AbstractMojo
                     }
                     else
                     {
-                        try (BufferedReader input = new BufferedReader(new FileReader(new File(new File(scriptsDirectory), scriptPath))))
+                        try (BufferedReader input = new BufferedReader(new FileReader(new File(scriptsDirectoryReference.get(), scriptPath))))
                         {
                             String extend = input.readLine();
 
@@ -105,7 +115,7 @@ public class ScriptingMavenPlugin extends AbstractMojo
                 }
                 else
                 {
-                    try (BufferedReader input = new BufferedReader(new FileReader(new File(new File(scriptsDirectory), scriptPath))))
+                    try (BufferedReader input = new BufferedReader(new FileReader(new File(scriptsDirectoryReference.get(), scriptPath))))
                     {
                         for (String line = input.readLine(); line != null; line = input.readLine())
                         {