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.List;
23  import java.util.Objects;
24  
25  import org.apache.maven.api.ProducedArtifact;
26  import org.apache.maven.api.RemoteRepository;
27  import org.apache.maven.api.Session;
28  import org.apache.maven.api.annotations.Experimental;
29  import org.apache.maven.api.annotations.Immutable;
30  import org.apache.maven.api.annotations.Nonnull;
31  import org.apache.maven.api.annotations.Nullable;
32  
33  import static java.util.Objects.requireNonNull;
34  
35  /**
36   * A request for deploying one or more artifacts to a remote repository.
37   *
38   * @since 4.0.0
39   */
40  @Experimental
41  @Immutable
42  public interface ArtifactDeployerRequest extends Request<Session> {
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(requireNonNull(session, "session cannot be null"))
64                  .repository(requireNonNull(repository, "repository cannot be null"))
65                  .artifacts(requireNonNull(artifacts, "artifacts cannot be null"))
66                  .build();
67      }
68  
69      class ArtifactDeployerRequestBuilder {
70          Session session;
71          RequestTrace trace;
72          RemoteRepository repository;
73          Collection<ProducedArtifact> artifacts;
74          int retryFailedDeploymentCount;
75  
76          ArtifactDeployerRequestBuilder() {}
77  
78          @Nonnull
79          public ArtifactDeployerRequestBuilder session(Session session) {
80              this.session = session;
81              return this;
82          }
83  
84          @Nonnull
85          public ArtifactDeployerRequestBuilder trace(RequestTrace trace) {
86              this.trace = trace;
87              return this;
88          }
89  
90          @Nonnull
91          public ArtifactDeployerRequestBuilder repository(RemoteRepository repository) {
92              this.repository = repository;
93              return this;
94          }
95  
96          public ArtifactDeployerRequestBuilder artifacts(Collection<ProducedArtifact> artifacts) {
97              this.artifacts = artifacts;
98              return this;
99          }
100 
101         public ArtifactDeployerRequestBuilder retryFailedDeploymentCount(int retryFailedDeploymentCount) {
102             this.retryFailedDeploymentCount = retryFailedDeploymentCount;
103             return this;
104         }
105 
106         @Nonnull
107         public ArtifactDeployerRequest build() {
108             return new DefaultArtifactDeployerRequest(
109                     session, trace, repository, artifacts, retryFailedDeploymentCount);
110         }
111 
112         private static class DefaultArtifactDeployerRequest extends BaseRequest<Session>
113                 implements ArtifactDeployerRequest {
114 
115             private final RemoteRepository repository;
116             private final Collection<ProducedArtifact> artifacts;
117             private final int retryFailedDeploymentCount;
118 
119             DefaultArtifactDeployerRequest(
120                     @Nonnull Session session,
121                     @Nullable RequestTrace trace,
122                     @Nonnull RemoteRepository repository,
123                     @Nonnull Collection<ProducedArtifact> artifacts,
124                     int retryFailedDeploymentCount) {
125                 super(session, trace);
126                 this.repository = requireNonNull(repository, "repository cannot be null");
127                 this.artifacts = List.copyOf(requireNonNull(artifacts, "artifacts cannot be null"));
128                 this.retryFailedDeploymentCount = retryFailedDeploymentCount;
129             }
130 
131             @Nonnull
132             @Override
133             public RemoteRepository getRepository() {
134                 return repository;
135             }
136 
137             @Nonnull
138             @Override
139             public Collection<ProducedArtifact> getArtifacts() {
140                 return artifacts;
141             }
142 
143             @Override
144             public int getRetryFailedDeploymentCount() {
145                 return retryFailedDeploymentCount;
146             }
147 
148             @Override
149             public boolean equals(Object o) {
150                 return o instanceof DefaultArtifactDeployerRequest that
151                         && retryFailedDeploymentCount == that.retryFailedDeploymentCount
152                         && Objects.equals(repository, that.repository)
153                         && Objects.equals(artifacts, that.artifacts);
154             }
155 
156             @Override
157             public int hashCode() {
158                 return Objects.hash(repository, artifacts, retryFailedDeploymentCount);
159             }
160 
161             @Override
162             public String toString() {
163                 return "ArtifactDeployerRequest[" + "repository="
164                         + repository + ", artifacts="
165                         + artifacts + ", retryFailedDeploymentCount="
166                         + retryFailedDeploymentCount + ']';
167             }
168         }
169     }
170 }