View Javadoc
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.obrplugin;
20  
21  
22  import java.net.URI;
23  import java.util.Arrays;
24  import java.util.List;
25  
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugin.logging.Log;
29  import org.apache.maven.plugins.annotations.LifecyclePhase;
30  import org.apache.maven.plugins.annotations.Mojo;
31  import org.apache.maven.plugins.annotations.Parameter;
32  import org.apache.maven.project.MavenProject;
33  
34  
35  /**
36   * Installs bundle details in the local OBR repository (command-line goal)
37   *
38   * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
39   */
40  @Mojo( name = "install-file", requiresProject = false, defaultPhase = LifecyclePhase.INSTALL )
41  public final class ObrInstallFile extends AbstractFileMojo
42  {
43      /**
44       * OBR Repository.
45       */
46      @Parameter( property = "obrRepository" )
47      private String obrRepository;
48  
49      /**
50       * Project types which this plugin supports.
51       */
52      @Parameter
53      private List supportedProjectTypes = Arrays.asList( new String[]
54          { "jar", "bundle" } );
55  
56      /**
57       * Local Repository.
58       */
59      @Parameter( defaultValue = "${localRepository}", readonly = true, required = true )
60      private ArtifactRepository localRepository;
61  
62  
63      public void execute() throws MojoExecutionException
64      {
65          MavenProject project = getProject();
66          String projectType = project.getPackaging();
67  
68          // ignore unsupported project types, useful when bundleplugin is configured in parent pom
69          if ( !supportedProjectTypes.contains( projectType ) )
70          {
71              getLog().warn(
72                  "Ignoring project type " + projectType + " - supportedProjectTypes = " + supportedProjectTypes );
73              return;
74          }
75          else if ( "NONE".equalsIgnoreCase( obrRepository ) || "false".equalsIgnoreCase( obrRepository ) )
76          {
77              getLog().info( "Local OBR update disabled (enable with -DobrRepository)" );
78              return;
79          }
80  
81          Log log = getLog();
82          ObrUpdate update;
83  
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 )
91          {
92              bundleJar = ObrUtils.getArtifactURI( localRepository, project.getArtifact() );
93          }
94          else
95          {
96              bundleJar = file.toURI();
97          }
98  
99          Config userConfig = new Config();
100 
101         update = new ObrUpdate( repositoryXml, obrXmlFile, project, mavenRepository, userConfig, log );
102         update.parseRepositoryXml();
103 
104         update.updateRepository( bundleJar, null, null );
105 
106         update.writeRepositoryXml();
107     }
108 }