Author: rombert Date: Fri Jul 19 15:03:15 2013 New Revision: 1504902 URL: http://svn.apache.org/r1504902 Log: SLING-2973 - [Tooling] Align Eclipse tooling to proposed structure
When starting a server, wait for it to become available before setting the state to 'STARTED'. Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadLaunchConfigurationDelegate.java Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java?rev=1504902&r1=1504901&r2=1504902&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java Fri Jul 19 15:03:15 2013 @@ -16,6 +16,8 @@ */ package org.apache.sling.slingclipse.api; +import java.net.URI; + public class RepositoryInfo { private String username; @@ -47,8 +49,8 @@ public class RepositoryInfo { } public int getPort(){ - String host=url.substring(7); - return Integer.parseInt(host.split(":")[1]); + + return URI.create(url).getPort(); } @Override Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java?rev=1504902&r1=1504901&r2=1504902&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java Fri Jul 19 15:03:15 2013 @@ -25,6 +25,7 @@ import org.apache.sling.slingclipse.api. import org.apache.sling.slingclipse.api.FileInfo; import org.apache.sling.slingclipse.api.Repository; import org.apache.sling.slingclipse.api.RepositoryInfo; +import org.apache.sling.slingclipse.api.ResponseType; import org.apache.sling.slingclipse.api.Result; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -32,6 +33,7 @@ import org.eclipse.core.resources.IResou 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.Status; import org.eclipse.debug.core.ILaunch; import org.eclipse.wst.server.core.IModule; @@ -44,13 +46,30 @@ public class SlingLaunchpadBehaviour ext @Override public void stop(boolean force) { - // TODO stub + setServerState(IServer.STATE_STOPPED); } - public void start() { - // TODO stub - setServerState(IServer.STATE_STARTED); + public void start(IProgressMonitor monitor) throws CoreException { + + boolean success = false; + + Result<String> result = null; + Command<String> command = getRepository(monitor).newListChildrenNodeCommand("/", ResponseType.XML); + result = command.execute(); + success = result.isSuccess(); + + if (success) { + setServerState(IServer.STATE_STARTED); + } else { + setServerState(IServer.STATE_STOPPED); + String message = "Unable to connect to Sling Lanchpad. Please make sure a Launchpad instance is running "; + if (result != null) { + message += " (" + result.toString() + ")"; + } + throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", + message)); + } } // TODO refine signature, visibility @@ -108,24 +127,10 @@ public class SlingLaunchpadBehaviour ext System.out.println(trace.toString()); - SlingLaunchpadServer launchpadServer = (SlingLaunchpadServer) getServer().loadAdapter( - SlingLaunchpadServer.class, monitor); - SlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration(); + Repository repository = getRepository(monitor); IModuleResource[] moduleResources = getResources(module); - Repository repository = SlingclipsePlugin.getDefault().getRepository(); - try { - // TODO configurable scheme? - URI uri = new URI("http", null, getServer().getHost(), configuration.getPort(), - configuration.getContextPath(), null, null); - RepositoryInfo repositoryInfo = new RepositoryInfo(configuration.getUsername(), - configuration.getPassword(), uri.toString()); - repository.setRepositoryInfo(repositoryInfo); - } catch (URISyntaxException e) { - // TODO handle error - } - switch (deltaKind) { case ServerBehaviourDelegate.CHANGED: IModuleResourceDelta[] publishedResourceDelta = getPublishedResourceDelta(module); @@ -186,6 +191,27 @@ public class SlingLaunchpadBehaviour ext super.publishModule(kind, deltaKind, module, monitor); } + private Repository getRepository(IProgressMonitor monitor) { + + SlingLaunchpadServer launchpadServer = (SlingLaunchpadServer) getServer().loadAdapter( + SlingLaunchpadServer.class, monitor); + + SlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration(); + + Repository repository = SlingclipsePlugin.getDefault().getRepository(); + try { + // TODO configurable scheme? + URI uri = new URI("http", null, getServer().getHost(), configuration.getPort(), + configuration.getContextPath(), null, null); + RepositoryInfo repositoryInfo = new RepositoryInfo(configuration.getUsername(), + configuration.getPassword(), uri.toString()); + repository.setRepositoryInfo(repositoryInfo); + } catch (URISyntaxException e) { + // TODO handle error + } + return repository; + } + private void execute(Command<?> command) throws CoreException { if (command == null) { return; Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java?rev=1504902&r1=1504901&r2=1504902&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java Fri Jul 19 15:03:15 2013 @@ -16,6 +16,8 @@ */ package org.apache.sling.ide.eclipse.wst.internal; +import org.eclipse.wst.server.core.IServerWorkingCopy; + public class SlingLaunchpadConfiguration { @@ -27,35 +29,43 @@ public class SlingLaunchpadConfiguration public int getPort() { // TODO central place for setting defaults - return server.getServerWorkingCopy().getAttribute(SlingLaunchpadServer.PROP_PORT, 8080); + return workingCopy().getAttribute(SlingLaunchpadServer.PROP_PORT, 8080); + } + + private IServerWorkingCopy workingCopy() { + IServerWorkingCopy workingCopy = server.getServerWorkingCopy(); + server.getServer().createWorkingCopy(); + if (workingCopy == null) + workingCopy = server.getServer().createWorkingCopy(); + return workingCopy; } public void setPort(int port) { - server.getServerWorkingCopy().setAttribute(SlingLaunchpadServer.PROP_PORT, port); + workingCopy().setAttribute(SlingLaunchpadServer.PROP_PORT, port); } public String getContextPath() { - return server.getServerWorkingCopy().getAttribute(SlingLaunchpadServer.PROP_CONTEXT_PATH, "/"); + return workingCopy().getAttribute(SlingLaunchpadServer.PROP_CONTEXT_PATH, "/"); } public void setContextPath(String contextPath) { - server.getServerWorkingCopy().setAttribute(SlingLaunchpadServer.PROP_CONTEXT_PATH, contextPath); + workingCopy().setAttribute(SlingLaunchpadServer.PROP_CONTEXT_PATH, contextPath); } public String getUsername() { - return server.getServerWorkingCopy().getAttribute(SlingLaunchpadServer.PROP_USERNAME, "admin"); + return workingCopy().getAttribute(SlingLaunchpadServer.PROP_USERNAME, "admin"); } public void setUsername(String username) { - server.getServerWorkingCopy().setAttribute(SlingLaunchpadServer.PROP_USERNAME, username); + workingCopy().setAttribute(SlingLaunchpadServer.PROP_USERNAME, username); } public String getPassword() { - return server.getServerWorkingCopy().getAttribute(SlingLaunchpadServer.PROP_PASSWORD, "admin"); + return workingCopy().getAttribute(SlingLaunchpadServer.PROP_PASSWORD, "admin"); } public void setPassword(String password) { - server.getServerWorkingCopy().setAttribute(SlingLaunchpadServer.PROP_PASSWORD, password); + workingCopy().setAttribute(SlingLaunchpadServer.PROP_PASSWORD, password); } } Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadLaunchConfigurationDelegate.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadLaunchConfigurationDelegate.java?rev=1504902&r1=1504901&r2=1504902&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadLaunchConfigurationDelegate.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadLaunchConfigurationDelegate.java Fri Jul 19 15:03:15 2013 @@ -16,31 +16,18 @@ */ package org.apache.sling.ide.eclipse.wst.internal; -import java.io.File; -import java.util.Map; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.core.model.LaunchConfigurationDelegate; import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate; -import org.eclipse.jdt.launching.ExecutionArguments; -import org.eclipse.jdt.launching.IVMInstall; -import org.eclipse.jdt.launching.IVMRunner; -import org.eclipse.jdt.launching.VMRunnerConfiguration; import org.eclipse.wst.server.core.IServer; -import org.eclipse.wst.server.core.ServerCore; import org.eclipse.wst.server.core.ServerUtil; public class SlingLaunchpadLaunchConfigurationDelegate extends AbstractJavaLaunchConfigurationDelegate { - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor) - */ @Override public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { @@ -51,30 +38,11 @@ public class SlingLaunchpadLaunchConfigu null)); } - if (server.shouldPublish() && ServerCore.isAutoPublishing()) - server.publish(IServer.PUBLISH_INCREMENTAL, monitor); - SlingLaunchpadBehaviour launchpad = (SlingLaunchpadBehaviour) server.loadAdapter(SlingLaunchpadBehaviour.class, monitor); - IVMInstall vm = verifyVMInstall(configuration); - - IVMRunner runner = vm.getVMRunner(mode); - if (runner == null) - runner = vm.getVMRunner(ILaunchManager.RUN_MODE); - - // TODO use - File workingDir = verifyWorkingDirectory(configuration); - String workingDirName = null; - if (workingDir != null) - workingDirName = workingDir.getAbsolutePath(); - - setDefaultSourceLocator(launch, configuration); - - File java = new File("/usr/bin/java"); // TODO configurable and use - launchpad.setupLaunch(launch, mode, monitor); - launchpad.start(); + launchpad.start(monitor); } }