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.api.services;
20
21 import org.apache.maven.api.Artifact;
22 import org.apache.maven.api.DependencyCoordinate;
23 import org.apache.maven.api.Project;
24 import org.apache.maven.api.Service;
25 import org.apache.maven.api.Session;
26 import org.apache.maven.api.annotations.Experimental;
27 import org.apache.maven.api.annotations.Nonnull;
28
29 /**
30 * The DependencyCollector service can be used to collect dependencies
31 * for a given artifact and builds a graph of them.
32 * The dependencies collection mechanism will not download any artifacts,
33 * and only the pom files will be downloaded.
34 *
35 * @since 4.0
36 */
37 @Experimental
38 public interface DependencyCollector extends Service {
39
40 /**
41 * Collects the transitive dependencies and builds a dependency graph.
42 * Note that this operation is only concerned about determining the coordinates of the
43 * transitive dependencies and does not actually resolve the artifact files.
44 *
45 * @param request the dependency collection request, must not be {@code null}
46 * @return the collection result, never {@code null}
47 * @throws DependencyCollectorException if the dependency tree could not be built
48 * @throws IllegalArgumentException if an argument is null or invalid
49 *
50 * @see DependencyCollector#collect(Session, Project)
51 * @see DependencyCollector#collect(Session, DependencyCoordinate)
52 * @see DependencyCollector#collect(Session, Artifact)
53 */
54 @Nonnull
55 DependencyCollectorResult collect(@Nonnull DependencyCollectorRequest request);
56
57 /**
58 * Collects the transitive dependencies of some artifacts and builds a dependency graph. Note that this operation is
59 * only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the
60 * artifact files.
61 *
62 * @param session the {@link Session}, must not be {@code null}
63 * @param root the Maven Dependency, must not be {@code null}
64 * @return the collection result, never {@code null}
65 * @throws DependencyCollectorException if the dependency tree could not be built
66 * @throws IllegalArgumentException if an argument is null or invalid
67 * @see #collect(DependencyCollectorRequest)
68 */
69 @Nonnull
70 default DependencyCollectorResult collect(@Nonnull Session session, @Nonnull DependencyCoordinate root) {
71 return collect(DependencyCollectorRequest.build(session, root));
72 }
73
74 /**
75 * Collects the transitive dependencies of some artifacts and builds a dependency graph. Note that this operation is
76 * only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the
77 * artifact files.
78 *
79 * @param session the {@link Session}, must not be {@code null}
80 * @param project the {@link Project}, must not be {@code null}
81 * @return the collection result, never {@code null}
82 * @throws DependencyCollectorException if the dependency tree could not be built
83 * @throws IllegalArgumentException if an argument is null or invalid
84 * @see #collect(DependencyCollectorRequest)
85 */
86 @Nonnull
87 default DependencyCollectorResult collect(@Nonnull Session session, @Nonnull Project project) {
88 return collect(DependencyCollectorRequest.build(session, project));
89 }
90
91 /**
92 * Collects the transitive dependencies of some artifacts and builds a dependency graph. Note that this operation is
93 * only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the
94 * artifact files.
95 *
96 * @param session the {@link Session}, must not be {@code null}
97 * @param artifact the {@link Artifact}, must not be {@code null}
98 * @return the collection result, never {@code null}
99 * @throws DependencyCollectorException if the dependency tree could not be built
100 * @throws IllegalArgumentException if an argument is null or invalid
101 * @see #collect(DependencyCollectorRequest)
102 */
103 @Nonnull
104 default DependencyCollectorResult collect(@Nonnull Session session, @Nonnull Artifact artifact) {
105 return collect(DependencyCollectorRequest.build(session, artifact));
106 }
107 }