Author: stefanegli
Date: Wed Aug 28 14:48:35 2013
New Revision: 1518221
URL: http://svn.apache.org/r1518221
Log:
SLING-3009, SLING-3029 and SLING-3030:
SLING-3009 : add support for deploying osgi bundles via the configured sling
launchpad server
there are two modes: locally (via SLING-3019) and via mvn
sling:install
SLING-3029 : allow to connect to the sling launchpad server both in 'run' and
in 'debug' mode. 'debug' mode sets all the necessary settings incl the source
code lookup
SLING-3030 : until we have SLING-2989 make sure we have at least one way of
deploying a content-bundle to a configured sling-launchpad. the chosen solution
for that is to use 'mvn content-package:intsall' - while this is certainly too
slow at the moment, it is still a usable temporary solution
Added:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/MavenLaunchHelper.java
(with props)
Modified:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
Added:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/MavenLaunchHelper.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/MavenLaunchHelper.java?rev=1518221&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/MavenLaunchHelper.java
(added)
+++
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/MavenLaunchHelper.java
Wed Aug 28 14:48:35 2013
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.core;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+public class MavenLaunchHelper {
+
+ private static final String NL = System.getProperty("line.separator");
+
+ public static String createMavenLaunchConfigMemento(String location,
String goals, String profile, boolean offline, Map<String, String>
mvnProperties) {
+ final StringBuffer m2propStr = new StringBuffer();
+ if (mvnProperties!=null) {
+ final Set<Entry<String, String>> entries =
mvnProperties.entrySet();
+ for (Iterator<Entry<String, String>> it =
entries.iterator(); it.hasNext();) {
+ final Entry<String, String> entry = it.next();
+ m2propStr.append("<listEntry
value=\""+entry.getKey()+"="+entry.getValue()+"\">" + NL);
+ }
+ }
+
+ String l = "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"no\"?>"+ NL+
+ " <launchConfiguration
type=\"org.eclipse.m2e.Maven2LaunchConfigurationType\" local=\"true\"
path=\""+location+"\">"+ NL+
+ " <booleanAttribute
key=\"M2_DEBUG_OUTPUT\" value=\"false\"/>"+ NL+
+ " <stringAttribute
key=\"M2_GOALS\" value=\""+goals +"\"/>"+ NL+
+ " <booleanAttribute
key=\"M2_NON_RECURSIVE\" value=\"false\"/>"+ NL+
+ " <booleanAttribute
key=\"M2_OFFLINE\" value=\""+offline+"\"/>"+ NL+
+ " <stringAttribute
key=\"M2_PROFILES\" value=\""+(profile==null ? "" : profile) +"\"/>"+ NL+
+ " <listAttribute
key=\"M2_PROPERTIES\">"+ NL+
+ m2propStr.toString() + NL +
+ " </listAttribute>"+ NL+
+ " <stringAttribute
key=\"M2_RUNTIME\" value=\"EMBEDDED\"/>"+ NL+
+ " <booleanAttribute
key=\"M2_SKIP_TESTS\" value=\"true\"/>"+ NL+
+ " <intAttribute
key=\"M2_THREADS\" value=\"1\"/>"+ NL+
+ " <booleanAttribute
key=\"M2_UPDATE_SNAPSHOTS\" value=\"true\"/>"+ NL+
+ " <booleanAttribute
key=\"M2_WORKSPACE_RESOLUTION\" value=\"false\"/>"+ NL+
+ " <stringAttribute
key=\"org.eclipse.jdt.launching.WORKING_DIRECTORY\" value=\""+location+"\"/>"+
NL+
+ " </launchConfiguration>";
+ return l;
+ }
+
+}
Propchange:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/MavenLaunchHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java?rev=1518221&r1=1518220&r2=1518221&view=diff
==============================================================================
---
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java
(original)
+++
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java
Wed Aug 28 14:48:35 2013
@@ -25,7 +25,7 @@ import org.eclipse.wst.server.core.util.
public class SlingContentModuleFactory extends ProjectModuleFactoryDelegate {
- private static final String NATURE_ID = "sling.content";
+ static final String SLING_CONTENT_FACET_ID = "sling.content";
@Override
public ModuleDelegate getModuleDelegate(IModule module) {
@@ -39,8 +39,8 @@ public class SlingContentModuleFactory e
try {
IFacetedProject facetedProject =
ProjectFacetsManager.create(project);
for (IProjectFacetVersion facet :
facetedProject.getProjectFacets()) {
- if (facet.getProjectFacet().getId().equals(NATURE_ID)) {
- return createModule(project.getName(), project.getName(),
NATURE_ID, "1.0", project);
+ if
(facet.getProjectFacet().getId().equals(SLING_CONTENT_FACET_ID)) {
+ return createModule(project.getName(), project.getName(),
SLING_CONTENT_FACET_ID, "1.0", project);
}
}
} catch (CoreException ce) {
Modified:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java?rev=1518221&r1=1518220&r2=1518221&view=diff
==============================================================================
---
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
(original)
+++
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
Wed Aug 28 14:48:35 2013
@@ -16,12 +16,25 @@
*/
package org.apache.sling.ide.eclipse.core.internal;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
+import org.apache.sling.ide.eclipse.core.MavenLaunchHelper;
import org.apache.sling.ide.eclipse.core.ProjectUtil;
import org.apache.sling.ide.eclipse.core.ServerUtil;
import org.apache.sling.ide.filter.Filter;
@@ -44,7 +57,12 @@ import org.eclipse.core.runtime.IProgres
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.model.IModuleResource;
@@ -54,20 +72,32 @@ import org.eclipse.wst.server.core.model
public class SlingLaunchpadBehaviour extends ServerBehaviourDelegate {
private SerializationManager serializationManager;
-
+ private ILaunch launch;
+ private JVMDebuggerConnection debuggerConnection;
+
@Override
public void stop(boolean force) {
-
+ if (debuggerConnection!=null) {
+ debuggerConnection.stop(force);
+ }
setServerState(IServer.STATE_STOPPED);
}
public void start(IProgressMonitor monitor) throws CoreException {
boolean success = false;
+ Result<ResourceProxy> result = null;
- Command<ResourceProxy> command = ServerUtil.getRepository(getServer(),
monitor).newListChildrenNodeCommand("/");
- Result<ResourceProxy> result = command.execute();
- success = result.isSuccess();
+ if (getServer().getMode().equals(ILaunchManager.DEBUG_MODE)) {
+ debuggerConnection = new JVMDebuggerConnection();
+ success = debuggerConnection.connectInDebugMode(launch,
getServer(), monitor);
+
+ } else {
+
+ Command<ResourceProxy> command =
ServerUtil.getRepository(getServer(), monitor).newListChildrenNodeCommand("/");
+ result = command.execute();
+ success = result.isSuccess();
+ }
if (success) {
setServerState(IServer.STATE_STARTED);
@@ -86,6 +116,7 @@ public class SlingLaunchpadBehaviour ext
public void setupLaunch(ILaunch launch, String launchMode,
IProgressMonitor monitor) throws CoreException {
// TODO check that ports are free
+ this.launch = launch;
setServerRestartState(false);
setServerState(IServer.STATE_STARTING);
setMode(launchMode);
@@ -137,7 +168,86 @@ public class SlingLaunchpadBehaviour ext
System.out.println(trace.toString());
- Repository repository = ServerUtil.getRepository(getServer(), monitor);
+ if (ProjectHelper.isBundleProject(module[0].getProject())) {
+ if (getServer().getMode().equals(ILaunchManager.RUN_MODE)) {
+ publishBundleModule(module, monitor);
+ } else {
+ // otherwise, in debug mode, we rely on the hotcode
replacement feature of eclipse/jvm
+ // TODO: make this configurable as part of the server
config
+ }
+ } else if (ProjectHelper.isContentProject(module[0].getProject())) {
+ publishContentModule(kind, deltaKind, module, monitor);
+ }
+ }
+
+ private void publishBundleModule(IModule[] module, IProgressMonitor
monitor) throws CoreException {
+ final IProject project = module[0].getProject();
+ boolean installLocally =
getServer().getAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, true);
+ if (!installLocally) {
+ try{
+ final String launchMemento =
MavenLaunchHelper.createMavenLaunchConfigMemento(project.getLocation().toString(),
+ "sling:install", "bundle",
false, null);
+ IFolder dotLaunches =
project.getFolder(".settings").getFolder(".launches");
+ dotLaunches.create(true, true, monitor);
+ IFile launchFile =
dotLaunches.getFile("sling_install.launch");
+ InputStream in = new
ByteArrayInputStream(launchMemento.getBytes());
+ launchFile.create(in, true, monitor);
+
+ ILaunchConfiguration launchConfig =
+
DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(launchFile);
+ launchConfig.launch(ILaunchManager.RUN_MODE,
monitor);
+ } catch(Exception e) {
+ // TODO proper logging
+ e.printStackTrace();
+ }
+ } else {
+ monitor.beginTask("deploying via local install", 5);
+ HttpClient httpClient = new HttpClient();
+ String hostname = getServer().getHost();
+ int launchpadPort =
getServer().getAttribute(ISlingLaunchpadServer.PROP_PORT, 8080);
+ PostMethod method = new
PostMethod("http://"+hostname+":"+launchpadPort+"/system/sling/tooling/install");
+ String username =
getServer().getAttribute(ISlingLaunchpadServer.PROP_USERNAME, "admin");
+ String password =
getServer().getAttribute(ISlingLaunchpadServer.PROP_PASSWORD, "admin");
+ String userInfo = username+":"+password;
+ if (userInfo != null) {
+ Credentials c = new
UsernamePasswordCredentials(userInfo);
+ try {
+ httpClient.getState().setCredentials(
+ new
AuthScope(method.getURI().getHost(), method
+
.getURI().getPort()), c);
+ } catch (URIException e) {
+ // TODO proper logging
+ e.printStackTrace();
+ }
+ }
+ IJavaProject javaProject = ProjectHelper.asJavaProject(project);
+ IPath outputLocation = javaProject.getOutputLocation();
+ outputLocation =
outputLocation.makeRelativeTo(project.getFullPath());
+ method.addParameter("dir", project.getRawLocation().toString()
+ "/" + outputLocation.toString());
+ monitor.worked(1);
+ try {
+ httpClient.executeMethod(method);
+ monitor.worked(4);
+ setModulePublishState(module,
IServer.PUBLISH_STATE_NONE);
+ } catch (HttpException e) {
+ // TODO proper logging
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO proper logging
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void publishContentModule(int kind, int deltaKind,
+ IModule[] module, IProgressMonitor monitor) throws
CoreException {
+
+ if (runLaunchesIfExist(kind, deltaKind, module, monitor)) {
+ return;
+ }
+ // otherwise fallback to old behaviour
+
+ Repository repository = ServerUtil.getRepository(getServer(),
monitor);
IModuleResource[] moduleResources = getResources(module);
@@ -204,7 +314,63 @@ public class SlingLaunchpadBehaviour ext
// set state to published
super.publishModule(kind, deltaKind, module, monitor);
- }
+ setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
+// setServerPublishState(IServer.PUBLISH_STATE_NONE);
+ }
+
+ private boolean runLaunchesIfExist(int kind, int deltaKind, IModule[]
module,
+ IProgressMonitor monitor) throws CoreException {
+ final IProject project = module[0].getProject();
+ final IFolder dotLaunches =
project.getFolder(".settings").getFolder(".launches");
+ final List<IFile> launches = new LinkedList<IFile>();
+ if (dotLaunches.exists()) {
+ final IResource[] members = dotLaunches.members();
+ if (members!=null) {
+ for (int i = 0; i < members.length; i++) {
+ final IResource aMember = members[i];
+ if (aMember instanceof IFile) {
+ launches.add((IFile)aMember);
+ }
+ }
+ }
+ }
+ if (launches.size()>0) {
+ if (kind == IServer.PUBLISH_AUTO && deltaKind ==
ServerBehaviourDelegate.NO_CHANGE) {
+ // then nothing is to be done, there are no
changes
+ return true;
+ }
+ for (Iterator<IFile> it = launches.iterator(); it.hasNext();) {
+ IFile aLaunchFile = it.next();
+ try{
+// @SuppressWarnings("restriction")
+// IWorkbench workbench =
DebugUIPlugin.getDefault().getWorkbench();
+// if (workbench==null) {
+// // we're not in the context of
a workbench?
+// System.err.println("We're not
in the context of a workbench?");
+// }
+// IWorkbenchWindow aw =
workbench.getActiveWorkbenchWindow();
+// if (aw==null) {
+// // we're not in the context of
a workbench window?
+// System.err.println("We're not
in the context of a workbench window?");
+// }
+ ILaunchConfiguration launchConfig =
+
DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(aLaunchFile);
+ if (launchConfig!=null) {
+ DebugUITools.launch(
launchConfig, ILaunchManager.RUN_MODE);
+ }
+ } catch(Exception e) {
+ // TODO logging
+
+ e.printStackTrace();
+ }
+
+ }
+ super.publishModule(kind, deltaKind, module, monitor);
+ setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
+ return true;
+ }
+ return false;
+ }
private void execute(Command<?> command) throws CoreException {
if (command == null) {