You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by jr...@apache.org on 2003/03/27 15:54:42 UTC
cvs commit: jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/launcher CactusLaunchShortcut.java CactusLaunchConfiguration.java
jruaux 2003/03/27 06:54:42
Modified: integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui
ContainersPreferencePage.java
CactifyActionDelegate.java CactusPlugin.java
CactusPreferences.java
integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/launcher
CactusLaunchShortcut.java
CactusLaunchConfiguration.java
Log:
Added default Jetty container
Revision Changes Path
1.3 +9 -1 jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui/ContainersPreferencePage.java
Index: ContainersPreferencePage.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui/ContainersPreferencePage.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContainersPreferencePage.java 21 Mar 2003 16:38:11 -0000 1.2
+++ ContainersPreferencePage.java 27 Mar 2003 14:54:42 -0000 1.3
@@ -56,6 +56,7 @@
*/
package org.apache.cactus.eclipse.runner.ui;
+import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.ui.IWorkbench;
@@ -112,6 +113,13 @@
containerIds[i],
getFieldEditorParent()));
}
+ addField(
+ new BooleanFieldEditor(
+ CactusPreferences.JETTY,
+ "Jetty",
+ BooleanFieldEditor.SEPARATE_LABEL,
+ getFieldEditorParent()));
+
}
/**
1.3 +2 -21 jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui/CactifyActionDelegate.java
Index: CactifyActionDelegate.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui/CactifyActionDelegate.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CactifyActionDelegate.java 17 Mar 2003 09:45:15 -0000 1.2
+++ CactifyActionDelegate.java 27 Mar 2003 14:54:42 -0000 1.3
@@ -57,10 +57,10 @@
package org.apache.cactus.eclipse.runner.ui;
import java.io.File;
-import java.io.FilenameFilter;
import java.net.URL;
import java.util.Vector;
+import org.apache.cactus.eclipse.runner.common.JarFilenameFilter;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
@@ -204,25 +204,6 @@
}
return result;
}
- /**
- * Filter for jar files.
- * i.e. accepts files like 'library.jar'
- *
- * @author <a href="mailto:jruaux@octo.com">Julien Ruaux</a>
- *
- * @version $Id$
- */
- static class JarFilenameFilter implements FilenameFilter
- {
- /**
- * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
- */
- public boolean accept(File theDir, String theFilename)
- {
- return theFilename.endsWith(".jar");
- }
- }
-
/**
* @param theFirstArray an array of classpath entries
* @param theSecondArray an array of classpath entries
1.4 +15 -7 jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui/CactusPlugin.java
Index: CactusPlugin.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui/CactusPlugin.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CactusPlugin.java 21 Mar 2003 20:14:07 -0000 1.3
+++ CactusPlugin.java 27 Mar 2003 14:54:42 -0000 1.4
@@ -248,17 +248,25 @@
theStore.setDefault(
CactusPreferences.WEBAPP_DIR,
CactusMessages.getString("CactusPreferencePage.label.webapp.init"));
-
+ theStore.setDefault(
+ CactusPreferences.JETTY,
+ true
+ );
}
/**
- * Returns a container provider.
- * @return IContainerProvider a container provider to use for Cactus tests.
- * @throws CoreException if the container provider can't be contructed
+ * Returns a container manager.
+ * @return a container provider to use for Cactus tests
+ * or null if Jelly is selected as the container.
+ * @throws CoreException if the container manager can't be contructed
*/
public static IContainerManager getContainerManager()
throws CoreException
{
+ if (CactusPreferences.getJetty())
+ {
+ return null;
+ }
return new AntContainerManager(
BUILD_FILE_PATH,
CactusPreferences.getContextURLPort(),
@@ -353,7 +361,7 @@
* Sets the current CactusLaunchShortcut
* @param theCactusLaunchShortcut the instance to set
*/
- public void addCactusLaunchShortcut(
+ public void setCactusLaunchShortcut(
CactusLaunchShortcut theCactusLaunchShortcut)
{
this.launchShortcut = theCactusLaunchShortcut;
1.3 +18 -1 jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui/CactusPreferences.java
Index: CactusPreferences.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/ui/CactusPreferences.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CactusPreferences.java 21 Mar 2003 16:38:11 -0000 1.2
+++ CactusPreferences.java 27 Mar 2003 14:54:42 -0000 1.3
@@ -106,6 +106,11 @@
public static final String WEBAPP_DIR = "webapp_Dir";
/**
+ * id for the Jetty container selection preference.
+ */
+ public static final String JETTY = "jetty";
+
+ /**
* Returns the context URL that should be used by the client, as
* configured in the plug-in preferences.
*
@@ -211,6 +216,18 @@
String result = store.getString(theContainerId);
CactusPlugin.log(
"Cactus preference : " + theContainerId + "= [" + result + "]");
+ return result;
+ }
+
+ /**
+ * Returns true if Jetty is selected.
+ * @return true if Jetty is selected
+ */
+ public static boolean getJetty()
+ {
+ IPreferenceStore store = CactusPlugin.getDefault().getPreferenceStore();
+ boolean result = store.getBoolean(JETTY);
+ CactusPlugin.log("Cactus preference : Jetty = [" + result + "]");
return result;
}
1.8 +113 -69 jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/launcher/CactusLaunchShortcut.java
Index: CactusLaunchShortcut.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/launcher/CactusLaunchShortcut.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- CactusLaunchShortcut.java 21 Mar 2003 16:38:11 -0000 1.7
+++ CactusLaunchShortcut.java 27 Mar 2003 14:54:42 -0000 1.8
@@ -107,7 +107,7 @@
/**
* The container provider that is used in this launch.
*/
- private IContainerProvider provider;
+ private IContainerProvider provider = null;
/**
* The current search to launch on.
@@ -191,61 +191,91 @@
// Register the instance of CactusLaunchShortcut to the JUnitPlugin
// for TestRunEnd notification.
JUnitPlugin.getDefault().addTestRunListener(this);
- this.search = theSearch;
- this.mode = theMode;
- CactusPlugin.getDefault().addCactusLaunchShortcut(this);
- final IJavaProject theJavaProject = type.getJavaProject();
- final IRunnableWithProgress runnable = new IRunnableWithProgress()
+ CactusPlugin.getDefault().setCactusLaunchShortcut(this);
+ try
{
- public void run(IProgressMonitor thePM)
- throws InterruptedException
+ IContainerManager manager = CactusPlugin.getContainerManager();
+ // when manager is null we use Jetty as the container
+ if (manager == null)
{
- try
- {
- CactusPlugin.log("Preparing cactus tests");
- prepareCactusTests(theJavaProject, thePM);
- }
- catch (CoreException e)
- {
- throw new InterruptedException(e.getMessage());
- }
+ super.launchType(theSearch, theMode);
}
- };
- Display.getDefault().asyncExec(new Runnable()
- {
- public void run()
+ else
{
- try
- {
- ProgressMonitorDialog dialog =
- new ProgressMonitorDialog(getShell());
- dialog.run(true, true, runnable);
- }
- catch (InvocationTargetException e)
- {
- CactusPlugin.displayErrorMessage(
- CactusMessages.getString(
- "CactusLaunch.message.prepare.error"),
- e.getTargetException().getMessage(),
- null);
- cancelPreparation();
- return;
- }
- catch (InterruptedException e)
- {
- CactusPlugin.displayErrorMessage(
- CactusMessages.getString(
- "CactusLaunch.message.prepare.error"),
- e.getMessage(),
- null);
- cancelPreparation();
- return;
- }
+ this.search = theSearch;
+ this.mode = theMode;
+ this.provider = manager.getContainerProviders()[0];
+ prepare(type.getJavaProject(), getContainerProvider());
}
- });
+ }
+ catch (CoreException e)
+ {
+ CactusPlugin.displayErrorMessage(
+ CactusMessages.getString(
+ "CactusLaunch.message.prepare.error"),
+ e.getMessage(),
+ e.getStatus());
+ }
}
}
-
+
+ /**
+ * Prepares the Cactus test launch.
+ * @param theJavaProject the project that the Cactus tests are run from
+ * @param theProvider the provider to be prepared for the tests
+ */
+ private void prepare(
+ final IJavaProject theJavaProject,
+ final IContainerProvider theProvider)
+ {
+ final IRunnableWithProgress runnable = new IRunnableWithProgress()
+ {
+ public void run(IProgressMonitor thePM) throws InterruptedException
+ {
+ try
+ {
+ CactusPlugin.log("Preparing cactus tests");
+ prepareCactusTests(theJavaProject, thePM, theProvider);
+ }
+ catch (CoreException e)
+ {
+ throw new InterruptedException(e.getMessage());
+ }
+ }
+ };
+ Display.getDefault().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ ProgressMonitorDialog dialog =
+ new ProgressMonitorDialog(getShell());
+ dialog.run(true, true, runnable);
+ }
+ catch (InvocationTargetException e)
+ {
+ CactusPlugin.displayErrorMessage(
+ CactusMessages.getString(
+ "CactusLaunch.message.prepare.error"),
+ e.getTargetException().getMessage(),
+ null);
+ cancelPreparation(theProvider);
+ return;
+ }
+ catch (InterruptedException e)
+ {
+ CactusPlugin.displayErrorMessage(
+ CactusMessages.getString(
+ "CactusLaunch.message.prepare.error"),
+ e.getMessage(),
+ null);
+ cancelPreparation(theProvider);
+ return;
+ }
+ }
+ });
+ }
/**
* Launches the Junit tests.
*/
@@ -256,7 +286,8 @@
}
/**
- * Returns the provider associated with this CactusLaunchShortcut instance.
+ * Returns the provider associated with this CactusLaunchShortcut instance,
+ * or null if there is none (i.e. Jelly).
* @return the provider associated with this instance
*/
public IContainerProvider getContainerProvider()
@@ -266,8 +297,9 @@
/**
* Launches a new progress dialog for preparation cancellation.
+ * @param theProvider the provider which preparation to cancel
*/
- private void cancelPreparation()
+ private void cancelPreparation(final IContainerProvider theProvider)
{
ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
IRunnableWithProgress tearDownRunnable = new IRunnableWithProgress()
@@ -276,7 +308,7 @@
{
try
{
- teardownCactusTests(thePM);
+ teardownCactusTests(thePM, theProvider);
}
catch (CoreException e)
{
@@ -308,18 +340,18 @@
* creates the war file, deploys and launches the container.
* @param theJavaProject the Java file
* @param thePM the progress monitor to report to
+ * @param theProvider the provider to prepare
* @throws CoreException if anything goes wrong during preparation
*/
private void prepareCactusTests(
IJavaProject theJavaProject,
- IProgressMonitor thePM)
+ IProgressMonitor thePM,
+ IContainerProvider theProvider)
throws CoreException
{
thePM.beginTask(
CactusMessages.getString("CactusLaunch.message.prepare"),
10);
- IContainerManager manager = CactusPlugin.getContainerManager();
- this.provider = manager.getContainerProviders()[0];
try
{
WarBuilder newWar = new WarBuilder(theJavaProject);
@@ -332,8 +364,8 @@
"CactusLaunch.message.invalidproperty.contextpath",
null);
}
- this.provider.deploy(contextURLPath, warURL, null, thePM);
- this.provider.start(null, thePM);
+ theProvider.deploy(contextURLPath, warURL, null, thePM);
+ theProvider.start(null, thePM);
}
catch (MalformedURLException e)
{
@@ -349,20 +381,20 @@
* Stops the container and undeploys (cleans) it.
* @param thePM a progress monitor that reflects progress made while tearing
* down the container setup
+ * @param theProvider the provider of the container to stop and undeploy
* @throws CoreException if an error occurs when tearing down
*/
- private void teardownCactusTests(IProgressMonitor thePM)
+ private void teardownCactusTests(
+ IProgressMonitor thePM,
+ IContainerProvider theProvider)
throws CoreException
{
thePM.beginTask(
CactusMessages.getString("CactusLaunch.message.teardown"),
100);
- if (this.provider != null)
- {
- this.provider.stop(null, thePM);
- this.provider.undeploy(null, null, thePM);
- this.war.delete();
- }
+ theProvider.stop(null, thePM);
+ theProvider.undeploy(null, null, thePM);
+ this.war.delete();
thePM.done();
}
@@ -386,6 +418,19 @@
return;
}
CactusPlugin.log("Test run ended");
+ if (getContainerProvider() != null)
+ {
+ teardown(getContainerProvider());
+ }
+ this.launchEnded = true;
+ }
+
+ /**
+ * Tears down the Cactus tests
+ * @param theProvider the container provider to tear down
+ */
+ private void teardown(final IContainerProvider theProvider)
+ {
final IRunnableWithProgress runnable = new IRunnableWithProgress()
{
public void run(IProgressMonitor thePM) throws InterruptedException
@@ -393,7 +438,7 @@
CactusPlugin.log("Tearing down cactus tests");
try
{
- teardownCactusTests(thePM);
+ teardownCactusTests(thePM, theProvider);
}
catch (CoreException e)
{
@@ -418,7 +463,7 @@
"CactusLaunch.message.teardown.error"),
e.getTargetException().getMessage(),
null);
- cancelPreparation();
+ cancelPreparation(theProvider);
return;
}
catch (InterruptedException e)
@@ -428,7 +473,7 @@
"CactusLaunch.message.teardown.error"),
e.getMessage(),
null);
- cancelPreparation();
+ cancelPreparation(theProvider);
return;
}
finally
@@ -438,7 +483,6 @@
}
});
- this.launchEnded = true;
}
/**
1.3 +158 -8 jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/launcher/CactusLaunchConfiguration.java
Index: CactusLaunchConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/integration/eclipse/org.apache.cactus.eclipse.runner/src/java/org/apache/cactus/eclipse/runner/launcher/CactusLaunchConfiguration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CactusLaunchConfiguration.java 17 Mar 2003 10:32:43 -0000 1.2
+++ CactusLaunchConfiguration.java 27 Mar 2003 14:54:42 -0000 1.3
@@ -56,9 +56,23 @@
*/
package org.apache.cactus.eclipse.runner.launcher;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Vector;
+
+import org.apache.cactus.eclipse.runner.common.JarFilenameFilter;
import org.apache.cactus.eclipse.runner.ui.CactusPlugin;
import org.apache.cactus.eclipse.runner.ui.CactusPreferences;
+import org.apache.cactus.eclipse.webapp.Webapp;
+import org.apache.cactus.eclipse.webapp.ui.WebappPlugin;
+import org.eclipse.ant.core.AntCorePlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.ILibrary;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfiguration;
@@ -83,7 +97,11 @@
*/
public static final String ID_CACTUS_APPLICATION =
"org.apache.cactus.eclipse.runner.launchconfig";
-
+ /**
+ * Path to the Jetty library directory in the Cactus plugin
+ * structure
+ */
+ private static final String JETTY_LIBRARY_PATH = "./lib/";
/**
* Returns a valid VM configuration for Cactus. This method overrides
* the JUnit plugin one in order to add Cactus required VM parameters.
@@ -105,14 +123,92 @@
CactusPlugin.log("creating VMRunnerConfiguration for Cactus");
VMRunnerConfiguration configuration =
super.launchTypes(theConfiguration, theMode, theTests, thePort);
-
- String[] cactusVMArgs =
- {"-Dcactus.contextURL=" + CactusPreferences.getContextURL()};
String[] jUnitArgs = configuration.getVMArguments();
- String[] globalArgs = concatenateStringArrays(jUnitArgs, cactusVMArgs);
+ String[] cactusVMArgs = getCactusVMArgs(theTests);
+ String[] globalArgs =
+ concatenateStringArrays(
+ jUnitArgs,
+ cactusVMArgs);
configuration.setVMArguments(globalArgs);
- CactusPlugin.log("Cactus VM arguments : [" + cactusVMArgs[0] + "]");
- return configuration;
+ CactusPlugin.log("Cactus VM arguments : [" + cactusVMArgs + "]");
+
+ String[] junitClasspath = configuration.getClassPath();
+ String[] cactusJarPaths = getCactusJarPaths();
+ String[] globalClasspath =
+ concatenateStringArrays(
+ junitClasspath,
+ cactusJarPaths);
+ VMRunnerConfiguration cactusConfig =
+ new VMRunnerConfiguration(
+ configuration.getClassToLaunch(),
+ globalClasspath);
+ String cactusClasspathRepresentation = "";
+ for (int i = 0; i < cactusJarPaths.length; i++)
+ {
+ cactusClasspathRepresentation += cactusJarPaths[i] + ";";
+ }
+ CactusPlugin.log(
+ "Cactus VM classpath : [" + cactusClasspathRepresentation + "]");
+
+ cactusConfig.setBootClassPath(configuration.getBootClassPath());
+ cactusConfig.setProgramArguments(configuration.getProgramArguments());
+ cactusConfig.setVMArguments(configuration.getVMArguments());
+ cactusConfig.setWorkingDirectory(configuration.getWorkingDirectory());
+ return cactusConfig;
+ }
+
+ /**
+ * @return an array of Jar paths needed for Cactus
+ */
+ private String[] getCactusJarPaths()
+ {
+ CactusPlugin thePlugin = CactusPlugin.getDefault();
+ URL libURL = thePlugin.find(new Path(JETTY_LIBRARY_PATH));
+ File libDir = new File(libURL.getPath());
+ String[] jettyJarPaths = getJarPaths(libDir);
+ URL[] antURLs =
+ AntCorePlugin.getPlugin().getPreferences().getAntURLs();
+ String[] apacheJarPaths = getJarPaths(antURLs);
+ Plugin xercesPlugin = Platform.getPlugin("org.apache.xerces");
+ if (xercesPlugin != null)
+ {
+ IPluginDescriptor descriptor = xercesPlugin.getDescriptor();
+ apacheJarPaths =
+ concatenateStringArrays(
+ apacheJarPaths,
+ getLibrariesPaths(descriptor));
+ }
+ return concatenateStringArrays(jettyJarPaths, apacheJarPaths);
+ }
+
+ /**
+ * @param theTests the types to get the arguments for
+ * @return an array of the specific Cactus VM arguments
+ */
+ private String[] getCactusVMArgs(IType[] theTests)
+ {
+ Vector cactusVMArgs = new Vector();
+ cactusVMArgs.add(
+ "-Dcactus.contextURL=" + CactusPreferences.getContextURL());
+ if (CactusPreferences.getJetty())
+ {
+ if (theTests.length > 0)
+ {
+ Webapp webapp =
+ WebappPlugin.getWebapp(theTests[0].getJavaProject());
+ webapp.init();
+ File webappDir = webapp.getAbsoluteDir();
+ if (webappDir != null && webappDir.exists())
+ {
+ cactusVMArgs.add(
+ "-Dcactus.jetty.resourceDir=" + webappDir.getPath());
+ }
+ }
+ cactusVMArgs.add(
+ "-Dcactus.initializer="
+ + "org.apache.cactus.extension.jetty.JettyInitializer");
+ }
+ return (String[]) cactusVMArgs.toArray(new String[cactusVMArgs.size()]);
}
/**
@@ -133,4 +229,58 @@
return newArray;
}
+ /**
+ * @param theDirectory the directory to list jars from
+ * @return the array of jar paths in the given directory
+ */
+ private String[] getJarPaths(File theDirectory)
+ {
+ File[] jars = theDirectory.listFiles(new JarFilenameFilter());
+ String[] jarPaths = new String[jars.length];
+ for (int i = 0; i < jarPaths.length; i++)
+ {
+ jarPaths[i] = jars[i].getAbsolutePath();
+ }
+ return jarPaths;
+ }
+
+ /**
+ * @param theAntURLs array of URLs to convert to Jar paths
+ * @return the array of jar paths from the given URLs
+ */
+ private String[] getJarPaths(URL[] theAntURLs)
+ {
+ String[] jarPaths = new String[theAntURLs.length];
+ for (int i = 0; i < theAntURLs.length; i++)
+ {
+ jarPaths[i] = theAntURLs[i].getFile();
+ }
+ return jarPaths;
+ }
+
+ /**
+ * @param theDescriptor the plug-in descriptor to get libraries from
+ * @return an array of jar paths exposed by the plug-in
+ */
+ private String[] getLibrariesPaths(IPluginDescriptor theDescriptor)
+ {
+ Vector result = new Vector();
+ URL root = theDescriptor.getInstallURL();
+ ILibrary[] libraries = theDescriptor.getRuntimeLibraries();
+ for (int i = 0; i < libraries.length; i++)
+ {
+ try
+ {
+ URL url = new URL(root, libraries[i].getPath().toString());
+ result.add(Platform.asLocalURL(url).getFile());
+ }
+ catch (IOException e)
+ {
+ // if the URL is not valid we don't add it
+ CactusPlugin.log(e);
+ continue;
+ }
+ }
+ return (String[]) result.toArray(new String[result.size()]);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org