You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2016/04/01 16:26:11 UTC

svn commit: r1737398 - /sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/SetupServerWizardPage.java

Author: rombert
Date: Fri Apr  1 14:26:11 2016
New Revision: 1737398

URL: http://svn.apache.org/viewvc?rev=1737398&view=rev
Log:
SLING-5635 - Project creation wizards should not unconditionally create
new runtimes

Modified:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/SetupServerWizardPage.java

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/SetupServerWizardPage.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/SetupServerWizardPage.java?rev=1737398&r1=1737397&r2=1737398&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/SetupServerWizardPage.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/SetupServerWizardPage.java Fri Apr  1 14:26:11 2016
@@ -53,6 +53,10 @@ import org.eclipse.wst.server.core.Serve
 
 public class SetupServerWizardPage extends WizardPage {
 	
+    private static final String RUNTIME_TYPE_LAUNCHPAD = "org.apache.sling.ide.launchpadRuntimeType";
+
+    private static final String SERVER_TYPE_LAUNCHPAD = "org.apache.sling.ide.launchpadServer";
+
     private static final int HORIZONTAL_INDENT = 10;
 
     private Button useExistingServer;
@@ -303,23 +307,13 @@ public class SetupServerWizardPage exten
 		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 (IRuntime runtime : existingRuntimes) {
-				if (runtime.getRuntimeType().getId().equals("org.apache.sling.ide.launchpadRuntimeType")) {
-					existingRuntime = runtime;
-				}
-			}
+		    
+			IServerType serverType = ServerCore.findServerType(SERVER_TYPE_LAUNCHPAD);
+			IRuntime slingRuntime = getOrCreateSlingRuntime(monitor);
 			
-			IRuntimeType serverRuntime = ServerCore.findRuntimeType("org.apache.sling.ide.launchpadRuntimeType");
 			try {
                 // TODO there should be a nicer API for creating this
-                // 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);
+                IServerWorkingCopy wc = serverType.createServer(null, null, slingRuntime, monitor);
 				wc.setHost(getHostname());
                 wc.setName(newServerName.getText());
 				wc.setAttribute(ISlingLaunchpadServer.PROP_PORT, getPort());
@@ -329,7 +323,7 @@ public class SetupServerWizardPage exten
                 
                 SlingLaunchpadConfigurationDefaults.applyDefaultValues(wc);
                 
-				wc.setRuntime(runtime);
+				wc.setRuntime(slingRuntime);
                 server = wc.save(true, monitor);
                 return server;
 			} catch (CoreException e) {
@@ -340,6 +334,18 @@ public class SetupServerWizardPage exten
 		}
 	}
 
+    private IRuntime getOrCreateSlingRuntime(IProgressMonitor monitor) throws CoreException {
+        
+        for ( IRuntime runtime : ServerCore.getRuntimes()) {
+            if ( runtime.getRuntimeType().getId().equals(RUNTIME_TYPE_LAUNCHPAD)) {
+                return runtime;
+            }
+        }
+        
+        IRuntimeType serverRuntime = ServerCore.findRuntimeType(RUNTIME_TYPE_LAUNCHPAD);
+        return serverRuntime.createRuntime(null, monitor).createWorkingCopy().save(true, monitor);
+    }
+
 	private int getPort() {
 		return Integer.parseInt(newServerPort.getText());
 	}