if (useExistingServer.getSelection()) {
return existingServerCombo.getServer();
} else {
IServerType serverType = ServerCore.findServerType("org.apache.sling.ide.launchpadServer");
@SuppressWarnings("unused")
IRuntime existingRuntime = null;//ServerCore.findRuntime("org.apache.sling.ide.launchpadRuntimeType");
IRuntime[] existingRuntimes = ServerCore.getRuntimes();
for (int i = 0; i < existingRuntimes.length; i++) {
IRuntime aRuntime = existingRuntimes[i];
if (aRuntime.getRuntimeType().getId().equals("org.apache.sling.ide.launchpadRuntimeType")) {
existingRuntime = aRuntime;
}
}
Version finalVersion = null;
if (installToolingSupportBundle.getSelection()) {
Version installedVersion;
try {
installedVersion = getToolingSupportBundleVersion();
} catch (OsgiClientException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"Failed reading the tooling support bundle version", e));
}
finalVersion = installedVersion;
EmbeddedArtifactLocator artifactsLocator = Activator.getDefault().getArtifactLocator();
EmbeddedArtifact toolingSupportBundle = artifactsLocator.loadToolingSupportBundle();
Version ourVersion = new Version(toolingSupportBundle.getVersion());
if (installedVersion == null || ourVersion.compareTo(installedVersion) > 0) {
// then auto-install it if possible
try {
InputStream contents = null;
try {
contents = toolingSupportBundle.openInputStream();
newOsgiClient().installBundle(contents, toolingSupportBundle.getName());
} finally {
IOUtils.closeQuietly(contents);
}
finalVersion = ourVersion;
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"Failed installing the tooling support bundle version", e));
} catch (OsgiClientException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"Failed installing the tooling support bundle version", e));
}
}
}
IRuntimeType serverRuntime = ServerCore.findRuntimeType("org.apache.sling.ide.launchpadRuntimeType");
try {
// TODO there should be a nicer API for creating this, and also a central place for defaults
// TODO - we should not be creating runtimes, but maybe matching against existing ones
IRuntime runtime = serverRuntime.createRuntime(null, monitor);
runtime = runtime.createWorkingCopy().save(true, monitor);
IServerWorkingCopy wc = serverType.createServer(null, null, runtime, monitor);
wc.setHost(getHostname());
wc.setName(newServerName.getText());
wc.setAttribute(ISlingLaunchpadServer.PROP_PORT, getPort());
wc.setAttribute(ISlingLaunchpadServer.PROP_DEBUG_PORT, Integer.parseInt(newServerDebugPort.getText()));