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