View Javadoc
1   package org.apache.maven.api.services;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.api.ArtifactCoordinate;
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  
29  import static org.apache.maven.api.services.BaseRequest.nonNull;
30  
31  /**
32   * A request for creating a {@link ArtifactCoordinate} object.
33   *
34   * @since 4.0
35   */
36  @Experimental
37  @Immutable
38  public interface ArtifactCoordinateFactoryRequest
39  {
40  
41      @Nonnull
42      Session getSession();
43  
44      String getGroupId();
45  
46      String getArtifactId();
47  
48      String getVersion();
49  
50      String getClassifier();
51  
52      String getExtension();
53  
54      String getType();
55  
56      @Nonnull
57      static ArtifactCoordinateFactoryRequest build( @Nonnull Session session, String groupId, String artifactId,
58                                                     String version, String extension )
59      {
60          return ArtifactCoordinateFactoryRequest.builder()
61                  .session( nonNull( session, "session cannot be null" ) )
62                  .groupId( groupId )
63                  .artifactId( artifactId )
64                  .version( version )
65                  .extension( extension )
66                  .build();
67      }
68  
69      @Nonnull
70      static ArtifactCoordinateFactoryRequest build( @Nonnull Session session, String groupId, String artifactId,
71                                                     String version, String classifier, String extension, String type )
72      {
73          return ArtifactCoordinateFactoryRequest.builder()
74                  .session( nonNull( session, "session cannot be null" ) )
75                  .groupId( groupId )
76                  .artifactId( artifactId )
77                  .version( version )
78                  .classifier( classifier )
79                  .extension( extension )
80                  .type( type )
81                  .build();
82      }
83  
84      @Nonnull
85      static ArtifactCoordinateFactoryRequest build( @Nonnull Session session, @Nonnull ArtifactCoordinate coordinate )
86      {
87          return ArtifactCoordinateFactoryRequest.builder()
88                  .session( nonNull( session, "session cannot be null" ) )
89                  .groupId( nonNull( coordinate, "coordinate cannot be null" ).getGroupId() )
90                  .artifactId( coordinate.getArtifactId() )
91                  .classifier( coordinate.getClassifier() )
92                  .version( coordinate.getVersion().asString() )
93                  .extension( coordinate.getExtension() )
94                  .build();
95      }
96  
97  
98      static ArtifactFactoryRequestBuilder builder()
99      {
100         return new ArtifactFactoryRequestBuilder();
101     }
102 
103     @NotThreadSafe
104     class ArtifactFactoryRequestBuilder
105     {
106         private Session session;
107         private String groupId;
108         private String artifactId;
109         private String version;
110         private String classifier;
111         private String extension;
112         private String type;
113 
114         ArtifactFactoryRequestBuilder()
115         {
116         }
117 
118         public ArtifactFactoryRequestBuilder session( Session session )
119         {
120             this.session = session;
121             return this;
122         }
123 
124         public ArtifactFactoryRequestBuilder groupId( String groupId )
125         {
126             this.groupId = groupId;
127             return this;
128         }
129 
130         public ArtifactFactoryRequestBuilder artifactId( String artifactId )
131         {
132             this.artifactId = artifactId;
133             return this;
134         }
135 
136         public ArtifactFactoryRequestBuilder version( String version )
137         {
138             this.version = version;
139             return this;
140         }
141 
142         public ArtifactFactoryRequestBuilder classifier( String classifier )
143         {
144             this.classifier = classifier;
145             return this;
146         }
147 
148         public ArtifactFactoryRequestBuilder extension( String extension )
149         {
150             this.extension = extension;
151             return this;
152         }
153 
154         public ArtifactFactoryRequestBuilder type( String type )
155         {
156             this.type = type;
157             return this;
158         }
159 
160         public ArtifactCoordinateFactoryRequest build()
161         {
162             return new DefaultArtifactFactoryRequestArtifact( session, groupId, artifactId, version,
163                                                       classifier, extension, type );
164         }
165 
166         private static class DefaultArtifactFactoryRequestArtifact extends BaseRequest implements
167                                                                                        ArtifactCoordinateFactoryRequest
168         {
169             private final String groupId;
170             private final String artifactId;
171             private final String version;
172             private final String classifier;
173             private final String extension;
174             private final String type;
175 
176             DefaultArtifactFactoryRequestArtifact( @Nonnull Session session,
177                                                    String groupId,
178                                                    String artifactId,
179                                                    String version,
180                                                    String classifier,
181                                                    String extension,
182                                                    String type )
183             {
184                 super( session );
185                 this.groupId = groupId;
186                 this.artifactId = artifactId;
187                 this.version = version;
188                 this.classifier = classifier;
189                 this.extension = extension;
190                 this.type = type;
191             }
192 
193             @Override
194             public String getGroupId()
195             {
196                 return groupId;
197             }
198 
199             @Override
200             public String getArtifactId()
201             {
202                 return artifactId;
203             }
204 
205             @Override
206             public String getVersion()
207             {
208                 return version;
209             }
210 
211             @Override
212             public String getClassifier()
213             {
214                 return classifier;
215             }
216 
217             @Override
218             public String getExtension()
219             {
220                 return extension;
221             }
222 
223             @Override
224             public String getType()
225             {
226                 return type;
227             }
228         }
229     }
230 
231 }