Author: stefanegli
Date: Wed Aug 28 14:45:18 2013
New Revision: 1518220

URL: http://svn.apache.org/r1518220
Log:
SLING-3009 and SLING-3029:
 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

Added:
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleInstallLocallyCommand.java
   (with props)
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetServerDebugPortCommand.java
   (with props)
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/JVMDebuggerConnection.java
   (with props)
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java
   (with props)
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetInstallDelegate.java
   (with props)
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetUninstallDelegate.java
   (with props)
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleModuleFactory.java
   (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-core/META-INF/MANIFEST.MF
    sling/trunk/tooling/ide/eclipse-core/plugin.xml
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadConfiguration.java
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadConfiguration.java
    
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java

Modified: sling/trunk/tooling/ide/eclipse-core/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/META-INF/MANIFEST.MF?rev=1518220&r1=1518219&r2=1518220&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-core/META-INF/MANIFEST.MF Wed Aug 28 
14:45:18 2013
@@ -5,23 +5,40 @@ Bundle-Version: 0.0.1.qualifier
 Bundle-Activator: org.apache.sling.ide.eclipse.core.internal.Activator
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.equinox.ds;bundle-version="1.2.1",
- org.eclipse.osgi.services;bundle-version="3.2.100"
+ org.eclipse.osgi.services;bundle-version="3.2.100",
+ org.eclipse.core.resources,
+ org.eclipse.ui,
+ org.eclipse.m2e.core;bundle-version="1.4.0",
+ org.eclipse.m2e.archetype.common;bundle-version="1.4.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ClassPath: .
-Import-Package: org.apache.sling.ide.filter,
+Import-Package: org.apache.commons.httpclient;version="3.1.0",
+ org.apache.commons.httpclient.auth;version="3.1.0",
+ org.apache.commons.httpclient.methods;version="3.1.0",
+ org.apache.maven.artifact.repository,
+ org.apache.sling.ide.filter,
  org.apache.sling.ide.serialization,
  org.apache.sling.ide.transport,
  org.eclipse.core.commands,
  org.eclipse.core.commands.operations,
  org.eclipse.core.resources,
  org.eclipse.debug.core,
+ org.eclipse.debug.core.model,
+ org.eclipse.debug.core.sourcelookup,
+ org.eclipse.debug.core.sourcelookup.containers,
+ org.eclipse.debug.internal.ui,
+ org.eclipse.debug.ui,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.internal.launching,
  org.eclipse.jdt.launching,
+ org.eclipse.jdt.launching.sourcelookup.containers,
  org.eclipse.osgi.service.debug;version="1.2.0",
  org.eclipse.wst.common.project.facet.core,
  org.eclipse.wst.server.core,
  org.eclipse.wst.server.core.model,
  org.eclipse.wst.server.core.util,
  org.osgi.service.component;version="1.1.0"
-Export-Package: org.apache.sling.ide.eclipse.core
+Export-Package: org.apache.sling.ide.eclipse.core,
+ org.apache.sling.ide.eclipse.core.internal
 Service-Component: OSGI-INF/Tracer.xml

Modified: sling/trunk/tooling/ide/eclipse-core/plugin.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/plugin.xml?rev=1518220&r1=1518219&r2=1518220&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-core/plugin.xml Wed Aug 28 14:45:18 2013
@@ -6,9 +6,15 @@
   <extension point="org.eclipse.wst.server.core.moduleTypes">
     <moduleType
        id="sling.content"
-       name="Sling module type"/>
+       name="Sling content module type"/>
   </extension>
   
+  <extension point="org.eclipse.wst.server.core.moduleTypes">
+    <moduleType
+       id="sling.bundle"
+       name="Sling bundle module type"/>
+  </extension>
+
   <!-- Define a sling module factory -->
   <extension point="org.eclipse.wst.server.core.moduleFactories">
        <moduleFactory
@@ -21,6 +27,18 @@
        </moduleFactory>
   </extension>
   
+  <extension
+        point="org.eclipse.wst.server.core.moduleFactories">
+       <moduleFactory
+               projects="true"
+               
class="org.apache.sling.ide.eclipse.core.internal.SlingBundleModuleFactory"
+               id="org.apache.sling.ide.bundleModuleFactory">
+           <moduleType
+              versions="1.0"
+              types="sling.bundle"/>
+       </moduleFactory>
+  </extension>
+
        <!-- Define the sling facet we support -->
        <extension point="org.eclipse.wst.common.project.facet.core.facets">
                <project-facet id="sling.content">
@@ -37,6 +55,21 @@
                <action facet="sling.content" version="1.0" type="UNINSTALL">
                        <delegate 
class="org.apache.sling.ide.eclipse.core.internal.SlingContentFacetUninstallDelegate"/>
                </action>
+
+               <project-facet id="sling.bundle">
+                       <label>Sling bundle module</label>
+                       <description>Sling/OSGi bundle modules contain java 
code which is installed as an OSGi bundle in Sling.</description>
+               </project-facet>
+               
+               <project-facet-version facet="sling.bundle" version="1.0"/>
+               
+               <action facet="sling.bundle" version="1.0" type="INSTALL">
+                       <delegate 
class="org.apache.sling.ide.eclipse.core.internal.SlingBundleFacetInstallDelegate"/>
+               </action>
+
+               <action facet="sling.bundle" version="1.0" type="UNINSTALL">
+                       <delegate 
class="org.apache.sling.ide.eclipse.core.internal.SlingBundleFacetUninstallDelegate"/>
+               </action>
        </extension>  
 
        <!-- Define the Sling launchpad runtime type -->
@@ -49,6 +82,7 @@
        version="1.0"
        
class="org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadRuntime">
        <moduleType types="sling.content" versions="1.0"/> 
+       <moduleType types="sling.bundle" versions="1.0"/> 
     </runtimeType>
   </extension>
   
@@ -56,8 +90,8 @@
   <extension point="org.eclipse.wst.server.core.serverTypes">
      <serverType
        id="org.apache.sling.ide.launchpadServer"
-       name="Sling Launchpad (server name)"
-       description="Sling Launchpad (server description)"
+       name="External Sling Launchpad (server name)"
+       description="External Sling Launchpad (server description)"
        supportsRemoteHosts="true"
        runtime="true"
        startTimeout="30000"
@@ -83,7 +117,7 @@
         id="org.apache.sling.ide.launchpadLaunchConfigurationType"
         name="Sling Launchpad"
         
delegate="org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadLaunchConfigurationDelegate"
-        modes="run"
+        modes="run,debug"
         
sourceLocatorId="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
   </extension>
     
@@ -114,6 +148,10 @@
       <runtime-component 
id="org.apache.sling.ide.launchpadRuntimeComponentType"/>
       <facet id="sling.content" version="1.0"/>
     </default-facets>
+    <default-facets>
+      <runtime-component 
id="org.apache.sling.ide.launchpadRuntimeComponentType"/>
+      <facet id="sling.bundle" version="1.0"/>
+    </default-facets>
   </extension>
        
        <!-- Map from the launchpad runtime type to our runtime components -->

Modified: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadConfiguration.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadConfiguration.java?rev=1518220&r1=1518219&r2=1518220&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadConfiguration.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadConfiguration.java
 Wed Aug 28 14:45:18 2013
@@ -19,6 +19,8 @@ package org.apache.sling.ide.eclipse.cor
 public interface ISlingLaunchpadConfiguration {
 
     int getPort();
+    
+    int getDebugPort();
 
     String getContextPath();
 
@@ -26,4 +28,5 @@ public interface ISlingLaunchpadConfigur
 
     String getPassword();
 
+    boolean bundleInstallLocally();
 }
\ No newline at end of file

Modified: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java?rev=1518220&r1=1518219&r2=1518220&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java
 Wed Aug 28 14:45:18 2013
@@ -28,7 +28,10 @@ public interface ISlingLaunchpadServer {
     public static final String PROP_USERNAME = "launchpad.username";
     public static final String PROP_CONTEXT_PATH = "launchpad.contextPath";
     public static final String PROP_PORT = "launchpad.port";
+    public static final String PROP_DEBUG_PORT = "launchpad.debugPort";
 
+    public static final String PROP_INSTALL_LOCALLY = 
"launchpad.installLocally";
+    
     void setPublishState(int publishState, IProgressMonitor monitor);
 
     int getPublishState();

Added: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleInstallLocallyCommand.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleInstallLocallyCommand.java?rev=1518220&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleInstallLocallyCommand.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleInstallLocallyCommand.java
 Wed Aug 28 14:45:18 2013
@@ -0,0 +1,72 @@
+/*
+ * 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 org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+public class SetBundleInstallLocallyCommand extends AbstractOperation {
+
+    private IServerWorkingCopy server;
+    private boolean oldValue;
+       private boolean installLocally;
+
+    public SetBundleInstallLocallyCommand(IServerWorkingCopy server, boolean 
installLocally) {
+        super("Setting install locally parameter...");
+        this.server = server;
+        this.installLocally = installLocally;
+    }
+
+    @Override
+    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        oldValue = 
server.getAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, true);
+
+        server.setAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, 
installLocally);
+
+        return Status.OK_STATUS;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see 
org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor,
+     * org.eclipse.core.runtime.IAdaptable)
+     */
+    @Override
+    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        return execute(monitor, info);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see 
org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor,
+     * org.eclipse.core.runtime.IAdaptable)
+     */
+    @Override
+    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        server.setAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, 
oldValue);
+
+        return Status.OK_STATUS;
+    }
+
+}

Propchange: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleInstallLocallyCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetServerDebugPortCommand.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetServerDebugPortCommand.java?rev=1518220&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetServerDebugPortCommand.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetServerDebugPortCommand.java
 Wed Aug 28 14:45:18 2013
@@ -0,0 +1,72 @@
+/*
+ * 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 org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+public class SetServerDebugPortCommand extends AbstractOperation {
+
+    private IServerWorkingCopy server;
+    private int debugPort;
+    private int oldValue;
+
+    public SetServerDebugPortCommand(IServerWorkingCopy server, int debugPort) 
{
+        super("Setting server debugPort...");
+        this.server = server;
+        this.debugPort = debugPort;
+    }
+
+    @Override
+    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        oldValue = server.getAttribute(ISlingLaunchpadServer.PROP_DEBUG_PORT, 
30303);
+
+        server.setAttribute(ISlingLaunchpadServer.PROP_DEBUG_PORT, debugPort);
+
+        return Status.OK_STATUS;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see 
org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor,
+     * org.eclipse.core.runtime.IAdaptable)
+     */
+    @Override
+    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        return execute(monitor, info);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see 
org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor,
+     * org.eclipse.core.runtime.IAdaptable)
+     */
+    @Override
+    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        server.setAttribute(ISlingLaunchpadServer.PROP_DEBUG_PORT, oldValue);
+
+        return Status.OK_STATUS;
+    }
+
+}

