Author: hibou
Date: Fri Aug 22 06:29:11 2008
New Revision: 688080

URL: http://svn.apache.org/viewvc?rev=688080&view=rev
Log:
IVYDE-144:
* add a new context entry in the context menu to clean the caches
* the new menu entry offer different kind of cache cleaning:
** clean the resolution cache
** clean every repository cache
** clean each repository cache individually
** clean every cache

Added:
    
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheAction.java
   (with props)
    
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheMenuAction.java
   (with props)
Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml
    
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
    
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt?rev=688080&r1=688079&r2=688080&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt Fri Aug 22 
06:29:11 2008
@@ -7,6 +7,7 @@
 - NEW: Option to resolve to local eclipse projects (IVYDE-89) (thanks to 
Antony James Wilkins and Matt Goldspink)
 - NEW: Add errors marker to the Ivy container (IVYDE-78)
 - NEW: Handle a project: scheme for the path of the ivysettings.xml (IVYDE-94)
+- NEW: Need CleanCache task in context menu (IVYDE-114)
 
 - IMPROVE: Retrieve after resolve feature does not clean target directory 
first (IVYDE-105)
 

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml?rev=688080&r1=688079&r2=688080&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml Fri Aug 22 06:29:11 
2008
@@ -88,6 +88,16 @@
             class="org.apache.ivyde.eclipse.ui.actions.CreateContainerAction" 
             enablesFor="1"
                        /> 
+      </objectContribution>
+      <objectContribution
+            adaptable="false"
+            id="org.apache.ivyde.eclipse.ui.actions.CleanCacheMenuAction"
+            
objectClass="org.eclipse.jdt.internal.ui.packageview.ClassPathContainer">
+         <action
+               class="org.apache.ivyde.eclipse.ui.actions.CleanCacheMenuAction"
+               id="org.apache.ivyde.eclipse.ui.actions.CleanCacheMenuAction"
+               label="Clean Ivy cache">
+         </action>
       </objectContribution> 
    </extension> 
 

Modified: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java?rev=688080&r1=688079&r2=688080&view=diff
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
 (original)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
 Fri Aug 22 06:29:11 2008
@@ -32,7 +32,9 @@
 import org.apache.ivyde.eclipse.ui.preferences.PreferenceConstants;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.core.IJavaModel;
 import org.eclipse.jdt.core.IJavaProject;
