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.ProducedArtifact;
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<ProducedArtifact> 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,
60              @Nonnull RemoteRepository repository,
61              @Nonnull Collection<ProducedArtifact> artifacts) {
62          return builder()
63                  .session(nonNull(session, "session cannot be null"))
64                  .repository(nonNull(repository, "repository cannot be null"))
65                  .artifacts(nonNull(artifacts, "artifacts cannot be null"))
66                  .build();
67      }
68  
69      class ArtifactDeployerRequestBuilder {
70          Session session;
71          RemoteRepository repository;
72          Collection<ProducedArtifact> artifacts;
73          int retryFailedDeploymentCount;
74  
75          ArtifactDeployerRequestBuilder() {}
76  
77          @Nonnull
78          public ArtifactDeployerRequestBuilder session(Session session) {
79              this.session = session;
80              return this;
81          }
82  
83          @Nonnull
84          public ArtifactDeployerRequestBuilder repository(RemoteRepository repository) {
85              this.repository = repository;
86              return this;
87          }
88  
89          public ArtifactDeployerRequestBuilder artifacts(Collection<ProducedArtifact> artifacts) {
90              this.artifacts = artifacts;
91              return this;
92          }
93  
94          public ArtifactDeployerRequestBuilder retryFailedDeploymentCount(int retryFailedDeploymentCount) {
95              this.retryFailedDeploymentCount = retryFailedDeploymentCount;
96              return this;
97          }
98  
99          @Nonnull
100         public ArtifactDeployerRequest build() {
101             return new DefaultArtifactDeployerRequest(session, repository, artifacts, retryFailedDeploymentCount);
102         }
103 
104         private static class DefaultArtifactDeployerRequest extends BaseRequest<Session>
105                 implements ArtifactDeployerRequest {
106 
107             private final RemoteRepository repository;
108             private final Collection<ProducedArtifact> artifacts;
109             private final int retryFailedDeploymentCount;
110 
111             DefaultArtifactDeployerRequest(
112                     @Nonnull Session session,
113                     @Nonnull RemoteRepository repository,
114                     @Nonnull Collection<ProducedArtifact> artifacts,
115                     int retryFailedDeploymentCount) {
116                 super(session);
117                 this.repository = nonNull(repository, "repository cannot be null");
118                 this.artifacts = unmodifiable(nonNull(artifacts, "artifacts cannot be null"));
119                 this.retryFailedDeploymentCount = retryFailedDeploymentCount;
120             }
121 
122             @Nonnull
123             @Override
124             public RemoteRepository getRepository() {
125                 return repository;
126             }
127 
128             @Nonnull
129             @Override
130             public Collection<ProducedArtifact> getArtifacts() {
131                 return artifacts;
132             }
133 
134             @Override
135             public int getRetryFailedDeploymentCount() {
136                 return retryFailedDeploymentCount;
137             }
138         }
139     }
140 }