Stuart McCulloch | cda5cba | 2008-02-05 05:34:35 +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 | */ |
| 19 | package org.apache.felix.obr.plugin; |
| 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.project.MavenProject; |
| 29 | |
| 30 | |
| 31 | /** |
| 32 | * Base class for the command-line install-file and deploy-file goals. |
| 33 | * |
| 34 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 35 | */ |
| 36 | public abstract class AbstractFileMojo extends AbstractMojo |
| 37 | { |
| 38 | /** |
| 39 | * GroupId of the bundle. Retrieved from POM file if specified. |
| 40 | * |
| 41 | * @parameter expression="${groupId}" |
| 42 | */ |
| 43 | private String groupId; |
| 44 | |
| 45 | /** |
| 46 | * ArtifactId of the bundle. Retrieved from POM file if specified. |
| 47 | * |
| 48 | * @parameter expression="${artifactId}" |
| 49 | */ |
| 50 | private String artifactId; |
| 51 | |
| 52 | /** |
| 53 | * Version of the bundle. Retrieved from POM file if specified. |
| 54 | * |
| 55 | * @parameter expression="${version}" |
| 56 | */ |
| 57 | private String version; |
| 58 | |
| 59 | /** |
| 60 | * Packaging type of the bundle. Retrieved from POM file if specified. |
| 61 | * |
| 62 | * @parameter expression="${packaging}" |
| 63 | */ |
| 64 | private String packaging; |
| 65 | |
| 66 | /** |
| 67 | * Classifier type of the bundle. Defaults to none. |
| 68 | * |
| 69 | * @parameter expression="${classifier}" |
| 70 | */ |
| 71 | private String classifier; |
| 72 | |
| 73 | /** |
| 74 | * Location of an existing POM file. |
| 75 | * |
| 76 | * @parameter expression="${pomFile}" |
| 77 | */ |
| 78 | private File pomFile; |
| 79 | |
| 80 | /** |
| 81 | * Bundle file, defaults to the artifact in the local Maven repository. |
| 82 | * |
| 83 | * @parameter expression="${file}" |
| 84 | */ |
| 85 | protected File file; |
| 86 | |
| 87 | /** |
| 88 | * Optional XML file describing additional requirements and capabilities. |
| 89 | * |
| 90 | * @parameter expression="${obrXml}" |
| 91 | */ |
| 92 | protected String obrXml; |
| 93 | |
| 94 | /** |
| 95 | * Component factory for Maven artifacts |
| 96 | * |
| 97 | * @component |
| 98 | */ |
| 99 | private ArtifactFactory m_factory; |
| 100 | |
| 101 | |
| 102 | /** |
| 103 | * @return project based on command-line settings, with bundle attached |
| 104 | * @throws MojoExecutionException |
| 105 | */ |
| 106 | public MavenProject getProject() throws MojoExecutionException |
| 107 | { |
| 108 | final MavenProject project; |
| 109 | if ( pomFile != null && pomFile.exists() ) |
| 110 | { |
| 111 | project = PomHelper.readPom( pomFile ); |
| 112 | |
| 113 | groupId = project.getGroupId(); |
| 114 | artifactId = project.getArtifactId(); |
| 115 | version = project.getVersion(); |
| 116 | packaging = project.getPackaging(); |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | project = PomHelper.buildPom( groupId, artifactId, version, packaging ); |
| 121 | } |
| 122 | |
| 123 | if ( groupId == null || artifactId == null || version == null || packaging == null ) |
| 124 | { |
| 125 | throw new MojoExecutionException( "Missing group, artifact, version, or packaging information" ); |
| 126 | } |
| 127 | |
| 128 | Artifact bundle = m_factory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier ); |
| 129 | project.setArtifact( bundle ); |
| 130 | |
| 131 | return project; |
| 132 | } |
| 133 | } |