Propchange: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetServerDebugPortCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/JVMDebuggerConnection.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/JVMDebuggerConnection.java?rev=1518220&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/JVMDebuggerConnection.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/JVMDebuggerConnection.java
 Wed Aug 28 14:45:18 2013
@@ -0,0 +1,165 @@
+/*
+ * 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.internal;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sling.ide.eclipse.core.ISlingLaunchpadConfiguration;
+import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
+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.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.sourcelookup.ISourceContainer;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.internal.launching.JavaSourceLookupDirector;
+import org.eclipse.jdt.launching.IVMConnector;
+import org.eclipse.jdt.launching.JavaRuntime;
+import 
org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer;
+import org.eclipse.wst.server.core.IServer;
+
+public class JVMDebuggerConnection {
+       
+       private ILaunch launch;
+
+       boolean connectInDebugMode(ILaunch launch, IServer iServer, 
IProgressMonitor monitor)
+                       throws CoreException {
+               this.launch = launch;
+               boolean success = false;
+               IVMConnector connector = null;
+               connector = 
JavaRuntime.getVMConnector("org.eclipse.jdt.launching.socketAttachConnector");
+               if (connector == null) {
+                       connector = JavaRuntime.getDefaultVMConnector();
+               }
+               if (connector == null) {
+                       throw new CoreException(new Status(IStatus.ERROR, 
"org.apache.sling.ide.eclipse.wst",
+                                       "Could not get jvm connctor"));
+               }
+               
+               ISlingLaunchpadServer launchpadServer = (ISlingLaunchpadServer) 
iServer.loadAdapter(SlingLaunchpadServer.class,
+                       monitor);
+
+               ISlingLaunchpadConfiguration configuration = 
launchpadServer.getConfiguration();
+               
+               int debugPort = configuration.getDebugPort();
+               
+               if (debugPort<=0) {
+                       throw new CoreException(new Status(IStatus.ERROR, 
"org.apache.sling.ide.eclipse.wst",
+                           "debug port not configured"));
+               }
+               
+               Map<String, String> connectMap = new HashMap<String, String>();
+               connectMap.put("hostname", iServer.getHost());
+               connectMap.put("port", String.valueOf(debugPort));
+               
+//                     Map argMap = 
null;//configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP,
 (Map)null);
+               
+               int connectTimeout = 
JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
+               connectMap.put("timeout", Integer.toString(connectTimeout));  
//$NON-NLS-1$
+
+               // set the default source locator if required
+               @SuppressWarnings("restriction")
+               ISourceLookupDirector sourceLocator = new 
JavaSourceLookupDirector();
+               sourceLocator
+                               
.setSourcePathComputer(DebugPlugin.getDefault().getLaunchManager()
+                                               .getSourcePathComputer(
+                                                               
"org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer")); //$NON-NLS-1$
+               List<ISourceContainer> l = new LinkedList<ISourceContainer>();
+               IJavaProject[] javaProjects = 
ProjectHelper.getAllJavaProjects();
+               if (javaProjects!=null) {
+                       for (int i = 0; i < javaProjects.length; i++) {
+                               IJavaProject javaProject = javaProjects[i];
+                               JavaProjectSourceContainer sc = new 
JavaProjectSourceContainer(javaProject);
+                               l.add(sc);
+//                                     ISourceContainer[] scs = 
sc.getSourceContainers();
+//                                     if (scs!=null && scs.length>0) {
+//                                             for (int j = 0; j < scs.length; 
j++) {
+//                                                     ISourceContainer 
iSourceContainer = scs[j];
+//                                                     l.add(iSourceContainer);
+//                                             }
+//                                     } else {
+//                                     }
+                       }
+                       ISourceContainer[] containers = l.toArray(new 
ISourceContainer[l.size()]);
+                       sourceLocator.setSourceContainers(containers);
+                       sourceLocator.initializeParticipants();
+//                     sourceLocator.initializeDefaults(configuration);
+                       launch.setSourceLocator(sourceLocator);
+               }
+
+//                     setDefaultSourceLocator(getServer().getLaunch(), null);
+               monitor.worked(1);              
+               
+               // connect to remote VM
+               try{
+                       connector.connect(connectMap, monitor, launch);
+                       success = true;
+               } catch(Exception e) {
+                       throw new CoreException(new Status(IStatus.ERROR, 
"org.apache.sling.ide.eclipse.wst",
+                           "could not establish debug connection to 
"+iServer.getHost()+" : "+debugPort, e));
+               }
+               return success;
+       }
+
+       public void stop(boolean force) {
+               IProcess[] processes = launch.getProcesses();
+               if (processes!=null) {
+                       for (int i = 0; i < processes.length; i++) {
+                               IProcess iProcess = processes[i];
+                               try {
+                                       iProcess.terminate();
+                               } catch (DebugException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       }
+               }
+               IDebugTarget[] debugTargets = launch.getDebugTargets();
+               if (debugTargets != null) {
+                       for (int i = 0; i < debugTargets.length; i++) {
+                               IDebugTarget iDebugTarget = debugTargets[i];
+                               try {
+                                       iDebugTarget.disconnect();
+                               } catch (DebugException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       }
+               }
+               IDebugTarget dt = launch.getDebugTarget();
+               if (dt!=null) {
+                       try {
+                               dt.disconnect();
+                       } catch (DebugException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+               }
+       }
+
+
+
+}

Propchange: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/JVMDebuggerConnection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java?rev=1518220&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java
 Wed Aug 28 14:45:18 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.internal;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jdt.core.IJavaModel;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+
+public class ProjectHelper {
+
+       public static boolean isBundleProject(IProject project) {
+               return containsFacet(project, 
SlingBundleModuleFactory.SLING_BUNDLE_FACET_ID);
+       }
+
+       public static boolean isContentProject(IProject project) {
+               return containsFacet(project, 
SlingContentModuleFactory.SLING_CONTENT_FACET_ID);
+       }
+
+       private static boolean containsFacet(IProject project, String facetId) {
+               IFacetedProject facetedProject = (IFacetedProject) 
project.getAdapter(IFacetedProject.class);
+               if (facetedProject==null ) {
+                       return false;
+               }
+               IProjectFacet facet = 
ProjectFacetsManager.getProjectFacet(facetId);
+               return facetedProject.hasProjectFacet(facet);
+       }
+       
+       static IJavaProject asJavaProject(IProject project) {
+               return JavaCore.create(project);
+       }
+       
+       static IJavaProject[] getAllJavaProjects() {
+               IJavaModel model = 
JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
+               IJavaProject[] jps;
+               try {
+                       jps = model.getJavaProjects();
+                       return jps;
+               } catch (JavaModelException e) {
+                       e.printStackTrace();
+                       return null;
+               }
+       }
+       
+}

Propchange: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetInstallDelegate.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetInstallDelegate.java?rev=1518220&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetInstallDelegate.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetInstallDelegate.java
 Wed Aug 28 14:45:18 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.internal;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.project.facet.core.IDelegate;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+
+public class SlingBundleFacetInstallDelegate implements IDelegate {
+
+    @Override
+    public void execute(IProject project, IProjectFacetVersion facetVersion, 
Object config, IProgressMonitor monitor)
+            throws CoreException {
+
+    }
+
+}

Propchange: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetInstallDelegate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetUninstallDelegate.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetUninstallDelegate.java?rev=1518220&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetUninstallDelegate.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetUninstallDelegate.java
 Wed Aug 28 14:45:18 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.internal;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.project.facet.core.IDelegate;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+
+public class SlingBundleFacetUninstallDelegate implements IDelegate {
+
+    @Override
+    public void execute(IProject arg0, IProjectFacetVersion arg1, Object arg2, 
IProgressMonitor arg3)
+            throws CoreException {
+
+    }
+
+}

Propchange: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleFacetUninstallDelegate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleModuleFactory.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleModuleFactory.java?rev=1518220&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleModuleFactory.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleModuleFactory.java
 Wed Aug 28 14:45:18 2013
@@ -0,0 +1,162 @@
+/*
+ * 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.internal;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.ModuleDelegate;
+import org.eclipse.wst.server.core.util.ModuleFile;
+import org.eclipse.wst.server.core.util.ProjectModuleFactoryDelegate;
+
+public class SlingBundleModuleFactory extends ProjectModuleFactoryDelegate {
+
+    static final String SLING_BUNDLE_FACET_ID = "sling.bundle";
+
+    @Override
+    public ModuleDelegate getModuleDelegate(IModule module) {
+
+        return new SlingBundleModuleDelegate(module);
+    }
+
+    @Override
+    protected IModule createModule(IProject project) {
+
+        try {
+            IFacetedProject facetedProject = 
ProjectFacetsManager.create(project);
+            for (IProjectFacetVersion facet : 
facetedProject.getProjectFacets()) {
+                if 
(facet.getProjectFacet().getId().equals(SLING_BUNDLE_FACET_ID)) {
+                    return createModule(project.getName(), project.getName(), 
SLING_BUNDLE_FACET_ID, "1.0", project);
+                }
+            }
+        } catch (CoreException ce) {
+            // TODO logging
+        }
+
+        return null;
+    }
+
+    static class SlingBundleModuleDelegate extends ModuleDelegate {
+
+        private final IModule module;
+
+        public SlingBundleModuleDelegate(IModule module) {
+            this.module = module;
+        }
+
+        @Override
+        public IStatus validate() {
+            return Status.OK_STATUS; // TODO actually validate
+        }
+
+        /**
+         * This returns the list of module resources that make up the bundle.
+         * <p>
+         * This list is composed of all files which are not derived. Derived 
files
+         * are those that are generated by m2eclipse/eclipse - and typically 
are 
+         * the derived files and/or the files under target/classes (the output 
dirs).
+         * <p>
+         * This list is further down used as the input to 
SlingLaunchpadBehaviour
+         * and there evaluated. Depending on that class's behavior, this method
+         * might have to be adjusted (as for example in one version the 
SlingLaunchpadBehaviour
+         * completely ignores the list of changed files and redeploys 
everything - if another
+         * behaviour is used where only diffs are published, this members 
might have
+         * to return exactly the opposite: everything derived..)
+         */
+        @Override
+        public IModuleResource[] members() throws CoreException {
+            IProject project = module.getProject();
+            final IJavaProject javaProject = 
ProjectHelper.asJavaProject(project);
+            final List<IModuleResource> resources = new 
ArrayList<IModuleResource>();
+            
+            final Set<String> filteredLocations = new HashSet<String>();
+
+            final IJavaProject jp = javaProject;
+            final IClasspathEntry[] rawCp = jp.getRawClasspath();
+            for (int i = 0; i < rawCp.length; i++) {
+                               IClasspathEntry aCp = rawCp[i];
+                               IPath outputLocation = aCp.getOutputLocation();
+                               if (outputLocation!=null) {
+                                       outputLocation = 
outputLocation.makeRelativeTo(project.getFullPath());
+                                       
filteredLocations.add(outputLocation.toString());
+                               }
+                       }
+            
+            project.accept(new IResourceVisitor() {
+                @Override
+                public boolean visit(IResource resource) throws CoreException {
+
+                    if (resource.getType() == IResource.PROJECT) {
+                        return true;
+                    }
+
+                    final IPath relativePath = 
resource.getProjectRelativePath();
+                    if (relativePath == null) {
+                       return false;
+                    }
+                    final String relPathStr = relativePath.toString();
+                    if (relPathStr == null || relPathStr.length()==0) {
+                       return false;
+                    }
+                    if (resource.isDerived()) {
+                       // then dont accept it
+                       return false;
+                    }
+                                       if 
(filteredLocations.contains(relPathStr)) {
+                       return false;
+                    }
+                                       if (resource.getType() == 
IResource.FILE) {
+                                               // the bundle facet accepts all 
files that are not in the output directory/derived
+                                               ModuleFile moduleFile = new 
ModuleFile((IFile) resource, resource.getName(), relativePath);
+                                               resources.add(moduleFile);
+                                       }
+                    return true;
+                }
+            });
+
+            for (Iterator<IModuleResource> it = resources.iterator(); 
it.hasNext();) {
+                               IModuleResource iModuleResource = it.next();
+                               System.out.println(" ADDED: 
"+iModuleResource.getModuleRelativePath().toString());
+                               
+                       }
+            return resources.toArray(new IModuleResource[resources.size()]);
+        }
+
+        @Override
+        public IModule[] getChildModules() {
+            return new IModule[0]; // TODO revisit, do we need child modules?
+        }
+    }
+}

