Gentoo Archives: gentoo-commits

From: "Miroslav Šulc" <fordfrog@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/java-ebuilder:master commit in: src/main/java/org/gentoo/java/ebuilder/maven/
Date: Sun, 30 Aug 2020 18:22:08
Message-Id: 1598811707.a34a975a19e5c9a963cb96c1c0496d55a1430f3c.fordfrog@gentoo
1 commit: a34a975a19e5c9a963cb96c1c0496d55a1430f3c
2 Author: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
3 AuthorDate: Sun Aug 30 18:21:47 2020 +0000
4 Commit: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
5 CommitDate: Sun Aug 30 18:21:47 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/java-ebuilder.git/commit/?id=a34a975a
7
8 filtering out resource directories that are not valid
9
10 Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org>
11
12 .../gentoo/java/ebuilder/maven/MavenProject.java | 77 +++++++++++-----------
13 1 file changed, 38 insertions(+), 39 deletions(-)
14
15 diff --git a/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java b/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java
16 index e91bb80..48c6506 100644
17 --- a/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java
18 +++ b/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java
19 @@ -32,14 +32,6 @@ public class MavenProject {
20 * Maven group id.
21 */
22 private String groupId;
23 - /**
24 - * Whether the package has resources.
25 - */
26 - private Boolean hasResources;
27 - /**
28 - * Whether the package has test resources.
29 - */
30 - private Boolean hasTestResources;
31 /**
32 * Whether the package has test classes.
33 */
34 @@ -126,18 +118,38 @@ public class MavenProject {
35 * Adds path to {@link #resourceDirectories}.
36 *
37 * @param path resource path
38 + *
39 + * @return true if the path was added, otherwise false
40 + *
41 + * @see #isValidResourcesDir(java.nio.file.Path)
42 */
43 - public void addResourceDirectory(final Path path) {
44 + public boolean addResourceDirectory(final Path path) {
45 + if (!isValidResourcesDir(path)) {
46 + return false;
47 + }
48 +
49 resourceDirectories.add(path);
50 +
51 + return true;
52 }
53
54 /**
55 - * Adds path to {@link #testResourceDirectories}.
56 + * Adds path to {@link #testResourceDirectories}. The path must be valid.
57 *
58 * @param path resource path
59 + *
60 + * @return true if the path was added, otherwise false
61 + *
62 + * @see #isValidResourcesDir(java.nio.file.Path)
63 */
64 - public void addTestResourceDirectory(final Path path) {
65 + public boolean addTestResourceDirectory(final Path path) {
66 + if (!isValidResourcesDir(path)) {
67 + return false;
68 + }
69 +
70 testResourceDirectories.add(path);
71 +
72 + return true;
73 }
74
75 /**
76 @@ -549,20 +561,7 @@ public class MavenProject {
77 * @return {@link #hasResources}
78 */
79 public boolean hasResources() {
80 - if (hasResources == null) {
81 - hasResources = false;
82 -
83 - for (final Path resources : resourceDirectories) {
84 - if (resources.toFile().exists()
85 - && resources.toFile().list().length != 0) {
86 - hasResources = true;
87 -
88 - break;
89 - }
90 - }
91 - }
92 -
93 - return hasResources;
94 + return !resourceDirectories.isEmpty();
95 }
96
97 /**
98 @@ -571,20 +570,7 @@ public class MavenProject {
99 * @return {@link #hasTestResources}
100 */
101 public boolean hasTestResources() {
102 - if (hasTestResources == null) {
103 - hasTestResources = false;
104 -
105 - for (final Path resources : testResourceDirectories) {
106 - if (resources.toFile().exists()
107 - && resources.toFile().list().length != 0) {
108 - hasTestResources = true;
109 -
110 - break;
111 - }
112 - }
113 - }
114 -
115 - return hasTestResources;
116 + return !testResourceDirectories.isEmpty();
117 }
118
119 /**
120 @@ -633,4 +619,17 @@ public class MavenProject {
121
122 return result;
123 }
124 +
125 + /**
126 + * Checks whether the provided path is a valid directory for resources. It
127 + * must exist and contain at least one file.
128 + *
129 + * @param resources path to resources
130 + *
131 + * @return true if the resources directory is valid, otherwise false
132 + */
133 + private boolean isValidResourcesDir(final Path resources) {
134 + return resources.toFile().exists()
135 + && resources.toFile().list().length != 0;
136 + }
137 }