View Javadoc
1   package org.apache.maven.plugin.ear;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.ear.output.FileNameMapping;
23  import org.apache.maven.plugin.ear.output.FileNameMappingFactory;
24  import org.apache.maven.plugin.ear.util.ArtifactRepository;
25  import org.apache.maven.plugin.ear.util.ArtifactTypeMappingService;
26  import org.apache.maven.project.MavenProject;
27  
28  /**
29   * Contains various runtime parameters used to customize the generated EAR file.
30   * 
31   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
32   * @version $Id: EarExecutionContext.java 1645331 2014-12-13 17:31:09Z khmarbaise $
33   */
34  public class EarExecutionContext
35  {
36      private String defaultLibBundleDir;
37  
38      private JbossConfiguration jbossConfiguration;
39  
40      private FileNameMapping fileNameMapping;
41  
42      private ArtifactRepository artifactRepository;
43  
44      /**
45       * @param project {@link MavenProject}
46       * @param mainArtifactId The artifactId.
47       * @param defaultLibBundleDir The defaultLibBundleDir.
48       * @param jbossConfiguration {@link JbossConfiguration}
49       * @param fileNameMappingName file name mapping.
50       * @param typeMappingService {@link ArtifactTypeMappingService}
51       */
52      public EarExecutionContext( MavenProject project, String mainArtifactId, String defaultLibBundleDir,
53                                  JbossConfiguration jbossConfiguration, String fileNameMappingName,
54                                  ArtifactTypeMappingService typeMappingService )
55      {
56          initialize( project, mainArtifactId, defaultLibBundleDir, jbossConfiguration, fileNameMappingName,
57                      typeMappingService );
58  
59      }
60  
61      /**
62       * @return {@link #defaultLibBundleDir}
63       */
64      public String getDefaultLibBundleDir()
65      {
66          return defaultLibBundleDir;
67      }
68  
69      /**
70       * @return {@link #jbossConfiguration}
71       */
72      public boolean isJbossConfigured()
73      {
74          return jbossConfiguration != null;
75      }
76  
77      /**
78       * @return {@link #fileNameMapping}
79       */
80      public FileNameMapping getFileNameMapping()
81      {
82          return fileNameMapping;
83      }
84  
85      /**
86       * @return {@link #artifactRepository}
87       */
88      public ArtifactRepository getArtifactRepository()
89      {
90          return artifactRepository;
91      }
92  
93      @SuppressWarnings( "unchecked" )
94      private void initialize( MavenProject project, String mainArtifactId, String defaultLibBundleDir,
95                               JbossConfiguration jbossConfiguration, String fileNameMappingName,
96                               ArtifactTypeMappingService typeMappingService )
97      {
98          this.artifactRepository = new ArtifactRepository( project.getArtifacts(), mainArtifactId, typeMappingService );
99          this.defaultLibBundleDir = defaultLibBundleDir;
100         this.jbossConfiguration = jbossConfiguration;
101         if ( fileNameMappingName == null || fileNameMappingName.trim().length() == 0 )
102         {
103             this.fileNameMapping = FileNameMappingFactory.getDefaultFileNameMapping();
104         }
105         else
106         {
107             this.fileNameMapping = FileNameMappingFactory.getFileNameMapping( fileNameMappingName );
108         }
109     }
110 }