View Javadoc

1   /*
2    * Copyright 2011-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.maven.recode;
17  
18  import java.nio.charset.Charset;
19  
20  import org.apache.maven.plugin.AbstractMojo;
21  import org.apache.maven.plugin.MojoExecutionException;
22  import org.apache.maven.plugin.MojoFailureException;
23  
24  /**
25   * Lists supported encodings of the platform.
26   *
27   * @goal list
28   * @phase initialize
29   * @description Lists supported encodings of the platform.
30   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
31   * @version $Revision$
32   */
33  public class MavenListEncodingsMojo extends AbstractMojo
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    // --- members --------------------------------------------------------------
40  
41    /**
42     * A simple flag to skip recoding. If set on the command line use
43     * <code>-Drecode.skip</code>.
44     *
45     * @parameter expression="${recode.skip}" default-value="false"
46     * @since 1.0
47     */
48    private boolean skip;
49  
50    /**
51     * A simple flag to request a compact (<code>true</code>) representation of
52     * the supported encodings (only separated by a space) or a pretty-printed
53     * (<code>false</code>) representation with each encoding on a new line,
54     * prefixed by a space.
55     * <p>
56     * If set on the command line use <code>-Drecode.compact</code>.
57     * </p>
58     *
59     * @parameter expression="${recode.compact}" default-value="false"
60     * @since 1.0
61     */
62    private boolean compact;
63  
64    // ****************************** Initializer *******************************
65  
66    // ****************************** Constructors ******************************
67  
68    // ****************************** Inner Classes *****************************
69  
70    // ********************************* Methods ********************************
71  
72    // --- init -----------------------------------------------------------------
73  
74    // --- get&set --------------------------------------------------------------
75  
76    // --- business -------------------------------------------------------------
77  
78    /**
79     * {@inheritDoc}
80     *
81     * @see org.apache.maven.plugin.AbstractMojo#execute()
82     */
83    public void execute() throws MojoExecutionException, MojoFailureException
84    {
85      if (!skip)
86      {
87        final StringBuilder buffer = new StringBuilder(512);
88        buffer.append("Supported charsets:");
89        for (final String charset : Charset.availableCharsets().keySet())
90        {
91          buffer.append(' ').append(charset);
92          if (!compact)
93          {
94            buffer.append('\n');
95          }
96        }
97        getLog().info(buffer.toString());
98      }
99      else
100     {
101       getLog().info("Skipping list of supported encodings.");
102     }
103   }
104 
105   // --- object basics --------------------------------------------------------
106 
107 }