Author: snjeza
Date: 2010-08-25 16:04:59 -0400 (Wed, 25 Aug 2010)
New Revision: 24452
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/META-INF/MANIFEST.MF
trunk/runtime/plugins/org.jboss.tools.runtime/plugin.xml
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/Activator.java
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeLocator.java
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeStartup.java
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimePreferencePage.java
Log:
https://jira.jboss.org/browse/JBDS-1289 EAP 5.1 cannot be added as a runtime during JBDS
installation
Modified: trunk/runtime/plugins/org.jboss.tools.runtime/META-INF/MANIFEST.MF
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime/META-INF/MANIFEST.MF 2010-08-25 20:00:29
UTC (rev 24451)
+++ trunk/runtime/plugins/org.jboss.tools.runtime/META-INF/MANIFEST.MF 2010-08-25 20:04:59
UTC (rev 24452)
@@ -8,10 +8,11 @@
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.jboss.tools.seam.core,
- org.drools.eclipse,
+ org.drools.eclipse;resolution:=optional,
org.eclipse.ui,
org.eclipse.wst.server.core,
org.eclipse.ui.navigator,
+ org.eclipse.debug.core,
org.eclipse.jdt.launching,
org.eclipse.ui.workbench,
org.eclipse.datatools.connectivity;visibility:=reexport,
Modified: trunk/runtime/plugins/org.jboss.tools.runtime/plugin.xml
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime/plugin.xml 2010-08-25 20:00:29 UTC (rev
24451)
+++ trunk/runtime/plugins/org.jboss.tools.runtime/plugin.xml 2010-08-25 20:04:59 UTC (rev
24452)
@@ -22,7 +22,45 @@
id="org.jboss.tools.runtime.preferences.RuntimePreferencePage"
name="%JBoss_Runtimes"/>
</extension>
-
+
+ <extension
+ point="org.eclipse.ui.preferenceTransfer">
+ <transfer
+ id="org.jboss.tools.runtime.jbossruntime"
+ icon="$nl$/icons/jboss.gif"
+ name="JBoss Runtimes">
+ <mapping
+ scope="instance">
+ <entry
+ node="org.drools.eclipse">
+ <key name="Drools.Runtimes"></key>
+ </entry>
+ <entry
+ node="org.eclipse.wst.server.core">
+ <key name="runtimes"></key>
+ </entry>
+ <entry
+ node="org.jboss.tools.seam.core">
+ <key
name="org.jboss.tools.seam.core.runtime.list"></key>
+ </entry>
+ <entry
+ node="org.jboss.tools.jbpm.common">
+ <key name="jbpm-name"></key>
+ </entry>
+ <entry
+ node="org.jboss.tools.runtime">
+ <key name="servers"></key>
+ <key name="jbpms"></key>
+ </entry>
+ <entry
+ node="org.jboss.ide.eclipse.as.ui">
+ </entry>
+ </mapping>
+ <description>
+ Export JBoss Runtimes
+ </description>
+ </transfer>
+ </extension>
<!--
<extension
point="org.eclipse.wst.server.core.runtimeLocators">
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/Activator.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/Activator.java 2010-08-25
20:00:29 UTC (rev 24451)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/Activator.java 2010-08-25
20:04:59 UTC (rev 24452)
@@ -15,6 +15,12 @@
public static final String FIRST_START = "firstStart"; //$NON-NLS-1$
+ public static final String SERVERS = "servers";
+
+ public static final String JBPMS = "jbpms";
+
+ public static final String WORKSPACES = "workspaces";
+
// The shared instance
private static Activator plugin;
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeLocator.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeLocator.java 2010-08-25
20:00:29 UTC (rev 24451)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeLocator.java 2010-08-25
20:04:59 UTC (rev 24452)
@@ -11,8 +11,12 @@
package org.jboss.tools.runtime;
import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -24,6 +28,12 @@
public class JBossRuntimeLocator extends RuntimeLocatorDelegate {
+ public static final String JBPM3 = "jBPM3";
+
+ public static final String JBPM4 = "jBPM4";
+ private final static String seamJarName = "jboss-seam.jar";
+ private final static String seamVersionAttributeName = "Seam-Version";
+
public JBossRuntimeLocator() {
}
@@ -50,6 +60,41 @@
if (!ServerType.UNKNOWN.equals(serverBean.getType())) {
serverDefinitions.add(new ServerDefinition(serverBean));
} else {
+ String seamVersion = getSeamVersionFromManifest(root.getAbsolutePath());
+ if (seamVersion != null) {
+ serverDefinitions.add(new ServerDefinition(root.getName(), seamVersion,
JBossRuntimeStartup.SEAM, root.getAbsoluteFile()));
+ } else {
+ String[] files = root.list(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ if (name.startsWith("drools-api") &&
name.endsWith(".jar") ) {
+ return true;
+ }
+ return false;
+ }
+ });
+ boolean droolsFound = false;
+ if (files.length > 0) {
+ String version = getImplementationVersion(root,files[0]);
+ if (version != null) {
+ version = version.substring(0,3);
+ serverDefinitions.add(new ServerDefinition(root.getName(), version,
JBossRuntimeStartup.DROOLS, root.getAbsoluteFile()));
+ droolsFound = true;
+ }
+ }
+ if (!droolsFound) {
+ boolean isJBPM = isValidJbpmInstallation(root.getAbsolutePath());
+ if (isJBPM) {
+ String version = "unknown";
+ if (isJbpm3(root.getAbsolutePath())) {
+ version = JBPM3;
+ } else if (isJbpm4(root.getAbsolutePath())) {
+ version = JBPM4;
+ }
+ serverDefinitions.add(new ServerDefinition(root.getName(), version,
JBossRuntimeStartup.JBPM, root.getAbsoluteFile()));
+ }
+ }
+ }
children = root.listFiles();
}
} else {
@@ -67,6 +112,55 @@
}
}
monitor.done();
+ }
+
+ /**
+ * @param dir
+ * @param string
+ * @return
+ */
+ private String getImplementationVersion(File dir, String file) {
+ File jarFile = new File(dir, file);
+ if(!jarFile.isFile()) {
+ return null;
+ }
+ try {
+ JarFile jar = new JarFile(jarFile);
+ Attributes attributes = jar.getManifest().getMainAttributes();
+ String version = attributes.getValue("Implementation-Version");
+ return version;
+ } catch (IOException e) {
+ return null;
+ }
}
+ public static String getSeamVersionFromManifest(String seamHome) {
+ File jarFile = new File(seamHome, "lib/" + seamJarName);
+ if(!jarFile.isFile()) {
+ jarFile = new File(seamHome, seamJarName);
+ if(!jarFile.isFile()) {
+ return null;
+ }
+ }
+ try {
+ JarFile jar = new JarFile(jarFile);
+ Attributes attributes = jar.getManifest().getMainAttributes();
+ String version = attributes.getValue(seamVersionAttributeName);
+ return version;
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ public static boolean isJbpm3(String location) {
+ return new
Path(location).append("/src/resources/gpd/version.info.xml").toFile().exists();
+ }
+
+ public static boolean isJbpm4(String location) {
+ return new Path(location).append("/jbpm.jar").toFile().exists();
+ }
+
+ private boolean isValidJbpmInstallation(String location) {
+ return isJbpm3(location) || isJbpm4(location);
+ }
}
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeStartup.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeStartup.java 2010-08-25
20:00:29 UTC (rev 24451)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/JBossRuntimeStartup.java 2010-08-25
20:04:59 UTC (rev 24452)
@@ -7,6 +7,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
@@ -16,6 +17,8 @@
import org.drools.eclipse.util.DroolsRuntime;
import org.drools.eclipse.util.DroolsRuntimeManager;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -26,6 +29,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
@@ -57,6 +61,7 @@
import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
import org.jboss.ide.eclipse.as.core.util.JBossServerType;
import org.jboss.ide.eclipse.as.core.util.ServerBeanLoader;
+import org.jboss.tools.jbpm.preferences.JbpmInstallation;
import org.jboss.tools.jbpm.preferences.PreferencesManager;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.SeamUtil;
@@ -64,9 +69,15 @@
import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
import org.jboss.tools.seam.core.project.facet.SeamVersion;
import org.osgi.framework.Bundle;
+import org.osgi.service.prefs.BackingStoreException;
public class JBossRuntimeStartup implements IStartup {
+ /**
+ *
+ */
+ private static final String DEFAULT_DS = "DefaultDS";
+
private static final String RUNTIME = Messages.JBossRuntimeStartup_Runtime;
private static final String EAP = "EAP"; //$NON-NLS-1$
@@ -78,6 +89,10 @@
private static final String EPP = "EPP"; //$NON-NLS-1$
private static final String EWP = "EWP"; //$NON-NLS-1$
+
+ public static final String SEAM = "SEAM"; // NON-NLS-1$
+
+ public static final String DROOLS = "DROOLS"; // NON-NLS-1$
public static final String JBOSS_EAP_HOME = "../../../../jboss-eap/jboss-as";
// JBoss AS home directory (relative to plugin)- <RHDS_HOME>/jbossas.
//$NON-NLS-1$
@@ -102,11 +117,7 @@
public static final String SEAM_2_0_HOME_CONFIGURATION_CP =
"../../jboss-eap/seam2"; //$NON-NLS-1$
public static final String[] SEAM_HOME_FOLDER_OPTIONS =
{"seam","seam1","seam2","seamfp"};
-
-
- private static final String JBPM_VERSION="jBPM3"; //$NON-NLS-1$
-
// This constants are made to avoid dependency with org.jboss.ide.eclipse.as.core
plugin
public static final String JBOSS_AS_RUNTIME_TYPE_ID[] = {
"org.jboss.ide.eclipse.as.runtime.32", //$NON-NLS-1$
@@ -177,22 +188,79 @@
= "org.eclipse.datatools.connectivity.db.URL"; //$NON-NLS-1$
private static final String HSQL_PROFILE_ID =
"org.eclipse.datatools.enablement.hsqldb.connectionProfile";
+
+ public static final String JBPM = "JBPM";
private List<ServerDefinition> serverDefinitions = new
ArrayList<ServerDefinition>();
+
+ private IEclipsePreferences preferences;
public void earlyStartup() {
if (!isJBDS()) {
return;
}
- boolean firstStart =
Activator.getDefault().getPreferenceStore().getBoolean(Activator.FIRST_START);
- if (!firstStart) {
+ if (!willBeInitialized()) {
return;
}
- Activator.getDefault().getPreferenceStore().setValue(Activator.FIRST_START, false);
parseServerFile();
initializeRuntimes(serverDefinitions);
+ saveWorkspacePreferences();
}
+ private void saveWorkspacePreferences() {
+ String workspaces = getWorkspaces();
+ String newWorkspaces = "";
+ if (workspaces == null || workspaces.trim().length() == 0) {
+ newWorkspaces = getWorkspace();
+ } else {
+ newWorkspaces = workspaces + "," + getWorkspace();
+ }
+ IEclipsePreferences prefs = getPreferences();
+ prefs.put(Activator.WORKSPACES, newWorkspaces);
+ try {
+ prefs.flush();
+ } catch (BackingStoreException e) {
+ Activator.log(e);
+ }
+ }
+
+ /**
+ * @return
+ */
+ private boolean willBeInitialized() {
+ String workspaces = getWorkspaces();
+ if (workspaces == null || workspaces.trim().length() == 0) {
+ return true;
+ }
+ StringTokenizer tokenizer = new StringTokenizer(workspaces, ",");
+ while (tokenizer.hasMoreTokens()) {
+ String workspace = tokenizer.nextToken();
+ if (workspace.equals(getWorkspace())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private String getWorkspaces() {
+ IEclipsePreferences prefs = getPreferences();
+ String workspaces = prefs.get(Activator.WORKSPACES, "");
+ return workspaces;
+ }
+
+ private String getWorkspace() {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IPath workspacePath = root.getLocation();
+ return workspacePath.toOSString();
+ }
+
+ private IEclipsePreferences getPreferences() {
+ if (preferences == null) {
+ preferences = new ConfigurationScope().getNode(Activator.PLUGIN_ID);
+ }
+ return preferences;
+ }
+
private boolean isJBDS() {
Bundle jbdsProduct = Platform.getBundle("com.jboss.jbds.product");
return jbdsProduct != null;
@@ -236,11 +304,7 @@
}
public void initializeSeam(List<ServerDefinition> serverDefinitions) {
- IEclipsePreferences node = (IEclipsePreferences)
- Platform.getPreferencesService()
- .getRootNode()
- .node(InstanceScope.SCOPE)
- .node(SeamCorePlugin.PLUGIN_ID);
+
Map<String, SeamRuntime> map = new HashMap<String,SeamRuntime>();
// to fix
https://jira.jboss.org/jira/browse/JBDS-682
@@ -326,17 +390,33 @@
}
private void addSeam(Map<String, SeamRuntime> map, String seamPath,SeamVersion
seamVersion, String name) {
- File seamFolder = new File(seamPath);
- if(seamFolder.exists() && seamFolder.isDirectory()) {
- SeamRuntime rt = new SeamRuntime();
- rt.setHomeDir(seamPath);
- rt.setName(name);
- rt.setDefault(true);
- rt.setVersion(seamVersion);
- SeamRuntimeManager.getInstance().addRuntime(rt);
+ if (!seamExists(seamPath)) {
+ File seamFolder = new File(seamPath);
+ if(seamFolder.exists() && seamFolder.isDirectory()) {
+ SeamRuntime rt = new SeamRuntime();
+ rt.setHomeDir(seamPath);
+ rt.setName(name);
+ rt.setDefault(true);
+ rt.setVersion(seamVersion);
+ SeamRuntimeManager.getInstance().addRuntime(rt);
+ }
}
}
+ /**
+ * @param seamPath
+ * @return
+ */
+ private boolean seamExists(String seamPath) {
+ SeamRuntime[] seamRuntimes = SeamRuntimeManager.getInstance().getRuntimes();
+ for (SeamRuntime sr:seamRuntimes) {
+ if (seamPath != null && seamPath.equals(sr.getHomeDir())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private String getSeamGenBuildPath(String seamHomePath,
String seamHomePathConfiguration) {
try {
@@ -409,7 +489,10 @@
index = 6;
} else if ("5.0".equals(version)) { //$NON-NLS-1$
index = 7;
- }
+ } else if ("5.1".equals(version)) { //$NON-NLS-1$
+ // FIXME - this needs to be changed when adding a new runtime type for JBoss EAP 5.1
+ index = 7;
+ }
}
return index;
}
@@ -581,14 +664,20 @@
* @throws CoreException
*/
private static IServerWorkingCopy createServer(IProgressMonitor progressMonitor,
IRuntime runtime, int index, String name) throws CoreException {
+ if (name == null) {
+ name = JBOSS_AS_NAME[index];
+ }
+ IServer[] servers = ServerCore.getServers();
+ for (IServer server:servers) {
+ if (name.equals(server.getName()) ) {
+ return null;
+ }
+ }
IServerType serverType = ServerCore.findServerType(JBOSS_AS_TYPE_ID[index]);
IServerWorkingCopy server = serverType.createServer(null, null, runtime,
progressMonitor);
server.setHost(JBOSS_AS_HOST);
- if(name != null)
- server.setName(name);
- else
- server.setName(JBOSS_AS_NAME[index]);
+ server.setName(name);
// JBossServer.DEPLOY_DIRECTORY
String deployVal =
runtime.getLocation().append("server").append(JBOSS_AS_DEFAULT_CONFIGURATION_NAME).append("deploy").toOSString();
//$NON-NLS-1$ //$NON-NLS-2$
@@ -606,8 +695,6 @@
return server;
}
- private static boolean driverIsCreated = false;
-
/**
* Creates HSQL DB Driver
* @param jbossASLocation location of JBoss AS
@@ -616,7 +703,7 @@
* @return driver instance
*/
private static void createDriver(String jbossASLocation, int index) throws
ConnectionProfileException {
- if(driverIsCreated) {
+ if(ProfileManager.getInstance().getProfileByName(DEFAULT_DS) != null) {
// Don't create the driver a few times
return;
}
@@ -656,7 +743,7 @@
}
driver = DriverManager.getInstance().getDriverInstanceByName(HSQL_DRIVER_NAME);
- if (driver != null &&
ProfileManager.getInstance().getProfileByName("DefaultDS") == null) {
//$NON-NLS-1$
+ if (driver != null && ProfileManager.getInstance().getProfileByName(DEFAULT_DS)
== null) { //$NON-NLS-1$
// create profile
Properties props = new Properties();
props.setProperty(ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID,
HSQL_DRIVER_DEFINITION_ID);
@@ -670,26 +757,30 @@
props.setProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID,
driver.getProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID));
props.setProperty(IDBDriverDefinitionConstants.URL_PROP_ID,
driver.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID));
- ProfileManager.getInstance().createProfile("DefaultDS", Messages.JBossRuntimeStartup_The_JBoss_AS_Hypersonic_embedded_database,
HSQL_PROFILE_ID, props, "", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProfileManager.getInstance().createProfile(DEFAULT_DS, Messages.JBossRuntimeStartup_The_JBoss_AS_Hypersonic_embedded_database,
HSQL_PROFILE_ID, props, "", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if(driver!=null) {
- driverIsCreated = true;
- }
+
}
public void initializeDroolsRuntime(List<ServerDefinition> serverDefinitions) {
List<DroolsRuntime> droolsRuntimes = new ArrayList<DroolsRuntime>();
for (ServerDefinition serverDefinition : serverDefinitions) {
String type = serverDefinition.getType();
- if (SOA_P.equals(type)) {
- File droolsRoot = serverDefinition.getLocation(); //$NON-NLS-1$
- if (droolsRoot.isDirectory()) {
- DroolsRuntime runtime = new DroolsRuntime();
- runtime.setName("Drools - " + serverDefinition.getName());
//$NON-NLS-1$
- runtime.setPath(droolsRoot.getAbsolutePath());
- DroolsRuntimeManager.recognizeJars(runtime);
- runtime.setDefault(true);
- droolsRuntimes.add(runtime);
+ if (!droolsExists(serverDefinition)) {
+ if (SOA_P.equals(type) || DROOLS.equals(type)) {
+ File droolsRoot = serverDefinition.getLocation(); //$NON-NLS-1$
+ if (droolsRoot.isDirectory()) {
+ DroolsRuntime runtime = new DroolsRuntime();
+ if (SOA_P.equals(type)) {
+ runtime.setName("Drools - " + serverDefinition.getName());
//$NON-NLS-1$
+ } else {
+ runtime.setName("Drools " + serverDefinition.getVersion()+ " -
" + serverDefinition.getName()); //$NON-NLS-1$
+ }
+ runtime.setPath(droolsRoot.getAbsolutePath());
+ DroolsRuntimeManager.recognizeJars(runtime);
+ runtime.setDefault(true);
+ droolsRuntimes.add(runtime);
+ }
}
}
}
@@ -700,17 +791,56 @@
}
+ /**
+ * @param serverDefinition
+ * @return
+ */
+ private boolean droolsExists(ServerDefinition serverDefinition) {
+ DroolsRuntime[] droolsRuntimes = DroolsRuntimeManager.getDroolsRuntimes();
+ for (DroolsRuntime dr:droolsRuntimes) {
+ String location = dr.getPath();
+ if (location != null &&
location.equals(serverDefinition.getLocation().getAbsolutePath())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public void initializeJbpmRuntime(List<ServerDefinition> serverDefinitions) {
for (ServerDefinition serverDefinition : serverDefinitions) {
- String type = serverDefinition.getType();
- if (SOA_P.equals(type)) {
- File jbpmRoot = new File(serverDefinition.getLocation(),"jbpm-jpdl");
//$NON-NLS-1$
- if (jbpmRoot.isDirectory()) {
- PreferencesManager.getInstance().initializeDefaultJbpmInstallation(serverDefinition.getName(),
jbpmRoot.getAbsolutePath(), JBPM_VERSION);
+ if (!jbpmExists(serverDefinition)) {
+ String type = serverDefinition.getType();
+ if (SOA_P.equals(type)) {
+ File jbpmRoot = new File(serverDefinition.getLocation(),"jbpm-jpdl");
//$NON-NLS-1$
+ if (jbpmRoot.isDirectory()) {
+ String version = JBossRuntimeLocator.JBPM3;
+ if (JBossRuntimeLocator.isJbpm4(serverDefinition.getLocation().getAbsolutePath()))
{
+ version = JBossRuntimeLocator.JBPM4;
+ }
+ PreferencesManager.getInstance().initializeDefaultJbpmInstallation(serverDefinition.getName(),
jbpmRoot.getAbsolutePath(), version);
+ }
+ } else if (JBPM.equals(type)) {
+ PreferencesManager.getInstance().addJbpmInstallation(serverDefinition.getName(),
serverDefinition.getLocation().getAbsolutePath(), serverDefinition.getVersion());
}
}
}
}
+ /**
+ * @param serverDefinition
+ * @return
+ */
+ private boolean jbpmExists(ServerDefinition serverDefinition) {
+ Map<String, JbpmInstallation> jbpmMap =
PreferencesManager.getInstance().getJbpmInstallationMap();
+ Collection<JbpmInstallation> jbpmInstalations = jbpmMap.values();
+ for (JbpmInstallation jbpm:jbpmInstalations) {
+ String location = jbpm.location;
+ if (location != null &&
location.equals(serverDefinition.getLocation().getAbsolutePath())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
\ No newline at end of file
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimePreferencePage.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimePreferencePage.java 2010-08-25
20:00:29 UTC (rev 24451)
+++
trunk/runtime/plugins/org.jboss.tools.runtime/src/org/jboss/tools/runtime/preferences/RuntimePreferencePage.java 2010-08-25
20:04:59 UTC (rev 24452)
@@ -10,8 +10,17 @@
************************************************************************************/
package org.jboss.tools.runtime.preferences;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
@@ -20,6 +29,9 @@
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -34,7 +46,17 @@
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.eclipse.ui.internal.wizards.preferences.PreferencesExportWizard;
+import org.eclipse.ui.internal.wizards.preferences.PreferencesImportWizard;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.internal.IMemento;
+import org.eclipse.wst.server.core.internal.Server;
+import org.eclipse.wst.server.core.internal.ServerPlugin;
+import org.eclipse.wst.server.core.internal.XMLMemento;
+import org.jboss.tools.jbpm.preferences.JbpmInstallation;
+import org.jboss.tools.jbpm.preferences.PreferencesManager;
import org.jboss.tools.runtime.Activator;
import org.jboss.tools.runtime.JBossRuntimeLocator;
@@ -45,12 +67,15 @@
public class RuntimePreferencePage extends PreferencePage implements
IWorkbenchPreferencePage {
+ private static final String SERVER_DATA_FILE = "servers.xml";
+
private static final String LASTPATH = "lastPath";
public static final String SEAM_PREFERENCES_ID =
"org.jboss.tools.common.model.ui.seam"; //$NON-NLS-1$
public static final String WTP_PREFERENCES_ID =
"org.eclipse.wst.server.ui.runtime.preferencePage"; //$NON-NLS-1$
private static final String DROOLS_PREFERENCES_ID =
"org.drools.eclipse.preferences.DroolsRuntimesPreferencePage";
private static final String JBPM_PREFERENCES_ID =
"org.jboss.tools.jbpm.locations";
+ protected Map<String, Object> map = new HashMap<String, Object>();
/*
* (non-Javadoc)
@@ -67,10 +92,6 @@
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
- //layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- //layout.marginWidth= 0;
- //layout.verticalSpacing= convertVerticalDLUsToPixels(10);
- //layout.horizontalSpacing=
convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
createLink(composite, "See <a>WTP Runtime</a>",
WTP_PREFERENCES_ID);
@@ -125,13 +146,117 @@
}
private void exportRuntimes() {
- // TODO Auto-generated method stub
+ exportServers();
+ exportJbpms();
+ PreferencesExportWizard wizard = new PreferencesExportWizard();
+ wizard.init(PlatformUI.getWorkbench(), new StructuredSelection());
+ WizardDialog dialog = new WizardDialog(getShell(), wizard);
+ dialog.create();
+ dialog.open();
}
+ private void exportJbpms() {
+ File file =
org.jboss.tools.jbpm.Activator.getDefault().getStateLocation().append("jbpm-installations.xml").toFile();
+ if (!file.exists()) {
+ Activator.getDefault().getPreferenceStore().setValue(Activator.JBPMS, "");
+ return;
+ }
+ try {
+ XMLMemento memento = (XMLMemento) XMLMemento.loadMemento(file.getAbsolutePath());
+ String xmlString = memento.saveToString();
+ Activator.getDefault().getPreferenceStore().setValue(Activator.JBPMS, xmlString);
+ Activator.getDefault().savePluginPreferences();
+ } catch (Exception e) {
+ Activator.log (e);
+ }
+ }
+
+ private void exportServers() {
+ String filename =
ServerPlugin.getInstance().getStateLocation().append(SERVER_DATA_FILE).toOSString();
+ if ( !(new File(filename).exists()) ) {
+ Activator.getDefault().getPreferenceStore().setValue(Activator.SERVERS,
"");
+ return;
+ }
+ try {
+ XMLMemento memento = (XMLMemento) XMLMemento.loadMemento(filename);
+ String xmlString = memento.saveToString();
+ Activator.getDefault().getPreferenceStore().setValue(Activator.SERVERS, xmlString);
+ Activator.getDefault().savePluginPreferences();
+ } catch (Exception e) {
+ Activator.log (e);
+ }
+ }
+
private void importRuntimes() {
- // TODO Auto-generated method stub
+ PreferencesImportWizard wizard = new PreferencesImportWizard();
+ wizard.init(PlatformUI.getWorkbench(), new StructuredSelection());
+ WizardDialog dialog = new WizardDialog(getShell(), wizard);
+ dialog.create();
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ String jbpms =
Activator.getDefault().getPreferenceStore().getString(Activator.JBPMS);
+ if (jbpms != null && jbpms.trim().length() > 0) {
+ loadJBPMInstalations(jbpms);
+ }
+ String servers =
Activator.getDefault().getPreferenceStore().getString(Activator.SERVERS);
+ if (servers != null && servers.trim().length() > 0) {
+ loadServerInstalations(servers);
+ }
+ }
}
+ /**
+ * @param servers
+ */
+ private void loadServerInstalations(String servers) {
+ InputStream in = null;
+ try {
+ in = new ByteArrayInputStream(servers.getBytes("UTF-8"));
+ IMemento memento = XMLMemento.loadMemento(in);
+
+ IMemento[] children = memento.getChildren("server");
+ int size = children.length;
+
+ for (int i = 0; i < size; i++) {
+ ServerEx server = new ServerEx(null);
+ server.loadFromMemento(children[i], null);
+ IServerWorkingCopy wc = server.createWorkingCopy();
+ wc.save(false, null);
+ }
+ } catch (Exception e) {
+ Activator.log(e);
+ }
+ }
+
+ /**
+ * @param jbpms
+ */
+ private void loadJBPMInstalations(String jbpms) {
+ InputStream in = null;
+ try {
+ in = new ByteArrayInputStream(jbpms.getBytes("UTF-8"));
+ IMemento memento = XMLMemento.loadMemento(in);
+ IMemento[] children = memento.getChildren("installation");
+ for (int i = 0; i < children.length; i++) {
+ JbpmInstallation installation = new JbpmInstallation();
+ installation.name = children[i].getString("name");
+ installation.location = children[i].getString("location");
+ installation.version = children[i].getString("version");
+ PreferencesManager.getInstance().getJbpmInstallationMap()
+ .put(installation.name, installation);
+ }
+ } catch (Exception e) {
+ Activator.log(e);
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException e) {
+ }
+ }
+ }
+
private Button createButton(Composite parent, String labelText, String buttonText) {
GridLayout layout;
Composite composite = new Composite(parent,SWT.NONE);
@@ -156,10 +281,10 @@
}
private void createLink(Composite composite, String text, final String preferencesId) {
- Link wtpRuntime = new Link(composite, SWT.NONE);
- wtpRuntime.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
- wtpRuntime.setText(text);
- wtpRuntime.addSelectionListener(new SelectionAdapter() {
+ Link link = new Link(composite, SWT.NONE);
+ link.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ link.setText(text);
+ link.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
PreferenceDialog dialog =
PreferencesUtil.createPreferenceDialogOn(getShell(),preferencesId, new String[]
{preferencesId},null);
if (dialog != null) {
@@ -217,5 +342,20 @@
((GridData)gd).horizontalAlignment = GridData.FILL;
}
}
+
+ private static class ServerEx extends Server {
+ /**
+ * @param file
+ */
+ public ServerEx(IFile file) {
+ super(file);
+ }
+
+ @Override
+ public void loadFromMemento(IMemento memento, IProgressMonitor monitor) {
+ super.loadFromMemento(memento, monitor);
+ }
+
+ }
}