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.ArtifactCoordinate;
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  @Experimental
30  public interface VersionResolverRequest {
31  
32      @Nonnull
33      Session getSession();
34  
35      @Nonnull
36      ArtifactCoordinate getArtifactCoordinate();
37  
38      @Nonnull
39      static VersionResolverRequest build(@Nonnull Session session, @Nonnull ArtifactCoordinate artifactCoordinate) {
40          return builder()
41                  .session(nonNull(session, "session cannot be null"))
42                  .artifactCoordinate(nonNull(artifactCoordinate, "artifactCoordinate cannot be null"))
43                  .build();
44      }
45  
46      @Nonnull
47      static VersionResolverRequestBuilder builder() {
48          return new VersionResolverRequestBuilder();
49      }
50  
51      @NotThreadSafe
52      class VersionResolverRequestBuilder {
53          Session session;
54          ArtifactCoordinate artifactCoordinate;
55  
56          public VersionResolverRequestBuilder session(Session session) {
57              this.session = session;
58              return this;
59          }
60  
61          public VersionResolverRequestBuilder artifactCoordinate(ArtifactCoordinate artifactCoordinate) {
62              this.artifactCoordinate = artifactCoordinate;
63              return this;
64          }
65  
66          public VersionResolverRequest build() {
67              return new DefaultVersionResolverRequest(session, artifactCoordinate);
68          }
69  
70          private static class DefaultVersionResolverRequest extends BaseRequest implements VersionResolverRequest {
71              private final ArtifactCoordinate artifactCoordinate;
72  
73              @SuppressWarnings("checkstyle:ParameterNumber")
74              DefaultVersionResolverRequest(@Nonnull Session session, @Nonnull ArtifactCoordinate artifactCoordinate) {
75                  super(session);
76                  this.artifactCoordinate = artifactCoordinate;
77              }
78  
79              @Nonnull
80              @Override
81              public ArtifactCoordinate getArtifactCoordinate() {
82                  return artifactCoordinate;
83              }
84          }
85      }
86  }