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      /** {@inheritDoc} */
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          // Eclipse Aether supports three-valued logic
66          if ( nodeDependency.getOptional() != null )
67          {
68              mavenDependency.setOptional( nodeDependency.isOptional() );
69          }
70          if ( nodeDependency.getExclusions() != null )
71          {
72              List<org.apache.maven.model.Exclusion> mavenExclusions =
73                      new ArrayList<>( nodeDependency.getExclusions().size() );
74  
75              for ( Exclusion aetherExclusion : nodeDependency.getExclusions() )
76              {
77                  org.apache.maven.model.Exclusion mavenExclusion = new org.apache.maven.model.Exclusion();
78  
79                  mavenExclusion.setGroupId( aetherExclusion.getGroupId() );
80                  mavenExclusion.setArtifactId( aetherExclusion.getArtifactId() );
81                  // that's all folks, although Aether has more metadata
82  
83                  mavenExclusions.add( mavenExclusion );
84              }
85  
86              mavenDependency.setExclusions( mavenExclusions );
87          }
88  
89          return mavenDependency;
90      }
91       
92  }