View Javadoc
1   package org.apache.maven.api.services;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.api.annotations.Experimental;
23  import org.apache.maven.api.annotations.Immutable;
24  import org.apache.maven.api.annotations.Nonnull;
25  
26  import java.util.Collection;
27  
28  import org.apache.maven.api.Session;
29  import org.apache.maven.api.Artifact;
30  import org.apache.maven.api.RemoteRepository;
31  
32  import static org.apache.maven.api.services.BaseRequest.nonNull;
33  
34  /**
35   * A request for deploying one or more artifacts to a remote repository.
36   *
37   * @since 4.0
38   */
39  @Experimental
40  @Immutable
41  public interface ArtifactDeployerRequest
42  {
43  
44      @Nonnull
45      Session getSession();
46  
47      @Nonnull
48      RemoteRepository getRepository();
49  
50      @Nonnull
51      Collection<Artifact> getArtifacts();
52  
53      int getRetryFailedDeploymentCount();
54  
55      @Nonnull
56      static ArtifactDeployerRequestBuilder builder()
57      {
58          return new ArtifactDeployerRequestBuilder();
59      }
60  
61      @Nonnull
62      static ArtifactDeployerRequest build( @Nonnull Session session,
63                                            @Nonnull RemoteRepository repository,
64                                            @Nonnull Collection<Artifact> artifacts )
65      {
66          return builder()
67                  .session( nonNull( session, "session cannot be null" ) )
68                  .repository( nonNull( repository, "repository cannot be null" ) )
69                  .artifacts( nonNull( artifacts, "artifacts cannot be null" ) )
70                  .build();
71      }
72  
73      class ArtifactDeployerRequestBuilder
74      {
75          Session session;
76          RemoteRepository repository;
77          Collection<Artifact> artifacts;
78          int retryFailedDeploymentCount;
79  
80          ArtifactDeployerRequestBuilder()
81          {
82          }
83  
84          @Nonnull
85          public ArtifactDeployerRequestBuilder session( Session session )
86          {
87              this.session = session;
88              return this;
89          }
90  
91          @Nonnull
92          public ArtifactDeployerRequestBuilder repository( RemoteRepository repository )
93          {
94              this.repository = repository;
95              return this;
96          }
97  
98          public ArtifactDeployerRequestBuilder artifacts( Collection<Artifact> artifacts )
99          {
100             this.artifacts = artifacts;
101             return this;
102         }
103 
104         public ArtifactDeployerRequestBuilder retryFailedDeploymentCount( int retryFailedDeploymentCount )
105         {
106             this.retryFailedDeploymentCount = retryFailedDeploymentCount;
107             return this;
108         }
109 
110         @Nonnull
111         public ArtifactDeployerRequest build()
112         {
113             return new DefaultArtifactDeployerRequest( session, repository, artifacts, retryFailedDeploymentCount );
114         }
115 
116         private static class DefaultArtifactDeployerRequest extends BaseRequest
117                 implements ArtifactDeployerRequest
118         {
119 
120             private final RemoteRepository repository;
121             private final Collection<Artifact> artifacts;
122             private final int retryFailedDeploymentCount;
123 
124             DefaultArtifactDeployerRequest( @Nonnull Session session,
125                                             @Nonnull RemoteRepository repository,
126                                             @Nonnull Collection<Artifact> artifacts,
127                                             int retryFailedDeploymentCount )
128             {
129                 super( session );
130                 this.repository = nonNull( repository, "repository cannot be null" );
131                 this.artifacts = unmodifiable( nonNull( artifacts, "artifacts cannot be null" ) );
132                 this.retryFailedDeploymentCount = retryFailedDeploymentCount;
133             }
134 
135             @Nonnull
136             @Override
137             public RemoteRepository getRepository()
138             {
139                 return repository;
140             }
141 
142             @Nonnull
143             @Override
144             public Collection<Artifact> getArtifacts()
145             {
146                 return artifacts;
147             }
148 
149             @Override
150             public int getRetryFailedDeploymentCount()
151             {
152                 return retryFailedDeploymentCount;
153             }
154         }
155 
156     }
157 }