You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ds...@apache.org on 2010/08/02 10:00:56 UTC

svn commit: r981398 - in /felix/trunk/sigil/eclipse/ui: plugin.properties plugin.xml src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorPackageParticipant.java

Author: dsavage
Date: Mon Aug  2 08:00:56 2010
New Revision: 981398

URL: http://svn.apache.org/viewvc?rev=981398&view=rev
Log:
add support for updating bundle activator on package rename (FELIX-2502)

Added:
    felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorPackageParticipant.java
Modified:
    felix/trunk/sigil/eclipse/ui/plugin.properties
    felix/trunk/sigil/eclipse/ui/plugin.xml

Modified: felix/trunk/sigil/eclipse/ui/plugin.properties
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/plugin.properties?rev=981398&r1=981397&r2=981398&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/ui/plugin.properties (original)
+++ felix/trunk/sigil/eclipse/ui/plugin.properties Mon Aug  2 08:00:56 2010
@@ -3,6 +3,7 @@ newtonRepoPrefs=Newton Repository
 librariesPrefsPage=OSGi Libraries
 commandConvertProject=Convert Project To Sigil Project
 commandRefreshClasspath=Refresh bundle classpath
+RenameActivatorPackageParticipant.name=Rename Activator Package Participant
 RenameActivatorParticipant.name=Rename Activator Participant
 RenamePackageParticipant.name=Rename Package Participant
 MoveActivatorParticipant.name=Move Activator Participant

Modified: felix/trunk/sigil/eclipse/ui/plugin.xml
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/plugin.xml?rev=981398&r1=981397&r2=981398&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/ui/plugin.xml (original)
+++ felix/trunk/sigil/eclipse/ui/plugin.xml Mon Aug  2 08:00:56 2010
@@ -289,6 +289,21 @@
          </with>
        </enablement>
      </renameParticipant>
+     <renameParticipant
+        id="org.apache.felix.sigil.movePackageParticipant"
+        name="%RenameActivatorPackageParticipant.name" 
+        class="org.apache.felix.sigil.ui.eclipse.refactor.RenameActivatorPackageParticipant">
+       <enablement>
+         <with variable="affectedNatures">
+           <iterate operator="or">
+             <equals value="org.apache.felix.sigil.sigilnature"/>
+           </iterate>
+         </with>
+         <with variable="element">
+           <instanceof value="org.eclipse.jdt.core.IPackageFragment"/>
+         </with>
+       </enablement>
+     </renameParticipant>
    </extension>  
    <extension point="org.eclipse.ltk.core.refactoring.moveParticipants">
      <moveParticipant

Added: felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorPackageParticipant.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorPackageParticipant.java?rev=981398&view=auto
==============================================================================
--- felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorPackageParticipant.java (added)
+++ felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorPackageParticipant.java Mon Aug  2 08:00:56 2010
@@ -0,0 +1,118 @@
+/*
+ * 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.felix.sigil.ui.eclipse.refactor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.felix.sigil.eclipse.SigilCore;
+import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.NullChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+
+public class RenameActivatorPackageParticipant extends RenameParticipant
+{
+    private IPackageFragment packageFragment;
+    private List<Change> changes = new LinkedList<Change>();
+
+    @Override
+    public RefactoringStatus checkConditions(IProgressMonitor monitor,
+        CheckConditionsContext ctx) throws OperationCanceledException
+    {
+        RefactoringStatus status = null;
+        if(getArguments().getUpdateReferences()) {
+            try
+            {
+                ISigilProjectModel sigil = SigilCore.create(packageFragment.getJavaProject().getProject());
+                RefactorUtil.touch(ctx, sigil);
+                
+                String oldName = sigil.getBundle().getBundleInfo().getActivator();
+                if ( oldName != null ) {
+                    String[] parts = splitPackageClass(oldName);
+                    if (parts[0].equals(packageFragment.getElementName())) {
+                        String newName = getArguments().getNewName() + "." + parts[1];
+                        changes.add(new BundleActivatorChange(sigil, oldName, newName));
+                        status = RefactoringStatus.createInfoStatus("Updating bundle activator from " + oldName + " to " + newName );
+                    }
+                }
+            }
+            catch (CoreException e)
+            {
+                SigilCore.warn("Failed to update activator", e);
+            }
+        }
+        
+        return status;
+    }
+
+    private static String[] splitPackageClass(String className)
+    {
+        String[] parts = new String[2];
+        int i = className.lastIndexOf('.');
+        if ( i == -1 ) {
+            parts[0] = "";
+            parts[1] = className;
+        }
+        else {
+            parts[0] = className.substring(0, i);
+            parts[1] = className.substring(i + 1);
+        }
+        return parts;
+    }
+
+    @Override
+    public Change createChange(IProgressMonitor monitor) throws CoreException,
+        OperationCanceledException
+    {
+        if (changes.isEmpty()) {
+            return new NullChange();
+        }
+        else 
+        {
+            CompositeChange ret = new CompositeChange("Export-Package update");
+            
+            ret.addAll(changes.toArray(new Change[changes.size()]));
+            
+            return ret;
+        }
+    }
+
+    @Override
+    public String getName()
+    {        
+        return "Sigil Rename Activator Package Participant";
+    }
+
+    @Override
+    protected boolean initialize(Object element)
+    {
+        packageFragment = (IPackageFragment) element;
+        return true;
+    }
+
+}