vmassol     2002/10/19 04:20:26

  Modified:    Eclipse-Plugin/src/java/org/apache/cactus/eclipse/launcher
                        CactusLaunchConfiguration.java
  Log:
  Simplified a lot the cactus launch configuration now that I understand better ... I 
hope I haven't broken anything ... :-)
  
  Revision  Changes    Path
  1.13      +56 -215   
jakarta-cactus/Eclipse-Plugin/src/java/org/apache/cactus/eclipse/launcher/CactusLaunchConfiguration.java
  
  Index: CactusLaunchConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/Eclipse-Plugin/src/java/org/apache/cactus/eclipse/launcher/CactusLaunchConfiguration.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CactusLaunchConfiguration.java    19 Oct 2002 09:58:36 -0000      1.12
  +++ CactusLaunchConfiguration.java    19 Oct 2002 11:20:26 -0000      1.13
  @@ -56,33 +56,11 @@
    */
   package org.apache.cactus.eclipse.launcher;
   
  -import java.io.File;
  -import java.io.IOException;
  -import java.lang.reflect.Method;
  -import java.net.MalformedURLException;
  -import java.net.URL;
  -import java.text.MessageFormat;
  -
  -import org.eclipse.core.boot.BootLoader;
   import org.eclipse.core.runtime.CoreException;
  -import org.eclipse.core.runtime.IProgressMonitor;
  -import org.eclipse.core.runtime.Platform;
  -import org.eclipse.debug.core.ILaunch;
   import org.eclipse.debug.core.ILaunchConfiguration;
  -import org.eclipse.debug.core.model.ISourceLocator;
  -import org.eclipse.jdt.core.IJavaProject;
   import org.eclipse.jdt.core.IType;
   import org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfiguration;
  -import org.eclipse.jdt.internal.junit.ui.JUnitMessages;
  -import org.eclipse.jdt.internal.junit.ui.JUnitPlugin;
  -import org.eclipse.jdt.launching.ExecutionArguments;
  -import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
  -import org.eclipse.jdt.launching.IVMInstall;
  -import org.eclipse.jdt.launching.IVMInstallType;
  -import org.eclipse.jdt.launching.IVMRunner;
  -import org.eclipse.jdt.internal.junit.util.SocketUtil;
   import org.eclipse.jdt.launching.VMRunnerConfiguration;
  -import org.eclipse.jdt.launching.sourcelookup.JavaSourceLocator;
   
   /**
    * Provides a launcher to start Cactus tests. This is done by implementing
  @@ -107,212 +85,75 @@
           "org.apache.cactus.eclipse.launchconfig";
   
       /**
  -     * @see 
org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(ILaunchConfiguration, 
String, ILaunch, IProgressMonitor)
  -     */
  -    public void launch(ILaunchConfiguration theConfiguration, String theMode,
  -        ILaunch theLaunch, IProgressMonitor thePm) throws CoreException
  -    {
  -        IJavaProject javaProject = getJavaProject(theConfiguration);
  -        if ((javaProject == null) || !javaProject.exists())
  -        {
  -            abort(JUnitMessages.getString(
  -                "JUnitBaseLaunchConfiguration.error.invalidproject"), null, 
  -                IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT);
  -        }
  -
  -        // Get the first Cactus/JUnit test to run.
  -        // TODO: Add support for several tests to be run at once (needs 
  -        // Eclipse 2.1).
  -        IType testType = getFirstTestType(theConfiguration, javaProject, 
  -            thePm);
  -
  -        IVMInstallType type = getVMInstallType(theConfiguration);
  -        IVMInstall install = getVMInstall(theConfiguration);
  -        IVMRunner runner = install.getVMRunner(theMode);
  -
  -        if (runner == null)
  -        {
  -            abort(MessageFormat.format(JUnitMessages.getString(
  -                "JUnitBaseLaunchConfiguration.error.novmrunner"),
  -                new String[] { install.getId()}), null, 
  -                IJavaLaunchConfigurationConstants.ERR_VM_RUNNER_DOES_NOT_EXIST);
  -        }
  -
  -        File workingDir = verifyWorkingDirectory(theConfiguration);
  -        String workingDirName = null;
  -        if (workingDir != null)
  -        {
  -            workingDirName = workingDir.getAbsolutePath();
  -        }
  -
  -        // Program & VM args
  -        String vmArgs = getVMArguments(theConfiguration);
  -        ExecutionArguments execArgs = new ExecutionArguments(vmArgs, "");
  -
  -        // Create VM config
  -        IType types[] = { testType };
  -        int port = SocketUtil.findUnusedLocalPort("", 5000, 15000);
  -
  -        VMRunnerConfiguration runConfig =
  -            createVMRunner(theConfiguration, types, port, theMode);
  -
  -        // Surprisingly enough the JUnit plugin discards all VM arguments set 
  -        // in the configuration. This is why we add the cactus VM argument here
  -        String[] cactusVMArgs = runConfig.getVMArguments();
  -        String[] configVMArgs = execArgs.getVMArgumentsArray();
  -        String[] globalVMArgs =
  -            new String[cactusVMArgs.length + configVMArgs.length];
  -        System.arraycopy(configVMArgs, 0, globalVMArgs, 0, configVMArgs.length);
  -        System.arraycopy(cactusVMArgs, 0, globalVMArgs, configVMArgs.length, 
  -            cactusVMArgs.length);
  -
  -        runConfig.setVMArguments(globalVMArgs);
  -        runConfig.setWorkingDirectory(workingDirName);
  -
  -        String[] bootpath = getBootpath(theConfiguration);
  -        runConfig.setBootClassPath(bootpath);
  -
  -        //  set default source locator if none specified
  -        String id =
  -            theConfiguration.getAttribute(
  -                ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID,
  -                (String) null);
  -        if (id == null)
  -        {
  -            ISourceLocator sourceLocator = new JavaSourceLocator(javaProject);
  -            theLaunch.setSourceLocator(sourceLocator);
  -        }
  -
  -        theLaunch.setAttribute(PORT_ATTR, Integer.toString(port));
  -        theLaunch.setAttribute(TESTTYPE_ATTR, testType.getHandleIdentifier());
  -        runner.run(runConfig, theLaunch, thePm);
  -    }
  -
  -    /**
  -     * Create a VM which will be used to run the Cactus tests. This VM is 
  -     * created by getting the JUnit plugin VM and adding Cactus specific
  -     * parameters to it. This method overrides the JUnit Plugin one.
  +     * Create a VM configuration which will be used to run the Cactus tests.
  +     * The only difference between the Cactus plugin and JUnit plugin in term
  +     * of launch configuration is the VM configuration. Cactus needs more
  +     * jars in the classpath and need to pass additional VM arguments (the
  +     * Cactus configuration).
  +     *
  +     * Note: This method is called by the
  +     * {@link JUnitBaseLaunchConfiguration#launch()} method. That 
  +     * <code>launch()</code> method is the entry point of this extension point
  +     * and is called by Eclipse when the user press the run button.
  +     * 
  +     * @param theConfiguration the launch configuration
  +     * @param theTestTypes the JUnit tests that will be run
  +     * @param thePort the JUnit remote port
  +     * @param theRunMode the run mode (debug, run)
  +     * @return the configuration for the VM in which to run the tests 
  +     * 
  +     * @exception CoreException on critical failures
        */
       protected VMRunnerConfiguration createVMRunner(
           ILaunchConfiguration theConfiguration, IType[] theTestTypes, 
           int thePort, String theRunMode) throws CoreException
       {
           // Get the VM used by the JUnit plugin
  -        VMRunnerConfiguration vmConfig = super.createVMRunner(theConfiguration,
  -            theTestTypes, thePort, theRunMode);
  +        VMRunnerConfiguration junitVmConfig = super.createVMRunner(
  +            theConfiguration, theTestTypes, thePort, theRunMode);
               
  -        // Add Cactus specific arguments
  +        // Compute new classpath : JUnit CP + Cactus CP        
  +        // TODO: Add Cactus specific jars to the classpath here
  +        String[] cactusClasspath = {};     
  +        String[] classpath = concatenateStringArrays(
  +            junitVmConfig.getClassPath(), cactusClasspath);
  +
  +        // Compute new VM arguments : JUnit VM argument + Cactus VM arguments
           // TODO: Get this from the plugin preference page.
  -        String[] vmArgs = { "-Dcactus.contextURL=http://localhost:8081/test"; };
  -        vmConfig.setVMArguments(vmArgs);
  +        String[] cactusVmArgs = { 
  +            "-Dcactus.contextURL=http://localhost:8081/test"; 
  +        };
  +        String[] vmArgs = concatenateStringArrays(
  +            junitVmConfig.getVMArguments(), cactusVmArgs);
  +                         
  +        // Create a new VM that includes both JUnit parameters and the new
  +        // Cactus parameters.
  +        VMRunnerConfiguration cactusVmConfig = new VMRunnerConfiguration(
  +            junitVmConfig.getClassToLaunch(), classpath);        
  +        cactusVmConfig.setBootClassPath(junitVmConfig.getBootClassPath());
  +        cactusVmConfig.setProgramArguments(
  +            junitVmConfig.getProgramArguments());
  +        cactusVmConfig.setVMArguments(vmArgs);
  +        cactusVmConfig.setVMSpecificAttributesMap(
  +            junitVmConfig.getVMSpecificAttributesMap());        
  +        cactusVmConfig.setWorkingDirectory(
  +            junitVmConfig.getWorkingDirectory());        
   
  -        return vmConfig;
  +        return cactusVmConfig;
       }
   
       /**
  -     * Adds the junitsupport.jar path to the given configuration and returns 
  -     * it.
  -     * 
  -     * @param theConfiguration
  -     * @param theType
  -     * @return
  -     * @throws CoreException
  -     */
  -    private String[] createClassPath(ILaunchConfiguration theConfiguration, 
  -        IType theType) throws CoreException
  +     * Concatenate two string arrays.
  +     * 
     * @param theArray1 the first array
     * @param theArray2 the second 
