Index: java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java =================================================================== --- java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java (revision 648204) +++ java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java (working copy) @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -51,6 +52,7 @@ import org.apache.ivy.core.report.ArtifactDownloadReport; import org.apache.ivy.core.report.ResolveReport; import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.IvyNode; import org.apache.ivy.core.resolve.ResolveOptions; import org.apache.ivy.core.retrieve.RetrieveOptions; import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; @@ -60,6 +62,8 @@ import org.apache.ivy.util.Message; import org.apache.ivyde.eclipse.IvyPlugin; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -68,22 +72,13 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jdt.core.ElementChangedEvent; import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IClasspathContainer; import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElementDelta; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.core.DeltaProcessingState; -import org.eclipse.jdt.internal.core.JavaElementDelta; -import org.eclipse.jdt.internal.core.JavaModelManager; -import org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider; import org.eclipse.swt.widgets.Display; -import org.osgi.framework.Bundle; -import org.osgi.framework.Constants; /** * Eclipse classpath container that will contain the ivy resolved entries. @@ -205,7 +200,7 @@ Thread.currentThread().setContextClassLoader( IvyClasspathContainer.class.getClassLoader()); try { - + Map dependencies = Collections.EMPTY_MAP; if (_usePreviousResolveIfExist) { md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor( _ivy.getSettings(), ivyURL, false); @@ -226,12 +221,13 @@ .getConfigurationResolveReportInCache( ResolveOptions.getDefaultResolveId(md), confs[i]); boolean resolved = false; + if (report.exists()) { // found a report, try to parse it. try { XmlReportParser parser = new XmlReportParser(); parser.parse(report); - all.addAll(Arrays.asList(parser.getArtifactReports())); + all.addAll(Arrays.asList(parser.getArtifactReports())); resolved = true; } catch (ParseException e) { Message.info("\n\nIVYDE: Error while parsing the report " @@ -249,8 +245,14 @@ ResolveReport r = _ivy.resolve(ivyURL, new ResolveOptions() .setConfs((String[]) conf.confs .toArray(new String[conf.confs.size()]))); - all.addAll(Arrays.asList(r.getArtifactsReports(null, false))); + + ArtifactDownloadReport[] artifactsReports = r.getArtifactsReports(null, false); + + all.addAll(Arrays.asList(artifactsReports)); confs = r.getConfigurations(); + + dependencies = listDependencies(r); + problemMessages.addAll(r.getAllProblemMessages()); maybeRetrieve(md, confs); @@ -268,6 +270,8 @@ confs = report.getConfigurations(); md = report.getModuleDescriptor(); + dependencies = listDependencies(report); + if (_monitor.isCanceled()) { status[0] = Status.CANCEL_STATUS; return; @@ -278,7 +282,7 @@ warnIfDuplicates(all); - classpathEntries[0] = artifacts2ClasspathEntries(all); + classpathEntries[0] = artifacts2ClasspathEntries(all, dependencies); } catch (ParseException e) { String errorMsg = "Error while parsing the ivy file " + _ivyXmlFile + "\n" + e.getMessage(); @@ -410,20 +414,41 @@ } } - private IClasspathEntry[] artifacts2ClasspathEntries(Collection all) { + private IClasspathEntry[] artifacts2ClasspathEntries(Collection all, Map dependencies) { IClasspathEntry[] classpathEntries; Collection paths = new LinkedHashSet(); for (Iterator iter = all.iterator(); iter.hasNext();) { ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next(); - if (artifact.getLocalFile() != null && accept(artifact.getArtifact())) { - Path classpathArtifact = new Path(artifact.getLocalFile().getAbsolutePath()); - Path sourcesArtifact = getSourcesArtifactPath(artifact, all); - Path javadocArtifact = getJavadocArtifactPath(artifact, all); - paths.add(JavaCore.newLibraryEntry(classpathArtifact, getSourceAttachment( - classpathArtifact, sourcesArtifact), getSourceAttachmentRoot( - classpathArtifact, sourcesArtifact), null, getExtraAttribute( - classpathArtifact, javadocArtifact), false)); + + // first attempt to use local eclipse project if the dependency is latest.integration, and it exists + String moduleName = artifact.getArtifact().getModuleRevisionId().getModuleId().getName(); + ModuleRevisionId moduleRevisionId = dependencies.get(moduleName); + boolean usedProject = false; + if (moduleRevisionId != null && moduleRevisionId.getRevision().equals("latest.integration")) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(moduleName); + if (project.exists() && project.isOpen()) { + IJavaProject javaProject = JavaCore.create(project); + if (javaProject.exists()) { + IClasspathEntry entry = JavaCore.newProjectEntry(javaProject.getPath()); + if (entry != null && !paths.contains(entry)) { + paths.add(entry); + } + usedProject = true; + } + } } + + if (!usedProject) { + if (artifact.getLocalFile() != null && accept(artifact.getArtifact())) { + Path classpathArtifact = new Path(artifact.getLocalFile().getAbsolutePath()); + Path sourcesArtifact = getSourcesArtifactPath(artifact, all); + Path javadocArtifact = getJavadocArtifactPath(artifact, all); + paths.add(JavaCore.newLibraryEntry(classpathArtifact, getSourceAttachment( + classpathArtifact, sourcesArtifact), getSourceAttachmentRoot( + classpathArtifact, sourcesArtifact), null, getExtraAttribute( + classpathArtifact, javadocArtifact), false)); + } + } } classpathEntries = (IClasspathEntry[]) paths.toArray(new IClasspathEntry[paths.size()]); @@ -568,6 +593,16 @@ return (IClasspathAttribute[]) result.toArray(new IClasspathAttribute[result.size()]); } + private Map listDependencies(ResolveReport r) { + Map result = new HashMap(); + for(Object d : r.getDependencies()) { + IvyNode node = (IvyNode) d; + ModuleRevisionId moduleId = node.getId(); + result.put(moduleId.getName(), moduleId); + } + return result; + } + } public static final String IVY_CLASSPATH_CONTAINER_ID = "org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER";