View Javadoc

1   package org.apache.maven.plugin;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.ArtifactUtils;
23  import org.apache.maven.model.Plugin;
24  import org.apache.maven.plugin.descriptor.PluginDescriptor;
25  import org.codehaus.plexus.util.StringUtils;
26  
27  /**
28   * Provides utility methods for plugin management.
29   * 
30   * @author Benjamin Bentmann
31   */
32  class PluginUtils
33  {
34  
35      /**
36       * Creates a lookup key for the specified plugin.
37       * 
38       * @param plugin The plugin, must not be <code>null</code>.
39       * @return The lookup key for the plugin in the form groupId:artifactId:baseVersion, never <code>null</code>.
40       */
41      public static String constructVersionedKey( Plugin plugin )
42      {
43          return constructVersionedKey( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
44      }
45  
46      /**
47       * Creates a lookup key for the specified plugin.
48       * 
49       * @param plugin The plugin's descriptor, must not be <code>null</code>.
50       * @return The lookup key for the plugin in the form groupId:artifactId:baseVersion, never <code>null</code>.
51       */
52      public static String constructVersionedKey( PluginDescriptor plugin )
53      {
54          return constructVersionedKey( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
55      }
56  
57      /**
58       * Creates a lookup key from the specified plugin coordinates.
59       * 
60       * @param groupId The group id of the plugin, must not be <code>null</code> or empty.
61       * @param artifactId The artifact id of the plugin, must not be <code>null</code> or empty.
62       * @param version The (possibly) timestamped version of the plugin, must not be <code>null</code> or empty.
63       * @return The lookup key for the plugin in the form groupId:artifactId:baseVersion, never <code>null</code>.
64       */
65      private static String constructVersionedKey( String groupId, String artifactId, String version )
66      {
67          if ( StringUtils.isEmpty( version ) )
68          {
69              throw new IllegalStateException( "version for plugin " + groupId + ":" + artifactId + " is not set" );
70          }
71  
72          String baseVersion = ArtifactUtils.toSnapshotVersion( version );
73  
74          StringBuffer key = new StringBuffer( 128 );
75          key.append( groupId ).append( ':' ).append( artifactId ).append( ':' ).append( baseVersion );
76          return key.toString();
77      }
78  
79  }