Author: rob.stryker(a)jboss.com
Date: 2011-01-06 17:12:24 -0500 (Thu, 06 Jan 2011)
New Revision: 27958
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/ConvertRSEToServerWizard.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java
Log:
JBIDE-7889 throw up an error and a new wizard if remote file is missing or does not have
all the required property keys
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/ConvertRSEToServerWizard.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/ConvertRSEToServerWizard.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/ConvertRSEToServerWizard.java 2011-01-06
22:12:24 UTC (rev 27958)
@@ -0,0 +1,35 @@
+package org.jboss.tools.deltacloud.integration.wizard;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.rse.core.model.IHost;
+import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+
+public class ConvertRSEToServerWizard extends Wizard {
+ private RSEandASWizardPage page1;
+ private DeltaCloudInstance instance;
+ private IHost host;
+
+ public ConvertRSEToServerWizard(DeltaCloudInstance instance) {
+ this.instance = instance;
+ }
+
+ public ConvertRSEToServerWizard(DeltaCloudInstance instance, IHost host) {
+ this(instance);
+ this.host = host;
+ }
+
+
+ @Override
+ public boolean performFinish() {
+ Job j = page1.getPerformFinishJob(instance);
+ if( j != null ) {
+ j.schedule();
+ }
+ return false;
+ }
+ public void addPages() {
+ page1 = new RSEandASWizardPage(host);
+ addPage(page1);
+ }
+}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java 2011-01-06
22:02:33 UTC (rev 27957)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java 2011-01-06
22:12:24 UTC (rev 27958)
@@ -27,11 +27,17 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IRuntimeType;
import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
@@ -43,22 +49,32 @@
import org.jboss.ide.eclipse.as.core.util.ServerCreationUtils;
import org.jboss.ide.eclipse.as.rse.core.RSEUtils;
import org.jboss.tools.common.jobs.ChainedJob;
+import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+import org.jboss.tools.deltacloud.integration.DeltaCloudIntegrationPlugin;
public class CreateServerFromRSEJob extends ChainedJob {
+ public static final String JBOSS_HOME_KEY = "JBOSS_HOME";
+ public static final String JBOSS_CONFIG_KEY = "JBOSS_CONFIG";
public static final String CREATE_DEPLOY_ONLY_SERVER =
"CREATE_DEPLOY_ONLY_SERVER";
public static final String CHECK_SERVER_FOR_DETAILS =
"CHECK_SERVER_FOR_DETAILS";
public static final String SET_DETAILS_NOW = "SET_DETAILS_NOW";
private String type;
- private String name;
private String[] data;
private IHost host;
+ private String imageId;
+ private DeltaCloudInstance instance;
- public CreateServerFromRSEJob(String type, String[] data, String name) {
+ public CreateServerFromRSEJob(String type, String[] data, DeltaCloudInstance instance)
{
+ this(type, data, instance.getImageId());
+ this.instance = instance;
+ }
+
+ public CreateServerFromRSEJob(String type, String[] data, String imageId) {
super("Create Server From RSE Host");
this.data = data;
this.type = type;
- this.name = name;
+ this.imageId = imageId;
}
public void setHost(IHost host) {
@@ -66,6 +82,7 @@
}
protected IStatus run(IProgressMonitor monitor) {
+ System.out.println(imageId);
try {
IServer result = null;
if( type.equals(CREATE_DEPLOY_ONLY_SERVER) ) {
@@ -81,7 +98,7 @@
return Status.OK_STATUS;
}
protected IServer createDeployOnlyServer() throws CoreException {
- IServer server = createDeployOnlyServerWithRuntime(data[0], data[0], name);
+ IServer server = createDeployOnlyServerWithRuntime(data[0], data[0], imageId);
server = RSEUtils.setServerToRSEMode(server, host);
return server;
}
@@ -106,11 +123,18 @@
}
}
- protected String loadRemoteFileData(IRemoteFileSubSystem system) {
- IPath p = new Path(data[0]);
+ protected String loadRemoteFileData(String path, IRemoteFileSubSystem system) throws
CoreException {
+ Throwable e;
+ IPath p = new Path(path);
IPath remoteParent = p.removeLastSegments(1);
String remoteFile = p.lastSegment();
try {
+ boolean exists = system.getRemoteFileObject(path, new
NullProgressMonitor()).exists();
+ if( !exists ) {
+ throw new CoreException(new Status(IStatus.ERROR,
DeltaCloudIntegrationPlugin.PLUGIN_ID,
+ "Remote file " + path + " does not exist."));
+ }
+
Writer writer = new StringWriter();
char[] buffer = new char[1024];
@@ -126,15 +150,22 @@
is.close();
}
} catch(SystemMessageException sme) {
- sme.getCause().printStackTrace();
+ e = sme;
} catch(IOException ioe) {
- ioe.printStackTrace();
+ e = ioe;
}
+ if( e.getCause() != null )
+ e = e.getCause();
+ if( e != null )
+ throw new CoreException(new Status(IStatus.ERROR,
DeltaCloudIntegrationPlugin.PLUGIN_ID,
+ e.getMessage() ));
return null;
}
protected Properties turnRemoteFileIntoProperties(String content) {
Properties p = new Properties();
+ if( content == null )
+ return p;
String[] byLine = content.split("\n");
String line, key, val;
int eqIn;
@@ -162,30 +193,78 @@
IRemoteFileSubSystem system = findRemoteFileSubSystem();
if( system != null ) {
verifySystemConnected(system);
- String contents = loadRemoteFileData(system);
+ String contents = null;
+ CoreException ce = null;
+ try {
+ contents = loadRemoteFileData(data[0], system);
+ } catch( CoreException ce2) {
+ ce = ce2;
+ }
+
Properties props = turnRemoteFileIntoProperties(contents);
- String home = (String) props.get("JBOSS_HOME");
- String config = (String) props.get("JBOSS_CONFIG");
+ String home = (String) props.get(JBOSS_HOME_KEY);
+ String config = (String) props.get(JBOSS_CONFIG_KEY);
+
if( home != null && config != null ) {
- System.out.println(home + ", " + config);
String rtId = data[1];
IRuntime runtime = ServerCore.findRuntime(rtId);
IServer newServer = null;
- newServer = ServerCreationUtils.createServer2(name, runtime);
+ newServer = ServerCreationUtils.createServer2(imageId, runtime);
newServer = RSEUtils.setServerToRSEMode(newServer, host, home, config);
return newServer;
}
+
+ // Handle the case in which the file doesn't exist, or home / config are null
+ final IServer[] result = new IServer[]{null};
+ final Properties props2 = props;
+ final Exception ce2 = ce;
+ Display.getDefault().syncExec(new Runnable(){
+ public void run() {
+ result[0] = handleRemoteFileIncomplete(host, props2, ce2);
+ }
+ });
+ return result[0];
}
return null;
}
+ protected IServer handleRemoteFileIncomplete(IHost host, Properties props, Exception e)
{
+ String message = "";
+ if( e != null ) {
+ message = "Error reading remote file: " + data[0] + ", " +
e.getMessage();
+ } else {
+ String home = (String) props.get(JBOSS_HOME_KEY);
+ String config = (String) props.get(JBOSS_CONFIG_KEY);
+ if( home == null )
+ message += "Remote property file missing JBOSS_HOME property.\n";
+ if( config == null )
+ message += "Remote property file missing JBOSS_CONFIG property.";
+ }
+ message += "\n\nTry again?";
+
+ MessageBox messageBox = new MessageBox(new Shell(), SWT.ICON_WARNING | SWT.OK |
SWT.CANCEL);
+ messageBox.setText("Cannot create Server");
+ messageBox.setMessage(message);
+ int buttonID = messageBox.open();
+ switch(buttonID) {
+ case SWT.OK:
+ // saves changes ...
+ ConvertRSEToServerWizard w = new ConvertRSEToServerWizard(instance, host);
+ new WizardDialog(new Shell(), w).open();
+ break;
+ case SWT.CANCEL:
+ break;
+ }
+ return null;
+ }
+
protected IServer createServerSetDetailsNow() throws CoreException {
String home = data[0];
String config = data[1];
String rtId = data[2];
IRuntime runtime = ServerCore.findRuntime(rtId);
- IServer newServer = ServerCreationUtils.createServer2(name, runtime);
+ IServer newServer = ServerCreationUtils.createServer2(imageId, runtime);
newServer = RSEUtils.setServerToRSEMode(newServer, host, home, config);
return newServer;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java 2011-01-06
22:02:33 UTC (rev 27957)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java 2011-01-06
22:12:24 UTC (rev 27958)
@@ -15,6 +15,7 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.rse.core.model.IHost;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
@@ -30,10 +31,8 @@
import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.ui.ServerUIUtil;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
-import org.jboss.tools.deltacloud.core.DeltaCloudException;
+import org.jboss.tools.common.jobs.ChainedJob;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
-import org.jboss.tools.deltacloud.core.DeltaCloudKey;
-import org.jboss.tools.deltacloud.core.job.AbstractInstanceJob;
import org.jboss.tools.deltacloud.integration.DeltaCloudIntegrationPlugin;
import org.jboss.tools.deltacloud.ui.INewInstanceWizardPage;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
@@ -43,7 +42,6 @@
* @author Rob Stryker
*/
public class RSEandASWizardPage extends WizardPage implements INewInstanceWizardPage {
-
private Button createRSE, createServer;
private Group serverDetailsGroup;
private Button autoScanCheck, hardCodeServerDetails, deployOnlyRadio,
@@ -60,7 +58,15 @@
setTitle("Create RSE Connection and Server");
setDescription("Here you can choose to create a matching RSE connection and a
Server adapter");
}
+
+ private IHost initialHost;
+ public RSEandASWizardPage(IHost host) {
+ this();
+ this.initialHost = host;
+ }
+
+
public void createControl(Composite parent) {
Composite c2 = new Composite(parent, SWT.NONE);
c2.setLayout(new FormLayout());
@@ -82,6 +88,7 @@
autoScanCheck = new Button(g, SWT.RADIO);
autoScanCheck.setText("Determine server details from this remote file:");
autoScanCheck.setLayoutData(UIUtils.createFormData(0,5,null,0,0,5,null,0));
+ autoScanCheck.setSelection(true);
remoteDetailsLoc = new Text(g, SWT.BORDER);
remoteDetailsLoc.setLayoutData(UIUtils.createFormData(autoScanCheck,5,null,0,0,INDENTATION,100,-5));
@@ -151,7 +158,6 @@
deployFolderText = new Text(g, SWT.BORDER);
deployFolderText.setText("/path/to/deploy");
deployFolderText.setLayoutData(UIUtils.createFormData(deployOnlyRadio, 5, null, 0,
deployFolder, 5, 100, -5));
- deployOnlyRadio.setSelection(true);
IEclipsePreferences prefs = new
InstanceScope().getNode(DeltaCloudIntegrationPlugin.PLUGIN_ID);
@@ -160,6 +166,11 @@
initServer = prefs.getBoolean(CREATE_SERVER_PREF_KEY, true);
createRSE.setSelection(initRSE);
createServer.setSelection(initServer);
+ if( initialHost != null ) {
+ createRSE.setEnabled(false);
+ createRSE.setSelection(true);
+ createServer.setSelection(true);
+ }
SelectionListener listener = new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
@@ -215,6 +226,10 @@
}
private void refreshServerWidgets() {
+ if( initialHost != null ) {
+ createRSE.setEnabled(false);
+ }
+
boolean enabled = createServer.getSelection();
serverDetailsGroup.setEnabled(enabled);
autoScanCheck.setEnabled(enabled);
@@ -231,10 +246,9 @@
deployOnlyRadio.setEnabled(enabled);
localRuntimeLabel.setEnabled(enabled);
localRuntimeCombo.setEnabled(enabled);
- System.out.println(deployFolderText.getEditable());
}
- public AbstractInstanceJob getPerformFinishJob(final DeltaCloudInstance instance) {
+ public ChainedJob getPerformFinishJob(final DeltaCloudInstance instance) {
IEclipsePreferences prefs = new
InstanceScope().getNode(DeltaCloudIntegrationPlugin.PLUGIN_ID);
prefs.putBoolean(CREATE_RSE_PREF_KEY, createRSE.getSelection());
prefs.putBoolean(CREATE_SERVER_PREF_KEY, createServer.getSelection());
@@ -265,7 +279,9 @@
data = new String[]{serverHomeText.getText(), serverConfigText.getText(), rtId};
}
if( type != null && data != null ) {
- CreateServerFromRSEJob job2 = new CreateServerFromRSEJob(type, data,
instance.getImageId());
+ CreateServerFromRSEJob job2 = new CreateServerFromRSEJob(type, data, instance);
+ if( initialHost == null )
+ return job2;
j.setNextJob(job2);
}
}