Coverage Report - org.apache.maven.plugin.eclipse.MakeArtifactsMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
MakeArtifactsMojo
58%
11/19
50%
6/12
2,2
 
 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.maven.plugin.eclipse;
 20  
 
 21  
 import java.util.Map;
 22  
 import java.util.StringTokenizer;
 23  
 
 24  
 import org.apache.maven.model.Model;
 25  
 import org.apache.maven.plugin.MojoExecutionException;
 26  
 import org.apache.maven.plugin.MojoFailureException;
 27  
 import org.apache.maven.plugin.eclipse.osgiplugin.EclipseOsgiPlugin;
 28  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 29  
 import org.codehaus.plexus.util.StringUtils;
 30  
 
 31  
 /**
 32  
  * Add eclipse artifacts from an eclipse installation to the local repo. This mojo automatically analize the eclipse
 33  
  * directory, copy plugins jars to the local maven repo, and generates appropriate poms. Use
 34  
  * <code>eclipse:to-maven</code> for the latest naming conventions in place, <code>groupId</code>.
 35  
  * <code>artifactId</code>.
 36  
  * 
 37  
  * @author Fabrizio Giustina
 38  
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
 39  
  * @version $Id: MakeArtifactsMojo.java 691404 2008-09-02 21:57:19Z aheritier $
 40  
  * @goal make-artifacts
 41  
  * @requiresProject false
 42  
  * @deprecated use {@link EclipseToMavenMojo} for the latest naming conventions
 43  
  */
 44  30
 public class MakeArtifactsMojo
 45  
     extends EclipseToMavenMojo
 46  
     implements Contextualizable
 47  
 {
 48  
 
 49  
     /**
 50  
      * Strip qualifier (fourth token) from the plugin version. Qualifiers are for eclipse plugin the equivalent of
 51  
      * timestamped snapshot versions for Maven, but the date is maintained also for released version (e.g. a jar for the
 52  
      * release <code>3.2</code> can be named <code>org.eclipse.core.filesystem_1.0.0.v20060603.jar</code>. It's usually
 53  
      * handy to not to include this qualifier when generating maven artifacts for major releases, while it's needed when
 54  
      * working with eclipse integration/nightly builds.
 55  
      * 
 56  
      * @parameter expression="${stripQualifier}" default-value="true"
 57  
      */
 58  
     private boolean stripQualifier;
 59  
 
 60  
     /**
 61  
      * Default token to use as a qualifier. Tipically qualifiers for plugins in the same eclipse build are different.
 62  
      * This parameter can be used to "align" qualifiers so that all the plugins coming from the same eclipse build can
 63  
      * be easily identified. For example, setting this to "M3" will force the pluging versions to be "*.*.*.M3"
 64  
      * 
 65  
      * @parameter expression="${forcedQualifier}"
 66  
      */
 67  
     private String forcedQualifier;
 68  
 
 69  
     /**
 70  
      * Resolve version ranges in generated pom dependencies to versions of the other plugins being converted
 71  
      * 
 72  
      * @parameter expression="${resolveVersionRanges}" default-value="false"
 73  
      */
 74  
     private boolean resolveVersionRanges;
 75  
 
 76  
     protected String osgiVersionToMavenVersion( String version )
 77  
     {
 78  0
         return osgiVersionToMavenVersion( version, forcedQualifier, stripQualifier );
 79  
     }
 80  
 
 81  
     /**
 82  
      * Get the group id as the three first tokens in artifacts Id e.g. <code>org.eclipse.jdt</code> ->
 83  
      * <code>org.eclipse.jdt</code>
 84  
      * 
 85  
      * @param bundleName bundle name
 86  
      * @return group id
 87  
      */
 88  
     protected String createGroupId( String bundleName )
 89  
     {
 90  78
         if ( StringUtils.countMatches( bundleName, "." ) > 1 )
 91  
         {
 92  66
             StringTokenizer st = new StringTokenizer( bundleName, "." );
 93  66
             int i = 0;
 94  66
             String groupId = "";
 95  264
             while ( st.hasMoreTokens() && ( i < 3 ) )
 96  
             {
 97  198
                 groupId += "." + st.nextToken();
 98  198
                 i++;
 99  
             }
 100  66
             return groupId.substring( 1 );
 101  
         }
 102  12
         return bundleName;
 103  
     }
 104  
 
 105  
     /**
 106  
      * Get the artifact id equal to the bundleName e.g. <code>org.eclipse.jdt</code> -> <code>org.eclipse.jdt</code>
 107  
      * 
 108  
      * @param bundleName bundle name
 109  
      * @return artifact id
 110  
      */
 111  
     protected String createArtifactId( String bundleName )
 112  
     {
 113  78
         return bundleName;
 114  
     }
 115  
 
 116  
     protected void resolveVersionRanges( Model model, Map models )
 117  
         throws MojoFailureException
 118  
     {
 119  0
         if ( resolveVersionRanges )
 120  
         {
 121  0
             super.resolveVersionRanges( model, models );
 122  
         }
 123  
         else
 124  
         {
 125  
             // do nothing
 126  
         }
 127  0
     }
 128  
 
 129  
     protected void processPlugin( EclipseOsgiPlugin plugin, Model model, Map plugins, Map models )
 130  
         throws MojoExecutionException, MojoFailureException
 131  
     {
 132  0
         if ( this.resolveVersionRanges && plugins.containsKey( getKey( model ) ) )
 133  
         {
 134  0
             throw new MojoFailureException( "There are two versions of the same plugin, can not resolve versions: "
 135  
                 + getKey( model ) );
 136  
         }
 137  
 
 138  0
         super.processPlugin( plugin, model, plugins, models );
 139  0
     }
 140  
 
 141  
 }