View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.felix.obrplugin;
20  
21  
22  import java.io.File;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.factory.ArtifactFactory;
26  import org.apache.maven.plugin.AbstractMojo;
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugins.annotations.Component;
29  import org.apache.maven.plugins.annotations.Parameter;
30  import org.apache.maven.project.MavenProject;
31  
32  
33  /**
34   * Base class for the command-line install-file and deploy-file goals.
35   * 
36   * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
37   */
38  public abstract class AbstractFileMojo extends AbstractMojo
39  {
40      /**
41       * GroupId of the bundle. Retrieved from POM file if specified.
42       */
43      @Parameter( property = "groupId" )
44      private String groupId;
45  
46      /**
47       * ArtifactId of the bundle. Retrieved from POM file if specified.
48       */
49      @Parameter( property = "artifactId" )
50      private String artifactId;
51  
52      /**
53       * Version of the bundle. Retrieved from POM file if specified.
54       */
55      @Parameter( property = "version" )
56      private String version;
57  
58      /**
59       * Packaging type of the bundle. Retrieved from POM file if specified.
60       */
61      @Parameter( property = "packaging" )
62      private String packaging;
63  
64      /**
65       * Classifier type of the bundle. Defaults to none.
66       */
67      @Parameter( property = "classifier" )
68      private String classifier;
69  
70      /**
71       * Location of an existing POM file.
72       */
73      @Parameter( property = "pomFile" )
74      private File pomFile;
75  
76      /**
77       * Bundle file, defaults to the artifact in the local Maven repository.
78       */
79      @Parameter( property = "file" )
80      protected File file;
81  
82      /**
83       * Optional XML file describing additional requirements and capabilities.
84       */
85      @Parameter( property = "obrXml" )
86      protected String obrXml;
87  
88      /**
89       * Component factory for Maven artifacts
90       */
91      @Component
92      private ArtifactFactory m_factory;
93  
94  
95      /**
96       * @return project based on command-line settings, with bundle attached
97       * @throws MojoExecutionException
98       */
99      public MavenProject getProject() throws MojoExecutionException
100     {
101         final MavenProject project;
102         if ( pomFile != null && pomFile.exists() )
103         {
104             project = PomHelper.readPom( pomFile );
105 
106             groupId = project.getGroupId();
107             artifactId = project.getArtifactId();
108             version = project.getVersion();
109             packaging = project.getPackaging();
110         }
111         else
112         {
113             project = PomHelper.buildPom( groupId, artifactId, version, packaging );
114         }
115 
116         if ( groupId == null || artifactId == null || version == null || packaging == null )
117         {
118             throw new MojoExecutionException( "Missing group, artifact, version, or packaging information" );
119         }
120 
121         Artifact bundle = m_factory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier );
122         project.setArtifact( bundle );
123 
124         return project;
125     }
126 }