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.Objects;
22  
23  import org.apache.maven.api.Session;
24  import org.apache.maven.api.annotations.Experimental;
25  import org.apache.maven.api.annotations.Immutable;
26  import org.apache.maven.api.annotations.Nonnull;
27  import org.apache.maven.api.annotations.NotThreadSafe;
28  import org.apache.maven.api.annotations.Nullable;
29  
30  import static java.util.Objects.requireNonNull;
31  
32  /**
33   *
34   *
35   * @since 4.0.0
36   */
37  @Experimental
38  @Immutable
39  public interface ArtifactFactoryRequest extends Request<Session> {
40  
41      String getGroupId();
42  
43      String getArtifactId();
44  
45      String getVersion();
46  
47      String getClassifier();
48  
49      String getExtension();
50  
51      String getType();
52  
53      static ArtifactFactoryRequest build(
54              Session session, String groupId, String artifactId, String version, String extension) {
55          return ArtifactFactoryRequest.builder()
56                  .session(requireNonNull(session, "session cannot be null"))
57                  .groupId(groupId)
58                  .artifactId(artifactId)
59                  .version(version)
60                  .extension(extension)
61                  .build();
62      }
63  
64      static ArtifactFactoryRequest build(
65              Session session,
66              String groupId,
67              String artifactId,
68              String version,
69              String classifier,
70              String extension,
71              String type) {
72          return ArtifactFactoryRequest.builder()
73                  .session(requireNonNull(session, "session cannot be null"))
74                  .groupId(groupId)
75                  .artifactId(artifactId)
76                  .version(version)
77                  .classifier(classifier)
78                  .extension(extension)
79                  .type(type)
80                  .build();
81      }
82  
83      static ArtifactFactoryRequestBuilder builder() {
84          return new ArtifactFactoryRequestBuilder();
85      }
86  
87      @NotThreadSafe
88      class ArtifactFactoryRequestBuilder {
89          private Session session;
90          private RequestTrace trace;
91          private String groupId;
92          private String artifactId;
93          private String version;
94          private String classifier;
95          private String extension;
96          private String type;
97  
98          ArtifactFactoryRequestBuilder() {}
99  
100         public ArtifactFactoryRequestBuilder session(Session session) {
101             this.session = session;
102             return this;
103         }
104 
105         public ArtifactFactoryRequestBuilder trace(RequestTrace trace) {
106             this.trace = trace;
107             return this;
108         }
109 
110         public ArtifactFactoryRequestBuilder groupId(String groupId) {
111             this.groupId = groupId;
112             return this;
113         }
114 
115         public ArtifactFactoryRequestBuilder artifactId(String artifactId) {
116             this.artifactId = artifactId;
117             return this;
118         }
119 
120         public ArtifactFactoryRequestBuilder version(String version) {
121             this.version = version;
122             return this;
123         }
124 
125         public ArtifactFactoryRequestBuilder classifier(String classifier) {
126             this.classifier = classifier;
127             return this;
128         }
129 
130         public ArtifactFactoryRequestBuilder extension(String extension) {
131             this.extension = extension;
132             return this;
133         }
134 
135         public ArtifactFactoryRequestBuilder type(String type) {
136             this.type = type;
137             return this;
138         }
139 
140         public ArtifactFactoryRequest build() {
141             return new DefaultArtifactFactoryRequest(
142                     session, trace, groupId, artifactId, version, classifier, extension, type);
143         }
144 
145         private static class DefaultArtifactFactoryRequest extends BaseRequest<Session>
146                 implements ArtifactFactoryRequest {
147             private final String groupId;
148             private final String artifactId;
149             private final String version;
150             private final String classifier;
151             private final String extension;
152             private final String type;
153 
154             @SuppressWarnings("checkstyle:ParameterNumber")
155             DefaultArtifactFactoryRequest(
156                     @Nonnull Session session,
157                     @Nullable RequestTrace trace,
158                     String groupId,
159                     String artifactId,
160                     String version,
161                     String classifier,
162                     String extension,
163                     String type) {
164                 super(session, trace);
165                 this.groupId = groupId;
166                 this.artifactId = artifactId;
167                 this.version = version;
168                 this.classifier = classifier;
169                 this.extension = extension;
170                 this.type = type;
171             }
172 
173             @Override
174             public String getGroupId() {
175                 return groupId;
176             }
177 
178             @Override
179             public String getArtifactId() {
180                 return artifactId;
181             }
182 
183             @Override
184             public String getVersion() {
185                 return version;
186             }
187 
188             @Override
189             public String getClassifier() {
190                 return classifier;
191             }
192 
193             @Override
194             public String getExtension() {
195                 return extension;
196             }
197 
198             @Override
199             public String getType() {
200                 return type;
201             }
202 
203             @Override
204             public boolean equals(Object o) {
205                 return o instanceof DefaultArtifactFactoryRequest that
206                         && Objects.equals(groupId, that.groupId)
207                         && Objects.equals(artifactId, that.artifactId)
208                         && Objects.equals(version, that.version)
209                         && Objects.equals(classifier, that.classifier)
210                         && Objects.equals(extension, that.extension)
211                         && Objects.equals(type, that.type);
212             }
213 
214             @Override
215             public int hashCode() {
216                 return Objects.hash(groupId, artifactId, version, classifier, extension, type);
217             }
218 
219             @Override
220             public String toString() {
221                 return "ArtifactFactoryRequest[" + "groupId='"
222                         + groupId + '\'' + ", artifactId='"
223                         + artifactId + '\'' + ", version='"
224                         + version + '\'' + ", classifier='"
225                         + classifier + '\'' + ", extension='"
226                         + extension + '\'' + ", type='"
227                         + type + '\'' + ']';
228             }
229         }
230     }
231 }