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 org.apache.maven.api.ArtifactCoordinates;
22  import org.apache.maven.api.Session;
23  import org.apache.maven.api.annotations.Experimental;
24  import org.apache.maven.api.annotations.Nonnull;
25  import org.apache.maven.api.annotations.NotThreadSafe;
26  
27  import static org.apache.maven.api.services.BaseRequest.nonNull;
28  
29  /**
30   *
31   * @since 4.0.0
32   */
33  @Experimental
34  public interface VersionResolverRequest {
35  
36      @Nonnull
37      Session getSession();
38  
39      @Nonnull
40      ArtifactCoordinates getArtifactCoordinates();
41  
42      @Nonnull
43      static VersionResolverRequest build(@Nonnull Session session, @Nonnull ArtifactCoordinates artifactCoordinates) {
44          return builder()
45                  .session(nonNull(session, "session cannot be null"))
46                  .artifactCoordinates(nonNull(artifactCoordinates, "artifactCoordinates cannot be null"))
47                  .build();
48      }
49  
50      @Nonnull
51      static VersionResolverRequestBuilder builder() {
52          return new VersionResolverRequestBuilder();
53      }
54  
55      @NotThreadSafe
56      class VersionResolverRequestBuilder {
57          Session session;
58          ArtifactCoordinates artifactCoordinates;
59  
60          public VersionResolverRequestBuilder session(Session session) {
61              this.session = session;
62              return this;
63          }
64  
65          public VersionResolverRequestBuilder artifactCoordinates(ArtifactCoordinates artifactCoordinates) {
66              this.artifactCoordinates = artifactCoordinates;
67              return this;
68          }
69  
70          public VersionResolverRequest build() {
71              return new DefaultVersionResolverRequest(session, artifactCoordinates);
72          }
73  
74          private static class DefaultVersionResolverRequest extends BaseRequest implements VersionResolverRequest {
75              private final ArtifactCoordinates artifactCoordinates;
76  
77              @SuppressWarnings("checkstyle:ParameterNumber")
78              DefaultVersionResolverRequest(@Nonnull Session session, @Nonnull ArtifactCoordinates artifactCoordinates) {
79                  super(session);
80                  this.artifactCoordinates = artifactCoordinates;
81              }
82  
83              @Nonnull
84              @Override
85              public ArtifactCoordinates getArtifactCoordinates() {
86                  return artifactCoordinates;
87              }
88          }
89      }
90  }