
org.ow2.petals.ant.AbstractInstallerAntTask Maven / Gradle / Ivy
/**
* Copyright (c) 2005-2012 EBM WebSourcing, 2012-2016 Linagora
*
* This program/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 program/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 program/library; If not, see http://www.gnu.org/licenses/
* for the GNU Lesser General Public License version 2.1.
*/
package org.ow2.petals.ant;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.tools.ant.BuildException;
/**
* This class is used to install or deploy a JBI component, shared library or service assembly.
* @author ddesjardins - EBM WebSourcing
* @author Christophe Hamerling - EBM WebSourcing
*/
public abstract class AbstractInstallerAntTask extends AbstractJBIAntTask {
/**
* Fully qualified installation file path name
*/
protected String file;
/**
*
* @param file
*/
public void setFile(String file) {
this.file = file;
}
/**
* Validate the file parameter. The file parameter should not be null and
* must be a jar or a zip archive.
*
* @throws BuildException
*/
protected URL validateFileParameter() throws BuildException {
if (file == null) {
throw new BuildException("Missing attribute 'file'");
}
if (file.isEmpty()) {
throw new BuildException("Empty attribute 'file'");
}
if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
throw new BuildException("File '" + file
+ "' is not a valid archive (zip or jar required)");
}
URL fileURL;
try {
// in the case it is an URL (file://..., http://...)
fileURL = new URL(file);
} catch (MalformedURLException e) {
try {
// in the case it is simply a path
fileURL = new File(file).toURI().toURL();
} catch (MalformedURLException e1) {
BuildException e2 = new BuildException(
"Wrong format for attribute 'file', a valid file location is required", e1);
e2.addSuppressed(e);
throw e2;
}
}
return fileURL;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy