View Javadoc

1   /*
2    * Copyright 2006-2012 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.plugin.buildmetadata;
17  
18  import java.io.File;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.apache.maven.model.Build;
23  import org.apache.maven.project.MavenProject;
24  
25  /**
26   * Maps project types to property files.
27   *
28   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
29   * @version $Revision:591 $
30   */
31  final class PropertyOutputFileMapper
32  {
33    // ********************************* Fields *********************************
34  
35    // --- constants ------------------------------------------------------------
36  
37    // --- members --------------------------------------------------------------
38  
39    /**
40     * The Maven project.
41     */
42    private final MavenProject project;
43  
44    /**
45     * The mapping property.
46     */
47    private List<FileMapping> propertyOutputFileMapping;
48  
49    // ****************************** Initializer *******************************
50  
51    // ****************************** Constructors ******************************
52  
53    PropertyOutputFileMapper(final MavenProject project,
54        final List<FileMapping> propertyOutputFileMapping)
55    {
56      this.project = project;
57      this.propertyOutputFileMapping = propertyOutputFileMapping;
58    }
59  
60    // ****************************** Inner Classes *****************************
61  
62    // ********************************* Methods ********************************
63  
64    // --- init -----------------------------------------------------------------
65  
66    // --- get&set --------------------------------------------------------------
67  
68    // --- business -------------------------------------------------------------
69  
70    List<FileMapping> initPropertyOutputFileMapping()
71    {
72      if (propertyOutputFileMapping == null)
73      {
74        propertyOutputFileMapping = new ArrayList<FileMapping>(10);
75        final Build build = project.getBuild();
76        final String classesDir = build.getOutputDirectory();
77        final File jarFile = new File(classesDir, "META-INF/build.properties");
78        final File targetDir = new File(build.getDirectory());
79        final String finalName = build.getFinalName();
80        final File deploymentUnitFile =
81            new File(targetDir, finalName + "/META-INF/build.properties");
82  
83        propertyOutputFileMapping.add(new FileMapping("pom", new File(targetDir,
84            "build.properties"))); // NOPMD
85        propertyOutputFileMapping.add(new FileMapping("war", deploymentUnitFile));
86        propertyOutputFileMapping.add(new FileMapping("ear", deploymentUnitFile));
87        propertyOutputFileMapping.add(new FileMapping("sar", deploymentUnitFile));
88        propertyOutputFileMapping.add(new FileMapping("rar", deploymentUnitFile));
89        propertyOutputFileMapping.add(new FileMapping("par", deploymentUnitFile));
90        propertyOutputFileMapping.add(new FileMapping("jar", jarFile));
91        propertyOutputFileMapping.add(new FileMapping("ejb", jarFile));
92        propertyOutputFileMapping.add(new FileMapping("maven-plugin", jarFile));
93        propertyOutputFileMapping
94            .add(new FileMapping("maven-archetype", jarFile));
95        propertyOutputFileMapping.add(new FileMapping("eclipse-plugin", new File(targetDir,
96        "build.properties")));
97        propertyOutputFileMapping.add(new FileMapping("eclipse-feature", new File(targetDir,
98        "build.properties")));
99        propertyOutputFileMapping.add(new FileMapping("eclipse-repository", new File(targetDir,
100       "build.properties")));
101       propertyOutputFileMapping.add(new FileMapping("eclipse-update-site", new File(targetDir,
102       "build.properties")));
103       propertyOutputFileMapping.add(new FileMapping("targetplatform", new File(targetDir,
104       "build.properties")));
105       return propertyOutputFileMapping;
106 
107     }
108 
109     return propertyOutputFileMapping;
110   }
111 
112   /**
113    * Returns the output location for the build meta data properties.
114    *
115    * @return the output location for the build meta data properties.
116    */
117   File getPropertiesOutputFile(final boolean activatePropertyOutputFileMapping,
118       final File propertiesOutputFile)
119   {
120     if (activatePropertyOutputFileMapping)
121     {
122       final String packaging = project.getPackaging();
123       for (final FileMapping mapping : propertyOutputFileMapping)
124       {
125         if (packaging.equals(mapping.getPackaging()))
126         {
127           return mapping.getOutputFile();
128         }
129       }
130     }
131 
132     return propertiesOutputFile;
133   }
134 
135   // --- object basics --------------------------------------------------------
136 
137 }