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  
23  import org.apache.maven.api.Artifact;
24  import org.apache.maven.api.RemoteRepository;
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  
30  import static org.apache.maven.api.services.BaseRequest.nonNull;
31  
32  /**
33   * A request for deploying one or more artifacts to a remote repository.
34   *
35   * @since 4.0.0
36   */
37  @Experimental
38  @Immutable
39  public interface ArtifactDeployerRequest {
40  
41      @Nonnull
42      Session getSession();
43  
44      @Nonnull
45      RemoteRepository getRepository();
46  
47      @Nonnull
48      Collection<Artifact> getArtifacts();
49  
50      int getRetryFailedDeploymentCount();
51  
52      @Nonnull
53      static ArtifactDeployerRequestBuilder builder() {
54          return new ArtifactDeployerRequestBuilder();
55      }
56  
57      @Nonnull
58      static ArtifactDeployerRequest build(
59              @Nonnull Session session, @Nonnull RemoteRepository repository, @Nonnull Collection<Artifact> artifacts) {
60          return builder()
61                  .session(nonNull(session, "session cannot be null"))
62                  .repository(nonNull(repository, "repository cannot be null"))
63                  .artifacts(nonNull(artifacts, "artifacts cannot be null"))
64                  .build();
65      }
66  
67      class ArtifactDeployerRequestBuilder {
68          Session session;
69          RemoteRepository repository;
70          Collection<Artifact> artifacts;
71          int retryFailedDeploymentCount;
72  
73          ArtifactDeployerRequestBuilder() {}
74  
75          @Nonnull
76          public ArtifactDeployerRequestBuilder session(Session session) {
77              this.session = session;
78              return this;
79          }
80  
81          @Nonnull
82          public ArtifactDeployerRequestBuilder repository(RemoteRepository repository) {
83              this.repository = repository;
84              return this;
85          }
86  
87          public ArtifactDeployerRequestBuilder artifacts(Collection<Artifact> artifacts) {
88              this.artifacts = artifacts;
89              return this;
90          }
91  
92          public ArtifactDeployerRequestBuilder retryFailedDeploymentCount(int retryFailedDeploymentCount) {
93              this.retryFailedDeploymentCount = retryFailedDeploymentCount;
94              return this;
95          }
96  
97          @Nonnull
98          public ArtifactDeployerRequest build() {
99              return new DefaultArtifactDeployerRequest(session, repository, artifacts, retryFailedDeploymentCount);
100         }
101 
102         private static class DefaultArtifactDeployerRequest extends BaseRequest implements ArtifactDeployerRequest {
103 
104             private final RemoteRepository repository;
105             private final Collection<Artifact> artifacts;
106             private final int retryFailedDeploymentCount;
107 
108             DefaultArtifactDeployerRequest(
109                     @Nonnull Session session,
110                     @Nonnull RemoteRepository repository,
111                     @Nonnull Collection<Artifact> artifacts,
112                     int retryFailedDeploymentCount) {
113                 super(session);
114                 this.repository = nonNull(repository, "repository cannot be null");
115                 this.artifacts = unmodifiable(nonNull(artifacts, "artifacts cannot be null"));
116                 this.retryFailedDeploymentCount = retryFailedDeploymentCount;
117             }
118 
119             @Nonnull
120             @Override
121             public RemoteRepository getRepository() {
122                 return repository;
123             }
124 
125             @Nonnull
126             @Override
127             public Collection<Artifact> getArtifacts() {
128                 return artifacts;
129             }
130 
131             @Override
132             public int getRetryFailedDeploymentCount() {
133                 return retryFailedDeploymentCount;
134             }
135         }
136     }
137 }