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