Author: chris.laprun(a)jboss.com
Date: 2007-02-15 00:32:59 -0500 (Thu, 15 Feb 2007)
New Revision: 6288
Added:
trunk/common/src/main/org/jboss/portal/ant/
trunk/common/src/main/org/jboss/portal/ant/AbstractDeploymentTask.java
trunk/common/src/main/org/jboss/portal/ant/CannotCreateDirException.java
trunk/common/src/main/org/jboss/portal/ant/Deploy.java
trunk/common/src/main/org/jboss/portal/ant/DirException.java
trunk/common/src/main/org/jboss/portal/ant/Explode.java
trunk/common/src/main/org/jboss/portal/ant/FileIsNotDirException.java
trunk/common/src/main/org/jboss/portal/ant/Implode.java
trunk/common/src/main/org/jboss/portal/ant/Undeploy.java
Log:
Re-added ant directory which seems to have been erased by mistake (please correct me if
I'm wrong).
Added: trunk/common/src/main/org/jboss/portal/ant/AbstractDeploymentTask.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/ant/AbstractDeploymentTask.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/ant/AbstractDeploymentTask.java 2007-02-15
05:32:59 UTC (rev 6288)
@@ -0,0 +1,116 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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 software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.ant;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.codehaus.cargo.container.ContainerType;
+import org.codehaus.cargo.container.RemoteContainer;
+import org.codehaus.cargo.container.configuration.Configuration;
+import org.codehaus.cargo.container.configuration.ConfigurationType;
+import org.codehaus.cargo.container.jboss.JBossJMXDeployer;
+import org.codehaus.cargo.container.property.GeneralPropertySet;
+import org.codehaus.cargo.container.property.ServletPropertySet;
+import org.codehaus.cargo.generic.ContainerFactory;
+import org.codehaus.cargo.generic.DefaultContainerFactory;
+import org.codehaus.cargo.generic.configuration.ConfigurationFactory;
+import org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory;
+
+import java.io.File;
+
+/**
+ * A deployment task.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public abstract class AbstractDeploymentTask extends Task
+{
+
+ /** The file. */
+ private File file;
+
+ /** The JBoss config. */
+ private String config;
+
+ public AbstractDeploymentTask()
+ {
+ file = null;
+ config = "default";
+ }
+
+ public File getFile()
+ {
+ return file;
+ }
+
+ public void setFile(File file)
+ {
+ this.file = file;
+ }
+
+ public String getConfig()
+ {
+ return config;
+ }
+
+ public void setConfig(String config)
+ {
+ this.config = config;
+ }
+
+ public void execute() throws BuildException
+ {
+ //
+ ConfigurationFactory cfgFactory = new DefaultConfigurationFactory();
+ Configuration cfg = cfgFactory.createConfiguration("jboss4x",
ConfigurationType.RUNTIME);
+
+ // Configure the container
+ if ("default".equals(config))
+ {
+ cfg.setProperty(GeneralPropertySet.PROTOCOL, "http");
+ cfg.setProperty(GeneralPropertySet.HOSTNAME, "localhost");
+ cfg.setProperty(ServletPropertySet.PORT, "8080");
+ }
+ else
+ {
+ throw new BuildException("Unknown configuration " + config);
+ }
+
+ //
+ if (file == null)
+ {
+ throw new BuildException("No specified file to deploy");
+ }
+
+ //
+ ContainerFactory containerFactory = new DefaultContainerFactory();
+ RemoteContainer container =
(RemoteContainer)containerFactory.createContainer("jboss4x",
ContainerType.REMOTE, cfg);
+
+ //
+ JBossJMXDeployer deployer = new JBossJMXDeployer(container);
+ execute(deployer);
+ }
+
+ protected abstract void execute(JBossJMXDeployer deployer);
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/ant/AbstractDeploymentTask.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native
Added: trunk/common/src/main/org/jboss/portal/ant/CannotCreateDirException.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/ant/CannotCreateDirException.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/ant/CannotCreateDirException.java 2007-02-15
05:32:59 UTC (rev 6288)
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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 software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.ant;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class CannotCreateDirException extends DirException
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 4911314548182164515L;
+
+ public CannotCreateDirException(File file)
+ {
+ super(file, "Cannot create directory " + file.getName());
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/ant/CannotCreateDirException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native
Added: trunk/common/src/main/org/jboss/portal/ant/Deploy.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/ant/Deploy.java (rev
0)
+++ trunk/common/src/main/org/jboss/portal/ant/Deploy.java 2007-02-15 05:32:59 UTC (rev
6288)
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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 software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.ant;
+
+import org.codehaus.cargo.container.deployable.Deployable;
+import org.codehaus.cargo.container.deployable.EAR;
+import org.codehaus.cargo.container.jboss.JBossJMXDeployer;
+
+/**
+ * A blocking deploy task.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class Deploy extends AbstractDeploymentTask
+{
+
+ public Deploy()
+ {
+ }
+
+ protected void execute(JBossJMXDeployer deployer)
+ {
+ //
+ Deployable deployable = new EAR(getFile().getAbsolutePath());
+
+ //
+ deployer.deploy(deployable);
+ }
+}
Property changes on: trunk/common/src/main/org/jboss/portal/ant/Deploy.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native
Added: trunk/common/src/main/org/jboss/portal/ant/DirException.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/ant/DirException.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/ant/DirException.java 2007-02-15 05:32:59 UTC
(rev 6288)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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 software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.ant;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class DirException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 7944765663293180164L;
+ private File file;
+
+ public DirException(File file, String msg)
+ {
+ super(msg);
+ this.file = file;
+ }
+
+ public File getFile()
+ {
+ return file;
+ }
+}
Property changes on: trunk/common/src/main/org/jboss/portal/ant/DirException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native
Added: trunk/common/src/main/org/jboss/portal/ant/Explode.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/ant/Explode.java (rev
0)
+++ trunk/common/src/main/org/jboss/portal/ant/Explode.java 2007-02-15 05:32:59 UTC (rev
6288)
@@ -0,0 +1,274 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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 software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.ant;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipInputStream;
+
+/**
+ * Ant task that explode an archive.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class Explode extends Task
+{
+
+ /** Unzipped extensions. */
+ private static final Set extensions = new HashSet(Arrays.asList(new
String[]{"ear", "war", "sar", "har"}));
+
+ /** The exploded file. */
+ private File file;
+
+ /** The target directory. */
+ private File todir;
+
+ /** The target optional name. */
+ private String name;
+
+ /** filename to exclude from decompression * */
+ private String exclude;
+
+ public void setExclude(String exclude)
+ {
+ this.exclude = exclude;
+ }
+
+ public void setFile(File file)
+ {
+ this.file = file;
+ }
+
+ public void setTodir(File todir)
+ {
+ this.todir = todir;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public void execute() throws BuildException
+ {
+ try
+ {
+ explode(file, todir);
+ }
+ catch (DirException e)
+ {
+ throw new BuildException(e.getMessage());
+ }
+ }
+
+ public void explode(File file, File todir) throws BuildException, DirException
+ {
+ if (!file.exists())
+ {
+ throw new BuildException("source file does not exists");
+ }
+ if (!file.isFile())
+ {
+ throw new BuildException("source file is not file");
+ }
+ if (name == null)
+ {
+ name = file.getName();
+ }
+ ZipInputStream zip = null;
+ try
+ {
+ zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(file)));
+ log("Process archive " + name);
+ explode(this, name, zip, todir, this.exclude);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new BuildException("Unexpected error " + e.getMessage());
+ }
+ finally
+ {
+ if (zip != null)
+ {
+ try
+ {
+ zip.close();
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+ }
+ }
+
+ /**
+ * Explode a zip stream into a directory.
+ *
+ * @param explode used to log
+ * @param name the name of the created directory
+ * @param zip the zip stream will not be closed
+ * @param todir the parent directory
+ * @throws BuildException
+ * @throws DirException
+ */
+ public static void explode(Explode explode, String name, ZipInputStream zip, File
todir, String exclude) throws BuildException, DirException
+ {
+ // First ensure the target directory exists
+ if (!todir.exists())
+ {
+ throw new BuildException("target dir does not exists");
+ }
+ if (!todir.isDirectory())
+ {
+ throw new BuildException("target dir is not a directory");
+ }
+ try
+ {
+ // Buffer
+ byte[] buffer = new byte[512];
+
+ // The real target dir
+ todir = new File(todir, name);
+
+ // Get the directory
+ ensureDirExist(explode, todir);
+
+ // Process each file
+ for (ZipEntry entry = zip.getNextEntry(); entry != null; entry =
zip.getNextEntry())
+ {
+ // Next entry
+ File fic = new File(todir, entry.getName());
+ int lastDot = fic.getName().lastIndexOf(".");
+
+ if (entry.isDirectory())
+ {
+ // This is a directory that we must create
+ try
+ {
+ ensureDirExist(explode, fic);
+ }
+ catch (DirException e)
+ {
+ explode.log(e.getMessage());
+ }
+ }
+ else if (lastDot != -1 &&
extensions.contains(fic.getName().substring(lastDot + 1)))
+ {
+ // This is a nested archive, we explode it
+ try
+ {
+ explode.log("Process nested archive " + fic.getName());
+ if (!fic.getName().equalsIgnoreCase(exclude))
+ {
+ explode(explode, fic.getName(), new ZipInputStream(zip), todir,
exclude);
+ }
+ }
+ catch (DirException e)
+ {
+ explode.log(e.getMessage());
+ }
+ }
+ else
+ {
+ // This is a file we write it
+ OutputStream out = null;
+ try
+ {
+ out = new BufferedOutputStream(new FileOutputStream(fic));
+ for (int size = zip.read(buffer); size != -1; size = zip.read(buffer))
+ {
+ out.write(buffer, 0, size);
+ }
+ }
+ catch (IOException e)
+ {
+ explode.log("Problem when writing file " + e.getMessage());
+ }
+ finally
+ {
+ if (out != null)
+ {
+ try
+ {
+ out.close();
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (ZipException e)
+ {
+ throw new BuildException(e);
+ }
+ catch (IOException e)
+ {
+ throw new BuildException(e);
+ }
+ }
+
+ /** When it returns the dir exists otherwise it throws a BuildException */
+ private static void ensureDirExist(Explode explode, File dir) throws
FileIsNotDirException, CannotCreateDirException
+ {
+ if (dir.exists())
+ {
+ if (dir.isDirectory())
+ {
+ // explode.log(dir.getName() + " exists and is used");
+ }
+ else
+ {
+ throw new FileIsNotDirException(dir);
+ }
+ }
+ else
+ {
+ if (dir.mkdirs())
+ {
+ // explode.log("Created directory " + dir.getName());
+ }
+ else
+ {
+ throw new CannotCreateDirException(dir);
+ }
+ }
+ }
+}
Property changes on: trunk/common/src/main/org/jboss/portal/ant/Explode.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native
Added: trunk/common/src/main/org/jboss/portal/ant/FileIsNotDirException.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/ant/FileIsNotDirException.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/ant/FileIsNotDirException.java 2007-02-15
05:32:59 UTC (rev 6288)
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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 software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.ant;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class FileIsNotDirException extends DirException
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 7596495857634457803L;
+
+ public FileIsNotDirException(File file)
+ {
+ super(file, file.getName() + " exists and is not a directory");
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/ant/FileIsNotDirException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native
Added: trunk/common/src/main/org/jboss/portal/ant/Implode.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/ant/Implode.java (rev
0)
+++ trunk/common/src/main/org/jboss/portal/ant/Implode.java 2007-02-15 05:32:59 UTC (rev
6288)
@@ -0,0 +1,207 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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 software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.ant;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class Implode extends Task
+{
+
+ /** Unzipped extensions. */
+ private static final Set extensions = new HashSet(Arrays.asList(new
String[]{"ear", "war", "sar", "har"}));
+
+ /** The exploded dir. */
+ private File dir;
+
+ /** The target file. */
+ private File tofile;
+
+ public void setDir(File dir)
+ {
+ this.dir = dir;
+ }
+
+ public void setTofile(File tofile)
+ {
+ this.tofile = tofile;
+ }
+
+ public void execute() throws BuildException
+ {
+ if (tofile == null)
+ {
+ throw new BuildException("target file should not be null");
+ }
+ if (dir == null)
+ {
+ throw new BuildException("source dir should not be null");
+ }
+ if (!dir.exists())
+ {
+ throw new BuildException("source dir does not exist");
+ }
+ if (dir.isFile())
+ {
+ throw new BuildException("source dir is a file");
+ }
+ if (tofile.exists() && tofile.isDirectory())
+ {
+ throw new BuildException("target file " + tofile + " designates a
directory");
+ }
+ //if (tofile == null || tofile.lastModified() < dir.lastModified())
+
+
+ OutputStream out = null;
+ try
+ {
+ byte[] bytes = implode(dir);
+ out = new BufferedOutputStream(new FileOutputStream(tofile));
+ out.write(bytes);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ throw new BuildException(e.getMessage());
+ }
+ finally
+ {
+ if (out != null)
+ {
+ try
+ {
+ out.close();
+ }
+ catch (IOException ignore)
+ {
+ }
+ }
+ }
+
+ }
+
+ public byte[] implode(File f) throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ JarOutputStream out = new JarOutputStream(baos);
+ implode(f, "", out);
+ out.close();
+ return baos.toByteArray();
+ }
+
+ public void implode(File f, String path, JarOutputStream out) throws IOException
+ {
+ if (f.isFile())
+ {
+ InputStream in = null;
+ try
+ {
+ in = new BufferedInputStream(new FileInputStream(f));
+ byte[] bytes = new byte[1024];
+
+ //
+ String fileName = path.substring(1);
+ JarEntry fileEntry = new JarEntry(fileName);
+ out.putNextEntry(fileEntry);
+
+ //
+ for (int l = in.read(bytes, 0, bytes.length); l > -0; l = in.read(bytes,
0, bytes.length))
+ {
+ out.write(bytes, 0, l);
+ }
+
+ //
+ out.closeEntry();
+ }
+ finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException ignore)
+ {
+ }
+ }
+ }
+ }
+ else
+ {
+ if (path.length() > 1)
+ {
+ String dirName = path.substring(1) + '/';
+ JarEntry dirEntry = new JarEntry(dirName);
+ out.putNextEntry(dirEntry);
+ out.closeEntry();
+ }
+
+ //
+ File[] children = f.listFiles();
+ for (int i = 0; i < children.length; i++)
+ {
+ File child = children[i];
+ int lastDot = child.getName().lastIndexOf(".");
+ if (extensions.contains(child.getName().substring(lastDot + 1)))
+ {
+ byte[] bytes = implode(child);
+
+ //
+ String fileName = (path + '/' + child.getName()).substring(1);
+ JarEntry fileEntry = new JarEntry(fileName);
+ out.putNextEntry(fileEntry);
+
+ //
+ out.write(bytes, 0, bytes.length);
+
+ //
+ out.closeEntry();
+ }
+ else
+ {
+ implode(child, path + '/' + child.getName(), out);
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/common/src/main/org/jboss/portal/ant/Implode.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native
Added: trunk/common/src/main/org/jboss/portal/ant/Undeploy.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/ant/Undeploy.java (rev
0)
+++ trunk/common/src/main/org/jboss/portal/ant/Undeploy.java 2007-02-15 05:32:59 UTC (rev
6288)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This 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 software 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 software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.ant;
+
+import org.codehaus.cargo.container.deployable.Deployable;
+import org.codehaus.cargo.container.deployable.EAR;
+import org.codehaus.cargo.container.jboss.JBossJMXDeployer;
+
+/**
+ * A blocking undeploy task.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class Undeploy extends AbstractDeploymentTask
+{
+
+ protected void execute(JBossJMXDeployer deployer)
+ {
+ //
+ Deployable deployable = new EAR(getFile().getAbsolutePath());
+
+ //
+ deployer.undeploy(deployable);
+ }
+}
Property changes on: trunk/common/src/main/org/jboss/portal/ant/Undeploy.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native