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