From a34a975a19e5c9a963cb96c1c0496d55a1430f3c Mon Sep 17 00:00:00 2001 From: Miroslav Šulc Date: Sun, 30 Aug 2020 20:21:47 +0200 Subject: filtering out resource directories that are not valid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Šulc --- .../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; + } } -- cgit v1.2.3-65-gdbad