View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.artifact.filter.resolve.transform;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.maven.shared.artifact.filter.resolve.Node;
25  import org.eclipse.aether.artifact.ArtifactProperties;
26  import org.eclipse.aether.graph.Dependency;
27  import org.eclipse.aether.graph.DependencyNode;
28  import org.eclipse.aether.graph.Exclusion;
29  
30  /**
31   * Adapter of an Eclipse Aether DependencyNode for common Node
32   *
33   * @author Robert Scholte
34   * @since 3.0
35   */
36  class EclipseAetherNode implements Node {
37  
38      private final DependencyNode node;
39  
40      EclipseAetherNode(DependencyNode node) {
41          this.node = node;
42      }
43  
44      /** {@inheritDoc} */
45      @Override
46      public org.apache.maven.model.Dependency getDependency() {
47          Dependency nodeDependency = node.getDependency();
48  
49          if (nodeDependency == null) {
50              return null;
51          }
52  
53          org.apache.maven.model.Dependency mavenDependency = new org.apache.maven.model.Dependency();
54          mavenDependency.setGroupId(nodeDependency.getArtifact().getGroupId());
55          mavenDependency.setArtifactId(nodeDependency.getArtifact().getArtifactId());
56          mavenDependency.setVersion(nodeDependency.getArtifact().getVersion());
57          mavenDependency.setClassifier(nodeDependency.getArtifact().getClassifier());
58          mavenDependency.setType(nodeDependency.getArtifact().getProperty(ArtifactProperties.TYPE, null));
59          mavenDependency.setScope(nodeDependency.getScope());
60          // Eclipse Aether supports three-valued logic
61          if (nodeDependency.getOptional() != null) {
62              mavenDependency.setOptional(nodeDependency.isOptional());
63          }
64          if (nodeDependency.getExclusions() != null) {
65              List<org.apache.maven.model.Exclusion> mavenExclusions =
66                      new ArrayList<>(nodeDependency.getExclusions().size());
67  
68              for (Exclusion aetherExclusion : nodeDependency.getExclusions()) {
69                  org.apache.maven.model.Exclusion mavenExclusion = new org.apache.maven.model.Exclusion();
70  
71                  mavenExclusion.setGroupId(aetherExclusion.getGroupId());
72                  mavenExclusion.setArtifactId(aetherExclusion.getArtifactId());
73                  // that's all folks, although Aether has more metadata
74  
75                  mavenExclusions.add(mavenExclusion);
76              }
77  
78              mavenDependency.setExclusions(mavenExclusions);
79          }
80  
81          return mavenDependency;
82      }
83  }