blob: c00455a472900626cb567e58d659600a3d29f7d5 [file] [log] [blame]
Stuart McCulloch61223202007-09-26 17:41:03 +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 McCulloch61223202007-09-26 17:41:03 +000020
Stuart McCulloch2b3b7132008-01-27 11:08:29 +000021
Stuart McCulloch61223202007-09-26 17:41:03 +000022import java.net.URI;
Stuart McCullochd7f187d2008-02-06 04:31:08 +000023import java.util.Arrays;
24import java.util.List;
Stuart McCulloch61223202007-09-26 17:41:03 +000025
Stuart McCulloch61223202007-09-26 17:41:03 +000026import org.apache.maven.artifact.repository.ArtifactRepository;
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000027import org.apache.maven.plugin.MojoExecutionException;
Stuart McCulloch61223202007-09-26 17:41:03 +000028import org.apache.maven.plugin.logging.Log;
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000029import org.apache.maven.plugins.annotations.LifecyclePhase;
30import org.apache.maven.plugins.annotations.Mojo;
31import org.apache.maven.plugins.annotations.Parameter;
Stuart McCulloch61223202007-09-26 17:41:03 +000032import org.apache.maven.project.MavenProject;
33
Stuart McCulloch2b3b7132008-01-27 11:08:29 +000034
Stuart McCulloch61223202007-09-26 17:41:03 +000035/**
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000036 * Installs bundle details in the local OBR repository (command-line goal)
Carsten Ziegeler0a4eff12015-05-12 06:04:41 +000037 *
Stuart McCulloch61223202007-09-26 17:41:03 +000038 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
39 */
Carsten Ziegeler0a4eff12015-05-12 06:04:41 +000040@Mojo( name = "install-file", requiresProject = false, defaultPhase = LifecyclePhase.INSTALL )
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000041public final class ObrInstallFile extends AbstractFileMojo
Stuart McCulloch61223202007-09-26 17:41:03 +000042{
43 /**
44 * OBR Repository.
Stuart McCulloch61223202007-09-26 17:41:03 +000045 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000046 @Parameter( property = "obrRepository" )
Stuart McCulloch61223202007-09-26 17:41:03 +000047 private String obrRepository;
48
49 /**
Stuart McCullochd7f187d2008-02-06 04:31:08 +000050 * Project types which this plugin supports.
Stuart McCullochd7f187d2008-02-06 04:31:08 +000051 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000052 @Parameter
Stuart McCullochd7f187d2008-02-06 04:31:08 +000053 private List supportedProjectTypes = Arrays.asList( new String[]
54 { "jar", "bundle" } );
55
56 /**
Stuart McCulloch61223202007-09-26 17:41:03 +000057 * Local Repository.
Stuart McCulloch61223202007-09-26 17:41:03 +000058 */
Carsten Ziegeler318c2cb2015-03-09 13:57:23 +000059 @Parameter( defaultValue = "${localRepository}", readonly = true, required = true )
Stuart McCulloch61223202007-09-26 17:41:03 +000060 private ArtifactRepository localRepository;
61
Stuart McCulloch61223202007-09-26 17:41:03 +000062
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000063 public void execute() throws MojoExecutionException
Stuart McCulloch61223202007-09-26 17:41:03 +000064 {
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000065 MavenProject project = getProject();
Stuart McCulloch3a965b92008-03-24 02:34:11 +000066 String projectType = project.getPackaging();
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000067
Stuart McCulloch3a965b92008-03-24 02:34:11 +000068 // ignore unsupported project types, useful when bundleplugin is configured in parent pom
69 if ( !supportedProjectTypes.contains( projectType ) )
Stuart McCulloch61223202007-09-26 17:41:03 +000070 {
Stuart McCulloch464dbac2008-08-03 09:47:04 +000071 getLog().warn(
72 "Ignoring project type " + projectType + " - supportedProjectTypes = " + supportedProjectTypes );
Stuart McCullochd7f187d2008-02-06 04:31:08 +000073 return;
74 }
Stuart McCulloch5d6cb732008-02-18 05:24:46 +000075 else if ( "NONE".equalsIgnoreCase( obrRepository ) || "false".equalsIgnoreCase( obrRepository ) )
Stuart McCullochd7f187d2008-02-06 04:31:08 +000076 {
Stuart McCulloch5d6cb732008-02-18 05:24:46 +000077 getLog().info( "Local OBR update disabled (enable with -DobrRepository)" );
Stuart McCulloch61223202007-09-26 17:41:03 +000078 return;
79 }
80
81 Log log = getLog();
Stuart McCullochb7d551a2007-09-27 12:08:11 +000082 ObrUpdate update;
Stuart McCulloch61223202007-09-26 17:41:03 +000083
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000084 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 McCullochb7d551a2007-09-27 12:08:11 +000091 {
Stuart McCulloch0ae86ab2008-02-19 06:24:30 +000092 bundleJar = ObrUtils.getArtifactURI( localRepository, project.getArtifact() );
Stuart McCullochb7d551a2007-09-27 12:08:11 +000093 }
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000094 else
Stuart McCullochb7d551a2007-09-27 12:08:11 +000095 {
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000096 bundleJar = file.toURI();
Stuart McCullochb7d551a2007-09-27 12:08:11 +000097 }
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000098
99 Config userConfig = new Config();
100
Stuart McCulloch0ae86ab2008-02-19 06:24:30 +0000101 update = new ObrUpdate( repositoryXml, obrXmlFile, project, mavenRepository, userConfig, log );
102 update.parseRepositoryXml();
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +0000103
Stuart McCullocha1d3a292008-02-20 00:53:52 +0000104 update.updateRepository( bundleJar, null, null );
Stuart McCulloch0ae86ab2008-02-19 06:24:30 +0000105
106 update.writeRepositoryXml();
Stuart McCulloch61223202007-09-26 17:41:03 +0000107 }
Stuart McCulloch61223202007-09-26 17:41:03 +0000108}