1 package org.apache.maven.shared.utils.io;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.File;
23
24 /**
25 * <p>Visitor pattern for the DirectoryScanner. A ScanConductor controls the scanning process.</p>
26 * <p/>
27 * <p>Create an instance and pass it to
28 * {@link org.apache.maven.shared.utils.io.DirectoryScanner#setScanConductor(ScanConductor)}.
29 * You will get notified about every visited directory and file. You can use the {@link ScanAction}
30 * to control what should happen next.</p>
31 * <p/>
32 * <p>A ScanConductor might also store own information but users must make sure that the state gets
33 * cleaned between two scan() invocations.</p>
34 *
35 * @author <a href="mailto:struberg@apache.org">Mark Struberg</a>
36 */
37 public interface ScanConductor
38 {
39 /**
40 *
41 */
42 public enum ScanAction
43 {
44 /**
45 * Abort the whole scanning process. The current file will not
46 * be added anymore.
47 */
48 ABORT,
49
50 /**
51 * Continue the scanning with the next item in the list.
52 */
53 CONTINUE,
54
55 /**
56 * This response is only valid for {@link ScanConductor#visitDirectory(String, java.io.File)}.
57 * Do not recurse into the current directory. The current directory will not be added
58 * and the processing will be continued with the next item in the list.
59 */
60 NO_RECURSE,
61
62 /**
63 * Abort processing the current directory.
64 * The current file will not be added.
65 * The processing will continue it's scan in the parent directory if any.
66 */
67 ABORT_DIRECTORY
68 }
69
70 /**
71 * This method will get invoked for every detected directory.
72 *
73 * @param name the directory name (contains parent folders up to the pwd)
74 * @param directory
75 * @return the ScanAction to control how to proceed with the scanning
76 */
77 ScanAction visitDirectory( String name, File directory );
78
79 /**
80 * This method will get invoked for every detected file.
81 *
82 * @param name the file name (contains parent folders up to the pwd)
83 * @param file
84 * @return the ScanAction to control how to proceed with the scanning
85 */
86 ScanAction visitFile( String name, File file );
87 }