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.annotations.Experimental;
23  import org.apache.maven.api.annotations.Immutable;
24  import org.apache.maven.api.annotations.Nonnull;
25  import org.apache.maven.api.annotations.NotThreadSafe;
26  import org.apache.maven.api.annotations.Nullable;
27  
28  import java.util.Collection;
29  import java.util.Collections;
30  
31  import org.apache.maven.api.Session;
32  import org.apache.maven.api.Artifact;
33  
34  import static org.apache.maven.api.services.BaseRequest.nonNull;
35  
36  /**
37   * A request for installing one or more artifacts in the local repository.
38   *
39   * @since 4.0
40   */
41  @Experimental
42  @Immutable
43  public interface ArtifactInstallerRequest
44  {
45  
46      @Nonnull
47      Session getSession();
48  
49      @Nonnull
50      Collection<Artifact> getArtifacts();
51  
52      @Nonnull
53      static ArtifactInstallerRequestBuilder builder()
54      {
55          return new ArtifactInstallerRequestBuilder();
56      }
57  
58      @Nonnull
59      static ArtifactInstallerRequest build( Session session, Collection<Artifact> artifacts )
60      {
61          return builder()
62                  .session( nonNull( session, "session cannot be null" ) )
63                  .artifacts( nonNull( artifacts, "artifacts cannot be null" ) )
64                  .build();
65      }
66  
67      @NotThreadSafe
68      class ArtifactInstallerRequestBuilder
69      {
70          Session session;
71          Collection<Artifact> artifacts = Collections.emptyList();
72  
73          ArtifactInstallerRequestBuilder()
74          {
75          }
76  
77          @Nonnull
78          public ArtifactInstallerRequestBuilder session( @Nonnull Session session )
79          {
80              this.session = session;
81              return this;
82          }
83  
84          @Nonnull
85          public ArtifactInstallerRequestBuilder artifacts( @Nullable Collection<Artifact> artifacts )
86          {
87              this.artifacts = artifacts != null ? artifacts : Collections.emptyList();
88              return this;
89          }
90  
91          @Nonnull
92          public ArtifactInstallerRequest build()
93          {
94              return new DefaultArtifactInstallerRequest( session, artifacts );
95          }
96  
97          static class DefaultArtifactInstallerRequest extends BaseRequest
98                  implements ArtifactInstallerRequest
99          {
100 
101             private final Collection<Artifact> artifacts;
102 
103             DefaultArtifactInstallerRequest( @Nonnull Session session,
104                                              @Nonnull Collection<Artifact> artifacts )
105             {
106                 super( session );
107                 this.artifacts = unmodifiable( nonNull( artifacts, "artifacts cannot be null" ) );
108             }
109 
110             @Nonnull
111             @Override
112             public Collection<Artifact> getArtifacts()
113             {
114                 return artifacts;
115             }
116         }
117     }
118 
119 }