aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Šulc <fordfrog@gentoo.org>2020-08-30 20:21:47 +0200
committerMiroslav Šulc <fordfrog@gentoo.org>2020-08-30 20:21:47 +0200
commita34a975a19e5c9a963cb96c1c0496d55a1430f3c (patch)
treee905937dbae21c3af2fe48059300cc9db85b5717
parentminor style fixes and sorted methods in MavenProject (diff)
downloadjava-ebuilder-a34a975a19e5c9a963cb96c1c0496d55a1430f3c.tar.gz
java-ebuilder-a34a975a19e5c9a963cb96c1c0496d55a1430f3c.tar.bz2
java-ebuilder-a34a975a19e5c9a963cb96c1c0496d55a1430f3c.zip
filtering out resource directories that are not valid
Signed-off-by: Miroslav Šulc <fordfrog@gentoo.org>
-rw-r--r--src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java77
1 files 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
@@ -33,14 +33,6 @@ public class MavenProject {
*/
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.
*/
private Boolean hasTests;
@@ -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;
+ }
}