View Javadoc
1   package org.apache.maven.plugins.deploy;
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.artifact.repository.ArtifactRepository;
23  import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
24  import org.apache.maven.artifact.repository.MavenArtifactRepository;
25  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
26  import org.apache.maven.execution.MavenSession;
27  import org.apache.maven.plugin.AbstractMojo;
28  import org.apache.maven.plugin.MojoFailureException;
29  import org.apache.maven.plugins.annotations.Parameter;
30  
31  /**
32   * Abstract class for Deploy mojo's.
33   */
34  public abstract class AbstractDeployMojo
35      extends AbstractMojo
36  {
37  
38      /**
39       * Flag whether Maven is currently in online/offline mode.
40       */
41      @Parameter( defaultValue = "${settings.offline}", readonly = true )
42      private boolean offline;
43  
44      /**
45       * Parameter used to control how many times a failed deployment will be retried before giving up and failing. If a
46       * value outside the range 1-10 is specified it will be pulled to the nearest value within the range 1-10.
47       * 
48       * @since 2.7
49       */
50      @Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" )
51      private int retryFailedDeploymentCount;
52  
53      @Parameter( defaultValue = "${session}", readonly = true, required = true )
54      private MavenSession session;
55      
56      /* Setters and Getters */
57  
58      void failIfOffline()
59          throws MojoFailureException
60      {
61          if ( offline )
62          {
63              throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" );
64          }
65      }
66  
67      int getRetryFailedDeploymentCount()
68      {
69          return retryFailedDeploymentCount;
70      }
71  
72      protected ArtifactRepository createDeploymentArtifactRepository( String id, String url )
73      {
74          return new MavenArtifactRepository( id, url, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(),
75                                              new ArtifactRepositoryPolicy() );
76      }
77      
78      protected final MavenSession getSession()
79      {
80          return session;
81      }
82  }