|
48 | 48 | import java.util.Collections;
|
49 | 49 | import java.util.LinkedHashSet;
|
50 | 50 | import java.util.List;
|
| 51 | +import java.util.Locale; |
51 | 52 | import java.util.NoSuchElementException;
|
52 | 53 | import java.util.Properties;
|
53 | 54 | import java.util.Set;
|
@@ -118,32 +119,54 @@ public class JavadocUtil {
|
118 | 119 | + "environment variable using -Xms:<size> and -Xmx:<size>.";
|
119 | 120 |
|
120 | 121 | /**
|
121 |
| - * Method that removes the invalid directories in the specified directories. <b>Note</b>: All elements in |
122 |
| - * <code>dirs</code> could be an absolute or relative against the project's base directory <code>String</code> path. |
| 122 | + * Method that removes invalid classpath elements in the specified paths. <b>Note</b>: All elements in |
| 123 | + * <code>paths</code> could be absolute or relative against the project's base directory <code>String</code> path. |
| 124 | + * When pruning class paths, you can optionally include "*.jar" files in the result, otherwise only directories are |
| 125 | + * permitted. |
123 | 126 | *
|
124 | 127 | * @param project the current Maven project not null
|
125 |
| - * @param dirs the collection of <code>String</code> directories path that will be validated. |
126 |
| - * @return a List of valid <code>String</code> directories absolute paths. |
| 128 | + * @param paths the collection of <code>String</code> paths that will be validated |
| 129 | + * @param includeJars whether to include JAR files in the result |
| 130 | + * @return a list of valid <code>String</code> directories and optionally JAR files as absolute paths |
127 | 131 | */
|
128 |
| - public static Collection<Path> pruneDirs(MavenProject project, Collection<String> dirs) { |
| 132 | + public static Collection<Path> prunePaths(MavenProject project, Collection<String> paths, boolean includeJars) { |
129 | 133 | final Path projectBasedir = project.getBasedir().toPath();
|
130 | 134 |
|
131 |
| - Set<Path> pruned = new LinkedHashSet<>(dirs.size()); |
132 |
| - for (String dir : dirs) { |
133 |
| - if (dir == null) { |
| 135 | + Set<Path> pruned = new LinkedHashSet<>(paths.size()); |
| 136 | + for (String path : paths) { |
| 137 | + if (path == null) { |
134 | 138 | continue;
|
135 | 139 | }
|
136 | 140 |
|
137 |
| - Path directory = projectBasedir.resolve(dir); |
138 |
| - |
139 |
| - if (Files.isDirectory(directory)) { |
140 |
| - pruned.add(directory.toAbsolutePath()); |
| 141 | + Path resolvedPath = projectBasedir.resolve(path); |
| 142 | + |
| 143 | + if (Files.isDirectory(resolvedPath) |
| 144 | + || includeJars |
| 145 | + && Files.isRegularFile(resolvedPath) |
| 146 | + && resolvedPath |
| 147 | + .getFileName() |
| 148 | + .toString() |
| 149 | + .toLowerCase(Locale.ROOT) |
| 150 | + .endsWith(".jar")) { |
| 151 | + pruned.add(resolvedPath.toAbsolutePath()); |
141 | 152 | }
|
142 | 153 | }
|
143 | 154 |
|
144 | 155 | return pruned;
|
145 | 156 | }
|
146 | 157 |
|
| 158 | + /** |
| 159 | + * Method that removes the invalid directories in the specified directories. <b>Note</b>: All elements in |
| 160 | + * <code>dirs</code> could be absolute or relative against the project's base directory <code>String</code> path. |
| 161 | + * |
| 162 | + * @param project the current Maven project not null |
| 163 | + * @param dirs the collection of <code>String</code> directories that will be validated |
| 164 | + * @return a list of valid <code>String</code> directories as absolute paths |
| 165 | + */ |
| 166 | + public static Collection<Path> pruneDirs(MavenProject project, Collection<String> dirs) { |
| 167 | + return prunePaths(project, dirs, false); |
| 168 | + } |
| 169 | + |
147 | 170 | /**
|
148 | 171 | * Method that removes the invalid files in the specified files. <b>Note</b>: All elements in <code>files</code>
|
149 | 172 | * should be an absolute <code>String</code> path.
|
|
0 commit comments