Author: rob.stryker(a)jboss.com
Date: 2010-11-24 02:18:49 -0500 (Wed, 24 Nov 2010)
New Revision: 26867
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/jdt/
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/jdt/JREUtils.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/StartupShutdownTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java
Log:
JBIDE-7725 - as test suite cleanup
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java 2010-11-24
00:56:43 UTC (rev 26866)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java 2010-11-24
07:18:49 UTC (rev 26867)
@@ -105,13 +105,10 @@
* @return
*/
protected IPath getDeployPath(IModule[] moduleTree, IDeployableServer server) {
- String defaultFolder = publishMethod.getPublishDefaultRootFolder(server.getServer());
- String folder = PublishUtil.getDeployRootFolder(
- moduleTree, server, defaultFolder,
- IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC);
- return PublishUtil.getDeployPath(moduleTree, folder);
+ return PublishUtil.getDeployPath(publishMethod, moduleTree, server);
}
+
/**
* Finish up the publishing. This may be moving a final zipped entity into the proper
* folder or sending it over the wire to a remote machine.
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java 2010-11-24
00:56:43 UTC (rev 26866)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java 2010-11-24
07:18:49 UTC (rev 26867)
@@ -37,6 +37,7 @@
import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
import org.jboss.ide.eclipse.as.core.server.xpl.ModulePackager;
import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
import
org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentModulePrefs;
@@ -191,7 +192,14 @@
return ModuleCoreNature.isFlexibleProject(lastmod.getProject());
}
-
+ public static IPath getDeployPath(IJBossServerPublishMethod method, IModule[]
moduleTree, IDeployableServer server) {
+ String defaultFolder = method.getPublishDefaultRootFolder(server.getServer());
+ String folder = PublishUtil.getDeployRootFolder(
+ moduleTree, server, defaultFolder,
+ IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC);
+ return PublishUtil.getDeployPath(moduleTree, folder);
+ }
+
private static String getSuffix(String type) {
// TODO
// VirtualReferenceUtilities.INSTANCE. has utility methods to help!!
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTest.java 2010-11-24
00:56:43 UTC (rev 26866)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTest.java 2010-11-24
07:18:49 UTC (rev 26867)
@@ -83,6 +83,9 @@
public static final String JBOSS_AS_50_HOME =
System.getProperty("jbosstools.test.jboss.home.5.0",
"C:\\apps\\jboss\\jboss-5.0.0.GA\\");
public static final String JBOSS_AS_51_HOME =
System.getProperty("jbosstools.test.jboss.home.5.1",
"C:\\apps\\jboss\\jboss-5.1.0.GA\\");
public static final String JBOSS_AS_52_HOME =
System.getProperty("jbosstools.test.jboss.home.5.2",
"C:\\apps\\jboss\\jboss-5.2.0.GA\\");
+ public static final String JRE_14_HOME =
System.getProperty("jbosstools.test.jre.1.4",
"C:\\apps\\jboss\\jboss-5.2.0.GA\\");
+ public static final String JRE_5_HOME =
System.getProperty("jbosstools.test.jre.5",
"C:\\apps\\jboss\\jboss-5.2.0.GA\\");
+ public static final String JRE_6_HOME =
System.getProperty("jbosstools.test.jre.6",
"C:\\apps\\jboss\\jboss-5.2.0.GA\\");
public static final String JBOSS_AS_HOME =
System.getProperty("jbosstools.test.jboss.home", JBOSS_AS_42_HOME);
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/StartupShutdownTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/StartupShutdownTest.java 2010-11-24
00:56:43 UTC (rev 26866)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/StartupShutdownTest.java 2010-11-24
07:18:49 UTC (rev 26867)
@@ -21,26 +21,8 @@
*/
package org.jboss.ide.eclipse.as.test.server;
-import java.util.ArrayList;
-import java.util.Date;
-
-import junit.framework.AssertionFailedError;
-
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.core.IStreamListener;
-import org.eclipse.debug.core.model.IStreamMonitor;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.IServer.IOperationListener;
-import org.eclipse.wst.server.core.IServerListener;
-import org.eclipse.wst.server.core.ServerEvent;
-import
org.jboss.ide.eclipse.as.core.extensions.polling.ProcessTerminatedPoller.IProcessProvider;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
-import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
-import org.jboss.ide.eclipse.as.test.ASTest;
import org.jboss.ide.eclipse.as.test.util.ServerRuntimeUtils;
/**
@@ -53,217 +35,69 @@
*/
public class StartupShutdownTest extends ServerRuntimeUtils {
- public static final int DEFAULT_STARTUP_TIME = 150000;
- public static final int DEFAULT_SHUTDOWN_TIME = 90000;
protected IServer currentServer;
- protected ServerStateListener stateListener;
public void setUp() {
- try {
- if( getName().equals("test32"))
- currentServer = createServer(IJBossToolingConstants.AS_32,
IJBossToolingConstants.SERVER_AS_32, ASTest.JBOSS_AS_32_HOME, DEFAULT_CONFIG);
- else if( getName().equals("test40"))
- currentServer = createServer(IJBossToolingConstants.AS_40,
IJBossToolingConstants.SERVER_AS_40, ASTest.JBOSS_AS_40_HOME, DEFAULT_CONFIG);
- else if( getName().equals("test42"))
- currentServer = createServer(IJBossToolingConstants.AS_42,
IJBossToolingConstants.SERVER_AS_42, ASTest.JBOSS_AS_42_HOME, DEFAULT_CONFIG);
- else if( getName().equals("test50"))
- currentServer = createServer(IJBossToolingConstants.AS_50,
IJBossToolingConstants.SERVER_AS_50, ASTest.JBOSS_AS_50_HOME, DEFAULT_CONFIG);
- else if( getName().equals("test51"))
- currentServer = createServer(IJBossToolingConstants.AS_51,
IJBossToolingConstants.SERVER_AS_51, ASTest.JBOSS_AS_51_HOME, DEFAULT_CONFIG);
-
- // first thing's first. Let's add a server state listener
- stateListener = new ServerStateListener();
- currentServer.addServerListener(stateListener);
-
- } catch( CoreException ce ) {
- fail("Failed during setUp for " + getName() + ": " +
ce.getMessage());
- }
}
public void tearDown() {
- System.out.println("tearing down " + getName());
try {
- currentServer.removeServerListener(stateListener);
- currentServer.delete();
+ if( currentServer != null )
+ currentServer.delete();
} catch( CoreException ce ) {
// report
}
}
-
-
-
- public class StatusWrapper {
- protected IStatus status;
- public IStatus getStatus() { return this.status; }
- public void setStatus(IStatus s) { this.status = s; }
- }
-
public void test32() {
- startup();
- shutdown();
+ try {
+ currentServer = create32Server();
+ startup(currentServer);
+ shutdown(currentServer);
+ } catch( CoreException ce ) {
+ fail("Failed during setUp for " + getName() + ": " +
ce.getMessage());
+ }
}
-//
-// public void test40() {
-// startup();
-// shutdown();
-// }
-//
-// public void test42() {
-// startup();
-// shutdown();
-// }
-//
-// public void test50() {
-// startup();
-// shutdown();
-// }
-//
-// public void test51() {
-// startup();
-// shutdown();
-// }
-
- protected class ServerStateListener implements IServerListener {
- private ArrayList stateChanges;
- public ServerStateListener() {
- this.stateChanges = new ArrayList();
+
+ public void test40() {
+ try {
+ currentServer = create40Server();
+ startup(currentServer);
+ shutdown(currentServer);
+ } catch( CoreException ce ) {
+ fail("Failed during setUp for " + getName() + ": " +
ce.getMessage());
}
- public ArrayList getStateChanges() {
- return stateChanges;
- }
- public void serverChanged(ServerEvent event) {
- if((event.getKind() & ServerEvent.SERVER_CHANGE) != 0) {
- if((event.getKind() & ServerEvent.STATE_CHANGE) != 0) {
- if( event.getState() != IServer.STATE_STOPPED)
- stateChanges.add(new Integer(event.getState()));
- }
- }
- }
}
- protected class ErrorStreamListener implements IStreamListener {
- protected boolean errorFound = false;
- String entireLog = "";
- public void streamAppended(String text, IStreamMonitor monitor) {
- entireLog += text;
- }
-
- // will need to be fixed or decided how to figure out errors
- public boolean hasError() {
- return errorFound;
+ public void test42() {
+ try {
+ currentServer = create42Server();
+ startup(currentServer);
+ shutdown(currentServer);
+ } catch( CoreException ce ) {
+ fail("Failed during setUp for " + getName() + ": " +
ce.getMessage());
}
}
- protected void startup() { startup(DEFAULT_STARTUP_TIME); }
- protected void startup(int maxWait) {
- long finishTime = new Date().getTime() + maxWait;
-
- // operation listener, which is only alerted when the startup is *done*
- final StatusWrapper opWrapper = new StatusWrapper();
- final IOperationListener listener = new IOperationListener() {
- public void done(IStatus result) {
- opWrapper.setStatus(result);
- } };
-
-
- // a stream listener to listen for errors
- ErrorStreamListener streamListener = new ErrorStreamListener();
-
- // the thread to actually start the server
- Thread startThread = new Thread() {
- public void run() {
- currentServer.start(ILaunchManager.RUN_MODE, listener);
- }
- };
-
- startThread.start();
-
- boolean addedStream = false;
- while( finishTime > new Date().getTime() && opWrapper.getStatus() == null)
{
- // we're waiting for startup to finish
- if( !addedStream ) {
- IStreamMonitor mon = getStreamMonitor();
- if( mon != null ) {
- mon.addListener(streamListener);
- addedStream = true;
- }
- }
- try {
- Display.getDefault().readAndDispatch();
- } catch( SWTException swte ) {}
- }
-
+ public void test50() {
try {
- assertTrue("Startup has taken longer than what is expected for a default
startup", finishTime >= new Date().getTime());
- assertNotNull("Startup never finished", opWrapper.getStatus());
- assertFalse("Startup failed", opWrapper.getStatus().getSeverity() ==
IStatus.ERROR);
- assertFalse("Startup had System.error output", streamListener.hasError());
- } catch( AssertionFailedError afe ) {
- // cleanup
- currentServer.stop(true);
- // rethrow
- throw afe;
+ currentServer = create50Server();
+ startup(currentServer);
+ shutdown(currentServer);
+ } catch( CoreException ce ) {
+ fail("Failed during setUp for " + getName() + ": " +
ce.getMessage());
}
- if( getStreamMonitor() != null )
- getStreamMonitor().removeListener(streamListener);
}
-
- protected void shutdown() { shutdown(DEFAULT_SHUTDOWN_TIME); }
- protected void shutdown(int maxWait) {
- long finishTime = new Date().getTime() + maxWait;
-
- // operation listener, which is only alerted when the startup is *done*
- final StatusWrapper opWrapper = new StatusWrapper();
- final IOperationListener listener = new IOperationListener() {
- public void done(IStatus result) {
- opWrapper.setStatus(result);
- } };
-
-
- // a stream listener to listen for errors
- ErrorStreamListener streamListener = new ErrorStreamListener();
- if( getStreamMonitor() != null )
- getStreamMonitor().addListener(streamListener);
-
- // the thread to actually start the server
- Thread stopThread = new Thread() {
- public void run() {
- currentServer.stop(false, listener);
- }
- };
-
- stopThread.start();
-
- while( finishTime > new Date().getTime() && opWrapper.getStatus() == null)
{
- // we're waiting for startup to finish
- try {
- Display.getDefault().readAndDispatch();
- } catch( SWTException swte ) {}
- }
-
+ public void test51() {
try {
- assertTrue("Startup has taken longer than what is expected for a default
startup", finishTime >= new Date().getTime());
- assertNotNull("Startup never finished", opWrapper.getStatus());
- assertFalse("Startup had System.error output", streamListener.hasError());
- } catch( AssertionFailedError afe ) {
- // cleanup
- currentServer.stop(true);
- // rethrow
- throw afe;
+ currentServer = create51Server();
+ startup(currentServer);
+ shutdown(currentServer);
+ } catch( CoreException ce ) {
+ fail("Failed during setUp for " + getName() + ": " +
ce.getMessage());
}
}
-
- protected IStreamMonitor getStreamMonitor() {
- JBossServerBehavior behavior =
- (JBossServerBehavior)currentServer.loadAdapter(JBossServerBehavior.class, null);
- if( behavior != null ) {
- if( ((IProcessProvider)behavior.getDelegate()).getProcess() != null ) {
- return
((IProcessProvider)behavior.getDelegate()).getProcess().getStreamsProxy().getOutputStreamMonitor();
- }
- }
- return null;
- }
+
}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java 2010-11-24
00:56:43 UTC (rev 26866)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java 2010-11-24
07:18:49 UTC (rev 26867)
@@ -3,8 +3,10 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.Date;
import java.util.HashMap;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.eclipse.core.runtime.CoreException;
@@ -15,22 +17,31 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.IStreamListener;
+import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IRuntimeType;
import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServer.IOperationListener;
import org.eclipse.wst.server.core.IServerType;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.core.ServerUtil;
import org.eclipse.wst.server.core.internal.RuntimeWorkingCopy;
import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
+import
org.jboss.ide.eclipse.as.core.extensions.polling.ProcessTerminatedPoller.IProcessProvider;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServer;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.core.util.FileUtil;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
@@ -104,7 +115,6 @@
return server;
}
-
public static IServer createMockServerWithRuntime(String serverType, String name, String
config) {
try {
IPath serverDir = createMockServerDirectory(name, twiddleMap.get(serverType),
config);
@@ -114,13 +124,39 @@
return null;
}
+ public static IServer create32Server() throws CoreException {
+ return createServer(IJBossToolingConstants.AS_32, IJBossToolingConstants.SERVER_AS_32,
ASTest.JBOSS_AS_32_HOME, DEFAULT_CONFIG);
+ }
+ public static IServer create40Server() throws CoreException {
+ return createServer(IJBossToolingConstants.AS_40, IJBossToolingConstants.SERVER_AS_40,
ASTest.JBOSS_AS_40_HOME, DEFAULT_CONFIG);
+ }
+ public static IServer create42Server() throws CoreException {
+ return createServer(IJBossToolingConstants.AS_42, IJBossToolingConstants.SERVER_AS_42,
ASTest.JBOSS_AS_42_HOME, DEFAULT_CONFIG);
+ }
+ public static IServer create50Server() throws CoreException {
+ return createServer(IJBossToolingConstants.AS_50, IJBossToolingConstants.SERVER_AS_50,
ASTest.JBOSS_AS_50_HOME, DEFAULT_CONFIG);
+ }
+
+ public static IServer create51Server() throws CoreException {
+ return createServer(IJBossToolingConstants.AS_51, IJBossToolingConstants.SERVER_AS_51,
ASTest.JBOSS_AS_51_HOME, DEFAULT_CONFIG);
+ }
+
+// public static IServer create60Server() throws CoreException {
+// }
+
public static IServer createServer(String runtimeID, String serverID,
String location, String configuration) throws CoreException {
- // if file doesnt exist, abort immediately.
- assertTrue("path \"" + location + "\" does not exist",
new Path(location).toFile().exists());
-
+ IRuntime currentRuntime = createRuntime(runtimeID, location,configuration);
+ return createServer2(currentRuntime, serverID);
+ }
+ public static IServer createServer(String runtimeID, String serverID,
+ String location, String configuration, IVMInstall install) throws CoreException {
IRuntime currentRuntime = createRuntime(runtimeID, location,
- configuration);
+ configuration, install);
+ return createServer2(currentRuntime, serverID);
+ }
+
+ private static IServer createServer2(IRuntime currentRuntime, String serverID) throws
CoreException {
IServerType serverType = ServerCore.findServerType(serverID);
IServerWorkingCopy serverWC = serverType.createServer(null, null,
new NullProgressMonitor());
@@ -129,11 +165,17 @@
serverWC.setServerConfiguration(null);
return serverWC.save(true, new NullProgressMonitor());
}
+
public static IRuntime createRuntime(String runtimeId, String homeDir,
String config) throws CoreException {
- IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(null, null,
- runtimeId);
+ return createRuntime(runtimeId, homeDir, config, VM_INSTALL);
+ }
+
+ public static IRuntime createRuntime(String runtimeId, String homeDir,
+ String config, IVMInstall install) throws CoreException {
+ assertTrue("path \"" + homeDir + "\" does not exist", new
Path(homeDir).toFile().exists());
+ IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(null, null,runtimeId);
assertEquals("expects only one runtime type", runtimeTypes.length, 1);
IRuntimeType runtimeType = runtimeTypes[0];
IRuntimeWorkingCopy runtimeWC = runtimeType.createRuntime(null,
@@ -141,9 +183,9 @@
runtimeWC.setName(runtimeId);
runtimeWC.setLocation(new Path(homeDir));
((RuntimeWorkingCopy) runtimeWC).setAttribute(
- IJBossServerRuntime.PROPERTY_VM_ID, VM_INSTALL.getId());
+ IJBossServerRuntime.PROPERTY_VM_ID, install.getId());
((RuntimeWorkingCopy) runtimeWC).setAttribute(
- IJBossServerRuntime.PROPERTY_VM_TYPE_ID, VM_INSTALL
+ IJBossServerRuntime.PROPERTY_VM_TYPE_ID, install
.getVMInstallType().getId());
((RuntimeWorkingCopy) runtimeWC).setAttribute(
IJBossServerRuntime.PROPERTY_CONFIGURATION_NAME, config);
@@ -151,7 +193,26 @@
IRuntime savedRuntime = runtimeWC.save(true, new NullProgressMonitor());
return savedRuntime;
}
-
+
+ public static IRuntime createRuntime(String runtimeId, String homeDir,
+ String config, IExecutionEnvironment environment) throws CoreException {
+ assertTrue("path \"" + homeDir + "\" does not exist", new
Path(homeDir).toFile().exists());
+ IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(null, null,runtimeId);
+ assertEquals("expects only one runtime type", runtimeTypes.length, 1);
+ IRuntimeType runtimeType = runtimeTypes[0];
+ IRuntimeWorkingCopy runtimeWC = runtimeType.createRuntime(null,
+ new NullProgressMonitor());
+ runtimeWC.setName(runtimeId);
+ runtimeWC.setLocation(new Path(homeDir));
+ ((RuntimeWorkingCopy) runtimeWC).setAttribute(
+ IJBossServerRuntime.PROPERTY_EXECUTION_ENVIRONMENT, environment.getId());
+ ((RuntimeWorkingCopy) runtimeWC).setAttribute(
+ IJBossServerRuntime.PROPERTY_CONFIGURATION_NAME, config);
+
+ IRuntime savedRuntime = runtimeWC.save(true, new NullProgressMonitor());
+ return savedRuntime;
+ }
+
public static void deleteAllServers() throws CoreException {
IServer[] servers = ServerCore.getServers();
for( int i = 0; i < servers.length; i++ ) {
@@ -246,5 +307,139 @@
return ServerRuntimeUtils.setServerAttribute(server,
IDeployableServer.ZIP_DEPLOYMENTS_PREF, val);
}
+ public static final int DEFAULT_STARTUP_TIME = 150000;
+ public static final int DEFAULT_SHUTDOWN_TIME = 90000;
+ public static void startup(IServer server) { startup(server, DEFAULT_STARTUP_TIME); }
+ public static void startup(final IServer currentServer, int maxWait) {
+ long finishTime = new Date().getTime() + maxWait;
+
+ // operation listener, which is only alerted when the startup is *done*
+ final StatusWrapper opWrapper = new StatusWrapper();
+ final IOperationListener listener = new IOperationListener() {
+ public void done(IStatus result) {
+ opWrapper.setStatus(result);
+ } };
+
+
+ // a stream listener to listen for errors
+ ErrorStreamListener streamListener = new ErrorStreamListener();
+
+ // the thread to actually start the server
+ Thread startThread = new Thread() {
+ public void run() {
+ currentServer.start(ILaunchManager.RUN_MODE, listener);
+ }
+ };
+
+ startThread.start();
+
+ boolean addedStream = false;
+ while( finishTime > new Date().getTime() && opWrapper.getStatus() == null)
{
+ // we're waiting for startup to finish
+ if( !addedStream ) {
+ IStreamMonitor mon = getStreamMonitor(currentServer);
+ if( mon != null ) {
+ mon.addListener(streamListener);
+ addedStream = true;
+ }
+ }
+ try {
+ Display.getDefault().readAndDispatch();
+ } catch( SWTException swte ) {}
+ }
+
+ try {
+ assertTrue("Startup has taken longer than what is expected for a default
startup", finishTime >= new Date().getTime());
+ assertNotNull("Startup never finished", opWrapper.getStatus());
+ assertFalse("Startup failed", opWrapper.getStatus().getSeverity() ==
IStatus.ERROR);
+ assertFalse("Startup had System.error output", streamListener.hasError());
+ } catch( AssertionFailedError afe ) {
+ // cleanup
+ currentServer.stop(true);
+ // rethrow
+ throw afe;
+ }
+ if( getStreamMonitor(currentServer) != null )
+ getStreamMonitor(currentServer).removeListener(streamListener);
+ }
+
+ public static void shutdown(IServer currentServer) { shutdown(currentServer,
DEFAULT_SHUTDOWN_TIME); }
+ public static void shutdown(final IServer currentServer, int maxWait) {
+ long finishTime = new Date().getTime() + maxWait;
+
+ // operation listener, which is only alerted when the startup is *done*
+ final StatusWrapper opWrapper = new StatusWrapper();
+ final IOperationListener listener = new IOperationListener() {
+ public void done(IStatus result) {
+ opWrapper.setStatus(result);
+ } };
+
+
+ // a stream listener to listen for errors
+ ErrorStreamListener streamListener = new ErrorStreamListener();
+ if( getStreamMonitor(currentServer) != null )
+ getStreamMonitor(currentServer).addListener(streamListener);
+
+ // the thread to actually start the server
+ Thread stopThread = new Thread() {
+ public void run() {
+ currentServer.stop(false, listener);
+ }
+ };
+
+ stopThread.start();
+
+ while( finishTime > new Date().getTime() && opWrapper.getStatus() == null)
{
+ // we're waiting for startup to finish
+ try {
+ Display.getDefault().readAndDispatch();
+ } catch( SWTException swte ) {}
+ }
+
+ try {
+ assertTrue("Startup has taken longer than what is expected for a default
startup", finishTime >= new Date().getTime());
+ assertNotNull("Startup never finished", opWrapper.getStatus());
+ assertFalse("Startup had System.error output", streamListener.hasError());
+ } catch( AssertionFailedError afe ) {
+ // cleanup
+ currentServer.stop(true);
+ // rethrow
+ throw afe;
+ }
+ }
+
+ protected static class ErrorStreamListener implements IStreamListener {
+ protected boolean errorFound = false;
+ String entireLog = "";
+ public void streamAppended(String text, IStreamMonitor monitor) {
+ entireLog += text;
+ }
+
+ // will need to be fixed or decided how to figure out errors
+ public boolean hasError() {
+ return errorFound;
+ }
+ }
+
+
+ protected static IStreamMonitor getStreamMonitor(IServer server) {
+ JBossServerBehavior behavior =
+ (JBossServerBehavior)server.loadAdapter(JBossServerBehavior.class, null);
+ if( behavior != null ) {
+ if( ((IProcessProvider)behavior.getDelegate()).getProcess() != null ) {
+ return
((IProcessProvider)behavior.getDelegate()).getProcess().getStreamsProxy().getOutputStreamMonitor();
+ }
+ }
+ return null;
+ }
+
+ public static class StatusWrapper {
+ protected IStatus status;
+ public IStatus getStatus() { return this.status; }
+ public void setStatus(IStatus s) { this.status = s; }
+ }
+
+
+
}
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/jdt/JREUtils.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/jdt/JREUtils.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/jdt/JREUtils.java 2010-11-24
07:18:49 UTC (rev 26867)
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.jboss.ide.eclipse.as.test.util.jdt;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.internal.launching.VMDefinitionsContainer;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.IVMInstallType;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.LibraryLocation;
+import org.eclipse.jdt.launching.VMStandin;
+import org.jboss.ide.eclipse.as.test.ASTest;
+
+/**
+ * Processes add/removed/changed VMs.
+ */
+public class JREUtils {
+
+ /**
+ * Contstructs a new VM updater to update VM install settings.
+ */
+ public JREUtils() {
+ }
+
+ public static IVMInstall createJRE() {
+ return createJRE(new Path(ASTest.JRE_5_HOME));
+ }
+
+ /*
+ * This method does *NOT* work and I can't figure out why ;)
+ */
+ public static void removeJRE(IVMInstall install) {
+ ArrayList<IVMInstall> vms = new ArrayList<IVMInstall>();
+ IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
+ for( int i = 0; i < types.length; i++ ) {
+ vms.addAll(Arrays.asList(types[i].getVMInstalls()));
+ }
+ vms.remove(install);
+ IVMInstall[] allInstalls = vms.toArray(new IVMInstall[vms.size()]);
+ updateJRESettings(allInstalls, JavaRuntime.getDefaultVMInstall());
+ }
+
+ public static int countJREs() {
+ int count = 0;
+ IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
+ for( int i = 0; i < types.length; i++ ) {
+ IVMInstall[] installs = types[i].getVMInstalls();
+ count+=installs.length;
+ }
+ return count;
+ }
+
+ public static IVMInstall createJRE(IPath jreBaseDir) {
+ IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
+ IVMInstallType t = null;
+ System.out.println(types.length);
+ for( int i = 0; i < types.length; i++ ) {
+ if(
types[i].getId().equals("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType"))
{
+ t = types[i];
+ }
+ }
+
+ String id = null;
+ do {
+ id = String.valueOf(System.currentTimeMillis());
+ } while (t.findVMInstall(id) != null);
+
+ VMStandin standin = new VMStandin(t, id);
+ standin.setInstallLocation(jreBaseDir.toFile());
+ standin.setName(jreBaseDir.lastSegment());
+ LibraryLocation[] libraryLocations = JavaRuntime.getLibraryLocations(standin);
+ standin.setLibraryLocations(libraryLocations);
+
+ return standin.convertToRealVM();
+ }
+
+
+
+ /**
+ * Updates VM settings and returns whether the update was successful.
+ *
+ * @param jres new installed JREs
+ * @param defaultJRE new default VM
+ * @return whether the update was successful
+ */
+ public static boolean updateJRESettings(IVMInstall[] jres, IVMInstall defaultJRE) {
+
+ // Create a VM definition container
+ VMDefinitionsContainer vmContainer = new VMDefinitionsContainer();
+
+ // Set the default VM Id on the container
+ String defaultVMId = JavaRuntime.getCompositeIdFromVM(defaultJRE);
+ vmContainer.setDefaultVMInstallCompositeID(defaultVMId);
+
+ // Set the VMs on the container
+ for (int i = 0; i < jres.length; i++) {
+ vmContainer.addVM(jres[i]);
+ }
+
+
+ // Generate XML for the VM defs and save it as the new value of the VM preference
+ saveVMDefinitions(vmContainer);
+
+ return true;
+ }
+
+ private static void saveVMDefinitions(final VMDefinitionsContainer container) {
+ try {
+ String vmDefXML = container.getAsXML();
+ JavaRuntime.getPreferences().setValue(JavaRuntime.PREF_VM_XML, vmDefXML);
+ JavaRuntime.savePreferences();
+ } catch( CoreException ce) {
+ }
+ }
+}