View Javadoc
1   package org.apache.maven.internal.impl;
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.Collections;
23  import java.util.List;
24  import java.util.function.Predicate;
25  import java.util.stream.Collectors;
26  
27  import org.apache.maven.api.Node;
28  import org.apache.maven.api.NodeVisitor;
29  import org.eclipse.aether.artifact.Artifact;
30  import org.eclipse.aether.graph.Dependency;
31  import org.eclipse.aether.graph.DependencyNode;
32  
33  public abstract class AbstractNode implements Node
34  {
35  
36      abstract org.eclipse.aether.graph.DependencyNode getDependencyNode();
37  
38      @Override
39      public boolean accept( NodeVisitor visitor )
40      {
41          if ( visitor.enter( this ) )
42          {
43              for ( Node child : getChildren() )
44              {
45                  if ( !child.accept( visitor ) )
46                  {
47                      break;
48                  }
49              }
50          }
51          return visitor.leave( this );
52      }
53  
54      @Override
55      public Node filter( Predicate<Node> filter )
56      {
57          List<Node> children = getChildren().stream().filter( filter )
58                  .map( n -> n.filter( filter ) )
59                  .collect( Collectors.toList() );
60          return new WrapperNode( this, Collections.unmodifiableList( children ) );
61      }
62  
63      @Override
64      public String asString()
65      {
66          StringBuilder sb = new StringBuilder();
67  
68          DependencyNode node = getDependencyNode();
69          Artifact artifact = node.getArtifact();
70          sb.append( artifact );
71  
72          Dependency dependency = node.getDependency();
73          if ( dependency != null )
74          {
75              sb.append( ":" ).append( dependency.getScope() );
76          }
77  
78          return sb.toString();
79      }
80  
81      @Override
82      public String toString()
83      {
84          return getDependencyNode().toString();
85      }
86  }