@@ -231,6 +233,25 @@
     }
 
     /**
+     * Utility class that tries to adapt a non null object to the specified 
type
+     * 
+     * @param object
+     *            the object to adapt
+     * @param type
+     *            the class to adapt to
+     * @return the adapted object
+     */
+
+    public static /*<T> T*/ Object adapt(Object object, Class/*<T>*/ type) {
+        if (type.isInstance(object)) {
+            return /*(T)*/ object;
+        } else if (object instanceof IAdaptable) {
+            return /*(T)*/ ((IAdaptable) object).getAdapter(type);
+        }
+        return /*(T)*/ Platform.getAdapterManager().getAdapter(object, type);
+    }
+
+    /**
      * Returns the plugin's resource bundle,
      */
     public ResourceBundle getResourceBundle() {

Modified: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java?rev=688080&r1=688079&r2=688080&view=diff
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
 (original)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
 Fri Aug 22 06:29:11 2008
@@ -27,7 +27,6 @@
 
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jdt.core.IClasspathAttribute;
@@ -36,7 +35,7 @@
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations;
 import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
@@ -118,27 +117,15 @@
         }
         for (Iterator it = selection.iterator(); it.hasNext();) {
             Object element = it.next();
-            IvyClasspathContainer cp = null;
-            if (element instanceof IvyClasspathContainer) {
-                return (IvyClasspathContainer) element;
-            }
-            if (element instanceof IJavaProject) {
-                return getIvyClasspathContainer((IJavaProject) element);
-            }
-            if (element instanceof IAdaptable) {
-                cp = (IvyClasspathContainer) ((IAdaptable) element)
-                        .getAdapter(IvyClasspathContainer.class);
-                if (cp == null) {
-                    IJavaProject p = (IJavaProject) ((IAdaptable) element)
-                            .getAdapter(IJavaProject.class);
-                    if (p != null) {
-                        cp = getIvyClasspathContainer(p);
-                    }
-                }
-            }
+            IvyClasspathContainer cp = (IvyClasspathContainer) 
IvyPlugin.adapt(element,
+                IvyClasspathContainer.class);
             if (cp != null) {
                 return cp;
             }
+            IJavaProject project = (IJavaProject) IvyPlugin.adapt(element, 
IJavaProject.class);
+            if (project != null) {
+                return getIvyClasspathContainer(project);
+            }
             if (element instanceof ClassPathContainer) {
                 // FIXME: we shouldn't check against internal JDT API but 
there are not adaptable to
                 // useful class

Added: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheAction.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheAction.java?rev=688080&view=auto
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheAction.java
 (added)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheAction.java
 Fri Aug 22 06:29:11 2008
@@ -0,0 +1,86 @@
+/*
+ *  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.ivyde.eclipse.ui.actions;
+
+import org.apache.ivy.core.cache.RepositoryCacheManager;
+import org.apache.ivy.core.cache.ResolutionCacheManager;
+import org.apache.ivyde.eclipse.IvyPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.action.Action;
+
+public class CleanCacheAction extends Action {
+
+    private final Cleanable[] cleanables;
+
+    public static interface Cleanable {
+        public void clean();
+        public String getName();
+    }
+
+    public static class ResolutionCacheCleanable implements Cleanable {
+        private final ResolutionCacheManager manager;
+
+        public ResolutionCacheCleanable(ResolutionCacheManager manager) {
+            this.manager = manager;
+        }
+
+        public void clean() {
+            manager.clean();
+        }
+        
+        public String getName() {
+            return "resolution";
+        }
+    }
+
+    public static class RepositoryCacheCleanable implements Cleanable {
+        private final RepositoryCacheManager manager;
+
+        public RepositoryCacheCleanable(RepositoryCacheManager manager) {
+            this.manager = manager;
+        }
+
+        public void clean() {
+            manager.clean();
+        }
+        
+        public String getName() {
+            return manager.getName();
+        }
+    }
+
+    public CleanCacheAction(Cleanable cleanable) {
+        this.cleanables = new Cleanable[] { cleanable };
+    }
+
+    public CleanCacheAction(Cleanable[] cleanables) {
+        this.cleanables = cleanables;
+    }
+
+    public void run() {
+        StringBuilder builder = new StringBuilder("Ivy cache cleaned: ");
+        for (int i = 0; i < cleanables.length; i++) {
+            cleanables[i].clean();
+            builder.append(cleanables[i].getName());
+            if (i < cleanables.length - 1) {
+                builder.append(", ");
+            }
+        }
+        IvyPlugin.log(IStatus.INFO, builder.toString(), null);
+    }
+}

Propchange: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheMenuAction.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheMenuAction.java?rev=688080&view=auto
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheMenuAction.java
 (added)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheMenuAction.java
 Fri Aug 22 06:29:11 2008
@@ -0,0 +1,131 @@
+/*
+ *  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.ivyde.eclipse.ui.actions;
+
+import org.apache.ivy.Ivy;
+import org.apache.ivy.core.cache.RepositoryCacheManager;
+import org.apache.ivy.core.cache.ResolutionCacheManager;
+import org.apache.ivyde.eclipse.IvyDEException;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
+import org.apache.ivyde.eclipse.ui.actions.CleanCacheAction.Cleanable;
+import 
org.apache.ivyde.eclipse.ui.actions.CleanCacheAction.RepositoryCacheCleanable;
+import 
org.apache.ivyde.eclipse.ui.actions.CleanCacheAction.ResolutionCacheCleanable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuCreator;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2;
+
+public class CleanCacheMenuAction implements IObjectActionDelegate, 
IMenuCreator,
+        IWorkbenchWindowPulldownDelegate2 {
+
+    IStructuredSelection selection;
+
+    public void init(IWorkbenchWindow window) {
+    }
+
+    public void dispose() {
+    }
+
+    public Menu getMenu(Control parent) {
+        Menu menu = new Menu(parent);
+        fill(menu);
+        return menu;
+    }
+
+    public Menu getMenu(Menu parent) {
+        Menu menu = new Menu(parent);
+        fill(menu);
+        return menu;
+    }
+
+    private void fill(Menu menu) {
+        IvyClasspathContainer cp = 
IvyClasspathUtil.getIvyClasspathContainer(selection);
+        if (cp != null) {
+            try {
+                fill(menu, cp.getConf().getIvy());
+            } catch (IvyDEException e) {
+                e.log(IStatus.WARNING,
+                    "Cache delection actions in the context menu could not be 
populated. ");
+            }
+            return;
+        }
+    }
+
+    private void fill(Menu menu, Ivy ivy) {
+        ResolutionCacheManager resolutionCacheManager = ivy.getSettings()
+                .getResolutionCacheManager();
+        ResolutionCacheCleanable resolutionCacheCleanable = new 
ResolutionCacheCleanable(
+                resolutionCacheManager);
+
+        RepositoryCacheManager[] repositoryCacheManagers = ivy.getSettings()
+                .getRepositoryCacheManagers();
+        RepositoryCacheCleanable[] repositoryCacheCleanables = new 
RepositoryCacheCleanable[repositoryCacheManagers.length];
+        for (int i = 0; i < repositoryCacheManagers.length; i++) {
+            repositoryCacheCleanables[i] = new 
RepositoryCacheCleanable(repositoryCacheManagers[i]);
+        }
+
+        Cleanable[] all = new Cleanable[repositoryCacheManagers.length + 1];
+        all[0] = resolutionCacheCleanable;
+        System.arraycopy(repositoryCacheCleanables, 0, all, 1, 
repositoryCacheManagers.length);
+
+        add(menu, "All", all);
+        add(menu, "Resolution cache", resolutionCacheCleanable);
+        add(menu, "Every repository cache", repositoryCacheCleanables);
+        for (int i = 0; i < repositoryCacheManagers.length; i++) {
+            add(menu, "Cache '" + repositoryCacheManagers[i].getName() + "'",
+                repositoryCacheCleanables[i]);
+        }
+    }
+
+    public void add(Menu menu, String name, Cleanable[] cleanables) {
+        add(menu, name, new CleanCacheAction(cleanables));
+    }
+
+    public void add(Menu menu, String name, Cleanable cleanable) {
+        add(menu, name, new CleanCacheAction(cleanable));
+    }
+
+    public void add(Menu menu, String name, CleanCacheAction action) {
+        action.setText(name);
+        new ActionContributionItem(action).fill(menu, -1);
+    }
+
+    public void run(IAction action) {
+    }
+
+    public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+    }
+
+    public void selectionChanged(IAction action, ISelection selection) {
+        if (selection instanceof IStructuredSelection) {
+            this.selection = (IStructuredSelection) selection;
+            action.setMenuCreator(this);
+            action.setEnabled(!selection.isEmpty());
+        }
+    }
+
+}

Propchange: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheMenuAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheMenuAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/CleanCacheMenuAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to