array
     * @return a string array containing the first array followed by the second
  +     *         one
     */    
  +    private String[] concatenateStringArrays(String[] theArray1, 
  +        String[] theArray2)
       {
  -        URL url = JUnitPlugin.getDefault().getDescriptor().getInstallURL();
  -        String[] cp = getClasspath(theConfiguration);
  -        boolean inDevelopmentMode = BootLoader.inDevelopmentMode();
  -
  -        String[] classPath = new String[cp.length + 1];
  -        System.arraycopy(cp, 0, classPath, 1, cp.length);
  -        try
  -        {
  -            if (inDevelopmentMode)
  -            {
  -                // assumption is that the output folder is called bin!
  -                classPath[0] = Platform.asLocalURL(
  -                    new URL(url, "bin")).getFile();
  -            } 
  -            else
  -            {
  -                classPath[0] = Platform.asLocalURL(
  -                    new URL(url, "junitsupport.jar")).getFile();
  -            }
  -        } 
  -        catch (MalformedURLException e)
  -        {
  -            JUnitPlugin.log(e); // TO DO abort run and inform user
  -        } 
  -        catch (IOException e)
  -        {
  -            JUnitPlugin.log(e); // TO DO abort run and inform user
  -        }
  -        return classPath;
  +        String[] newArray = new String[theArray1.length + theArray2.length];
  +        System.arraycopy(theArray1, 0, newArray, 0, theArray1.length);
  +        System.arraycopy(theArray2, 0, newArray, theArray1.length, 
  +            theArray2.length);
  +        return newArray;
       }
   
  -    /**
  -     * Helper method to make our class work both in Eclipse 2.0 and 2.1. Indeed,
  -     * in Eclipse 2.1, the JUnit plugin has changed and the 
  -     * <code>getTestType()</code> method has been removed in favor of a 
  -     * <code>getTestTypes()</code> to support running several tests at once.
  -     * 
     * @param theConfiguration the configuration to launch
  -     * @param theJavaProject reference to the current active java project
  -     * @param thePm the progress monitor, or <code>null</code>
  -     * @return the test to run. In Eclipse 2.1 returns the first test selected
     
*/
  -    private IType getFirstTestType(ILaunchConfiguration theConfiguration,
  -        IJavaProject theJavaProject, IProgressMonitor thePm)
  -    {                
  -        // TODO: Upon exception, stop the launch so that this method should
  -        // never have to return null.
  -                
  -        IType testType = null;
  -        
  -        try
  -        {
  -            // Test if the getTestType() method exist. It does for Eclipse 2.0
  -            // but not for Eclipse 2.1
  -            Method getTestTypeMethod = this.getClass().getMethod("getTestType", 
  -                new Class[] { ILaunchConfiguration.class, 
  -                IJavaProject.class });
  -            try
  -            {
  -                testType = (IType) getTestTypeMethod.invoke(this, 
  -                    new Object[] { theConfiguration, theJavaProject });
  -            }
  -            catch (Exception e)
  -            {
  -                JUnitPlugin.log(e); // TO DO abort run and inform user
  -            }
  -        }
  -        catch (NoSuchMethodException e)
  -        {
  -            try
  -            {
  -                // Ok, this means we should be in Eclipse 2.1
  -                Method getTestTypeMethod = this.getClass().getMethod(
  -                    "getTestTypes", new Class[] { ILaunchConfiguration.class, 
  -                    IJavaProject.class, IProgressMonitor.class });
  -                try
  -                {
  -                    testType = ((IType[]) getTestTypeMethod.invoke(this, 
  -                        new Object[] { theConfiguration, theJavaProject, 
  -                        thePm }))[0];
  -                }
  -                catch (Exception ee)
  -                {
  -                    JUnitPlugin.log(ee); // TO DO abort run and inform user
  -                }
  -            }
  -            catch (NoSuchMethodException ee)
  -            {
  -                JUnitPlugin.log(ee); // TO DO abort run and inform user
  -            }
  - 
  -        }
  -
  -        return testType;
  -    }
  -    
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:cactus-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-dev-help@;jakarta.apache.org>

Reply via email to