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