-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RAT-322: be able to scan hidden directories
- Loading branch information
Showing
13 changed files
with
316 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
apache-rat-core/src/main/java/org/apache/rat/walker/NameBasedHiddenFileFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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.rat.walker; | ||
|
||
import org.apache.commons.io.filefilter.AbstractFileFilter; | ||
import org.apache.commons.io.filefilter.IOFileFilter; | ||
|
||
import java.io.File; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* This filter accepts Files that are hidden, e.g. file name starts with . | ||
* | ||
* Example, showing how to print out a list of the current directory's hidden files: | ||
* | ||
* Using Classic IO | ||
* File dir = new File("."); | ||
* String[] files = dir.list(NameBasedHiddenFileFilter.HIDDEN); | ||
* for (String file : files) { | ||
* System.out.println(file); | ||
* } | ||
* | ||
* Using NIO | ||
* | ||
* final Path dir = Paths.get(""); | ||
* final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(NameBasedHiddenFileFilter.HIDDEN); | ||
* // | ||
* // Walk one dir | ||
* Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); | ||
* System.out.println(visitor.getPathCounters()); | ||
* System.out.println(visitor.getFileList()); | ||
* // | ||
* visitor.getPathCounters().reset(); | ||
* // | ||
* // Walk dir tree | ||
* Files.walkFileTree(dir, visitor); | ||
* System.out.println(visitor.getPathCounters()); | ||
* System.out.println(visitor.getDirList()); | ||
* System.out.println(visitor.getFileList()); | ||
*/ | ||
public class NameBasedHiddenFileFilter extends AbstractFileFilter implements Serializable { | ||
|
||
/** | ||
* Singleton instance of hidden filter. | ||
*/ | ||
public static final IOFileFilter HIDDEN = new NameBasedHiddenFileFilter(); | ||
|
||
/** | ||
* Restrictive constructor. | ||
*/ | ||
protected NameBasedHiddenFileFilter() { | ||
} | ||
|
||
/** | ||
* Checks to see if the file is hidden, e.g. file name starts with . | ||
* | ||
* @param file the File to check | ||
* @return true if the file is hidden (file name starting with .), false else | ||
*/ | ||
@Override | ||
public boolean accept(File file) { | ||
if (file.getName().startsWith(".")) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.