View Javadoc

1   /*
2    FileSetUtils.java
3    Creation date : 14/07/2010
4    Copyright © Benjamin Croizet (graffity2199@yahoo.fr)
5   
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License
8    or GNU Lesser General Public License as published by the
9    Free Software Foundation; either version 3 of the License,
10   or (at your option) any later version.
11  
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16  
17   You should have received copies of the GNU General Public License
18   and GNU Lesser General Public License along with this program;
19   if not, write to the Free Software Foundation, Inc.,
20   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21   http://www.fsf.org/licensing/licenses/gpl.html
22   http://www.gnu.org/licenses/lgpl.html
23   */
24  
25  package net.sourceforge.plantumldependency.commoncli.utils.fileset;
26  
27  import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
28  import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.COMMAND_LINE_ARGUMENTS_NULL_ERROR;
29  
30  import java.io.File;
31  
32  import org.apache.tools.ant.Project;
33  import org.apache.tools.ant.types.FileSet;
34  
35  /**
36   * The class utilities simplifying some {@link FileSet} tasks.
37   *
38   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
39   * @since 1.3.0
40   * @version 1.3.0
41   */
42  public abstract class FileSetUtils {
43  
44      /**
45       * Creates a {@link FileSet} instance following passed parameters.
46       *
47       * @param baseDirectory
48       *            the base directory, mustn't be <code>null</code>.
49       * @param includePattern
50       *            the include pattern, mustn't be <code>null</code>.
51       * @return the {@link FileSet} instance following passed parameters.
52       * @since 1.3.0
53       */
54      public static FileSet createFileSet(final File baseDirectory, final String includePattern) {
55          checkNull(baseDirectory, COMMAND_LINE_ARGUMENTS_NULL_ERROR);
56          checkNull(includePattern, COMMAND_LINE_ARGUMENTS_NULL_ERROR);
57  
58          final FileSet fileSet = new FileSet();
59          final Project project = new Project();
60          fileSet.setProject(project);
61          fileSet.setDir(baseDirectory);
62          fileSet.setIncludes(includePattern);
63          return fileSet;
64      }
65  
66      /**
67       * Creates a {@link FileSet} instance following passed parameters.
68       *
69       * @param baseDirectory
70       *            the base directory, mustn't be <code>null</code>.
71       * @param includePattern
72       *            the include pattern, mustn't be <code>null</code>.
73       * @param excludePattern
74       *            the exclude pattern, mustn't be <code>null</code>.
75       * @return the {@link FileSet} instance following passed parameters.
76       * @since 1.3.0
77       */
78      public static FileSet createFileSet(final File baseDirectory, final String includePattern,
79              final String excludePattern) {
80          checkNull(baseDirectory, COMMAND_LINE_ARGUMENTS_NULL_ERROR);
81          checkNull(includePattern, COMMAND_LINE_ARGUMENTS_NULL_ERROR);
82          checkNull(excludePattern, COMMAND_LINE_ARGUMENTS_NULL_ERROR);
83  
84          final FileSet fileSet = new FileSet();
85          final Project project = new Project();
86          fileSet.setProject(project);
87          fileSet.setDir(baseDirectory);
88          fileSet.setIncludes(includePattern);
89          fileSet.setExcludes(excludePattern);
90          return fileSet;
91      }
92  
93      /**
94       * Private constructor to prevent from instantiation.
95       *
96       * @since 1.3.0
97       */
98      private FileSetUtils() {
99          super();
100     }
101 }