Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +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 | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 20 | |
Stuart McCulloch | 2b3b713 | 2008-01-27 11:08:29 +0000 | [diff] [blame] | 21 | |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 22 | import java.net.URI; |
Stuart McCulloch | d7f187d | 2008-02-06 04:31:08 +0000 | [diff] [blame] | 23 | import java.util.Arrays; |
| 24 | import java.util.List; |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 25 | |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 26 | import org.apache.maven.artifact.repository.ArtifactRepository; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 27 | import org.apache.maven.plugin.MojoExecutionException; |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 28 | import org.apache.maven.plugin.logging.Log; |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 29 | import org.apache.maven.plugins.annotations.LifecyclePhase; |
| 30 | import org.apache.maven.plugins.annotations.Mojo; |
| 31 | import org.apache.maven.plugins.annotations.Parameter; |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 32 | import org.apache.maven.project.MavenProject; |
| 33 | |
Stuart McCulloch | 2b3b713 | 2008-01-27 11:08:29 +0000 | [diff] [blame] | 34 | |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 35 | /** |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 36 | * Installs bundle details in the local OBR repository (command-line goal) |
Carsten Ziegeler | 0a4eff1 | 2015-05-12 06:04:41 +0000 | [diff] [blame] | 37 | * |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 38 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 39 | */ |
Carsten Ziegeler | 0a4eff1 | 2015-05-12 06:04:41 +0000 | [diff] [blame] | 40 | @Mojo( name = "install-file", requiresProject = false, defaultPhase = LifecyclePhase.INSTALL ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 41 | public final class ObrInstallFile extends AbstractFileMojo |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 42 | { |
| 43 | /** |
| 44 | * OBR Repository. |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 45 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 46 | @Parameter( property = "obrRepository" ) |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 47 | private String obrRepository; |
| 48 | |
| 49 | /** |
Stuart McCulloch | d7f187d | 2008-02-06 04:31:08 +0000 | [diff] [blame] | 50 | * Project types which this plugin supports. |
Stuart McCulloch | d7f187d | 2008-02-06 04:31:08 +0000 | [diff] [blame] | 51 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 52 | @Parameter |
Stuart McCulloch | d7f187d | 2008-02-06 04:31:08 +0000 | [diff] [blame] | 53 | private List supportedProjectTypes = Arrays.asList( new String[] |
| 54 | { "jar", "bundle" } ); |
| 55 | |
| 56 | /** |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 57 | * Local Repository. |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 58 | */ |
Carsten Ziegeler | 318c2cb | 2015-03-09 13:57:23 +0000 | [diff] [blame] | 59 | @Parameter( defaultValue = "${localRepository}", readonly = true, required = true ) |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 60 | private ArtifactRepository localRepository; |
| 61 | |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 62 | |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 63 | public void execute() throws MojoExecutionException |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 64 | { |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 65 | MavenProject project = getProject(); |
Stuart McCulloch | 3a965b9 | 2008-03-24 02:34:11 +0000 | [diff] [blame] | 66 | String projectType = project.getPackaging(); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 67 | |
Stuart McCulloch | 3a965b9 | 2008-03-24 02:34:11 +0000 | [diff] [blame] | 68 | // ignore unsupported project types, useful when bundleplugin is configured in parent pom |
| 69 | if ( !supportedProjectTypes.contains( projectType ) ) |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 70 | { |
Stuart McCulloch | 464dbac | 2008-08-03 09:47:04 +0000 | [diff] [blame] | 71 | getLog().warn( |
| 72 | "Ignoring project type " + projectType + " - supportedProjectTypes = " + supportedProjectTypes ); |
Stuart McCulloch | d7f187d | 2008-02-06 04:31:08 +0000 | [diff] [blame] | 73 | return; |
| 74 | } |
Stuart McCulloch | 5d6cb73 | 2008-02-18 05:24:46 +0000 | [diff] [blame] | 75 | else if ( "NONE".equalsIgnoreCase( obrRepository ) || "false".equalsIgnoreCase( obrRepository ) ) |
Stuart McCulloch | d7f187d | 2008-02-06 04:31:08 +0000 | [diff] [blame] | 76 | { |
Stuart McCulloch | 5d6cb73 | 2008-02-18 05:24:46 +0000 | [diff] [blame] | 77 | getLog().info( "Local OBR update disabled (enable with -DobrRepository)" ); |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 78 | return; |
| 79 | } |
| 80 | |
| 81 | Log log = getLog(); |
Stuart McCulloch | b7d551a | 2007-09-27 12:08:11 +0000 | [diff] [blame] | 82 | ObrUpdate update; |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 83 | |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 84 | String mavenRepository = localRepository.getBasedir(); |
| 85 | |
| 86 | URI repositoryXml = ObrUtils.findRepositoryXml( mavenRepository, obrRepository ); |
| 87 | URI obrXmlFile = ObrUtils.toFileURI( obrXml ); |
| 88 | URI bundleJar; |
| 89 | |
| 90 | if ( null == file ) |
Stuart McCulloch | b7d551a | 2007-09-27 12:08:11 +0000 | [diff] [blame] | 91 | { |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 92 | bundleJar = ObrUtils.getArtifactURI( localRepository, project.getArtifact() ); |
Stuart McCulloch | b7d551a | 2007-09-27 12:08:11 +0000 | [diff] [blame] | 93 | } |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 94 | else |
Stuart McCulloch | b7d551a | 2007-09-27 12:08:11 +0000 | [diff] [blame] | 95 | { |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 96 | bundleJar = file.toURI(); |
Stuart McCulloch | b7d551a | 2007-09-27 12:08:11 +0000 | [diff] [blame] | 97 | } |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 98 | |
| 99 | Config userConfig = new Config(); |
| 100 | |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 101 | update = new ObrUpdate( repositoryXml, obrXmlFile, project, mavenRepository, userConfig, log ); |
| 102 | update.parseRepositoryXml(); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 103 | |
Stuart McCulloch | a1d3a29 | 2008-02-20 00:53:52 +0000 | [diff] [blame] | 104 | update.updateRepository( bundleJar, null, null ); |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 105 | |
| 106 | update.writeRepositoryXml(); |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 107 | } |
Stuart McCulloch | 6122320 | 2007-09-26 17:41:03 +0000 | [diff] [blame] | 108 | } |