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