View Javadoc

1   package org.apache.maven.artifact.deployer;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import org.apache.maven.MavenException;
22  import org.apache.maven.artifact.deployer.NamedArtifactDeployer;
23  import org.apache.maven.artifact.deployer.NamedArtifactTypeHandler;
24  import org.apache.maven.project.Project;
25  import org.apache.maven.repository.ArtifactTypeHandler;
26  
27  /**
28   * 
29   * The Bean which provides access to Artifact Deployement API from jelly scripts.
30   * 
31   * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
32   * @version $Id: DeployBean.java 532339 2007-04-25 12:28:56Z ltheussl $
33   */
34  public class DeployBean
35  {
36      private NamedArtifactDeployer artifactDeployer;
37  
38      private Project project;
39  
40      private String artifact;
41  
42      private String type;
43  
44      private String artifactIdOverride;
45  
46      private ArtifactTypeHandler typeHandler;
47  
48      public DeployBean()
49      {
50          this.artifactDeployer = new NamedArtifactDeployer();
51      }
52  
53      public ArtifactTypeHandler getTypeHandler()
54      {
55          return this.typeHandler;
56      }
57  
58      /**
59       * @param typeHandler
60       */
61      public void setTypeHandler( final ArtifactTypeHandler typeHandler )
62      {
63          this.typeHandler = typeHandler;
64      }
65  
66      public String getArtifact()
67      {
68          return this.artifact;
69      }
70  
71      /**
72       * @param artifact
73       */
74      public void setArtifact( final String artifact )
75      {
76          this.artifact = artifact;
77      }
78  
79      public Project getProject()
80      {
81          return this.project;
82      }
83  
84      /**
85       * @param project
86       */
87      public void setProject( final Project project )
88      {
89          this.project = project;
90      }
91  
92      public String getType()
93      {
94          return this.type;
95      }
96  
97      /**
98       * @param type
99       */
100     public void setType( final String type )
101     {
102         this.type = type;
103     }
104 
105     /**
106      * @return String
107      */
108     public String getArtifactIdOverride()
109     {
110         return this.artifactIdOverride;
111     }
112 
113     /**
114      * @param newIdOverride
115      *            The new id.
116      */
117     public void setArtifactIdOverride( final String newIdOverride )
118     {
119         this.artifactIdOverride = newIdOverride;
120     }
121 
122     /**
123      * @throws MavenException
124      *             MavenException
125      */
126     protected void checkAttributes() throws MavenException
127     {
128         if ( this.project == null )
129         {
130             throw new MavenException( "attribute 'project' is required" );
131         }
132 
133         if ( this.artifact == null )
134         {
135             throw new MavenException( "attribute 'artifact' is required" );
136         }
137         if ( this.type == null )
138         {
139             throw new MavenException( "attribute 'type' is required" );
140         }
141         if ( this.typeHandler == null )
142         {
143             this.typeHandler = new NamedArtifactTypeHandler();
144             if ( this.artifactIdOverride != null )
145             {
146                 ( (NamedArtifactTypeHandler) this.typeHandler ).setArtifactId( this.artifactIdOverride );
147             }
148         }
149     }
150 
151     /**
152      * @throws MavenException
153      *             MavenException
154      */
155     public void deploy() throws MavenException
156     {
157         this.checkAttributes();
158         if ( this.artifactIdOverride != null )
159         {
160             this.artifactDeployer.deploy( this.artifact, this.type, this.project,
161                                           (NamedArtifactTypeHandler) this.typeHandler );
162         }
163         else
164         {
165             this.artifactDeployer.deploy( this.artifact, this.type, this.project, this.typeHandler );
166         }
167     }
168 
169     /**
170      * @throws MavenException
171      *             MavenException
172      */
173     public void deploySnapshot() throws MavenException
174     {
175         this.checkAttributes();
176         if ( this.artifactIdOverride != null )
177         {
178             this.artifactDeployer.deploySnapshot( this.artifact, this.type, this.project,
179                                                   (NamedArtifactTypeHandler) this.typeHandler );
180         }
181         else
182         {
183             this.artifactDeployer.deploySnapshot( this.artifact, this.type, this.project, this.typeHandler );
184         }
185     }
186 
187     /**
188      * @throws MavenException
189      *             MavenException
190      */
191     public void install() throws MavenException
192     {
193         this.checkAttributes();
194         if ( this.artifactIdOverride != null )
195         {
196             this.artifactDeployer.install( this.artifact, this.type, this.project, this.typeHandler );
197         }
198         else
199         {
200             this.artifactDeployer.install( this.artifact, this.type, this.project, this.typeHandler );
201         }
202     }
203 
204     /**
205      * @throws MavenException
206      *             MavenException
207      */
208     public void installSnapshot() throws MavenException
209     {
210         this.checkAttributes();
211         if ( this.artifactIdOverride != null )
212         {
213             this.artifactDeployer.installSnapshot( this.artifact, this.type, this.project, this.typeHandler );
214         }
215         else
216         {
217             this.artifactDeployer.installSnapshot( this.artifact, this.type, this.project, this.typeHandler );
218         }
219     }
220 
221 }