Index: src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
===================================================================
--- src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java	(révision 595956)
+++ src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java	(copie de travail)
@@ -1,6 +1,5 @@
 package org.apache.ivyde.eclipse.cpcontainer;
 
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -10,10 +9,8 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -29,12 +26,11 @@
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.core.module.descriptor.DefaultArtifact;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
-import org.apache.ivy.core.module.id.ModuleId;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry;
-import org.apache.ivy.plugins.report.XmlReportParser;
 import org.apache.ivy.plugins.repository.TransferEvent;
 import org.apache.ivy.plugins.repository.TransferListener;
 import org.apache.ivy.util.Message;
@@ -60,10 +56,8 @@
 import org.eclipse.jdt.internal.core.JavaModelManager;
 import org.eclipse.swt.widgets.Display;
 
-
 /**
- *   
- * 
+ * Eclipse classpath container that will contain the ivy resolved entries.
  */
 public class IvyClasspathContainer implements IClasspathContainer {
 
@@ -155,100 +149,69 @@
 
         			_monitor.beginTask("resolving dependencies", 1000);
 					_monitor.setTaskName("resolving dependencies...");
-        			//context Classloader hook for commonlogging used by httpclient  
-        			ClassLoader old = Thread.currentThread().getContextClassLoader();
-        			List problemMessages = Collections.EMPTY_LIST;
-        			ModuleDescriptor md = null;
-        			try {
+
+                    ResolveReport report;
+                    ModuleRevisionId mrid;
+
+                    //context Classloader hook for commonlogging used by httpclient  
+                    ClassLoader old = Thread.currentThread().getContextClassLoader();
+                    try {
         				Thread.currentThread().setContextClassLoader(IvyClasspathContainer.class.getClassLoader());
-        				final URL ivyURL = _ivyXmlFile.toURL();
-        				String[] confs;
-        				boolean resolved = false;
+
+                        final URL ivyURL = _ivyXmlFile.toURL();
+                        Message.info("\n\nIVYDE: calling resolve on " + ivyURL + "\n");
+
+                        ResolveOptions options = new ResolveOptions();
+                        options.setConfs(_confs);
         				try {
+        				    report = _ivy.resolve(ivyURL, options);
+                        } catch (FileNotFoundException e) {
+                            String errorMsg = "ivy file not found: " + _ivyXmlFile
+                                    + "\nPlease configure your IvyDE ClasspathContainer properly";
+                            Message.error(errorMsg);
+                            status[0] = new Status(Status.ERROR, IvyPlugin.ID, Status.ERROR, errorMsg, e);
+                            return;
+                        } catch (ParseException e) {
+                            String errorMsg = "parse exception in: " + _ivyXmlFile + "\n"
+                                    + e.getMessage();
+                            Message.error(errorMsg);
+                            status[0] = new Status(Status.ERROR, IvyPlugin.ID, Status.ERROR, errorMsg, e);
+                            return;
+                        } finally {
+                            Thread.currentThread().setContextClassLoader(old);
+                        }
 
-        					if (_usePreviousResolveIfExist) {
-        						md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(_ivy.getSettings(), ivyURL, false);
-        						if (_confs.length == 1 && "*".equals(_confs[0])) {
-        							confs = md.getConfigurationsNames();
-        						} else {
-        							confs = _confs;
-        						}
+                        if (_monitor.isCanceled()) {
+                            status[0] = Status.CANCEL_STATUS;
+                            return;
+                        }
 
-        						// we check if all required configurations have been resolved
-        						for (int i = 0; i < confs.length; i++) {
-        							File report = 
-        									_cacheMgr
-        									.getConfigurationResolveReportInCache(
-        											ResolveOptions.getDefaultResolveId(md), 
-        											confs[i]);
-        							if (!report.exists()) {
-        								// no resolve previously done for at least one conf... we do it now
-        								Message.info("\n\nIVY DE: previous resolve of " + md.getModuleRevisionId().getModuleId() + " doesn't contain enough data: resolving again\n");
-        								ResolveReport r = _ivy.resolve(ivyURL, new ResolveOptions().setConfs(_confs));
-        								resolved = true;
-        								confs = r.getConfigurations();
-                						//eventually do a retrieve
-                						if(IvyPlugin.shouldDoRetrieve(_javaProject)) {
-                							_monitor.setTaskName("retrieving dependencies in "+IvyPlugin.getFullRetrievePatternHerited(_javaProject));
-                							_ivy.retrieve(
-                									md.getModuleRevisionId(), 
-                									IvyPlugin.getFullRetrievePatternHerited(_javaProject), 
-                									new RetrieveOptions().setConfs(confs));
-                						}
-        								break;
-        							}
-        						}
-        					} else {
-        						Message.info("\n\nIVYDE: calling resolve on " + ivyURL + "\n");
-        						ResolveReport report = _ivy.resolve(ivyURL, new ResolveOptions().setConfs(_confs));
-        						problemMessages = report.getAllProblemMessages();
-        						confs = report.getConfigurations();
-        						md = report.getModuleDescriptor();
-        						resolved = true;
+                        mrid = report.getModuleDescriptor().getModuleRevisionId();
 
-        						if (_monitor.isCanceled()) {
-        							status[0] = Status.CANCEL_STATUS;
-        							return;
-        						}
-        						// call retrieve if required
-        						if(IvyPlugin.shouldDoRetrieve(_javaProject)) {
-        							_monitor.setTaskName("retrieving dependencies in "+IvyPlugin.getFullRetrievePatternHerited(_javaProject));
-        							_ivy.retrieve(
-        									md.getModuleRevisionId(), 
-        									IvyPlugin.getFullRetrievePatternHerited(_javaProject),
-        									new RetrieveOptions().setConfs(confs));
-        						}
-        					}
-        				} catch (FileNotFoundException e) {
-        					String errorMsg = "ivy file not found: "+_ivyXmlFile+"\nPlease configure your IvyDE ClasspathContainer properly";
-            				Message.error(errorMsg);
-							status[0] = new Status(Status.ERROR, IvyPlugin.ID, Status.ERROR, errorMsg, e);
-        					return;
-        				} catch (ParseException e) {
-        					String errorMsg = "parse exception in: "+_ivyXmlFile+"\n"+e.getMessage();
-            				Message.error(errorMsg);
-							status[0] = new Status(Status.ERROR, IvyPlugin.ID, Status.ERROR, errorMsg, e);
-        					return;
-        				} finally {
-        					Thread.currentThread().setContextClassLoader(old);
-        				}
-        				ModuleId mid = md.getModuleRevisionId().getModuleId();
+                        // call retrieve if required
+                        if (IvyPlugin.shouldDoRetrieve(_javaProject)) {
+                            _monitor.setTaskName("retrieving dependencies in "
+                                    + IvyPlugin.getFullRetrievePatternHerited(_javaProject));
+                            RetrieveOptions o = new RetrieveOptions();
+                            o.setConfs(_confs);
+                            _ivy.retrieve(report.getModuleDescriptor().getModuleRevisionId(),
+                                IvyPlugin.getFullRetrievePatternHerited(_javaProject), o);
+                        }
 
-        				try {
-        					if (!resolved) {
-        						Message.info("\n\nIVY DE: using cached data of previous resolve of "+md.getModuleRevisionId().getModuleId()+"\n");
-        					}
-        					classpathItems[0] = parseResolvedConfs(confs, mid);
-        				} catch (Exception ex) {
-        					if (!resolved) {
-        						//maybe this is a problem with the cache, we retry with an actual resolve
-        						Message.info("\n\nIVYDE: tryed to build classpath from cache, but files seemed to be corrupted... trying with an actual resolve");
-        						ResolveReport report = _ivy.resolve(ivyURL, new ResolveOptions().setConfs(_confs));
-        						classpathItems[0] = parseResolvedConfs(report.getConfigurations(), mid);
-        					}
-        				}
-        			} catch (Exception e) {
-        				String errorMsg = "An internal error occured while resolving dependencies of "+_ivyXmlFile+"\nPlease see eclipse error log and IvyConsole for details";
+                        if (_monitor.isCanceled()) {
+                            status[0] = Status.CANCEL_STATUS;
+                            return;
+                        }
+
+                        // now try to get path to contruct the classpath entries
+                        // and also try to attach the source and the javadocs
+                        List all = report.getArtifacts();
+                        classpathItems[0] = getClasspathEntries(report.getArtifacts());
+
+                    } catch (Exception e) {
+        				String errorMsg = "An internal error occured while resolving dependencies of "
+                                + _ivyXmlFile
+                                + "\nPlease see eclipse error log and IvyConsole for details";
         				Message.error(errorMsg);
 						status[0] = new Status(Status.ERROR, IvyPlugin.ID, Status.ERROR, errorMsg, e);
         				return;
@@ -256,14 +219,16 @@
         				_monitor.done();
             			_ivy.getEventManager().removeIvyListener(IvyResolveJob.this);
         			}
-        			
-	    			if (!problemMessages.isEmpty()) {
+
+	    			if (!report.getAllProblemMessages().isEmpty()) {
 	    				StringBuffer problems = new StringBuffer();
-	    				for (Iterator iter = problemMessages.iterator(); iter.hasNext();) {
+	    				for (Iterator iter = report.getAllProblemMessages().iterator(); iter.hasNext();) {
 							String msg = (String) iter.next();
 							problems.append(msg).append("\n");
 						}
-	    				status[0] = new Status(Status.ERROR, IvyPlugin.ID, Status.ERROR, "Impossible to resolve dependencies of "+md.getModuleRevisionId()+":\n"+problems+"\nSee IvyConsole for further details", null);
+	    				status[0] = new Status(Status.ERROR, IvyPlugin.ID, Status.ERROR,
+                                "Impossible to resolve dependencies of " + mrid + ":\n" + problems
+                                        + "\nSee IvyConsole for further details", null);
 	    				return;
 	    			} else {
 	    				status[0] = Status.OK_STATUS;
@@ -271,7 +236,7 @@
 	    			}
         		}
         	};
-        	
+
         	try {
         		resolver.start();
         		while (true) {
@@ -305,36 +270,57 @@
 
         }
 
-		private ClasspathItem[] parseResolvedConfs(String[] confs, ModuleId mid) throws ParseException, IOException {
-			ClasspathItem[] classpathItems;
-            Collection all = new LinkedHashSet();
-            String resolveId = ResolveOptions.getDefaultResolveId(mid);
-            for (int i = 0; i < confs.length; i++) {
-            	XmlReportParser parser = new XmlReportParser();
-            	File report = _cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]);
-            	parser.parse(report);
-                Artifact[] artifacts = parser.getArtifacts();
-                all.addAll(Arrays.asList(artifacts));
+        private ClasspathItem[] getClasspathEntries(Collection all) {
+            Map sources = getSourcesArtifacts(all);
+            Map javadocs = getJavadocArtifacts(all);
+            Collection files = new ArrayList();
+            for (Iterator iter = all.iterator(); iter.hasNext();) {
+                Artifact a = (Artifact) iter.next();
+                if (IvyPlugin.accept(_javaProject, a)) {
+                    File sourcesArtifact = getPathOfArtifactType(a, sources, "source", "sources");
+                    File javadocArtifact = getPathOfArtifactType(a, javadocs, "javadoc", "javadoc");
+                    files.add(new ClasspathItem(_cacheMgr.getArchiveFileInCache(a),
+                            sourcesArtifact, javadocArtifact));
+                }
             }
-            Collection files = new LinkedHashSet();
+
+            return (ClasspathItem[]) files.toArray(new ClasspathItem[files.size()]);
+        }
+
+        private Map getSourcesArtifacts(Collection all) {
+            Map sources = new HashMap();
             for (Iterator iter = all.iterator(); iter.hasNext();) {
-                Artifact artifact = (Artifact)iter.next();
-                if (IvyPlugin.accept(_javaProject, artifact)) {
-                	File sourcesArtifact = getSourcesArtifact(artifact, all);
-                	File javadocArtifact = getJavadocArtifact(artifact, all);
-                	files.add(new ClasspathItem(
-                			_cacheMgr.getArchiveFileInCache(artifact),
-                			sourcesArtifact, 
-                			javadocArtifact
-                		));
+                Artifact a = (Artifact) iter.next();
+                if (IvyPlugin.isSources(_javaProject, a)) {
+                    sources.put(a.getModuleRevisionId(), a);
                 }
             }
-            classpathItems = (ClasspathItem[])files.toArray(new ClasspathItem[files.size()]);
-            
-            return classpathItems;
+            return sources;
         }
 
-		private File getSourcesArtifact(Artifact artifact, Collection all)
+        private Map getJavadocArtifacts(Collection all) {
+            Map sources = new HashMap();
+            for (Iterator iter = all.iterator(); iter.hasNext();) {
+                Artifact a = (Artifact) iter.next();
+                if (IvyPlugin.isJavadoc(_javaProject, a)) {
+                    sources.put(a.getModuleRevisionId(), a);
+                }
+            }
+            return sources;
+        }
+
+        private File getPathOfArtifactType(Artifact a, Map artifacts, String metaType, String metaClassifier) {
+            Artifact aType = (Artifact) artifacts.get(a.getModuleRevisionId());
+            if (aType != null) {
+                return _cacheMgr.getArchiveFileInCache(aType);
+            }
+            if (IvyPlugin.shouldTestNonDeclaredSources(_javaProject)) {
+                return getMetaArtifact(a, metaType, metaClassifier);
+            }
+            return null;
+        }
+
+        private File getSourcesArtifact(Artifact artifact, Collection all)
 		{
     		_monitor.subTask("searching sources for "+artifact);
             for (Iterator iter = all.iterator(); iter.hasNext();) {
