View Javadoc

1   /*
2    * Copyright 2012-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.issue.util;
17  
18  import org.apache.commons.lang.StringUtils;
19  
20  /**
21   * Utilities concerning the packaging information.
22   */
23  public final class PackagingUtils
24  {
25    // ********************************* Fields *********************************
26  
27    // --- constants ------------------------------------------------------------
28  
29    // --- members --------------------------------------------------------------
30  
31    // ****************************** Initializer *******************************
32  
33    // ****************************** Constructors ******************************
34  
35    /**
36     * Default constructor.
37     */
38    private PackagingUtils()
39    {
40    }
41  
42    // ****************************** Inner Classes *****************************
43  
44    // ********************************* Methods ********************************
45  
46    // --- init -----------------------------------------------------------------
47  
48    // --- get&set --------------------------------------------------------------
49  
50    // --- business -------------------------------------------------------------
51  
52    /**
53     * Maps the Maven packaging information of the Maven POM to the default file
54     * extension.
55     *
56     * @param packaging the packaging found in the POM.
57     * @return the default extension that maps to the given {@code packaging}. If
58     *         {@code packaging} is blank, <code>jar</code> is returned.
59     */
60    public static String mapToExtension(final String packaging)
61    {
62      final String extension;
63  
64      if (StringUtils.isBlank(packaging) || "maven-plugin".equals(packaging)
65          || "maven-archetype".equals(packaging)
66          || "ejb".equals(packaging))
67      {
68        extension = "jar";
69      }
70      else if (packaging.startsWith("jboss-") && !packaging.endsWith("-"))
71      {
72        final int lastDashIndex = packaging.lastIndexOf('-');
73        extension = packaging.substring(lastDashIndex + 1);
74      }
75      else
76      {
77        extension = packaging;
78      }
79  
80      return extension;
81    }
82  
83    // --- object basics --------------------------------------------------------
84  
85  }