
org.objectweb.petals.ant.AbstractInstallerAntTask Maven / Gradle / Ivy
The newest version!
/**
* PETALS - PETALS Services Platform.
* Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* -------------------------------------------------------------------------
* $Id$
* -------------------------------------------------------------------------
*/
package org.objectweb.petals.ant;
import java.net.MalformedURLException;
import java.net.URL;
import javax.management.MBeanServerConnection;
import org.apache.tools.ant.BuildException;
/**
* This class is used to install or deploy a JBI component, shared library or
* service assembly
*
* @author ddesjardins chamerling - eBMWebsourcing
*/
public abstract class AbstractInstallerAntTask extends AbstractJBIAntTask {
/**
* Action : installSharedLibrary
*/
protected static final String INSTALL_SHARED_LIBRARY = "installSharedLibrary";
/**
* Action : loadNewInstaller
*/
protected static final String LOAD_NEW_INSTALLED = "loadNewInstaller";
/**
* Fully qualified installation file path name
*/
protected String file;
/**
* Perform a Install or Deploy action
*
* @param connection
* @param action
* @return
* @throws Exception
*/
protected Object performAction(MBeanServerConnection connection,
String action) throws Exception {
validateFileParameter();
Object[] parameters = new Object[1];
parameters[0] = getFileAsUrl(file);
String[] signature = new String[] {"java.lang.String"};
Object result = connection.invoke(JBIJMXConnectorUtil
.getInstallationServiceMBeanName(connection), action, parameters,
signature);
return result;
}
/**
* Create an URL like file://fileName if the fileName is not a valid url.
*
* @param fileName
* @return
*/
protected String getFileAsUrl(String fileName) {
String result = fileName;
try {
new URL(fileName);
} catch (MalformedURLException e) {
// generate an url with the file name
try {
URL url = new URL("file", null, fileName);
result = url.toExternalForm();
} catch (MalformedURLException e1) {
}
}
return result;
}
/**
* Validate the file parameter. The file parameter should not be null and
* must be a jar or a zip archive.
*
* @throws BuildException
*/
protected void validateFileParameter() throws BuildException {
if (file == null) {
throw new BuildException("Missing attribute 'file'");
}
if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
throw new BuildException("File '" + file
+ "' is not a valid archive (zip or jar required)");
}
}
/**
*
* @param file
*/
public void setFile(String file) {
this.file = file;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy