ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r988124 - /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
Date Mon, 23 Aug 2010 13:57:44 GMT
Author: hibou
Date: Mon Aug 23 13:57:43 2010
New Revision: 988124

URL: http://svn.apache.org/viewvc?rev=988124&view=rev
Log:
IVYDE-56
 * when reading old conf, recreate the container so so won't apply the migration each time
we open the project 

Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java?rev=988124&r1=988123&r2=988124&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
Mon Aug 23 13:57:43 2010
@@ -17,6 +17,10 @@
  */
 package org.apache.ivyde.eclipse.cpcontainer;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
@@ -29,6 +33,7 @@ import org.eclipse.jdt.core.IClasspathEn
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.swt.widgets.Display;
 
 /**
  * Initializer the ivy class path container. It will create a container from the persisted
class
@@ -55,37 +60,46 @@ public class IvyClasspathInitializer ext
                 container = JavaCore.getClasspathContainer(containerPath, project);
             } catch (JavaModelException ex) {
                 // unless there are issues with the JDT, this should never happen
-                IvyPlugin.log(IStatus.ERROR, "Unable to get container for "
-                        + containerPath.toString(), ex);
+                IvyPlugin.log(IStatus.ERROR,
+                    "Unable to get container for " + containerPath.toString(), ex);
                 return;
             }
 
             try {
                 IvyClasspathContainer ivycp;
+                IClasspathEntry entry = IvyClasspathUtil.getIvyClasspathEntry(containerPath,
+                    project);
+                IClasspathAttribute[] attributes;
+                boolean exported;
+                if (entry != null) {
+                    attributes = entry.getExtraAttributes();
+                    exported = entry.isExported();
+                } else {
+                    exported = false;
+                    attributes = new IClasspathAttribute[0];
+                }
 
                 if (container instanceof IvyClasspathContainer) {
                     ivycp = (IvyClasspathContainer) container;
                 } else {
-
-                    IClasspathEntry entry =
-                            IvyClasspathUtil.getIvyClasspathEntry(containerPath, project);
-                    IClasspathAttribute[] attributes = new IClasspathAttribute[0];
-                    if (entry != null) {
-                        attributes = entry.getExtraAttributes();
-                    }
-
                     if (container == null) {
                         ivycp = new IvyClasspathContainer(project, containerPath,
                                 new IClasspathEntry[0], attributes);
                     } else {
                         // this might be the persisted one : reuse the persisted entries
-                        ivycp = new IvyClasspathContainer(project, containerPath, container
-                                .getClasspathEntries(), attributes);
-                    }                    
+                        ivycp = new IvyClasspathContainer(project, containerPath,
+                                container.getClasspathEntries(), attributes);
+                    }
                 }
 
-                // set the container
-                JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project},
+                // recompute the path as it may have been "upgraded"
+                IPath updatedPath = IvyClasspathContainerConfAdapter.getPath(ivycp.getConf());
+                if (!updatedPath.equals(containerPath)) {
+                    updateIvyDEContainerPath(project, entry, attributes, exported, updatedPath);
+                    return;
+                }
+
+                JavaCore.setClasspathContainer(updatedPath, new IJavaProject[] {project},
                     new IClasspathContainer[] {ivycp}, null);
 
                 int startupMode = IvyPlugin.getPreferenceStoreHelper().getResolveOnStartup();
@@ -104,6 +118,34 @@ public class IvyClasspathInitializer ext
         }
     }
 
+    private void updateIvyDEContainerPath(final IJavaProject project, final IClasspathEntry
entry,
+            final IClasspathAttribute[] attributes, final boolean exported, final IPath updatedPath)
{
+        Display.getDefault().asyncExec(new Runnable() {
+            public void run() {
+                try {
+                    // update the classpath of the project by updating the IvyDE container
+                    IClasspathEntry newEntry = JavaCore.newContainerEntry(updatedPath, null,
+                        attributes, exported);
+                    IClasspathEntry[] entries;
+                    entries = project.getRawClasspath();
+                    List newEntries = new ArrayList(Arrays.asList(entries));
+                    for (int i = 0; i < newEntries.size(); i++) {
+                        IClasspathEntry e = (IClasspathEntry) newEntries.get(i);
+                        if (e == entry) {
+                            newEntries.set(i, newEntry);
+                            break;
+                        }
+                    }
+                    entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries
+                            .size()]);
+                    project.setRawClasspath(entries, project.getOutputLocation(), null);
+                } catch (JavaModelException e) {
+                    IvyPlugin.log(IStatus.ERROR, "Unale to update the container path", e);
+                }
+            }
+        });
+    }
+
     public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project)
{
         return false;
     }



Mime
View raw message