/**
* Copyright 2006 Aldrin Leal, aldrin at leal dot eng dot bee ar
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.modafocas.pocketserver.core.packager.impl;
import java.net.URL;
import org.apache.commons.vfs.AllFileSelector;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.VFS;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.modafocas.pocketserver.core.packager.Packager;
import org.modafocas.pocketserver.core.packager.PackagingException;
/**
* Packager simples, que cria uma instância tomcat
*
* @plexus.component
* role="org.modafocas.pocketserver.core.packager.Packager"
* role-hint="SimpleTomcatPackager"
* lifecycle-handler="plexus-configurable"
* instantiation-strategy="singleton"
* @author Aldrin Leal
*/
public class SimpleTomcatPackager implements Packager {
/**
* FileSystemManager em usl
*/
private FileSystemManager fileSystemManager;
/**
* Path para o arquivo .zip do Tomcat
*
* @plexus.configuration
* default-value="http://www.apache.org/dist/tomcat/tomcat-5/v5.5.20/bin/apache-tomcat-5.5.20.zip"
*/
private String pathToTomcatZip;
/**
* Construtor
*/
public SimpleTomcatPackager() {
this.fileSystemManager = null;
this.pathToTomcatZip = null;
}
/**
* Getter do Path para o Zip do Tomcat
*
* @return the pathToTomcatZip
*/
public String getPathToTomcatZip() {
return pathToTomcatZip;
}
/**
* Setter do Path para o Zip do Tomcat
*
* @param pathToTomcatZip the pathToTomcatZip to set
*/
public void setPathToTomcatZip(String pathToTomcatZip) {
this.pathToTomcatZip = pathToTomcatZip;
}
/**
* Init and Setup
*/
public void initialize() throws InitializationException {
try {
this.fileSystemManager = VFS.getManager();
} catch (Exception exc) {
throw new InitializationException("initialize()", exc);
}
}
/**
* Entry-Point de Execução
*
* @see org.modafocas.pocketserver.core.packager.Packager#perform(URL, URL, Logger)
*/
public void perform(URL sourceURL, URL targetURL, Logger logger) throws PackagingException {
try {
FileObject tomcatDistFileObject = this.fileSystemManager.resolveFile(pathToTomcatZip);
if (! tomcatDistFileObject.getName().getURI().startsWith("file:")) {
FileObject tmpFileObject = this.fileSystemManager.resolveFile("tmp://packaging-temp/" + tomcatDistFileObject.getName().getBaseName());
if (!tmpFileObject.getParent().exists())
tmpFileObject.getParent().createFolder();
if (tmpFileObject.exists())
tmpFileObject.delete();
tmpFileObject.createFile();
tmpFileObject.copyFrom(tomcatDistFileObject, new AllFileSelector());
}
} catch (Exception exc) {
if (exc instanceof PackagingException)
throw (PackagingException) exc;
if (logger.isWarnEnabled())
logger.warn("perform()", exc);
throw new PackagingException("perform()", exc);
}
}
}