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