View Javadoc

1   package org.apache.maven.plugin.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 java.util.Map;
23  
24  import org.apache.maven.artifact.deployer.ArtifactDeployer;
25  import org.apache.maven.artifact.factory.ArtifactFactory;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
28  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
29  import org.apache.maven.plugin.AbstractMojo;
30  import org.apache.maven.plugin.MojoExecutionException;
31  import org.apache.maven.plugin.MojoFailureException;
32  
33  /**
34   * @version $Id: AbstractDeployMojo.java 892671 2009-12-20 22:36:12Z bentmann $
35   */
36  public abstract class AbstractDeployMojo
37      extends AbstractMojo
38  {
39      /**
40       * @component
41       */
42      private ArtifactDeployer deployer;
43  
44      /**
45       * Component used to create an artifact.
46       *
47       * @component
48       */
49      protected ArtifactFactory artifactFactory;
50  
51      /**
52       * Component used to create a repository.
53       *
54       * @component
55       */
56      ArtifactRepositoryFactory repositoryFactory;
57  
58      /**
59       * Map that contains the layouts.
60       *
61       * @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
62       */
63      private Map repositoryLayouts;
64  
65      /**
66       * @parameter default-value="${localRepository}"
67       * @required
68       * @readonly
69       */
70      private ArtifactRepository localRepository;
71  
72      /**
73       * Flag whether Maven is currently in online/offline mode.
74       * 
75       * @parameter default-value="${settings.offline}"
76       * @readonly
77       */
78      private boolean offline;
79  
80      /**
81       * Parameter used to update the metadata to make the artifact as release.
82       * 
83       * @parameter expression="${updateReleaseInfo}" default-value="false"
84       */
85      protected boolean updateReleaseInfo;
86  
87      /* Setters and Getters */
88  
89      public ArtifactDeployer getDeployer()
90      {
91          return deployer;
92      }
93  
94      public void setDeployer( ArtifactDeployer deployer )
95      {
96          this.deployer = deployer;
97      }
98  
99      public ArtifactRepository getLocalRepository()
100     {
101         return localRepository;
102     }
103 
104     public void setLocalRepository( ArtifactRepository localRepository )
105     {
106         this.localRepository = localRepository;
107     }
108 
109     void failIfOffline()
110         throws MojoFailureException
111     {
112         if ( offline )
113         {
114             throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" );
115         }
116     }
117 
118     ArtifactRepositoryLayout getLayout( String id )
119         throws MojoExecutionException
120     {
121         ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( id );
122 
123         if ( layout == null )
124         {
125             throw new MojoExecutionException( "Invalid repository layout: " + id );
126         }
127 
128         return layout;
129     }
130 
131 }