You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by hi...@apache.org on 2010/08/23 14:13:41 UTC

svn commit: r988098 - in /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer: IvyClasspathContainerConfiguration.java IvyClasspathContainerMapper.java IvyResolveJobThread.java

Author: hibou
Date: Mon Aug 23 12:13:41 2010
New Revision: 988098

URL: http://svn.apache.org/viewvc?rev=988098&view=rev
Log:
IVYDE-56
 * implementation of the retrieved classpath : to be tested

Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java?rev=988098&r1=988097&r2=988098&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java Mon Aug 23 12:13:41 2010
@@ -298,7 +298,7 @@ public class IvyClasspathContainerConfig
         return retrievedClasspath;
     }
 
-    public RetrieveSetup getInheritedRetrievedClasspathSet() {
+    public RetrieveSetup getInheritedRetrievedClasspathSetup() {
         if (!isAdvancedProjectSpecific) {
             return IvyPlugin.getPreferenceStoreHelper().getRetrievedClasspathSetup();
         }

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java?rev=988098&r1=988097&r2=988098&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java Mon Aug 23 12:13:41 2010
@@ -25,6 +25,7 @@ import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.module.descriptor.Artifact;
@@ -54,16 +55,26 @@ public class IvyClasspathContainerMapper
 
     private final IvyClasspathContainerConfiguration conf;
 
+    private final Collection/* <ArtifactDownloadReport> */all;
+
+    private final Map/* <ModuleRevisionId, Artifact[]> */artifactsByDependency;
+
+    private final Map/*
+                      * <ArtifactDownloadReport , Set<String>>
+                      */retrievedArtifacts;
+
     public IvyClasspathContainerMapper(IProgressMonitor monitor, Ivy ivy,
-            IvyClasspathContainerConfiguration conf) {
+            IvyClasspathContainerConfiguration conf, Collection all, Map artifactsByDependency,
+            Map retrievedArtifacts) {
         this.monitor = monitor;
         this.ivy = ivy;
         this.conf = conf;
+        this.all = all;
+        this.artifactsByDependency = artifactsByDependency;
+        this.retrievedArtifacts = retrievedArtifacts;
     }
 
-    public IClasspathEntry[] map(Collection all, Map/*
-                                                     * <ModuleRevisionId, Artifact[]>
-                                                     */artifactsByDependency) {
+    public IClasspathEntry[] map() {
         IClasspathEntry[] classpathEntries;
         Collection paths = new LinkedHashSet();
 
@@ -74,9 +85,9 @@ public class IvyClasspathContainerMapper
                 // This is a java project in the workspace, add project path
                 paths.add(JavaCore.newProjectEntry(new Path(artifact.getName()), true));
             } else if (artifact.getLocalFile() != null && accept(artifact.getArtifact())) {
-                Path classpathArtifact = new Path(artifact.getLocalFile().getAbsolutePath());
-                Path sourcesArtifact = getSourcesArtifactPath(artifact, all, artifactsByDependency);
-                Path javadocArtifact = getJavadocArtifactPath(artifact, all, artifactsByDependency);
+                Path classpathArtifact = getArtifactPath(artifact);
+                Path sourcesArtifact = getSourcesArtifactPath(artifact);
+                Path javadocArtifact = getJavadocArtifactPath(artifact);
                 paths.add(JavaCore.newLibraryEntry(classpathArtifact, getSourceAttachment(
                     classpathArtifact, sourcesArtifact), getSourceAttachmentRoot(classpathArtifact,
                     sourcesArtifact), null, getExtraAttribute(classpathArtifact, javadocArtifact),
@@ -89,8 +100,17 @@ public class IvyClasspathContainerMapper
         return classpathEntries;
     }
 
-    private Path getSourcesArtifactPath(ArtifactDownloadReport adr, Collection all,
-            Map/* <ModuleRevisionId, Artifact[]> */artifactsByDependency) {
+    private Path getArtifactPath(ArtifactDownloadReport artifact) {
+        if (retrievedArtifacts != null) {
+            Set pathSet = (Set) retrievedArtifacts.get(artifact);
+            if (pathSet != null && !pathSet.isEmpty()) {
+                return new Path((String) pathSet.iterator().next());
+            }
+        }
+        return new Path(artifact.getLocalFile().getAbsolutePath());
+    }
+
+    private Path getSourcesArtifactPath(ArtifactDownloadReport adr) {
         Artifact artifact = adr.getArtifact();
         monitor.subTask("searching sources for " + artifact);
         for (Iterator iter = all.iterator(); iter.hasNext();) {
@@ -100,7 +120,7 @@ public class IvyClasspathContainerMapper
                     && isSourceArtifactName(artifact.getName(), a.getName())
                     && a.getModuleRevisionId().equals(artifact.getModuleRevisionId())
                     && isSources(a)) {
-                return new Path(otherAdr.getLocalFile().getAbsolutePath());
+                return getArtifactPath(otherAdr);
             }
         }
         // we haven't found source artifact in resolved artifacts,
@@ -116,7 +136,7 @@ public class IvyClasspathContainerMapper
                     ArtifactDownloadReport metaAdr = ivy.getResolveEngine().download(metaArtifact,
                         new DownloadOptions());
                     if (metaAdr.getLocalFile() != null && metaAdr.getLocalFile().exists()) {
-                        return new Path(metaAdr.getLocalFile().getAbsolutePath());
+                        return getArtifactPath(metaAdr);
                     }
                 }
             }
@@ -124,8 +144,7 @@ public class IvyClasspathContainerMapper
         return null;
     }
 
-    private Path getJavadocArtifactPath(ArtifactDownloadReport adr, Collection all,
-            Map/* <ModuleRevisionId, Artifact[]> */artifactsByDependency) {
+    private Path getJavadocArtifactPath(ArtifactDownloadReport adr) {
         Artifact artifact = adr.getArtifact();
         monitor.subTask("searching javadoc for " + artifact);
         for (Iterator iter = all.iterator(); iter.hasNext();) {
@@ -135,7 +154,7 @@ public class IvyClasspathContainerMapper
                     && isJavadocArtifactName(artifact.getName(), a.getName())
                     && a.getModuleRevisionId().equals(artifact.getModuleRevisionId())
                     && isJavadoc(a)) {
-                return new Path(otherAdr.getLocalFile().getAbsolutePath());
+                return getArtifactPath(otherAdr);
             }
         }
         // we haven't found javadoc artifact in resolved artifacts,
@@ -151,7 +170,7 @@ public class IvyClasspathContainerMapper
                     ArtifactDownloadReport metaAdr = ivy.getResolveEngine().download(metaArtifact,
                         new DownloadOptions());
                     if (metaAdr.getLocalFile() != null && metaAdr.getLocalFile().exists()) {
-                        return new Path(metaAdr.getLocalFile().getAbsolutePath());
+                        return getArtifactPath(metaAdr);
                     }
                 }
             }

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java?rev=988098&r1=988097&r2=988098&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java Mon Aug 23 12:13:41 2010
@@ -42,13 +42,16 @@ import org.apache.ivy.core.resolve.IvyNo
 import org.apache.ivy.core.resolve.ResolveData;
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.core.resolve.ResolvedModuleRevision;
+import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.plugins.report.XmlReportParser;
 import org.apache.ivy.plugins.resolver.DependencyResolver;
 import org.apache.ivy.util.Message;
+import org.apache.ivy.util.filter.ArtifactTypeFilter;
+import org.apache.ivyde.eclipse.FakeProjectManager;
 import org.apache.ivyde.eclipse.IvyPlugin;
+import org.apache.ivyde.eclipse.retrieve.RetrieveSetup;
 import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
@@ -84,6 +87,15 @@ public class IvyResolveJobThread extends
 
     private Map artifactsByDependency = new HashMap();
 
+    /**
+     * Mapping of resolved artifact to their retrieved path, <code>null</code> if there were no
+     * retrieve
+     * <p>
+     * The paths may be relative It shouldn't be an issue has every relative path should be relative
+     * to the eclipse project FIXME: not sure why the Ivy API is returning a set of paths...
+     */
+    private Map/* <ArtifactDownloadReport, Set<String>> */retrievedArtifacts = null;
+
     public IvyResolveJobThread(IvyClasspathContainerConfiguration conf, Ivy ivy,
             ModuleDescriptor md, boolean usePreviousResolveIfExist, IProgressMonitor monitor) {
         this.ivy = ivy;
@@ -132,11 +144,11 @@ public class IvyResolveJobThread extends
                 }
 
                 IvyClasspathContainerMapper mapper = new IvyClasspathContainerMapper(monitor, ivy,
-                        conf);
+                        conf, all, artifactsByDependency, retrievedArtifacts);
 
                 warnIfDuplicates(mapper);
 
-                classpathEntries = mapper.map(all, artifactsByDependency);
+                classpathEntries = mapper.map();
             } catch (ParseException e) {
                 String errorMsg = "Error while parsing the ivy file " + conf.getIvyXmlPath() + "\n"
                         + e.getMessage();
@@ -240,6 +252,7 @@ public class IvyResolveJobThread extends
             status = Status.CANCEL_STATUS;
             return false;
         }
