incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1412046 - in /sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin: ./ src/org/apache/sling/slingclipse/ src/org/apache/sling/slingclipse/internal/
Date Wed, 21 Nov 2012 10:38:49 GMT
Author: asanso
Date: Wed Nov 21 10:38:48 2012
New Revision: 1412046

URL: http://svn.apache.org/viewvc?rev=1412046&view=rev
Log:
SLING-2660 -  [Tooling] Add a Sling project nature to control projects being synchronized.
Applying patch from Robert Munteanu, Thanks

Added:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/AddSlingNatureAction.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectBuilder.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectNature.java
Modified:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml?rev=1412046&r1=1412045&r2=1412046&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml (original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml Wed Nov 21 10:38:48
2012
@@ -19,12 +19,6 @@
       </initializer>
    </extension>
    <extension
-         point="org.eclipse.ui.startup">
-      <startup
-            class="org.apache.sling.slingclipse.SlingclipseStrartup">
-      </startup>
-   </extension>
-   <extension
          point="org.eclipse.ui.importWizards">
       <category
             id="org.apache.sling.slingclipse.ui.wizards.sampleCategory"
@@ -41,4 +35,53 @@
          </description>
       </wizard>
    </extension>
+   <extension
+         id="org.apache.sling.slingclipse.SlingProjectNature"
+         point="org.eclipse.core.resources.natures">
+      <runtime>
+         <run class="org.apache.sling.slingclipse.internal.SlingProjectNature"/>
+      </runtime>
+      <builder
+            id="org.apache.sling.slingclipse.SlingProjectBuilder">
+      </builder>
+   </extension>
+   <extension
+         point="org.eclipse.ui.popupMenus">
+      <objectContribution
+            id="org.apache.sling.slingclipse.convertToSlingProject"
+            objectClass="org.eclipse.core.resources.IProject">
+         <action
+               class="org.apache.sling.slingclipse.internal.AddSlingNatureAction"
+               id="org.apache.sling.slingclipse.enableNatureAction"
+               label="Convert to Sling Project"
+               menubarPath="org.eclipse.ui.projectConfigure/additions"
+               style="push">
+         </action>
+         <visibility>
+            <and>
+               <objectState
+                     name="open"
+                     value="true">
+               </objectState>
+               <not>
+                  <objectState
+                        name="nature"
+                        value="org.apache.sling.slingclipse.SlingProjectNature">
+                  </objectState>
+               </not>
+            </and>
+         </visibility>
+      </objectContribution>
+   </extension>
+   <extension
+         id="org.apache.sling.slingclipse.SlingProjectBuilder"
+         name="Sling Project Builder"
+         point="org.eclipse.core.resources.builders">
+      <builder
+            hasNature="true">
+            <run
+                  class="org.apache.sling.slingclipse.internal.SlingProjectBuilder">
+            </run>
+      </builder>
+   </extension>
 </plugin>

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java?rev=1412046&r1=1412045&r2=1412046&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java
Wed Nov 21 10:38:48 2012
@@ -33,6 +33,7 @@ import org.apache.sling.slingclipse.api.
 import org.apache.sling.slingclipse.api.RepositoryInfo;
 import org.apache.sling.slingclipse.api.Result;
 import org.apache.sling.slingclipse.helper.SlingclipseHelper;
+import org.apache.sling.slingclipse.internal.SlingProjectNature;
 import org.apache.sling.slingclipse.preferences.PreferencesMessages;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceChangeEvent;
@@ -63,7 +64,7 @@ public class SlingclipseListener impleme
 		}
 	}
 
