jruaux      2003/03/10 05:36:29

  Modified:    integration/eclipse/src/java/org/apache/cactus/eclipse/war
                        WarBuilder.java
  Log:
  Blank zip file did not work with Ant 1.5.2
  
  Revision  Changes    Path
  1.5       +38 -11    
jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/war/WarBuilder.java
  
  Index: WarBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/war/WarBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WarBuilder.java   7 Mar 2003 16:02:24 -0000       1.4
  +++ WarBuilder.java   10 Mar 2003 13:36:29 -0000      1.5
  @@ -58,20 +58,22 @@
   
   import java.io.File;
   import java.io.IOException;
  -import java.util.Vector;
   
   import org.apache.cactus.eclipse.ui.CactusMessages;
  +import org.apache.cactus.eclipse.ui.CactusPlugin;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.taskdefs.Copy;
   import org.apache.tools.ant.taskdefs.War;
  +import org.apache.tools.ant.taskdefs.Zip;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.ZipFileSet;
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IPath;
   import org.eclipse.core.runtime.IProgressMonitor;
  +import org.eclipse.core.runtime.IStatus;
   import org.eclipse.core.runtime.Path;
  +import org.eclipse.core.runtime.Status;
   import org.eclipse.jdt.core.IClasspathEntry;
  -import org.eclipse.jdt.core.IJavaModelStatusConstants;
   import org.eclipse.jdt.core.IJavaProject;
   import org.eclipse.jdt.core.JavaModelException;
   
  @@ -181,7 +183,8 @@
       public File createWar(IProgressMonitor thePM) throws CoreException
       {
           thePM.subTask(CactusMessages.getString("CactusLaunch.message.war"));
  -        Vector arguments = new Vector();
  +        war.delete();
  +        War warTask = new War();
           IPath tempJarsPath =
               new Path(tempDir.getAbsolutePath()).append(JARS_PATH);
           File tempJarsDir = tempJarsPath.toFile();
  @@ -194,7 +197,6 @@
           thePM.worked(1);
           Project antProject = new Project();
           antProject.init();
  -        War warTask = new War();
           warTask.setProject(antProject);
           warTask.setDestFile(war);
           ZipFileSet classes = new ZipFileSet();
  @@ -219,18 +221,25 @@
           {
               // Without a webxml attribute the Ant war task
               // requires the update attribute set to true
  -            // That's why we actually need an existing war file. 
  -            war.delete();
  +            // That's why we actually need an existing war file.
               try
               {
  -                war.createNewFile();
  +                // A file is needed for war creation
  +                File voidFile = File.createTempFile("void", null);
  +                createZipFile(war, voidFile);
  +                voidFile.delete();
               }
               catch (IOException e)
               {
  -                throw new JavaModelException(
  -                    e,
  -                    IJavaModelStatusConstants.IO_EXCEPTION);
  +                throw new CoreException(
  +                    new Status(
  +                        IStatus.ERROR,
  +                        CactusPlugin.getPluginId(),
  +                        IStatus.OK,
  +                        "Could not create temporary file",
  +                        e));
               }
  +
               warTask.setUpdate(true);
           }
           ZipFileSet lib = new ZipFileSet();
  @@ -291,6 +300,24 @@
               {
                   theFile.delete();
               }
  +    }
  +
  +    /**
  +     * Creates a zip file containing the given existing file. 
  +     * @param theZipFile the zip file to create
  +     * @param theExistingFile the file to include in the zip
  +     */
  +    private void createZipFile(File theZipFile, File theExistingFile)
  +    {
  +        Project antProject = new Project();
  +        antProject.init();
  +        Zip zip = new Zip();
  +        zip.setProject(antProject);
  +        zip.setDestFile(theZipFile);
  +        FileSet existingFileSet = new FileSet();
  +        existingFileSet.setFile(theExistingFile);
  +        zip.addFileset(existingFileSet);
  +        zip.execute();
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to