View Javadoc
1   package org.eclipse.aether.util.graph.transformer;
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 java.util.IdentityHashMap;
23  import java.util.Map;
24  
25  import org.eclipse.aether.RepositoryException;
26  import org.eclipse.aether.artifact.Artifact;
27  import org.eclipse.aether.collection.DependencyGraphTransformationContext;
28  import org.eclipse.aether.collection.DependencyGraphTransformer;
29  import org.eclipse.aether.graph.Dependency;
30  import org.eclipse.aether.graph.DependencyNode;
31  import org.eclipse.aether.util.graph.transformer.TransformationContextKeys;
32  
33  /**
34   * Set "groupId:artId:classifier:extension" as conflict marker for every node.
35   */
36  class SimpleConflictMarker
37      implements DependencyGraphTransformer
38  {
39  
40      public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context )
41          throws RepositoryException
42      {
43          @SuppressWarnings( "unchecked" )
44          Map<DependencyNode, Object> conflictIds =
45              (Map<DependencyNode, Object>) context.get( TransformationContextKeys.CONFLICT_IDS );
46          if ( conflictIds == null )
47          {
48              conflictIds = new IdentityHashMap<DependencyNode, Object>();
49              context.put( TransformationContextKeys.CONFLICT_IDS, conflictIds );
50          }
51  
52          mark( node, conflictIds );
53  
54          return node;
55      }
56  
57      private void mark( DependencyNode node, Map<DependencyNode, Object> conflictIds )
58      {
59          Dependency dependency = node.getDependency();
60          if ( dependency != null )
61          {
62              Artifact artifact = dependency.getArtifact();
63  
64              String key =
65                  String.format( "%s:%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(),
66                                 artifact.getClassifier(), artifact.getExtension() );
67  
68              if ( conflictIds.put( node, key ) != null )
69              {
70                  return;
71              }
72          }
73  
74          for ( DependencyNode child : node.getChildren() )
75          {
76              mark( child, conflictIds );
77          }
78      }
79  
80  }