Author: adietish
Date: 2011-06-28 10:57:26 -0400 (Tue, 28 Jun 2011)
New Revision: 32408
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSELaunchDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEUtils.java
Log:
[JBIDE-9054] created RSEUtils#checkedGetServerHome and refactored code in
RSELaunchDelegate accordingly
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSELaunchDelegate.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSELaunchDelegate.java 2011-06-28
14:53:38 UTC (rev 32407)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSELaunchDelegate.java 2011-06-28
14:57:26 UTC (rev 32408)
@@ -174,14 +174,8 @@
}
public static String getDefaultStopCommand(IServer server, boolean errorOnFail) throws
CoreException {
- String rseHome = server.getAttribute(RSEUtils.RSE_SERVER_HOME_DIR, (String)null);
- if( errorOnFail && rseHome == null ) {
- IStatus s = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID,
- "Remote Server Home not set.");
- throw new CoreException(s);
- }
- rseHome = rseHome == null ? "" : rseHome;
-
+ String rseHome = null;
+ rseHome = getServerHome(server, errorOnFail);
JBossServer jbs = ServerConverter.getJBossServer(server);
String stop = new Path(rseHome)
@@ -193,6 +187,16 @@
stop += StopLaunchConfiguration.getDefaultArgs(jbs);
return stop;
}
+
+ private static String getServerHome(IServer server, boolean errorOnFail) throws
CoreException {
+ String rseHome = null;
+ if (errorOnFail) {
+ rseHome = RSEUtils.checkedGetRSEHomeDir(server);
+ } else {
+ rseHome = RSEUtils.getRSEHomeDir(server);
+ }
+ return rseHome == null ? "" : rseHome;
+ }
public static IServer findServer(ILaunchConfiguration config) throws CoreException {
String serverId = config.getAttribute("server-id", (String)null);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEUtils.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEUtils.java 2011-06-28
14:53:38 UTC (rev 32407)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEUtils.java 2011-06-28
14:57:26 UTC (rev 32408)
@@ -7,7 +7,7 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.rse.core;
import org.eclipse.core.runtime.CoreException;
@@ -29,62 +29,74 @@
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.core.util.RuntimeUtils;
-
/*
* Some of this code will need to be abstracted out from JBossServer
* and turned into a proper API, but in as simple a way as possible
*/
public class RSEUtils {
- public static final String RSE_SERVER_CONFIG =
"org.jboss.ide.eclipse.as.rse.core.RSEServerConfig"; //$NON-NLS-1$
- public static final String RSE_SERVER_HOME_DIR =
"org.jboss.ide.eclipse.as.rse.core.RSEServerHomeDir"; //$NON-NLS-1$
- public static final String RSE_SERVER_HOST =
"org.jboss.ide.eclipse.as.rse.core.ServerHost"; //$NON-NLS-1$
- public static final String RSE_SERVER_DEFAULT_HOST = "Local"; //$NON-NLS-1$
+ public static final String RSE_SERVER_CONFIG =
"org.jboss.ide.eclipse.as.rse.core.RSEServerConfig"; //$NON-NLS-1$
+ public static final String RSE_SERVER_HOME_DIR =
"org.jboss.ide.eclipse.as.rse.core.RSEServerHomeDir"; //$NON-NLS-1$
+ public static final String RSE_SERVER_HOST =
"org.jboss.ide.eclipse.as.rse.core.ServerHost"; //$NON-NLS-1$
+ public static final String RSE_SERVER_DEFAULT_HOST = "Local"; //$NON-NLS-1$
public static final String RSE_MODE = "rse";
-
+
public static String getRSEConnectionName(IServer server) {
return server.getAttribute(RSEUtils.RSE_SERVER_HOST, RSE_SERVER_DEFAULT_HOST);
}
-
+
public static String getRSEHomeDir(IServerAttributes server) {
return server.getAttribute(RSEUtils.RSE_SERVER_HOME_DIR,
server.getRuntime().getLocation().toString());
}
-
+
+ public static String checkedGetRSEHomeDir(IServerAttributes server) throws CoreException
{
+ String serverHome = server.getAttribute(RSEUtils.RSE_SERVER_HOME_DIR,
server.getRuntime().getLocation()
+ .toString());
+ if (serverHome == null) {
+ throw new CoreException(new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID,
+ "Remote Server Home not set."));
+ }
+ return serverHome;
+ }
+
public static String getRSEConfigName(IServerAttributes server) {
IJBossServerRuntime runtime = RuntimeUtils.getJBossServerRuntime(server);
return server.getAttribute(RSEUtils.RSE_SERVER_CONFIG,
runtime.getJBossConfiguration());
}
-
+
public static String getDeployRootFolder(IDeployableServer server) {
return getDeployRootFolder(server.getServer(), server.getDeployLocationType());
}
-
+
/* Copied from JBossServer.getDeployFolder(etc) */
public static String getDeployRootFolder(IServer server, String type) {
- if( JBossServer.DEPLOY_CUSTOM.equals(type)) {
- String val = server.getAttribute(JBossServer.DEPLOY_DIRECTORY, (String)null);
- if( val != null ) {
+ if (JBossServer.DEPLOY_CUSTOM.equals(type)) {
+ String val = server.getAttribute(JBossServer.DEPLOY_DIRECTORY, (String) null);
+ if (val != null) {
IPath val2 = new Path(val);
return makeGlobal(server, val2).toString();
}
// if no value is set, default to metadata
type = JBossServer.DEPLOY_SERVER;
}
- // This should *NOT* happen, so if it does, we will default to server location
- else if( JBossServer.DEPLOY_METADATA.equals(type)) {
+ // This should *NOT* happen, so if it does, we will default to server
+ // location
+ else if (JBossServer.DEPLOY_METADATA.equals(type)) {
type = JBossServer.DEPLOY_SERVER;
- }
- else if(JBossServer.DEPLOY_SERVER.equals(type)) {
- // TODO !!!! Need API (nmaybe in JBossServer?) so servers can override this behavior
- // Cannot move this code to JBossServer because this requires an RSE-specific key!!
Damn!
-
- if( server.getServerType().getId().equals(IJBossToolingConstants.SERVER_AS_70)) {
+ }
+ else if (JBossServer.DEPLOY_SERVER.equals(type)) {
+ // TODO !!!! Need API (nmaybe in JBossServer?) so servers can
+ // override this behavior
+ // Cannot move this code to JBossServer because this requires an
+ // RSE-specific key!! Damn!
+
+ if (server.getServerType().getId().equals(IJBossToolingConstants.SERVER_AS_70)) {
IPath p = new Path("standalone/deployments/");
return makeGlobal(server, p).toString();
} else {
String loc = IConstants.SERVER;
String config = getRSEConfigName(server);
IPath p = new Path(loc).append(config)
- .append(IJBossRuntimeResourceConstants.DEPLOY);
+ .append(IJBossRuntimeResourceConstants.DEPLOY);
return makeGlobal(server, p).toString();
}
}
@@ -92,17 +104,17 @@
}
public static IPath makeRelative(IServer server, IPath p) {
- if( p.isAbsolute()) {
- if(new Path(getRSEHomeDir(server)).isPrefixOf(p)) {
+ if (p.isAbsolute()) {
+ if (new Path(getRSEHomeDir(server)).isPrefixOf(p)) {
int size = new Path(getRSEHomeDir(server)).toOSString().length();
return new Path(p.toOSString().substring(size)).makeRelative();
}
}
return p;
}
-
+
public static IPath makeGlobal(IServer server, IPath p) {
- if( !p.isAbsolute()) {
+ if (!p.isAbsolute()) {
return new Path(getRSEHomeDir(server)).append(p).makeAbsolute();
}
return p;
@@ -111,22 +123,23 @@
public static IHost findHost(String connectionName) {
// TODO ensure that all hosts are actually loaded, christ
IHost[] allHosts = RSECorePlugin.getTheSystemRegistry().getHosts();
- for( int i = 0; i < allHosts.length; i++ ) {
- if( allHosts[i].getAliasName().equals(connectionName))
+ for (int i = 0; i < allHosts.length; i++) {
+ if (allHosts[i].getAliasName().equals(connectionName))
return allHosts[i];
}
return null;
}
-
+
public static void waitForFullInit() throws CoreException {
try {
RSECorePlugin.waitForInitCompletion();
} catch (InterruptedException e) {
- throw new CoreException(new Status(IStatus.ERROR,
org.jboss.ide.eclipse.as.rse.core.RSECorePlugin.PLUGIN_ID,
- "The RSE model initialization has been interrupted."));
+ throw new CoreException(new Status(IStatus.ERROR,
+ org.jboss.ide.eclipse.as.rse.core.RSECorePlugin.PLUGIN_ID,
+ "The RSE model initialization has been interrupted."));
}
}
-
+
public static IServer setServerToRSEMode(IServer server, IHost newHost) throws
CoreException {
IServerWorkingCopy wc = server.createWorkingCopy();
wc.setAttribute(IDeployableServer.SERVER_MODE, RSE_MODE);
@@ -134,8 +147,8 @@
wc.setAttribute("hostname", newHost.getHostName());
return wc.save(false, new NullProgressMonitor());
}
-
- public static IServer setServerToRSEMode(IServer server, IHost newHost,
+
+ public static IServer setServerToRSEMode(IServer server, IHost newHost,
String jbossHome, String config) throws CoreException {
IServerWorkingCopy wc = server.createWorkingCopy();
wc.setAttribute(IDeployableServer.SERVER_MODE, RSE_MODE);
@@ -143,11 +156,9 @@
wc.setAttribute(RSE_SERVER_HOME_DIR, jbossHome);
wc.setAttribute(RSE_SERVER_HOST, newHost.getAliasName());
wc.setAttribute("hostname", newHost.getHostName());
- wc.setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE,
+ wc.setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE,
IDeployableServer.DEPLOY_SERVER);
return wc.save(false, new NullProgressMonitor());
}
-
-
}