Author: rob.stryker(a)jboss.com
Date: 2011-01-03 18:47:16 -0500 (Mon, 03 Jan 2011)
New Revision: 27854
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 - automatically scan remote system for a properties file to use to create the
server is now implemented
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-03
20:48:03 UTC (rev 27853)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java 2011-01-03
23:47:16 UTC (rev 27854)
@@ -10,11 +10,28 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.integration.wizard;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.Properties;
+
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+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.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IRuntimeType;
import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
@@ -68,9 +85,101 @@
server = RSEUtils.setServerToRSEMode(server, host);
return server;
}
- protected IServer createServerCheckRemoteDetails() {
+
+ protected IRemoteFileSubSystem findRemoteFileSubSystem() {
+ ISubSystem[] systems = RSECorePlugin.getTheSystemRegistry().getSubSystems(host);
+ for( int i = 0; i < systems.length; i++ ) {
+ if(systems[i] instanceof IRemoteFileSubSystem ) {
+ return (IRemoteFileSubSystem)systems[i];
+ }
+ }
return null;
}
+
+ protected void verifySystemConnected(IRemoteFileSubSystem system) {
+ if (!system.isConnected()) {
+ try {
+ system.connect(new NullProgressMonitor(), false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ protected String loadRemoteFileData(IRemoteFileSubSystem system) {
+ IPath p = new Path(data[0]);
+ IPath remoteParent = p.removeLastSegments(1);
+ String remoteFile = p.lastSegment();
+ try {
+ Writer writer = new StringWriter();
+ char[] buffer = new char[1024];
+
+ InputStream is = system.getInputStream(remoteParent.toOSString(), remoteFile, false,
new NullProgressMonitor());
+ Reader reader = new BufferedReader(new InputStreamReader(is));
+ int n;
+ try {
+ while ((n = reader.read(buffer)) != -1) {
+ writer.write(buffer, 0, n);
+ }
+ return writer.toString();
+ } finally {
+ is.close();
+ }
+ } catch(SystemMessageException sme) {
+ sme.getCause().printStackTrace();
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return null;
+ }
+
+ protected Properties turnRemoteFileIntoProperties(String content) {
+ Properties p = new Properties();
+ String[] byLine = content.split("\n");
+ String line, key, val;
+ int eqIn;
+ for( int i = 0; i < byLine.length; i++ ) {
+ line = byLine[i].trim();
+ eqIn = line.indexOf("=");
+ if( eqIn != -1 ) {
+ key = line.substring(0, eqIn);
+ val = line.substring(eqIn+1);
+ while(val.contains("$")) {
+ String tmpKey;
+ Iterator j = p.keySet().iterator();
+ while(j.hasNext()) {
+ tmpKey = j.next().toString();
+ val = val.replace("$" + tmpKey, p.getProperty(tmpKey));
+ }
+ }
+ p.put(key, val);
+ }
+ }
+ return p;
+ }
+
+ protected IServer createServerCheckRemoteDetails() throws CoreException {
+ IRemoteFileSubSystem system = findRemoteFileSubSystem();
+ if( system != null ) {
+ verifySystemConnected(system);
+ String contents = loadRemoteFileData(system);
+ Properties props = turnRemoteFileIntoProperties(contents);
+ String home = (String) props.get("JBOSS_HOME");
+ String config = (String) props.get("JBOSS_CONFIG");
+
+ 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 = RSEUtils.setServerToRSEMode(newServer, host, home, config);
+ return newServer;
+ }
+ }
+ return null;
+ }
+
protected IServer createServerSetDetailsNow() throws CoreException {
String home = data[0];
String config = data[1];
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-03
20:48:03 UTC (rev 27853)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/RSEandASWizardPage.java 2011-01-03
23:47:16 UTC (rev 27854)
@@ -46,10 +46,11 @@
private Button createRSE, createServer;
private Group serverDetailsGroup;
- private Button autoScanCheck, hardCodeServerDetails, deployOnlyRadio,
addLocalRuntimeButton;
+ private Button autoScanCheck, hardCodeServerDetails, deployOnlyRadio,
+ addLocalRuntimeButton, autoAddLocalRuntimeButton;
private Text remoteDetailsLoc, serverHomeText, serverConfigText, deployFolderText;
- private Label serverHome, serverConfig, localRuntimeLabel, deployFolder;
- private Combo localRuntimeCombo;
+ private Label serverHome, serverConfig, localRuntimeLabel, autoLocalRuntimeLabel,
deployFolder;
+ private Combo autoLocalRuntimeCombo,localRuntimeCombo;
private final static String CREATE_RSE_PREF_KEY =
"org.jboss.tools.deltacloud.integration.wizard.RSEandASWizard.CREATE_RSE_PREF_KEY";
private final static String CREATE_SERVER_PREF_KEY =
"org.jboss.tools.deltacloud.integration.wizard.RSEandASWizard.CREATE_SERVER_PREF_KEY";
@@ -86,10 +87,27 @@
remoteDetailsLoc.setLayoutData(UIUtils.createFormData(autoScanCheck,5,null,0,0,INDENTATION,100,-5));
remoteDetailsLoc.setText("/etc/sysconfig/jboss-eap");
+ autoLocalRuntimeLabel = new Label(g, SWT.NONE);
+ autoLocalRuntimeLabel.setText("Local Runtime: ");
+ autoLocalRuntimeLabel.setLayoutData(UIUtils.createFormData(remoteDetailsLoc, 7, null,
0, 0, INDENTATION, null, 0 ));
+ autoAddLocalRuntimeButton = new Button(g, SWT.DEFAULT);
+ autoAddLocalRuntimeButton.setText("Configure Runtimes...");
+ autoAddLocalRuntimeButton.setLayoutData(UIUtils.createFormData(remoteDetailsLoc, 7,
null, 0, null, 0, 100, -5));
+ autoAddLocalRuntimeButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ configureRuntimesPressed();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ autoLocalRuntimeCombo = new Combo(g, SWT.NONE);
+ autoLocalRuntimeCombo.setLayoutData(UIUtils.createFormData(remoteDetailsLoc, 5, null,
0, autoLocalRuntimeLabel, 5, autoAddLocalRuntimeButton, -5));
+
+
hardCodeServerDetails = new Button(g, SWT.RADIO);
hardCodeServerDetails.setText("Set remote server details manually");
- hardCodeServerDetails.setLayoutData(UIUtils.createFormData(remoteDetailsLoc,5,null,0,0,5,null,0));
+ hardCodeServerDetails.setLayoutData(UIUtils.createFormData(autoLocalRuntimeCombo,5,null,0,0,5,null,0));
serverHome = new Label(g, SWT.NONE);
serverHome.setText("JBoss Server Home: ");
@@ -173,6 +191,7 @@
}
}
localRuntimeCombo.setItems((String[]) names.toArray(new String[names.size()]));
+ autoLocalRuntimeCombo.setItems((String[]) names.toArray(new String[names.size()]));
}
protected void configureRuntimesPressed() {
@@ -199,8 +218,8 @@
boolean enabled = createServer.getSelection();
boolean enabled2 = false;
serverDetailsGroup.setEnabled(enabled);
- autoScanCheck.setEnabled(enabled2);
- remoteDetailsLoc.setEnabled(enabled2);
+ autoScanCheck.setEnabled(enabled);
+ remoteDetailsLoc.setEnabled(enabled);
hardCodeServerDetails.setEnabled(enabled);
serverHomeText.setEnabled(enabled);
serverConfigText.setEnabled(enabled);
@@ -209,6 +228,8 @@
deployFolder.setEnabled(enabled);
deployFolderText.setEnabled(enabled);
deployOnlyRadio.setEnabled(enabled);
+ localRuntimeLabel.setEnabled(enabled);
+ localRuntimeCombo.setEnabled(enabled);
System.out.println(deployFolderText.getEditable());
}
@@ -233,7 +254,9 @@
data = new String[]{deployFolderText.getText()};
} else if( autoScanCheck.getSelection()) {
type = CreateServerFromRSEJob.CHECK_SERVER_FOR_DETAILS;
- data = new String[]{remoteDetailsLoc.getText()};
+ int index = autoLocalRuntimeCombo.getSelectionIndex();
+ String rtId = localRuntimes.get(index).getId();
+ data = new String[]{remoteDetailsLoc.getText(), rtId};
} else if( hardCodeServerDetails.getSelection()) {
type = CreateServerFromRSEJob.SET_DETAILS_NOW;
int index = localRuntimeCombo.getSelectionIndex();