-	protected IResourceDeltaVisitor buildVisitor() {
+    public IResourceDeltaVisitor buildVisitor() {
 		IResourceDeltaVisitor result = new IResourceDeltaVisitor() {
 
 			@Override
@@ -71,12 +72,14 @@ public class SlingclipseListener impleme
 				
 				try {
 					return visitInternal(delta);
+                } catch (CoreException e) {
+                    throw e;
 				} catch ( Exception e) {
 					throw new CoreException(new Status(Status.ERROR, SlingclipsePlugin.PLUGIN_ID, "Failed
visiting resource based on delta " + delta, e));
 				}
 			}
 
-			private boolean visitInternal(IResourceDelta delta) throws IOException, JSONException
{
+            private boolean visitInternal(IResourceDelta delta) throws IOException, JSONException,
CoreException {
 				IPreferenceStore store = SlingclipsePlugin.getDefault().getPreferenceStore();
 				
 				// since the listener is disabled, instruct it not to recurse for changes
@@ -92,6 +95,10 @@ public class SlingclipseListener impleme
 				
 				IResource resource = delta.getResource();
 				
+                // if the project is not a Sling project skip processing and do not try to
recurse
+                if (!resource.getProject().getDescription().hasNature(SlingProjectNature.SLING_NATURE_ID))
+                    return false;
+
 				// don't process unhandled ( PROJECT, WORKSPACE ) resources but recurse if needed
 				if ( resource.getType() != IResource.FILE && resource.getType() != IResource.FOLDER){
 					return true;

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java?rev=1412046&r1=1412045&r2=1412046&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java
Wed Nov 21 10:38:48 2012
@@ -18,8 +18,6 @@ package org.apache.sling.slingclipse;
 
 import org.apache.sling.slingclipse.api.Repository;
 import org.apache.sling.slingclipse.helper.Tracer;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
@@ -35,20 +33,11 @@ public class SlingclipsePlugin extends A
 	// The shared instance
 	private static SlingclipsePlugin plugin;
 
-	private IResourceChangeListener listener;
-
 	//TODO is fine to be static?
 	private static Repository repository;
 	
 	private Tracer tracer;
 
-	/**
-	 * The constructor
-	 */
-	public SlingclipsePlugin() {
-		listener= new SlingclipseListener();
-	}
-
 	/*
 	 * (non-Javadoc)
 	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
@@ -56,7 +45,6 @@ public class SlingclipsePlugin extends A
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
 		plugin = this;
-		ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
 		tracer = new Tracer();
 		tracer.register(getBundle().getBundleContext());
 	}
@@ -68,7 +56,6 @@ public class SlingclipsePlugin extends A
 	public void stop(BundleContext context) throws Exception {
 		plugin = null;
 		super.stop(context);
-		ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
 		tracer.unregister();
 	}
 

Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/AddSlingNatureAction.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/AddSlingNatureAction.java?rev=1412046&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/AddSlingNatureAction.java
(added)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/AddSlingNatureAction.java
Wed Nov 21 10:38:48 2012
@@ -0,0 +1,114 @@
+/*
+ * 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.slingclipse.internal;
+
+import java.util.Iterator;
+
+import org.apache.sling.slingclipse.SlingclipsePlugin;
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class AddSlingNatureAction implements IObjectActionDelegate, IExecutableExtension
{
+
+    private ISelection selection;
+
+    @Override
+    public void run(IAction action) {
+        if (!(selection instanceof IStructuredSelection)) {
+            return;
+        }
+
+        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+
+        try {
+            for (Iterator<?> it = structuredSelection.iterator(); it.hasNext();) {
+                Object selected = it.next();
+                if (selected instanceof IProject) {
+                    IProject project = (IProject) selected;
+
+                    IProjectDescription description = project.getDescription();
+
+                    addSlingNature(description);
+                    addSlingBuilder(description);
+                    
+                    project.setDescription(description, null);
+                }
+            }
+        } catch (CoreException e) {
+            ErrorDialog.openError(null, "Error occurred while adding the sling nature", e.getMessage(),
e.getStatus());
+            SlingclipsePlugin.getDefault().getLog().log(e.getStatus());
+        }
+    }
+
+    private void addSlingNature(IProjectDescription description) {
+        String[] currentNatureIds = description.getNatureIds();
+        String[] newNatureIds = new String[currentNatureIds.length + 1];
+        System.arraycopy(currentNatureIds, 0, newNatureIds, 0, currentNatureIds.length);
+        newNatureIds[currentNatureIds.length] = SlingProjectNature.SLING_NATURE_ID;
+
+        description.setNatureIds(newNatureIds);
+    }
+
+    private void addSlingBuilder(IProjectDescription description) {
+        boolean addBuilder = true;
+        ICommand[] currentBuilders = description.getBuildSpec();
+        for ( ICommand command : currentBuilders ) {
+            if ( command.getBuilderName().equals(SlingProjectBuilder.SLING_BUILDER_ID) )
{
+                addBuilder = false;
+                break;
+            }
+        }
+        
+        if (!addBuilder)
+            return;
+
+        ICommand newBuilder = description.newCommand();
+        newBuilder.setBuilderName(SlingProjectBuilder.SLING_BUILDER_ID);
+
+        ICommand[] newBuilders = new ICommand[currentBuilders.length + 1];
+        newBuilders[currentBuilders.length] = newBuilder;
+        description.setBuildSpec(newBuilders);
+    }
+
+
+    @Override
+    public void selectionChanged(IAction action, ISelection selection) {
+
+        this.selection = selection;
+    }
+
+    @Override
+    public void setInitializationData(IConfigurationElement config, String propertyName,
Object data)
+            throws CoreException {
+        // nothing to do
+    }
+
+    @Override
+    public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+        // nothing to do
+    }
+}

Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectBuilder.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectBuilder.java?rev=1412046&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectBuilder.java
(added)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectBuilder.java
Wed Nov 21 10:38:48 2012
@@ -0,0 +1,61 @@
+/*************************************************************************
+ *
+ * ADOBE CONFIDENTIAL
+ * __________________
+ *
+ *  Copyright 2012 Adobe Systems Incorporated
+ *  All Rights Reserved.
+ *
+ * NOTICE:  All information contained herein is, and remains
+ * the property of Adobe Systems Incorporated and its suppliers,
+ * if any.  The intellectual and technical concepts contained
+ * herein are proprietary to Adobe Systems Incorporated and its
+ * suppliers and are protected by trade secret or copyright law.
+ * Dissemination of this information or reproduction of this material
+ * is strictly forbidden unless prior written permission is obtained
+ * from Adobe Systems Incorporated.
+ **************************************************************************/
+package org.apache.sling.slingclipse.internal;
+
+import java.util.Map;
+
+import org.apache.sling.slingclipse.SlingclipseListener;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class SlingProjectBuilder extends IncrementalProjectBuilder {
+
+    public static final String SLING_BUILDER_ID = "org.apache.sling.slingclipse.SlingProjectBuilder";
+
+    private static final IProject[] EMPTY_PROJECT_ARRAY = new IProject[0];
+
+    @Override
+    protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor
monitor) throws CoreException {
+        
+        switch (kind) {
+            case IncrementalProjectBuilder.AUTO_BUILD:
+            case IncrementalProjectBuilder.INCREMENTAL_BUILD:
+                return buildInternal(monitor);
+        }
+        
+        return EMPTY_PROJECT_ARRAY;
+
+    }
+
+    private IProject[] buildInternal(IProgressMonitor monitor) throws CoreException {
+        SlingclipseListener listener = new SlingclipseListener();
+
+        IResourceDelta delta = getDelta(getProject());
+
+        if (delta == null) {
+            return EMPTY_PROJECT_ARRAY;
+        }
+
+        delta.accept(listener.buildVisitor());
+
+        return new IProject[] { delta.getResource().getProject() };
+    }
+}

Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectNature.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectNature.java?rev=1412046&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectNature.java
(added)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/internal/SlingProjectNature.java
Wed Nov 21 10:38:48 2012
@@ -0,0 +1,49 @@
+/*
+ * 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.slingclipse.internal;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+
+public class SlingProjectNature implements IProjectNature {
+
+    public static final String SLING_NATURE_ID = "org.apache.sling.slingclipse.SlingProjectNature";
+
+    private IProject project;
+
+    @Override
+    public void configure() throws CoreException {
+
+    }
+
+    @Override
+    public void deconfigure() throws CoreException {
+    }
+
+    @Override
+    public IProject getProject() {
+        return project;
+    }
+
+    @Override
+    public void setProject(IProject project) {
+
+        this.project = project;
+    }
+
+}



Mime
View raw message