View Javadoc

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  
23  import java.io.File;
24  
25  /**
26   * <p>Visitor pattern for the DirectoryScanner. A ScanConductor controls the scanning process.</p>
27   * <p/>
28   * <p>Create an instance and pass it to
29   * {@link org.apache.maven.shared.utils.io.DirectoryScanner#setScanConductor(ScanConductor)}.
30   * You will get notified about every visited directory and file. You can use the {@link ScanAction}
31   * to control what should happen next.</p>
32   * <p/>
33   * <p>A ScanConductor might also store own information but users must make sure that the state gets
34   * cleaned between two scan() invocations.</p>
35   *
36   * @author <a href="mailto:struberg@apache.org">Mark Struberg</a>
37   */
38  public interface ScanConductor
39  {
40      public enum ScanAction
41      {
42          /**
43           * Abort the whole scanning process. The current file will not
44           * be added anymore.
45           */
46          ABORT,
47  
48          /**
49           * Continue the scanning with the next item in the list.
50           */
51          CONTINUE,
52  
53          /**
54           * This response is only valid for {@link ScanConductor#visitDirectory(String, java.io.File)}.
55           * Do not recurse into the current directory. The current directory will not be added
56           * and the processing will be continued with the next item in the list.
57           */
58          NO_RECURSE,
59  
60          /**
61           * Abort processing the current directory.
62           * The current file will not be added.
63           * The processing will continue it's scan in the parent directory if any.
64           */
65          ABORT_DIRECTORY
66      }
67  
68      /**
69       * This method will get invoked for every detected directory.
70       *
71       * @param name      the directory name (contains parent folders up to the pwd)
72       * @param directory
73       * @return the ScanAction to control how to proceed with the scanning
74       */
75      ScanAction visitDirectory( String name, File directory );
76  
77      /**
78       * This method will get invoked for every detected file.
79       *
80       * @param name the file name (contains parent folders up to the pwd)
81       * @param file
82       * @return the ScanAction to control how to proceed with the scanning
83       */
84      ScanAction visitFile( String name, File file );
85  }