Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 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 | */ |
Stuart McCulloch | c792b37 | 2008-02-17 16:12:24 +0000 | [diff] [blame] | 19 | package org.apache.felix.obrplugin; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 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; |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 28 | import org.apache.maven.plugins.annotations.Component; |
| 29 | import org.apache.maven.plugins.annotations.Parameter; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 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. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 42 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 43 | @Parameter( property = "groupId" ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 44 | private String groupId; |
| 45 | |
| 46 | /** |
| 47 | * ArtifactId of the bundle. Retrieved from POM file if specified. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 48 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 49 | @Parameter( property = "artifactId" ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 50 | private String artifactId; |
| 51 | |
| 52 | /** |
| 53 | * Version of the bundle. Retrieved from POM file if specified. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 54 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 55 | @Parameter( property = "version" ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 56 | private String version; |
| 57 | |
| 58 | /** |
| 59 | * Packaging type of the bundle. Retrieved from POM file if specified. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 60 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 61 | @Parameter( property = "packaging" ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 62 | private String packaging; |
| 63 | |
| 64 | /** |
| 65 | * Classifier type of the bundle. Defaults to none. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 66 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 67 | @Parameter( property = "classifier" ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 68 | private String classifier; |
| 69 | |
| 70 | /** |
| 71 | * Location of an existing POM file. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 72 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 73 | @Parameter( property = "pomFile" ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 74 | private File pomFile; |
| 75 | |
| 76 | /** |
| 77 | * Bundle file, defaults to the artifact in the local Maven repository. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 78 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 79 | @Parameter( property = "file" ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 80 | protected File file; |
| 81 | |
| 82 | /** |
| 83 | * Optional XML file describing additional requirements and capabilities. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 84 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 85 | @Parameter( property = "obrXml" ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 86 | protected String obrXml; |
| 87 | |
| 88 | /** |
| 89 | * Component factory for Maven artifacts |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 90 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 91 | @Component |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 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 | } |