+        maybeRetrieve(report);
         return true;
     }
 
@@ -328,4 +341,54 @@ public class IvyResolveJobThread extends
         return result;
     }
 
+    private void maybeRetrieve(ResolveReport report) throws IOException {
+        if (!conf.isInheritedRetrievedClasspath()) {
+            return;
+        }
+        if (FakeProjectManager.isFake(conf.getJavaProject())) {
+            return;
+        }
+        RetrieveSetup setup = conf.getInheritedRetrievedClasspathSetup();
+        IProject project = conf.getJavaProject().getProject();
+        String pattern = project.getLocation().toPortableString() + "/"
+                + setup.getRetrievePattern();
+        monitor.setTaskName("retrieving dependencies in " + pattern);
+        RetrieveOptions options = new RetrieveOptions();
+        options.setSync(setup.isRetrieveSync());
+        options.setResolveId(report.getResolveId());
+        options.setConfs(confs);
+        String inheritedRetrieveTypes = setup.getRetrieveTypes();
+        if (inheritedRetrieveTypes != null && !inheritedRetrieveTypes.equals("*")) {
+            options.setArtifactFilter(new ArtifactTypeFilter(IvyClasspathUtil
+                    .split(inheritedRetrieveTypes)));
+        }
+
+        // Actually do the retrieve
+        // FIXME here we will parse a report we already have
+        // with a better Java API, we could do probably better
+        int numberOfItemsRetrieved = ivy.retrieve(md.getModuleRevisionId(), pattern, options);
+        if (numberOfItemsRetrieved > 0) {
+            // Only refresh if we actually retrieved a file.
+            String refreshPath = IvyPatternHelper.getTokenRoot(setup.getRetrievePattern());
+            IFolder folder = project.getFolder(refreshPath);
+            RefreshFolderJob refreshFolderJob = new RefreshFolderJob(folder);
+            refreshFolderJob.schedule();
+        }
+
+        // recompute the files which has been copied to build a classpath
+        String resolvedPattern = IvyPatternHelper.substituteVariables(pattern, ivy.getSettings()
+                .getVariables());
+        try {
+            // FIXME same as above
+            retrievedArtifacts = ivy.getRetrieveEngine().determineArtifactsToCopy(
+                md.getModuleRevisionId(), resolvedPattern, options);
+        } catch (ParseException e) {
+            // ooops, failed to parse a report we already have...
+            IvyPlugin.log(IStatus.ERROR,
+                "failed to parse a resolve report in order to do the retrieve", e);
+            return;
+        }
+        all = new LinkedHashSet(retrievedArtifacts.keySet());
+    }
+
 }