1 package org.apache.maven.api; 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 org.apache.maven.api.annotations.Experimental; 23 import org.apache.maven.api.annotations.Immutable; 24 import org.apache.maven.api.annotations.Nonnull; 25 26 import java.util.List; 27 import java.util.Optional; 28 import java.util.function.Predicate; 29 import java.util.stream.Stream; 30 31 /** 32 * Represents a dependency node within a Maven project's dependency collector. 33 * 34 * @since 4.0 35 * @see org.apache.maven.api.services.DependencyCollectorResult#getRoot() 36 */ 37 @Experimental 38 @Immutable 39 public interface Node 40 { 41 42 /** 43 * @return dependency for this node 44 */ 45 Dependency getDependency(); 46 47 /** 48 * Gets the child nodes of this node. 49 * 50 * @return the child nodes of this node, never {@code null} 51 */ 52 @Nonnull 53 List<Node> getChildren(); 54 55 /** 56 * @return repositories of this node 57 */ 58 @Nonnull 59 List<RemoteRepository> getRemoteRepositories(); 60 61 /** 62 * The repository where this artifact has been downloaded from. 63 */ 64 @Nonnull 65 Optional<RemoteRepository> getRepository(); 66 67 /** 68 * Traverses this node and potentially its children using the specified visitor. 69 * 70 * @param visitor The visitor to call back, must not be {@code null}. 71 * @return {@code true} to visit siblings nodes of this node as well, {@code false} to skip siblings. 72 */ 73 boolean accept( @Nonnull NodeVisitor visitor ); 74 75 /** 76 * Returns a new tree starting at this node, filtering the children. 77 * Note that this node will not be filtered and only the children 78 * and its descendant will be checked. 79 * 80 * @param filter the filter to apply 81 * @return a new filtered graph 82 */ 83 Node filter( Predicate<Node> filter ); 84 85 /** 86 * Returns a string representation of this dependency node. 87 * 88 * @return the string representation 89 */ 90 String asString(); 91 92 /** 93 * Obtain a Stream containing this node and all its descendant. 94 * 95 * @return a stream containing this node and its descendant 96 */ 97 @Nonnull 98 default Stream<Node> stream() 99 { 100 return Stream.concat( Stream.of( this ), getChildren().stream().flatMap( Node::stream ) ); 101 } 102 103 }