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.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 ArtifactCoordinate} object.
32   *
33   * @since 4.0
34   */
35  @Experimental
36  @Immutable
37  public interface ArtifactCoordinateFactoryRequest {
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      @Nonnull
55      static ArtifactCoordinateFactoryRequest build(
56              @Nonnull Session session, String groupId, String artifactId, String version, String extension) {
57          return ArtifactCoordinateFactoryRequest.builder()
58                  .session(nonNull(session, "session cannot be null"))
59                  .groupId(groupId)
60                  .artifactId(artifactId)
61                  .version(version)
62                  .extension(extension)
63                  .build();
64      }
65  
66      @Nonnull
67      static ArtifactCoordinateFactoryRequest build(
68              @Nonnull Session session,
69              String groupId,
70              String artifactId,
71              String version,
72              String classifier,
73              String extension,
74              String type) {
75          return ArtifactCoordinateFactoryRequest.builder()
76                  .session(nonNull(session, "session cannot be null"))
77                  .groupId(groupId)
78                  .artifactId(artifactId)
79                  .version(version)
80                  .classifier(classifier)
81                  .extension(extension)
82                  .type(type)
83                  .build();
84      }
85  
86      @Nonnull
87      static ArtifactCoordinateFactoryRequest build(@Nonnull Session session, @Nonnull ArtifactCoordinate coordinate) {
88          return ArtifactCoordinateFactoryRequest.builder()
89                  .session(nonNull(session, "session cannot be null"))
90                  .groupId(nonNull(coordinate, "coordinate cannot be null").getGroupId())
91                  .artifactId(coordinate.getArtifactId())
92                  .classifier(coordinate.getClassifier())
93                  .version(coordinate.getVersion().asString())
94                  .extension(coordinate.getExtension())
95                  .build();
96      }
97  
98      static ArtifactFactoryRequestBuilder builder() {
99          return new ArtifactFactoryRequestBuilder();
100     }
101 
102     @NotThreadSafe
103     class ArtifactFactoryRequestBuilder {
104         private Session session;
105         private String groupId;
106         private String artifactId;
107         private String version;
108         private String classifier;
109         private String extension;
110         private String type;
111 
112         ArtifactFactoryRequestBuilder() {}
113 
114         public ArtifactFactoryRequestBuilder session(Session session) {
115             this.session = session;
116             return this;
117         }
118 
119         public ArtifactFactoryRequestBuilder groupId(String groupId) {
120             this.groupId = groupId;
121             return this;
122         }
123 
124         public ArtifactFactoryRequestBuilder artifactId(String artifactId) {
125             this.artifactId = artifactId;
126             return this;
127         }
128 
129         public ArtifactFactoryRequestBuilder version(String version) {
130             this.version = version;
131             return this;
132         }
133 
134         public ArtifactFactoryRequestBuilder classifier(String classifier) {
135             this.classifier = classifier;
136             return this;
137         }
138 
139         public ArtifactFactoryRequestBuilder extension(String extension) {
140             this.extension = extension;
141             return this;
142         }
143 
144         public ArtifactFactoryRequestBuilder type(String type) {
145             this.type = type;
146             return this;
147         }
148 
149         public ArtifactCoordinateFactoryRequest build() {
150             return new DefaultArtifactFactoryRequestArtifact(
151                     session, groupId, artifactId, version, classifier, extension, type);
152         }
153 
154         private static class DefaultArtifactFactoryRequestArtifact extends BaseRequest
155                 implements ArtifactCoordinateFactoryRequest {
156             private final String groupId;
157             private final String artifactId;
158             private final String version;
159             private final String classifier;
160             private final String extension;
161             private final String type;
162 
163             DefaultArtifactFactoryRequestArtifact(
164                     @Nonnull Session session,
165                     String groupId,
166                     String artifactId,
167                     String version,
168                     String classifier,
169                     String extension,
170                     String type) {
171                 super(session);
172                 this.groupId = groupId;
173                 this.artifactId = artifactId;
174                 this.version = version;
175                 this.classifier = classifier;
176                 this.extension = extension;
177                 this.type = type;
178             }
179 
180             @Override
181             public String getGroupId() {
182                 return groupId;
183             }
184 
185             @Override
186             public String getArtifactId() {
187                 return artifactId;
188             }
189 
190             @Override
191             public String getVersion() {
192                 return version;
193             }
194 
195             @Override
196             public String getClassifier() {
197                 return classifier;
198             }
199 
200             @Override
201             public String getExtension() {
202                 return extension;
203             }
204 
205             @Override
206             public String getType() {
207                 return type;
208             }
209         }
210     }
211 }