Propchange: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingBundleModuleFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadConfiguration.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadConfiguration.java?rev=1518220&r1=1518219&r2=1518220&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadConfiguration.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadConfiguration.java
 Wed Aug 28 14:45:18 2013
@@ -28,6 +28,11 @@ public class SlingLaunchpadConfiguration
     public SlingLaunchpadConfiguration(SlingLaunchpadServer server) {
         this.server = server;
     }
+    
+    @Override
+    public boolean bundleInstallLocally() {
+        return 
workingCopy().getAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, true);
+    }
 
     @Override
     public int getPort() {
@@ -35,6 +40,11 @@ public class SlingLaunchpadConfiguration
         return workingCopy().getAttribute(ISlingLaunchpadServer.PROP_PORT, 
8080);
     }
 
+    @Override
+    public int getDebugPort() {
+        return 
workingCopy().getAttribute(ISlingLaunchpadServer.PROP_DEBUG_PORT, 30303);
+    }
+    
     private IServerWorkingCopy workingCopy() {
         IServerWorkingCopy workingCopy = server.getServerWorkingCopy();
         server.getServer().createWorkingCopy();
@@ -46,6 +56,10 @@ public class SlingLaunchpadConfiguration
     public void setPort(int port) {
         workingCopy().setAttribute(ISlingLaunchpadServer.PROP_PORT, port);
     }
+    
+    public void setDebugPort(int debugPort) {
+       workingCopy().setAttribute(ISlingLaunchpadServer.PROP_DEBUG_PORT, 
debugPort);
+    }
 
     @Override
     public String getContextPath() {

Modified: 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java?rev=1518220&r1=1518219&r2=1518220&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java
 Wed Aug 28 14:45:18 2013
@@ -32,6 +32,8 @@ public class SlingLaunchpadServer extend
 
     private static final String MODULE_TYPE_SLING_CONTENT = "sling.content";
 
+    private static final String MODULE_TYPE_SLING_BUNDLE = "sling.bundle";
+
     private ISlingLaunchpadConfiguration config;
 
     @Override
@@ -61,9 +63,10 @@ public class SlingLaunchpadServer extend
 
         for (IModule module : toAdd) {
 
-            if 
(!MODULE_TYPE_SLING_CONTENT.equals(module.getModuleType().getId())) {
+            if 
(!MODULE_TYPE_SLING_CONTENT.equals(module.getModuleType().getId()) &&
+                       
!MODULE_TYPE_SLING_BUNDLE.equals(module.getModuleType().getId())) {
                 return new Status(IStatus.ERROR, 
"org.apache.sling.slingclipse", 0,
-                        "Will only handle modules of type 'sling.content'", 
null);
+                        "Will only handle modules of type 'sling.content' or 
'sling.bundle'", null);
             }
         }
 
@@ -88,12 +91,13 @@ public class SlingLaunchpadServer extend
     @Override
     public IModule[] getRootModules(IModule arg0) throws CoreException {
 
-        if (MODULE_TYPE_SLING_CONTENT.equals(arg0.getModuleType().getId())) {
+        if (MODULE_TYPE_SLING_CONTENT.equals(arg0.getModuleType().getId()) || 
+                       
MODULE_TYPE_SLING_BUNDLE.equals(arg0.getModuleType().getId())) {
             return new IModule[] { arg0 };
         }
 
         throw new CoreException(new Status(IStatus.ERROR, 
"org.apache.sling.slingclipse", 0,
-                "Will only handle modules of type 'sling.content'", null));
+                "Will only handle modules of type 'sling.content' or 
'sling.bundle'", null));
     }
 
     /*
@@ -125,6 +129,7 @@ public class SlingLaunchpadServer extend
     public void setDefaults(IProgressMonitor monitor) {
 
         setAttribute(PROP_PORT, 8080);
+        setAttribute(PROP_DEBUG_PORT, 30303);
         setAttribute(PROP_CONTEXT_PATH, "/");
         setAttribute(PROP_USERNAME, "admin");
         setAttribute(PROP_PASSWORD, "admin");


Reply via email to