View Javadoc

1   /*
2    PlantUMLDependencyIncludeOption.java
3    Creation date : 2/06/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.cli.main.option.include;
26  
27  import static java.util.Arrays.asList;
28  import static java.util.Collections.unmodifiableSet;
29  import static net.sourceforge.plantumldependency.cli.constants.PlantUMLDependencyConstants.DEFAULT_INCLUDE_OPTIONS;
30  import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.PROGRAMMING_LANGUAGE_OPTION_NULL_ERROR;
31  import static net.sourceforge.plantumldependency.cli.main.option.programminglanguage.PlantUMLDependencyProgrammingLanguageOption.DEFAULT_PROGRAMMING_LANGUAGE;
32  import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.SPACE_CHAR;
33  import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
34  import static net.sourceforge.plantumldependency.commoncli.option.status.OptionStatus.ACTIVE_OPTIONAL_OPTION_STATUS;
35  
36  import java.util.Set;
37  import java.util.TreeSet;
38  
39  import net.sourceforge.plantumldependency.cli.main.option.programminglanguage.PlantUMLDependencyProgrammingLanguageOption;
40  import net.sourceforge.plantumldependency.commoncli.command.CommandLine;
41  import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
42  import net.sourceforge.plantumldependency.commoncli.option.AbstractOptionWithArgument;
43  import net.sourceforge.plantumldependency.commoncli.option.argument.impl.filepattern.IncludeFilePatternOptionArgumentImpl;
44  
45  import org.apache.tools.ant.types.FileSet;
46  
47  /**
48   * The include option, allowing to specify an include file pattern, like ANT. <i>Note : no option
49   * should have the same main or secondary names</i>.
50   *
51   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
52   * @since 1.0.0
53   * @version 1.3.0
54   */
55  public class PlantUMLDependencyIncludeOption extends AbstractOptionWithArgument < FileSet > {
56  
57      /** Serial version UID. */
58      private static final long serialVersionUID = -7573306659605231967L;
59  
60      /** Option main synopsis. */
61      public static final String OPTION_MAIN_SYNOPSIS = "-i";
62  
63      /** Option synopsis alias. */
64      public static final Set < String > OPTION_SYNOPSIS = unmodifiableSet(new TreeSet < String >(
65              asList(new String[] {"--include"})));
66  
67      /** The programming language option. */
68      private PlantUMLDependencyProgrammingLanguageOption programmingLanguageOption;
69  
70      /**
71       * Default constructor.
72       *
73       * @param programmingLanguageOpt
74       *            the {@link PlantUMLDependencyProgrammingLanguageOption} instance, to know what is
75       *            the programming language to parse, mustn't be <code>null</code>.
76       * @since 1.0.0
77       */
78      public PlantUMLDependencyIncludeOption(final PlantUMLDependencyProgrammingLanguageOption programmingLanguageOpt) {
79          super(OPTION_MAIN_SYNOPSIS, OPTION_SYNOPSIS, new IncludeFilePatternOptionArgumentImpl(true), new StringBuilder(
80                  "To include files that match the provided pattern. If not specified, the default pattern is \"**/*."
81                          + DEFAULT_PROGRAMMING_LANGUAGE.getName() + "\"."), SPACE_CHAR, ACTIVE_OPTIONAL_OPTION_STATUS);
82          setProgrammingLanguageOption(programmingLanguageOpt);
83          // FIXME to uncomment if the PlantUMLDependencyProgrammingLanguageOption passes to ACTIVE
84          // (not
85          // HIDDEN)
86          // super(
87          // OPTION_MAIN_SYNOPSIS,
88          // OPTION_SYNOPSIS,
89          // new IncludeFilePatternOptionArgumentImpl(true),
90          // new StringBuilder(
91          // "To include files that match the provided pattern. If not specified, the default pattern is \"**/*.PROGRAMMING_LANGUAGE_FILE_EXTENSION\" depending on the programming language chosen (only \""
92          // + DEFAULT_PROGRAMMING_LANGUAGE.getName() + "\" is supported by now)."), SPACE_CHAR,
93          // ACTIVE_OPTIONAL_OPTION_STATUS);
94          // setProgrammingLanguageOption(programmingLanguageOpt);
95      }
96  
97      /**
98       * {@inheritDoc}
99       *
100      * @since 1.0.0
101      */
102     @Override
103     public String getDefaultArgumentAsStringIfOptionNotSpecified(final CommandLine commandLine)
104             throws CommandLineException {
105         return DEFAULT_INCLUDE_OPTIONS
106                 + getProgrammingLanguageOption().findAndParseArgumentOrGetDefaultArgument(commandLine).getName();
107     }
108 
109     /**
110      * {@inheritDoc}
111      *
112      * @since 1.0.0
113      */
114     @Override
115     public String getDefaultArgumentAsStringIfOptionSpecified(final CommandLine commandLine)
116             throws CommandLineException {
117         return DEFAULT_INCLUDE_OPTIONS
118                 + getProgrammingLanguageOption().findAndParseArgumentOrGetDefaultArgument(commandLine).getName();
119     }
120 
121     /**
122      * Gets the value of <code>programmingLanguageOption</code>.
123      *
124      * @return the value of <code>programmingLanguageOption</code>.
125      * @see #setProgrammingLanguageOption(PlantUMLDependencyProgrammingLanguageOption)
126      * @since 1.0.0
127      */
128     private PlantUMLDependencyProgrammingLanguageOption getProgrammingLanguageOption() {
129         return programmingLanguageOption;
130     }
131 
132     /**
133      * Sets the value of <code>programmingLanguageOption</code>.
134      *
135      * @param value
136      *            the <code>programmingLanguageOption</code> to set, can be <code>null</code>.
137      * @see #getProgrammingLanguageOption()
138      * @since 1.0.0
139      */
140     private void setProgrammingLanguageOption(final PlantUMLDependencyProgrammingLanguageOption value) {
141         checkNull(value, PROGRAMMING_LANGUAGE_OPTION_NULL_ERROR);
142 
143         programmingLanguageOption = value;
144     }
145 }