View Javadoc
1   package org.apache.maven.shared.artifact.filter.resolve.transform;
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.ArrayList;
23  import java.util.List;
24  
25  import org.apache.maven.shared.artifact.filter.resolve.Node;
26  import org.eclipse.aether.artifact.ArtifactProperties;
27  import org.eclipse.aether.graph.Dependency;
28  import org.eclipse.aether.graph.DependencyNode;
29  import org.eclipse.aether.graph.Exclusion;
30  
31  /**
32   * Adapter of an Eclipse Aether DependencyNode for common Node 
33   * 
34   * @author Robert Scholte
35   * @since 3.0
36   */
37  class EclipseAetherNode implements Node
38  {
39  
40      private final DependencyNode node;
41  
42      EclipseAetherNode( DependencyNode node )
43      {
44          this.node = node;
45      }
46  
47      @Override
48      public org.apache.maven.model.Dependency getDependency()
49      {
50          Dependency nodeDependency = node.getDependency();
51  
52          if ( nodeDependency == null )
53          {
54              return null;
55          }
56  
57          org.apache.maven.model.Dependency mavenDependency = new org.apache.maven.model.Dependency();
58          mavenDependency.setGroupId( nodeDependency.getArtifact().getGroupId() );
59          mavenDependency.setArtifactId( nodeDependency.getArtifact().getArtifactId() );
60          mavenDependency.setVersion( nodeDependency.getArtifact().getVersion() );
61          mavenDependency.setClassifier( nodeDependency.getArtifact().getClassifier() );
62          mavenDependency.setType( nodeDependency.getArtifact().getProperty( ArtifactProperties.TYPE, null ) );
63          mavenDependency.setScope( nodeDependency.getScope() );
64          // Eclipse Aether supports three-valued logic
65          if ( nodeDependency.getOptional() != null )
66          {
67              mavenDependency.setOptional( nodeDependency.isOptional() );
68          }
69          if ( nodeDependency.getExclusions() != null )
70          {
71              List<org.apache.maven.model.Exclusion> mavenExclusions =
72                  new ArrayList<org.apache.maven.model.Exclusion>( nodeDependency.getExclusions().size() );
73  
74              for ( Exclusion aetherExclusion : nodeDependency.getExclusions() )
75              {
76                  org.apache.maven.model.Exclusion mavenExclusion = new org.apache.maven.model.Exclusion();
77  
78                  mavenExclusion.setGroupId( aetherExclusion.getGroupId() );
79                  mavenExclusion.setArtifactId( aetherExclusion.getArtifactId() );
80                  // that's all folks, although Aether has more metadata
81  
82                  mavenExclusions.add( mavenExclusion );
83              }
84  
85              mavenDependency.setExclusions( mavenExclusions );
86          }
87  
88          return mavenDependency;
89      }
90       
91  }