View Javadoc

1   package org.codehaus.mojo.jboss;
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.io.UnsupportedEncodingException;
23  import java.net.URLEncoder;
24  import java.util.Iterator;
25  
26  import org.apache.maven.plugin.MojoExecutionException;
27  
28  /**
29   * Deploys a directory or file to JBoss via JMX.
30   * 
31   * @author <a href="mailto:jgenender@apache.org">Jeff Genender</a>
32   * @goal deploy
33   */
34  public class DeployMojo
35      extends AbstractJBossDeployerMojo
36  {
37  
38      public static final String DEFAULT_DEPLOY_URL =
39          "/jmx-console/HtmlAdaptor?action=invokeOpByName&name=jboss.system:service%3DMainDeployer&methodName=deploy&argType=java.net.URL&arg0=";
40  
41      /**
42       * The deployment URL path relative to the base URL path.
43       * 
44       * @parameter
45       */
46      protected String deployUrlPath;
47  
48      /**
49       * The character encoding for the fileName.
50       * 
51       * @parameter default-value="UTF-8" expression="${jboss.fileNameEncoding}"
52       */
53      protected String fileNameEncoding;
54  
55      /**
56       * Main plugin execution.
57       * 
58       * @throws MojoExecutionException
59       */
60      public void doExecute()
61          throws MojoExecutionException
62      {
63          // Note: the url path is set here instead of in the parameter default-value because of a parse error
64          // when generating the project site.
65          if ( deployUrlPath == null )
66          {
67              deployUrlPath = DEFAULT_DEPLOY_URL;
68          }
69  
70          Iterator iter = fileNames.iterator();
71          while ( iter.hasNext() )
72          {
73  
74              String fileName = (String) iter.next();
75              String fixedFile = null;
76              if ( fileName.toLowerCase().endsWith( "ejb" ) )
77              {
78                  // Fix the ejb packaging to a jar
79                  fixedFile = fileName.substring( 0, fileName.length() - 3 ) + "jar";
80              }
81              else
82              {
83                  fixedFile = fileName;
84              }
85  
86              try
87              {
88                  String encoding = fileNameEncoding;
89                  if ( encoding == null )
90                  {
91                      encoding = "UTF-8";
92                  }
93                  fixedFile = URLEncoder.encode( fixedFile, encoding );
94              }
95              catch ( UnsupportedEncodingException ex )
96              {
97                  throw new MojoExecutionException( ex.getMessage() );
98              }
99  
100             getLog().info( "Deploying " + fileName + " to JBoss." );
101             String url = "http://" + hostName + ":" + port + deployUrlPath + fixedFile;
102             doURL( url );
103         }
104     }
105 }