View Javadoc
1   package org.apache.maven.plugin.internal;
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.eclipse.aether.RepositoryException;
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.artifact.DefaultArtifact;
25  import org.eclipse.aether.collection.DependencyGraphTransformationContext;
26  import org.eclipse.aether.collection.DependencyGraphTransformer;
27  import org.eclipse.aether.graph.DefaultDependencyNode;
28  import org.eclipse.aether.graph.Dependency;
29  import org.eclipse.aether.graph.DependencyNode;
30  import org.eclipse.aether.util.artifact.JavaScopes;
31  
32  /**
33   * Injects plexus-utils:1.1 into a plugin's class path if it doesn't already declare a dependency on plexus-utils. This
34   * is another legacy bit to provide backward-compat with Maven 2.x.
35   *
36   * @author Benjamin Bentmann
37   */
38  class PlexusUtilsInjector
39      implements DependencyGraphTransformer
40  {
41  
42      private static final String GID = "org.codehaus.plexus";
43  
44      private static final String AID = "plexus-utils";
45  
46      private static final String VER = "1.1";
47  
48      private static final String EXT = "jar";
49  
50      public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context )
51          throws RepositoryException
52      {
53          if ( findPlexusUtils( node ) == null )
54          {
55              Artifact pu = new DefaultArtifact( GID, AID, null, EXT, VER );
56              DefaultDependencyNode child = new DefaultDependencyNode( new Dependency( pu, JavaScopes.RUNTIME ) );
57              child.setRepositories( node.getRepositories() );
58              child.setRequestContext( node.getRequestContext() );
59              node.getChildren().add( child );
60          }
61  
62          return node;
63      }
64  
65      private DependencyNode findPlexusUtils( DependencyNode node )
66      {
67          Artifact artifact = node.getDependency().getArtifact();
68  
69          if ( AID.equals( artifact.getArtifactId() ) && GID.equals( artifact.getGroupId() )
70              && EXT.equals( artifact.getExtension() ) && "".equals( artifact.getClassifier() ) )
71          {
72              return node;
73          }
74  
75          for ( DependencyNode child : node.getChildren() )
76          {
77              DependencyNode result = findPlexusUtils( child );
78              if ( result != null )
79              {
80                  return result;
81              }
82          }
83  
84          return null;
85      }
86  
87  }