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