commit:     a34a975a19e5c9a963cb96c1c0496d55a1430f3c
Author:     Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
AuthorDate: Sun Aug 30 18:21:47 2020 +0000
Commit:     Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
CommitDate: Sun Aug 30 18:21:47 2020 +0000
URL:        https://gitweb.gentoo.org/proj/java-ebuilder.git/commit/?id=a34a975a

filtering out resource directories that are not valid

Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org>

 .../gentoo/java/ebuilder/maven/MavenProject.java   | 77 +++++++++++-----------
 1 file changed, 38 insertions(+), 39 deletions(-)

diff --git a/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java 
b/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java
index e91bb80..48c6506 100644
--- a/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java
+++ b/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java
@@ -32,14 +32,6 @@ public class MavenProject {
      * Maven group id.
      */
     private String groupId;
-    /**
-     * Whether the package has resources.
-     */
-    private Boolean hasResources;
-    /**
-     * Whether the package has test resources.
-     */
-    private Boolean hasTestResources;
     /**
      * Whether the package has test classes.
      */
@@ -126,18 +118,38 @@ public class MavenProject {
      * Adds path to {@link #resourceDirectories}.
      *
      * @param path resource path
+     *
+     * @return true if the path was added, otherwise false
+     *
+     * @see #isValidResourcesDir(java.nio.file.Path)
      */
-    public void addResourceDirectory(final Path path) {
+    public boolean addResourceDirectory(final Path path) {
+        if (!isValidResourcesDir(path)) {
+            return false;
+        }
+
         resourceDirectories.add(path);
+
+        return true;
     }
 
     /**
-     * Adds path to {@link #testResourceDirectories}.
+     * Adds path to {@link #testResourceDirectories}. The path must be valid.
      *
      * @param path resource path
+     *
+     * @return true if the path was added, otherwise false
+     *
+     * @see #isValidResourcesDir(java.nio.file.Path)
      */
-    public void addTestResourceDirectory(final Path path) {
+    public boolean addTestResourceDirectory(final Path path) {
+        if (!isValidResourcesDir(path)) {
+            return false;
+        }
+
         testResourceDirectories.add(path);
+
+        return true;
     }
 
     /**
@@ -549,20 +561,7 @@ public class MavenProject {
      * @return {@link #hasResources}
      */
     public boolean hasResources() {
-        if (hasResources == null) {
-            hasResources = false;
-
-            for (final Path resources : resourceDirectories) {
-                if (resources.toFile().exists()
-                        && resources.toFile().list().length != 0) {
-                    hasResources = true;
-
-                    break;
-                }
-            }
-        }
-
-        return hasResources;
+        return !resourceDirectories.isEmpty();
     }
 
     /**
@@ -571,20 +570,7 @@ public class MavenProject {
      * @return {@link #hasTestResources}
      */
     public boolean hasTestResources() {
-        if (hasTestResources == null) {
-            hasTestResources = false;
-
-            for (final Path resources : testResourceDirectories) {
-                if (resources.toFile().exists()
-                        && resources.toFile().list().length != 0) {
-                    hasTestResources = true;
-
-                    break;
-                }
-            }
-        }
-
-        return hasTestResources;
+        return !testResourceDirectories.isEmpty();
     }
 
     /**
@@ -633,4 +619,17 @@ public class MavenProject {
 
         return result;
     }
+
+    /**
+     * Checks whether the provided path is a valid directory for resources. It
+     * must exist and contain at least one file.
+     *
+     * @param resources path to resources
+     *
+     * @return true if the resources directory is valid, otherwise false
+     */
+    private boolean isValidResourcesDir(final Path resources) {
+        return resources.toFile().exists()
+                && resources.toFile().list().length != 0;
+    }
 }

Reply via email to