This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch scanner in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
commit e8569990102d79db1ffae53d066751e75005978b Author: Elliotte Rusty Harold <elh...@ibiblio.org> AuthorDate: Sun Jul 9 22:24:34 2023 -0400 JDK > DirectoryScanner --- .../maven/plugins/javadoc/FileAccumulator.java | 75 ++++++++++++++++++++++ .../apache/maven/plugins/javadoc/JavadocUtil.java | 8 +++ 2 files changed, 83 insertions(+) diff --git a/src/main/java/org/apache/maven/plugins/javadoc/FileAccumulator.java b/src/main/java/org/apache/maven/plugins/javadoc/FileAccumulator.java new file mode 100644 index 00000000..f6c2b4a2 --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/javadoc/FileAccumulator.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.javadoc; + +import java.io.IOException; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.List; + +class FileAccumulator implements FileVisitor<Path> { + + private List<PathMatcher> sourceFileIncludes = new ArrayList<>(); + private List<PathMatcher> sourceFileExcludes = new ArrayList<>(); + private List<String> includedFiles = new ArrayList<>(); + + FileAccumulator(List<String> sourceFileIncludes, List<String> sourceFileExcludes) { + + FileSystem fileSystem = FileSystems.getDefault(); + for (String glob : sourceFileIncludes) { + this.sourceFileIncludes.add(fileSystem.getPathMatcher("glob:" + glob)); + } + } + + @Override + public FileVisitResult postVisitDirectory(Path path, IOException ex) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes arg1) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes ex) throws IOException { + for (PathMatcher matcher : sourceFileIncludes) { + if (matcher.matches(path)) { + includedFiles.add(path.toString()); + break; + } + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path path, IOException ex) throws IOException { + return FileVisitResult.CONTINUE; + } + + String[] getIncludedFiles() { + return includedFiles.toArray(new String[0]); + } +} diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java index 4e4e2c67..5eb7956f 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -414,7 +414,15 @@ public class JavadocUtil { ds.setBasedir(sourceDirectory); ds.scan(); + FileAccumulator accumulator = new FileAccumulator(sourceFileIncludes, sourceFileExcludes); + try { + Files.walkFileTree(sourceDirectory.toPath(), accumulator); + } catch (IOException e) { + throw new IllegalStateException(e); + } + String[] fileList = ds.getIncludedFiles(); + fileList = accumulator.getIncludedFiles(); List<String> files = new ArrayList<>(); if (fileList.length != 0) {