jruaux      2003/03/06 10:04:27

  Modified:    integration/eclipse/src/java/org/apache/cactus/eclipse/launcher
                        CactusLaunchShortcut.java
  Added:       integration/eclipse/src/java/org/apache/cactus/eclipse/war
                        Webapp.java WarBuilder.java
               integration/eclipse/src/java/org/apache/cactus/eclipse/war/ui
                        WebAppPropertyPage.java
                        WebAppConfigurationBlock.java
  Removed:     integration/eclipse/src/java/org/apache/cactus/eclipse/launcher
                        WarBuilder.java
  Log:
  Added project property page for the generated web application (WAR)
  Began separating the webapp generation from the Cactus test runner plugin
  
  This is not final : comments are missing on certain classes, and structure is likely 
to change
  
  Revision  Changes    Path
  1.1                  
jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/war/Webapp.java
  
  Index: Webapp.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus" and "Apache Software
   *    Foundation" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.war;
  
  import java.util.StringTokenizer;
  import java.util.Vector;
  
  import org.apache.cactus.eclipse.ui.CactusPlugin;
  import org.eclipse.core.resources.IProject;
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.Path;
  import org.eclipse.core.runtime.QualifiedName;
  import org.eclipse.jdt.core.IClasspathEntry;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.core.JavaCore;
  import org.eclipse.jdt.core.JavaModelException;
  import org.eclipse.jdt.internal.core.JavaProject;
  
  /**
   * Helper class for creating War files.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   * @version $Id: Webapp.java,v 1.1 2003/03/06 18:04:26 jruaux Exp $
   */
  public class Webapp
  {
      /**
       * Delimiter for classpaths in the String that will be persisted. 
       */
      private static final String CLASSPATH_DELIMITER = ";";
      /**
       * QualifiedName of the output war property
       * used for persistence of project properties. 
       */
      private QualifiedName outputQN =
          new QualifiedName(CactusPlugin.getPluginId(), "output");
      /**
       * QualifiedName of the webapp directory property
       * used for persistence of project properties. 
       */
      private QualifiedName dirQN =
          new QualifiedName(CactusPlugin.getPluginId(), "dir");
      /**
       * QualifiedName of the temporary directory property
       * used for persistence of project properties. 
       */
      private QualifiedName tempDirQN =
          new QualifiedName(CactusPlugin.getPluginId(), "tempDir");
      /**
       * QualifiedName of the classpath property
       * used for persistence of project properties. 
       */
      private QualifiedName classpathQN =
          new QualifiedName(CactusPlugin.getPluginId(), "webappClasspath");
      /**
       * Full path to the webapp War.
       */
      private String output;
      /**
       * Directory of the webapp relative to the user's project. 
       */
      private String dir;
      /**
       * Temporary directory for jars copy. 
       */
      private String tempDir;
      /**
       * Paths to the webapp libraries
       */
      private IClasspathEntry[] classpath;
      /**
       * The current project to which this webapp refers.  
       */
      private IJavaProject javaProject;
  
      /**
       * Constructor.
       * @param theProject the project this webapp is linked to
       */
      public Webapp(IProject theProject)
      {
          javaProject = JavaCore.create(theProject);
      }
  
      /**
       * Initialize the web app properties with default values or stored values
       * if they exist. 
       * @return boolean true if we loaded the default values
       */
      public boolean init()
      {
          try
          {
              loadValues();
              return false;
          }
          catch (CoreException e)
          {
              loadDefaultValues();
              return true;
          }
      }
  
      /**
       * Loads this webapp from the project properties.
       * @throws CoreException if an error occurs while loading the properties 
       */
      public void loadValues() throws CoreException
      {
          IProject theProject = javaProject.getProject();
          output = theProject.getPersistentProperty(outputQN);
          dir = theProject.getPersistentProperty(dirQN);
          tempDir = theProject.getPersistentProperty(tempDirQN);
          classpath =
              toClasspathEntryArray(
                  theProject.getPersistentProperty(classpathQN));
          if (output == null
              || dir == null
              || tempDir == null
              || classpath == null)
          {
              loadDefaultValues();
          }
      }
  
      /**
       *  Loads the default values of a webapp.
       */
      public void loadDefaultValues()
      {
          output = "c:/temp/webapp.war";
          dir = "src/webapp";
          tempDir = System.getProperty("java.io.tmpdir");
          try
          {
              classpath = javaProject.getRawClasspath();
          }
          catch (JavaModelException e)
          {
              classpath = new IClasspathEntry[0];
          }
      }
  
      /**
       * Saves this webapp in the project's properties
       * @throws CoreException if an error occurs while saving 
       */
      public void persist() throws CoreException
      {
          IProject project = javaProject.getProject();
          project.setPersistentProperty(outputQN, output);
          project.setPersistentProperty(dirQN, dir);
          project.setPersistentProperty(tempDirQN, tempDir);
          project.setPersistentProperty(classpathQN, toString(classpath));
      }
  
      /**
       * Converts a String classpath to an array of library classpath entries
       * @param theClasspathEntriesString string of delimiter-separated classpaths
       * @return an array of library entries
       */
      private IClasspathEntry[] toClasspathEntryArray(
          String theClasspathEntriesString)
      {
          if (theClasspathEntriesString == null)
          {
              return null;
          }
          Vector result = new Vector();
          StringTokenizer cpTokenizer =
              new StringTokenizer(theClasspathEntriesString, CLASSPATH_DELIMITER);
          while (cpTokenizer.hasMoreElements())
          {
              String element = cpTokenizer.nextToken();
              try
              {
                  JavaProject jp = (JavaProject) javaProject;
                  IClasspathEntry newEntry =
                      JavaCore.newLibraryEntry(new Path(element), null, null);
                  result.add(newEntry);
              }
              catch (Exception e)
              {
                  // Do not add the entry
              }
          }
          return (IClasspathEntry[]) result.toArray(
              new IClasspathEntry[result.size()]);
      }
  
      /**
       * Converts an array of library classpath entries to a String 
       * @param theClasspathEntries an array of library entries
       * @return String string of delimiter-separated classpaths
       */
      private String toString(IClasspathEntry[] theClasspathEntries)
      {
          String result = "";
          for (int i = 0; i < theClasspathEntries.length; i++)
          {
              IClasspathEntry current = theClasspathEntries[i];
              result += current.getPath() + CLASSPATH_DELIMITER;
          }
          return result;
      }
      /**
       * Sets the classpath.
       * @param theClasspath The classpath to set
       */
      public void setClasspath(IClasspathEntry[] theClasspath)
      {
          this.classpath = theClasspath;
      }
  
      /**
       * Sets the dir.
       * @param theDir The dir to set
       */
      public void setDir(String theDir)
      {
          this.dir = theDir;
      }
  
      /**
       * Sets the temporary directory.
       * @param theTempDir The temporary dir to set
       */
      public void setTempDir(String theTempDir)
      {
          this.tempDir = theTempDir;
      }
  
      /**
       * Sets the output.
       * @param theOutput The output to set
       */
      public void setOutput(String theOutput)
      {
          this.output = theOutput;
      }
  
      /**
       * @return IClasspathEntry[]
       */
      public IClasspathEntry[] getClasspath()
      {
          return classpath;
      }
  
      /**
       * @return String
       */
      public String getDir()
      {
          return dir;
      }
  
      /**
       * @return String
       */
      public String getTempDir()
      {
          return tempDir;
      }
  
      /**
       * @return String
       */
      public String getOutput()
      {
          return output;
      }
  
  }
  
  
  
  1.1                  
jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/war/WarBuilder.java
  
  Index: WarBuilder.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus" and "Apache Software
   *    Foundation" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.war;
  
  import java.io.File;
  import java.net.URL;
  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.types.FileSet;
  import org.eclipse.ant.core.AntRunner;
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IPath;
  import org.eclipse.core.runtime.IProgressMonitor;
  import org.eclipse.core.runtime.Path;
  import org.eclipse.core.runtime.SubProgressMonitor;
  import org.eclipse.jdt.core.IClasspathEntry;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.core.JavaModelException;
  
  /**
   * Helper class for creating War files.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   * @version $Id: WarBuilder.java,v 1.1 2003/03/06 18:04:26 jruaux Exp $
   */
  public class WarBuilder
  {
      /**
       * the directory where to find classes
       */
      private File userClassFilesDir;
      /**
       * the web.xml file
       */
      private File userWebXML;
  
      /**
       * directory where to find user's web files
       */
      private File userWebFilesDir;
      /**
       * the location of the Ant build file for creating wars
       */
      private File buildFileLocation;
  
      private File war;
  
      private File tempDir;
  
      private IClasspathEntry[] jarEntries;
      /**
       * Cactus plug-in relative path to the war build file
       */
      private static final String BUILD_FILE_PATH = "./ant/build-war.xml";
      /**
       * Cactus plug-in relative path to the web.xml file
       */
      private static final String WEB_XML_PATH = "./ant/confs/web.xml";
  
      public static final String WEBINF = "WEB-INF";
  
      public static final String LIB = "lib";
  
      public static final String WEBXML = "web.xml";
  
      private static final String JARS_PATH =
          "org.apache.cactus.eclipse.war.jars.temp";
  
      /**
       * Constructor.
       * @param theBuildFileLocation the build file for war creation
       * @param theClassFilesDir classes to include in the war file
       * @param theWebXML web.xml file to include in the war file
       * @param theJarFilesDir jars to include in the war file
       * @param theWebFilesDir web files to include in the war file
       */
      public WarBuilder(
          File theBuildFileLocation,
          File theClassFilesDir,
          File theWebXML,
          File theJarFilesDir,
          File theWebFilesDir)
      {
          this.buildFileLocation = theBuildFileLocation;
          this.userClassFilesDir = theClassFilesDir;
          this.userWebXML = theWebXML;
          //        this.userJarFilesDir = theJarFilesDir;
          this.userWebFilesDir = theWebFilesDir;
      }
  
      /**
       * Constructor.
       * @param theJavaProject the Java project which Java classes will be used
       * @throws JavaModelException if we can't get the ouput location
       */
      public WarBuilder(IJavaProject theJavaProject) throws JavaModelException
      {
          Webapp webapp = new Webapp(theJavaProject.getProject());
          try
          {
              webapp.loadValues();
          }
          catch (CoreException e)
          {
              throw new JavaModelException(e);
          }
  
          war = new File(webapp.getOutput());
          tempDir = new File(webapp.getTempDir());
          jarEntries = webapp.getClasspath();
          // User's project relative path to the web directory
          String userWebFilesPath = webapp.getDir();
          // User's project relative path to the web.xml file
          String userWebXMLPath = userWebFilesPath + "/" + WEBINF + "/" + WEBXML;
  
          CactusPlugin thePlugin = CactusPlugin.getDefault();
          URL buildFileURL = thePlugin.find(new Path(BUILD_FILE_PATH));
          if (buildFileURL == null)
          {
              throw new JavaModelException(
                  CactusPlugin.createCoreException(
                      "CactusLaunch.message.prepare.error.plugin.file",
                      " : " + BUILD_FILE_PATH,
                      null));
          }
          buildFileLocation = new File(buildFileURL.getPath());
          IPath projectPath = theJavaProject.getProject().getLocation();
          IPath classFilesPath =
              projectPath.removeLastSegments(1).append(
                  theJavaProject.getOutputLocation());
          userClassFilesDir = classFilesPath.toFile();
          userWebXML = projectPath.append(userWebXMLPath).toFile();
          // copy any web folder situated in the user's project
          userWebFilesDir = projectPath.append(userWebFilesPath).toFile();
      }
  
      /**
       * Creates the war file in the Java temp directory.
       * @param thePM a monitor that reflects the overall progress
       * @return File the location where the war file was created
       * @throws CoreException if we can't create the file
       */
      public File createWar(IProgressMonitor thePM) throws CoreException
      {
          thePM.subTask(CactusMessages.getString("CactusLaunch.message.war"));
          Vector arguments = new Vector();
          IPath tempJarsPath =
              new Path(tempDir.getAbsolutePath()).append(JARS_PATH);
          File tempJarsDir = tempJarsPath.toFile();
          tempJarsDir.mkdir();
          copyJars(jarEntries, tempJarsDir);
          String jarFilesPath = tempDir.getAbsolutePath();
          arguments.add("-Djars.dir=" + jarFilesPath);
          if (userWebXML.exists())
          {
              String webXMLPath = userWebXML.getAbsolutePath();
              arguments.add("-Dwebxml.path=" + webXMLPath);
          }
          String classFilesPath = userClassFilesDir.getAbsolutePath();
          arguments.add("-Dclasses.dir=" + classFilesPath);
  
          String warFilePath = war.getAbsolutePath();
          arguments.add("-Dwar.path=" + warFilePath);
  
          if (userWebFilesDir.exists())
          {
              String webFilesPath = userWebFilesDir.getAbsolutePath();
              arguments.add("-Dwebfiles.dir=" + webFilesPath);
          }
          String[] antArguments = (String[]) arguments.toArray(new String[0]);
          AntRunner runner = new AntRunner();
          runner.setBuildFileLocation(buildFileLocation.getAbsolutePath());
          runner.setArguments(antArguments);
          String[] targets = { "testwar" };
          runner.setExecutionTargets(targets);
          runner.run(new SubProgressMonitor(thePM, 3));
          delete(tempJarsDir);
          return war;
      }
  
      /**
       * Copies a set of Jar files to the destination directory.
       * @param theEntries set of Jars
       * @param theDestination the destination directory 
       */
      private void copyJars(IClasspathEntry[] theEntries, File theDestination)
      {
          if (!theDestination.isDirectory())
          {
              return;
          }
          Project antProject = new Project();
          antProject.init();
          Copy jarCopy = new Copy();
          jarCopy.setProject(antProject);
          jarCopy.setTodir(theDestination);
          for (int i = 0; i < theEntries.length; i++)
          {
              IClasspathEntry currentEntry = theEntries[i];
              if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
              {
                  File currentJar = currentEntry.getPath().toFile();
                  FileSet fileSet = new FileSet();
                  fileSet.setFile(currentJar);
                  jarCopy.addFileset(fileSet);
              }
          }
          jarCopy.execute();
      }
      /**
       * Removes the specified file or directory, and all subdirectories
       * @param theFile the file or directory to delete
       */
      public static void delete(File theFile)
      {
          if (theFile.isDirectory())
          {
              File[] dir = theFile.listFiles();
              for (int i = 0; i < dir.length; i++)
              {
                  delete(dir[i]);
              }
              theFile.delete();
          }
          else
              if (theFile.exists())
              {
                  theFile.delete();
              }
      }
  
  }
  
  
  
  1.1                  
jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/war/ui/WebAppPropertyPage.java
  
  Index: WebAppPropertyPage.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus" and "Apache Software
   *    Foundation" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.war.ui;
  
  import org.apache.cactus.eclipse.war.Webapp;
  import org.eclipse.core.resources.IProject;
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IAdaptable;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.core.JavaCore;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Control;
  import org.eclipse.ui.dialogs.PropertyPage;
  
  /**
   * Property page for the web application.
   * It is displayed in project's property pages.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   * @version $Id: WebAppPropertyPage.java,v 1.1 2003/03/06 18:04:26 jruaux Exp $
   */
  public class WebAppPropertyPage extends PropertyPage
  {
      /**
       * Block showing the jar path list. 
       */
      private WebAppConfigurationBlock webAppConfigurationBlock;
  
      /**
       * The webapp object that is loaded or persisted. 
       */
      private Webapp webapp;
  
      /**
       * @see org.eclipse.jface.preference.PreferencePage#createContents(
       *     org.eclipse.swt.widgets.Composite)
       */
      protected Control createContents(Composite theParent)
      {
          IJavaProject javaProject = JavaCore.create(getProject());
          webapp = new Webapp(getProject());
          boolean loadedDefaults = webapp.init();
          if (loadedDefaults)
          {
              // Status line indicating we loaded the defaults 
          }
          webAppConfigurationBlock =
              new WebAppConfigurationBlock(
                  getShell(),
                  javaProject,
                  webapp.getOutput(),
                  webapp.getDir(),
                  webapp.getTempDir(),
                  webapp.getClasspath());
          return webAppConfigurationBlock.createContents(theParent);
      }
  
      /**
       * @see org.eclipse.jface.preference.PreferencePage#performOk()
       */
      public boolean performOk()
      {
          webapp.setOutput(webAppConfigurationBlock.getOutput());
          webapp.setDir(webAppConfigurationBlock.getWebappDir());
          webapp.setTempDir(webAppConfigurationBlock.getTempDir());
          webapp.setClasspath(webAppConfigurationBlock.getWebappClasspath());
          try
          {
              webapp.persist();
          }
          catch (CoreException e)
          {
              //TODO: update status line
              return false;
          }
          return true;
      }
  
      /**
       * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
       */
      public void performDefaults()
      {
          super.performDefaults();
          webapp.loadDefaultValues();
          webAppConfigurationBlock.update(
              webapp.getOutput(),
              webapp.getDir(),
              webapp.getTempDir(),
              webapp.getClasspath());
          webAppConfigurationBlock.refresh();
      }
  
      /**
       * Returns the project on which this property page has been called.
       * @return the current project
       */
      private IProject getProject()
      {
          IAdaptable adaptable = getElement();
          IProject elem = (IProject) adaptable.getAdapter(IProject.class);
          return elem;
      }
  }
  
  
  1.1                  
jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/war/ui/WebAppConfigurationBlock.java
  
  Index: WebAppConfigurationBlock.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus" and "Apache Software
   *    Foundation" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.cactus.eclipse.war.ui;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Vector;
  
  import org.eclipse.core.resources.IWorkspaceRoot;
  import org.eclipse.jdt.core.IClasspathEntry;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.internal.ui.JavaPlugin;
  import org.eclipse.jdt.internal.ui.preferences.PreferencesMessages;
  import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
  import org.eclipse.jdt.internal.ui.wizards.buildpaths.LibrariesWorkbookPage;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.CheckedListDialogField;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
  import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
  import org.eclipse.jface.viewers.LabelProvider;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.layout.GridData;
  import org.eclipse.swt.layout.GridLayout;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Control;
  import org.eclipse.swt.widgets.DirectoryDialog;
  import org.eclipse.swt.widgets.FileDialog;
  import org.eclipse.swt.widgets.Shell;
  
  /**
   * Helper class for creating War files.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
   * @version $Id: WebAppConfigurationBlock.java,v 1.1 2003/03/06 18:04:26 jruaux Exp $
   */
  public class WebAppConfigurationBlock
  {
      private StringButtonDialogField outputField;
      private StringDialogField webappDirField;
      private StringButtonDialogField tempDirField;
      private LibrariesWorkbookPage libraryPage;
  
      private CheckedListDialogField classPathList;
      private IJavaProject javaProject;
      private Shell shell;
  
      public WebAppConfigurationBlock(
          Shell theShell,
          IJavaProject theJavaProject,
          String theOutput,
          String theDir,
          String theTempDir,
          IClasspathEntry[] theEntries)
      {
          shell = theShell;
          javaProject = theJavaProject;
          BuildPathAdapter adapter = new BuildPathAdapter();
  
          classPathList =
              new CheckedListDialogField(null, null, new LabelProvider());
          classPathList.setDialogFieldListener(adapter);
          IWorkspaceRoot root = JavaPlugin.getWorkspace().getRoot();
          libraryPage = new LibrariesWorkbookPage(root, classPathList);
          outputField = new StringButtonDialogField(adapter);
          outputField.setDialogFieldListener(adapter);
          outputField.setLabelText("Output war");
          outputField.setButtonLabel("Browse...");
  
          webappDirField = new StringDialogField();
          webappDirField.setDialogFieldListener(adapter);
          webappDirField.setLabelText("Webapp directory");
  
          tempDirField = new StringButtonDialogField(adapter);
          tempDirField.setDialogFieldListener(adapter);
          tempDirField.setLabelText("Temporary directory");
          tempDirField.setButtonLabel("Browse...");
  
          update(theOutput, theDir, theTempDir, theEntries);
      }
  
      private class BuildPathAdapter
          implements IStringButtonAdapter, IDialogFieldListener
      {
  
          // -------- IStringButtonAdapter --------
          public void changeControlPressed(DialogField field)
          {
              buildPathChangeControlPressed(field);
          }
  
          // ---------- IDialogFieldListener --------
          public void dialogFieldChanged(DialogField field)
          {
              buildPathDialogFieldChanged(field);
          }
      }
  
      private void buildPathDialogFieldChanged(DialogField field)
      {
      }
  
      private void buildPathChangeControlPressed(DialogField field)
      {
          if (field == tempDirField)
          {
              File tempDir = chooseTempDir();
              if (tempDir != null)
              {
                  tempDirField.setText(tempDir.getAbsolutePath());
              }
          }
          else
          {
              if (field == outputField)
              {
                  File output = chooseOutput();
                  if (output != null)
                  {
                      outputField.setText(output.getAbsolutePath());
                  }
              }
          }
      }
      
      private File chooseOutput()
      {
          File output = new File(outputField.getText());
          if (!output.exists()) {
                output = output.getParentFile();
          }
          String initPath = "";
          if (output != null)
          {
              initPath = output.getPath();
          }
          FileDialog dialog = new FileDialog(shell);
          dialog.setText(PreferencesMessages.getString("War file selection"));
          dialog.setFilterExtensions(new String[] {"*.war"});
          dialog.setFilterPath(initPath);
          String res = dialog.open();
          if (res != null)
          {
              return (new File(res));
          }
          return null;
      }
  
      private File chooseTempDir()
      {
          File tempDir = new File(tempDirField.getText());
          String initPath = "";
          if (tempDir != null)
          {
              initPath = tempDir.getPath();
          }
          DirectoryDialog dialog = new DirectoryDialog(shell);
          dialog.setText(
              PreferencesMessages.getString("Temp directory selection"));
          dialog.setMessage("Select temp directory:");
          dialog.setFilterPath(initPath);
          String res = dialog.open();
          if (res != null)
          {
              return (new File(res));
          }
          return null;
      }
  
      public Control createContents(Composite theParent)
      {
          final Composite topComp = new Composite(theParent, SWT.NONE);
          GridLayout topLayout = new GridLayout();
  
          topComp.setLayout(topLayout);
          topLayout.numColumns = 3;
          topLayout.marginWidth = 0;
          topLayout.marginHeight = 0;
          topComp.setLayout(topLayout);
  
          outputField.doFillIntoGrid(topComp, 3);
          webappDirField.doFillIntoGrid(topComp, 3);
          tempDirField.doFillIntoGrid(topComp, 3);
  
          Control libraryPageControl = libraryPage.getControl(topComp);
          GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
          gd.horizontalSpan = 3;
          libraryPageControl.setLayoutData(gd);
          libraryPage.init(javaProject);
  
          return topComp;
      }
  
      private void doValidation()
      {
  
          String text = outputField.getText();
          if (text.length() > 0)
          {
              //            File file = new File(text);
              //            if (!file.isFile())
              //            {
              //                
status.setError(PreferencesMessages.getString("JavadocPreferencePage.error.notexists"));
 
              //            }
          }
      }
  
      public String getOutput()
      {
          return outputField.getText();
      }
  
      public String getWebappDir()
      {
          return webappDirField.getText();
      }
  
      public String getTempDir()
      {
          return tempDirField.getText();
      }
  
      public IClasspathEntry[] getWebappClasspath()
      {
          Vector result = new Vector();
          List cplist = classPathList.getElements();
          for (int i = 0; i < cplist.size(); i++)
          {
              CPListElement elem = (CPListElement) cplist.get(i);
              if (elem.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
              {
                  result.add(elem.getClasspathEntry());
              }
          }
          return (IClasspathEntry[]) result.toArray(
              new IClasspathEntry[result.size()]);
      }
  
      private ArrayList getExistingEntries(IClasspathEntry[] classpathEntries)
      {
          ArrayList newClassPath = new ArrayList();
          for (int i = 0; i < classpathEntries.length; i++)
          {
              IClasspathEntry curr = classpathEntries[i];
              if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
              {
                  try
                  {
                      newClassPath.add(
                          CPListElement.createFromExisting(curr, javaProject));
                  }
                  catch (NullPointerException e)
                  {
                      // an error occured when parsing the entry
                      // (possibly invalid entry)
                      // We don't add it
                  }
              }
          }
          return newClassPath;
  
      }
  
      public void update(
          String theOutput,
          String theDir,
          String theTempDir,
          IClasspathEntry[] theEntries)
      {
          outputField.setText(theOutput);
          webappDirField.setText(theDir);
          tempDirField.setText(theTempDir);
          classPathList.setElements(getExistingEntries(theEntries));
      }
  
      public void refresh()
      {
          libraryPage.init(javaProject);
      }
  }
  
  
  
  1.8       +3 -1      
jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/launcher/CactusLaunchShortcut.java
  
  Index: CactusLaunchShortcut.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/launcher/CactusLaunchShortcut.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CactusLaunchShortcut.java 25 Feb 2003 17:58:54 -0000      1.7
  +++ CactusLaunchShortcut.java 6 Mar 2003 18:04:27 -0000       1.8
  @@ -65,6 +65,7 @@
   import org.apache.cactus.eclipse.ui.CactusMessages;
   import org.apache.cactus.eclipse.ui.CactusPlugin;
   import org.apache.cactus.eclipse.ui.CactusPreferences;
  +import org.apache.cactus.eclipse.war.WarBuilder;
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IProgressMonitor;
   import org.eclipse.debug.core.DebugPlugin;
  @@ -313,6 +314,7 @@
           try
           {
               WarBuilder newWar = new WarBuilder(theJavaProject);
  +            File tempDir = new File(CactusPreferences.getTempDir());
               war = newWar.createWar(thePM);
               URL warURL = war.toURL();
               String contextURLPath = CactusPreferences.getContextURLPath();
  
  
  

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

Reply via email to