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.api.services;
20  
21  import java.util.Collection;
22  import java.util.List;
23  
24  import org.apache.maven.api.Artifact;
25  import org.apache.maven.api.DependencyCoordinate;
26  import org.apache.maven.api.Project;
27  import org.apache.maven.api.ResolutionScope;
28  import org.apache.maven.api.Session;
29  import org.apache.maven.api.annotations.Experimental;
30  import org.apache.maven.api.annotations.Nonnull;
31  import org.apache.maven.api.annotations.NotThreadSafe;
32  import org.apache.maven.api.annotations.Nullable;
33  
34  @Experimental
35  public interface DependencyResolverRequest extends DependencyCollectorRequest {
36  
37      @Nonnull
38      ResolutionScope getResolutionScope();
39  
40      @Nonnull
41      static DependencyResolverRequestBuilder builder() {
42          return new DependencyResolverRequestBuilder();
43      }
44  
45      @Nonnull
46      static DependencyResolverRequest build(Session session, Project project) {
47          return build(session, project, ResolutionScope.PROJECT_RUNTIME);
48      }
49  
50      @Nonnull
51      static DependencyResolverRequest build(Session session, Project project, ResolutionScope scope) {
52          return new DependencyResolverRequestBuilder()
53                  .session(session)
54                  .project(project)
55                  .resolutionScope(scope)
56                  .build();
57      }
58  
59      @Nonnull
60      static DependencyResolverRequest build(Session session, DependencyCoordinate dependency) {
61          return build(session, dependency, ResolutionScope.PROJECT_RUNTIME);
62      }
63  
64      @Nonnull
65      static DependencyResolverRequest build(Session session, DependencyCoordinate dependency, ResolutionScope scope) {
66          return new DependencyResolverRequestBuilder()
67                  .session(session)
68                  .dependency(dependency)
69                  .resolutionScope(scope)
70                  .build();
71      }
72  
73      @Nonnull
74      static DependencyResolverRequest build(Session session, List<DependencyCoordinate> dependencies) {
75          return build(session, dependencies, ResolutionScope.PROJECT_RUNTIME);
76      }
77  
78      @Nonnull
79      static DependencyResolverRequest build(
80              Session session, List<DependencyCoordinate> dependencies, ResolutionScope scope) {
81          return new DependencyResolverRequestBuilder()
82                  .session(session)
83                  .dependencies(dependencies)
84                  .resolutionScope(scope)
85                  .build();
86      }
87  
88      @NotThreadSafe
89      class DependencyResolverRequestBuilder extends DependencyCollectorRequestBuilder {
90          ResolutionScope resolutionScope;
91  
92          @Nonnull
93          @Override
94          public DependencyResolverRequestBuilder session(@Nonnull Session session) {
95              super.session(session);
96              return this;
97          }
98  
99          @Nonnull
100         @Override
101         public DependencyResolverRequestBuilder project(@Nullable Project project) {
102             super.project(project);
103             return this;
104         }
105 
106         @Nonnull
107         @Override
108         public DependencyResolverRequestBuilder rootArtifact(@Nullable Artifact rootArtifact) {
109             super.rootArtifact(rootArtifact);
110             return this;
111         }
112 
113         @Nonnull
114         @Override
115         public DependencyResolverRequestBuilder root(@Nullable DependencyCoordinate root) {
116             super.root(root);
117             return this;
118         }
119 
120         @Nonnull
121         @Override
122         public DependencyResolverRequestBuilder dependencies(@Nullable List<DependencyCoordinate> dependencies) {
123             super.dependencies(dependencies);
124             return this;
125         }
126 
127         @Nonnull
128         @Override
129         public DependencyResolverRequestBuilder dependency(@Nullable DependencyCoordinate dependency) {
130             super.dependency(dependency);
131             return this;
132         }
133 
134         @Nonnull
135         @Override
136         public DependencyResolverRequestBuilder managedDependencies(
137                 @Nullable List<DependencyCoordinate> managedDependencies) {
138             super.managedDependencies(managedDependencies);
139             return this;
140         }
141 
142         @Nonnull
143         @Override
144         public DependencyResolverRequestBuilder managedDependency(@Nullable DependencyCoordinate managedDependency) {
145             super.managedDependency(managedDependency);
146             return this;
147         }
148 
149         @Nonnull
150         @Override
151         public DependencyResolverRequestBuilder verbose(boolean verbose) {
152             super.verbose(verbose);
153             return this;
154         }
155 
156         @Nonnull
157         public DependencyResolverRequestBuilder resolutionScope(@Nonnull ResolutionScope resolutionScope) {
158             this.resolutionScope = resolutionScope;
159             return this;
160         }
161 
162         @Override
163         public DependencyResolverRequest build() {
164             return new DefaultDependencyResolverRequest(
165                     session, project, rootArtifact, root, dependencies, managedDependencies, verbose, resolutionScope);
166         }
167 
168         static class DefaultDependencyResolverRequest extends DefaultDependencyCollectorRequest
169                 implements DependencyResolverRequest {
170             private final ResolutionScope resolutionScope;
171 
172             DefaultDependencyResolverRequest(
173                     Session session,
174                     Project project,
175                     Artifact rootArtifact,
176                     DependencyCoordinate root,
177                     Collection<DependencyCoordinate> dependencies,
178                     Collection<DependencyCoordinate> managedDependencies,
179                     boolean verbose,
180                     ResolutionScope resolutionScope) {
181                 super(session, project, rootArtifact, root, dependencies, managedDependencies, verbose);
182                 this.resolutionScope = nonNull(resolutionScope, "resolutionScope cannot be null");
183                 if (verbose) {
184                     throw new IllegalArgumentException("verbose cannot be true for resolving dependencies");
185                 }
186             }
187 
188             @Nonnull
189             @Override
190             public ResolutionScope getResolutionScope() {
191                 return resolutionScope;
192             }
193         }
194     }
195 }