From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 4906E13835A for ; Sun, 30 Aug 2020 18:22:08 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 486C5E0919; Sun, 30 Aug 2020 18:22:07 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 2F5F3E0919 for ; Sun, 30 Aug 2020 18:22:07 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 64E2A3409EC for ; Sun, 30 Aug 2020 18:22:05 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CD262336 for ; Sun, 30 Aug 2020 18:22:03 +0000 (UTC) From: "Miroslav Šulc" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Miroslav Šulc" Message-ID: <1598811707.a34a975a19e5c9a963cb96c1c0496d55a1430f3c.fordfrog@gentoo> Subject: [gentoo-commits] proj/java-ebuilder:master commit in: src/main/java/org/gentoo/java/ebuilder/maven/ X-VCS-Repository: proj/java-ebuilder X-VCS-Files: src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java X-VCS-Directories: src/main/java/org/gentoo/java/ebuilder/maven/ X-VCS-Committer: fordfrog X-VCS-Committer-Name: Miroslav Šulc X-VCS-Revision: a34a975a19e5c9a963cb96c1c0496d55a1430f3c X-VCS-Branch: master Date: Sun, 30 Aug 2020 18:22:03 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 02595509-66d7-47b3-b959-2eb3366394dc X-Archives-Hash: 94e404f151100f2642af3886bc2ded10 commit: a34a975a19e5c9a963cb96c1c0496d55a1430f3c Author: Miroslav Šulc gentoo org> AuthorDate: Sun Aug 30 18:21:47 2020 +0000 Commit: Miroslav Šulc gentoo 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 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; + } }