Author: xavier
Date: Mon Nov 19 06:09:19 2007
New Revision: 596306

URL: http://svn.apache.org/viewvc?rev=596306&view=rev
Log:
FIX: On startup IvyIDE can freeze eclipse (IVYDE-63) (thanks to Nicolas Lalevée)

Modified:
    incubator/ivy/ivyde/trunk/CHANGES.txt
    
incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
    
incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java

Modified: incubator/ivy/ivyde/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/ivy/ivyde/trunk/CHANGES.txt?rev=596306&r1=596305&r2=596306&view=diff
==============================================================================
--- incubator/ivy/ivyde/trunk/CHANGES.txt (original)
+++ incubator/ivy/ivyde/trunk/CHANGES.txt Mon Nov 19 06:09:19 2007
@@ -10,6 +10,7 @@
 
 - FIX: "Add Ivy library" not working in eclipse 3.3 (IVYDE-57)
 - FIX: Automatic javadoc attachment is not working (IVYDE-55)
+- FIX: On startup IvyIDE can freeze eclipse (IVYDE-63) (thanks to Nicolas 
Lalevée)
 
 - moved to apache, packages renamed to org.apache.ivyde
                                

Modified: 
incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java?rev=596306&r1=596305&r2=596306&view=diff
==============================================================================
--- 
incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
 (original)
+++ 
incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
 Mon Nov 19 06:09:19 2007
@@ -43,7 +43,6 @@
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
@@ -457,18 +456,31 @@
        private IvyResolveJob _job;
 
 
-       public IvyClasspathContainer(IJavaProject javaProject, IPath path, 
String ivyFile, String[] confs ) {
+       /**
+     * Create an Ivy class path container from some predefined classpath 
entries. The provided class
+     * path entries should come from the default "persisted" classpath 
container. Note that no
+     * resolve nor resolve are exectued here, so some inconsistencies might 
exist between the
+     * ivy.xml and the provided classpath entries.
+     * 
+     * @param javaProject
+     *            the project of containing this container
+     * @param path
+     *            the path the project
+     * @param ivyFile
+     *            the path to the ivy file
+     * @param confs
+     *            the configuration that will be resolved
+     * @param classpathEntries
+     *            the entries to start with
+     */
+       public IvyClasspathContainer(IJavaProject javaProject, IPath path, 
String ivyFile, String[] confs, IClasspathEntry[] classpathEntries ) {
                _javaProject = javaProject;
         _path = path;
                
         _ivyXmlPath = ivyFile;
                _ivyXmlFile = resolveFile( ivyFile );
-        _confs = confs;   
-        //do  execute this job in current thread 
-        computeClasspathEntries(true, false).run(new NullProgressMonitor());
-        if (_classpathEntries == null) {
-            _classpathEntries = new IClasspathEntry[0];
-        }
+        _confs = confs;
+        _classpathEntries = classpathEntries;
         IvyPlugin.getDefault().register(this);
        }
        

Modified: 
incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java?rev=596306&r1=596305&r2=596306&view=diff
==============================================================================
--- 
incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
 (original)
+++ 
incubator/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
 Mon Nov 19 06:09:19 2007
@@ -5,7 +5,7 @@
 import 
org.apache.ivyde.eclipse.cpcontainer.fragmentinfo.IPackageFragmentExtraInfo;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.core.ClasspathContainerInitializer;
 import org.eclipse.jdt.core.IClasspathContainer;
 import org.eclipse.jdt.core.IClasspathEntry;
@@ -16,28 +16,53 @@
 import org.eclipse.swt.widgets.Display;
 
 /**
- *
+ * Initializer the ivy class path container.
+ * 
+ * TODO : start the dependency resolving in the background, with the errors
+ * popuping more than getting silently logged
  */
 public class IvyClasspathInitializer extends ClasspathContainerInitializer {
 
-       /* (non-Javadoc)
-        * @see 
org.eclipse.jdt.core.ClasspathContainerInitializer#initialize(org.eclipse.core.runtime.IPath,
 org.eclipse.jdt.core.IJavaProject)
-        */
+    /**
+     * Initialize the container with the "persisted" class path entries, and 
then schedule the
+     * refresh
+     */
        public void initialize(IPath containerPath, IJavaProject project) 
throws CoreException {
         if (IvyClasspathContainer.isIvyClasspathContainer(containerPath)) {
-           try {
-                String ivyFilePath = 
IvyClasspathContainer.getIvyFilePath(containerPath);
-                String[] confs = 
IvyClasspathContainer.getConfigurations(containerPath);
-                IClasspathContainer ivyClasspathContainer = 
(IClasspathContainer)JavaCore.getClasspathContainer(containerPath, project);
-                if (!(ivyClasspathContainer instanceof IvyClasspathContainer)) 
{
-                    ivyClasspathContainer = new IvyClasspathContainer( 
project, containerPath, ivyFilePath, confs );
-                }
-                JavaCore.setClasspathContainer(containerPath, new 
IJavaProject[] { project },   new IClasspathContainer[] { ivyClasspathContainer 
}, null);
-            } catch (JavaModelException e) {
-                e.printStackTrace();
+            String ivyFilePath = 
IvyClasspathContainer.getIvyFilePath(containerPath);
+            String[] confs = 
IvyClasspathContainer.getConfigurations(containerPath);
+
+            // try to get an existing one
+            IClasspathContainer container = null;
+            try {
+                container = JavaCore.getClasspathContainer(containerPath, 
project);
+            } catch (JavaModelException ex) {
+                IvyPlugin.log(IStatus.ERROR, "Unable to get container for "
+                        + containerPath.toString(), ex);
+                return;
+            }
+
+            if (container == null) {
+                container = new IvyClasspathContainer(project, containerPath, 
ivyFilePath, confs,
+                        new IClasspathEntry[0]);
+            } else if (!(container instanceof IvyClasspathContainer)) {
+                // this might be the persisted one : reuse the persisted 
entries
+                container = new IvyClasspathContainer(project, containerPath, 
ivyFilePath, confs,
+                        container.getClasspathEntries());
             }
+
+            try {
+                JavaCore.setClasspathContainer(containerPath, new 
IJavaProject[] {project},
+                    new IClasspathContainer[] {container}, null);
+            } catch (JavaModelException ex) {
+                IvyPlugin.log(IStatus.ERROR, "Unable to set container for "
+                        + containerPath.toString(), ex);
+            }
+
+            // now refresh the container to be synchronized with the ivy.xml
+            ((IvyClasspathContainer) container).refresh();
         }
-       }
+    }
 
 
 


Reply via email to