blob: 6686b21f7d964c00bca979f251840594d454f062 [file] [log] [blame]
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +00001/*
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 */
Stuart McCullochc792b372008-02-17 16:12:24 +000019package org.apache.felix.obrplugin;
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000020
21
22import java.io.File;
23
24import org.apache.maven.artifact.Artifact;
25import org.apache.maven.artifact.factory.ArtifactFactory;
26import org.apache.maven.plugin.AbstractMojo;
27import org.apache.maven.plugin.MojoExecutionException;
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000028import org.apache.maven.plugins.annotations.Component;
29import org.apache.maven.plugins.annotations.Parameter;
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000030import 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 */
38public abstract class AbstractFileMojo extends AbstractMojo
39{
40 /**
41 * GroupId of the bundle. Retrieved from POM file if specified.
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000042 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000043 @Parameter( property = "groupId" )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000044 private String groupId;
45
46 /**
47 * ArtifactId of the bundle. Retrieved from POM file if specified.
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000048 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000049 @Parameter( property = "artifactId" )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000050 private String artifactId;
51
52 /**
53 * Version of the bundle. Retrieved from POM file if specified.
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000054 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000055 @Parameter( property = "version" )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000056 private String version;
57
58 /**
59 * Packaging type of the bundle. Retrieved from POM file if specified.
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000060 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000061 @Parameter( property = "packaging" )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000062 private String packaging;
63
64 /**
65 * Classifier type of the bundle. Defaults to none.
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000066 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000067 @Parameter( property = "classifier" )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000068 private String classifier;
69
70 /**
71 * Location of an existing POM file.
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000072 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000073 @Parameter( property = "pomFile" )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000074 private File pomFile;
75
76 /**
77 * Bundle file, defaults to the artifact in the local Maven repository.
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000078 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000079 @Parameter( property = "file" )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000080 protected File file;
81
82 /**
83 * Optional XML file describing additional requirements and capabilities.
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000084 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000085 @Parameter( property = "obrXml" )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000086 protected String obrXml;
87
88 /**
89 * Component factory for Maven artifacts
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000090 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000091 @Component
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000092 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}