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  
23  import org.apache.maven.api.ArtifactCoordinates;
24  import org.apache.maven.api.Session;
25  import org.apache.maven.api.annotations.Experimental;
26  import org.apache.maven.api.annotations.Immutable;
27  import org.apache.maven.api.annotations.Nonnull;
28  import org.apache.maven.api.annotations.NotThreadSafe;
29  
30  import static org.apache.maven.api.services.BaseRequest.nonNull;
31  
32  /**
33   * A request for resolving an artifact.
34   *
35   * @since 4.0.0
36   */
37  @Experimental
38  @Immutable
39  public interface ArtifactResolverRequest {
40      @Nonnull
41      Session getSession();
42  
43      @Nonnull
44      Collection<? extends ArtifactCoordinates> getCoordinates();
45  
46      @Nonnull
47      static ArtifactResolverRequestBuilder builder() {
48          return new ArtifactResolverRequestBuilder();
49      }
50  
51      @Nonnull
52      static ArtifactResolverRequest build(
53              @Nonnull Session session, @Nonnull Collection<? extends ArtifactCoordinates> coordinates) {
54          return builder()
55                  .session(nonNull(session, "session cannot be null"))
56                  .coordinates(nonNull(coordinates, "coordinates cannot be null"))
57                  .build();
58      }
59  
60      @NotThreadSafe
61      class ArtifactResolverRequestBuilder {
62          Session session;
63          Collection<? extends ArtifactCoordinates> coordinates;
64  
65          ArtifactResolverRequestBuilder() {}
66  
67          @Nonnull
68          public ArtifactResolverRequestBuilder session(Session session) {
69              this.session = session;
70              return this;
71          }
72  
73          @Nonnull
74          public ArtifactResolverRequestBuilder coordinates(Collection<? extends ArtifactCoordinates> coordinates) {
75              this.coordinates = coordinates;
76              return this;
77          }
78  
79          @Nonnull
80          public ArtifactResolverRequest build() {
81              return new DefaultArtifactResolverRequest(session, coordinates);
82          }
83  
84          private static class DefaultArtifactResolverRequest extends BaseRequest implements ArtifactResolverRequest {
85              @Nonnull
86              private final Collection<? extends ArtifactCoordinates> coordinates;
87  
88              DefaultArtifactResolverRequest(
89                      @Nonnull Session session, @Nonnull Collection<? extends ArtifactCoordinates> coordinates) {
90                  super(session);
91                  this.coordinates = unmodifiable(nonNull(coordinates, "coordinates cannot be null"));
92              }
93  
94              @Nonnull
95              @Override
96              public Collection<? extends ArtifactCoordinates> getCoordinates() {
97                  return coordinates;
98              }
99          }
100     }
101 }