View Javadoc

1   /*
2    * Copyright 2007-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.exceptions.report.scan;
17  
18  import java.io.File;
19  
20  import org.apache.tools.ant.BuildException;
21  import org.apache.tools.ant.DirectoryScanner;
22  import org.apache.tools.ant.types.selectors.FileSelector;
23  
24  /**
25   * Base implementation of the interface.
26   */
27  public abstract class AbstractScannerFactory implements ScannerFactory
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    // --- members --------------------------------------------------------------
34  
35    /**
36     * The includes for the scanner.
37     */
38    protected final String[] includes;
39  
40    /**
41     * The excludes for the scanner.
42     */
43    protected final String[] excludes;
44  
45    /**
46     * Standard selectors.
47     */
48    private final FileSelector[] selectors =
49        new FileSelector[] { new FileSelector()
50        {
51          @Override
52          public boolean isSelected(final File basedir, final String filename,
53              final File file) throws BuildException
54          {
55            return filename.endsWith(".java");
56          }
57        } };
58  
59    // ****************************** Initializer *******************************
60  
61    // ****************************** Constructors ******************************
62  
63    /**
64     * Default constructor.
65     *
66     * @param includes the includes for the scanner.
67     * @param excludes the excludes for the scanner.
68     */
69    protected AbstractScannerFactory(final String[] includes,
70        final String[] excludes)
71    {
72      this.includes = includes.clone();
73      this.excludes = excludes.clone();
74    }
75  
76    // ****************************** Inner Classes *****************************
77  
78    // ********************************* Methods ********************************
79  
80    // --- init -----------------------------------------------------------------
81  
82    // --- get&set --------------------------------------------------------------
83  
84    // --- business -------------------------------------------------------------
85  
86    /**
87     * Configures the scanner and runs the scan.
88     *
89     * @param scanner the scanner to configure and run the scan.
90     */
91    protected final void configureAndScan(final DirectoryScanner scanner)
92    {
93      scanner.setCaseSensitive(true);
94      if (includes.length > 0)
95      {
96        scanner.setIncludes(includes);
97      }
98      if (excludes.length > 0)
99      {
100       scanner.setExcludes(excludes);
101     }
102     scanner.setSelectors(selectors);
103 
104     scanner.scan();
105   }
106 
107   @Override
108   public final DirectoryScanner createScanner(final String root)
109   {
110     return createScanner(new File(root));
111   }
112 
113   // --- object basics --------------------------------------------------------
114 
115 }