ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r682179 - in /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse: ./ src/java/org/apache/ivyde/eclipse/ src/java/org/apache/ivyde/eclipse/cpcontainer/ src/java/org/apache/ivyde/eclipse/ui/preferences/
Date Sun, 03 Aug 2008 14:37:26 GMT
Author: hibou
Date: Sun Aug  3 07:37:25 2008
New Revision: 682179

URL: http://svn.apache.org/viewvc?rev=682179&view=rev
Log:
IVYDE-89 : Option to resolve to local eclipse projects

Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
    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/IvyResolveJob.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyDEPreferenceStoreHelper.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyPreferencePage.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/PreferenceConstants.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt?rev=682179&r1=682178&r2=682179&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt Sun Aug  3 07:37:25 2008
@@ -4,6 +4,7 @@
   next
 ==========================
 - NEW: settings files code completion support (IVYDE-22)
+- NEW: Option to resolve to local eclipse projects (IVYDE-89) (thanks to Antony James Wilkins
and Matt Goldspink)
 
 - IMPROVE: Retrieve after resolve feature does not clean target directory first (IVYDE-105)
 

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java?rev=682179&r1=682178&r2=682179&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
Sun Aug  3 07:37:25 2008
@@ -116,7 +116,8 @@
                             || event.getProperty() == PreferenceConstants.DO_RETRIEVE
                             || event.getProperty() == PreferenceConstants.RETRIEVE_PATTERN
                             || event.getProperty() == PreferenceConstants.RETRIEVE_SYNC
-                            || event.getProperty() == PreferenceConstants.ALPHABETICAL_ORDER)
{
+                            || event.getProperty() == PreferenceConstants.ALPHABETICAL_ORDER
+                            || event.getProperty() == PreferenceConstants.RESOLVE_IN_WORKSPACE)
{
                         prefStoreChanged();
                     }
                 } catch (JavaModelException e) {

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=682179&r1=682178&r2=682179&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
Sun Aug  3 07:37:25 2008
@@ -76,6 +76,8 @@
 
     boolean alphaOrder;
 
+    boolean resolveInWorkspace;
+
     /**
      * Constructor
      * 
@@ -184,6 +186,9 @@
                 // return false, so it is fine
                 alphaOrder = Boolean.valueOf(value).booleanValue();
                 isProjectSpecific = true;
+            } else if (parameter[0].equals("resolveInWorkspace")) {
+                resolveInWorkspace = Boolean.valueOf(value).booleanValue();
+                isProjectSpecific = true;
             }
         }
         if (isProjectSpecific) {
@@ -245,6 +250,8 @@
                 path.append(URLEncoder.encode(Boolean.toString(retrieveSync), "UTF-8"));
                 path.append("&alphaOrder=");
                 path.append(URLEncoder.encode(Boolean.toString(alphaOrder), "UTF-8"));
+                path.append("&resolveInWorkspace=");
+                path.append(URLEncoder.encode(Boolean.toString(this.resolveInWorkspace),
"UTF-8"));
             }
         } catch (UnsupportedEncodingException e) {
             String message = "The UTF-8 encoding support is required is endecode the path
of the container.";
@@ -357,6 +364,13 @@
         return alphaOrder;
     }
 
+    public boolean isResolveInWorkspace() {
+        if (this.ivySettingsPath == null) {
+            return IvyPlugin.getPreferenceStoreHelper().isResolveInWorkspace();
+        }
+        return resolveInWorkspace;
+    }
+
     public boolean isProjectSpecific() {
         return ivySettingsPath != null;
     }

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java?rev=682179&r1=682178&r2=682179&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java
Sun Aug  3 07:37:25 2008
@@ -25,6 +25,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -46,10 +47,12 @@
 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.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.report.XmlReportParser;
@@ -57,6 +60,7 @@
 import org.apache.ivy.plugins.repository.TransferListener;
 import org.apache.ivy.util.Message;
 import org.apache.ivyde.eclipse.IvyPlugin;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -67,7 +71,9 @@
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jdt.core.IClasspathAttribute;
 import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
 
 /**
  * Eclipse classpath container that will contain the ivy resolved entries.
@@ -165,6 +171,17 @@
         }
     }
 
+    private Map listDependencies(ResolveReport r) {
+        Map result = new HashMap();
+        Iterator it = r.getDependencies().iterator();
+        while (it.hasNext()) {
+            IvyNode node = (IvyNode) it.next();
+            ModuleRevisionId moduleId = node.getId();
+            result.put(moduleId.getName(), moduleId);
+        }
+        return result;
+    }
+
     protected IStatus run(IProgressMonitor monitor) {
         Message.info("resolving dependencies of " + conf.ivyXmlPath);
         _monitor = monitor;
@@ -187,7 +204,7 @@
                 ClassLoader old = Thread.currentThread().getContextClassLoader();
                 Thread.currentThread().setContextClassLoader(IvyResolveJob.class.getClassLoader());
                 try {
-
+                    Map dependencies = Collections.EMPTY_MAP;
                     if (_usePreviousResolveIfExist) {
                         if (conf.confs.size() == 1 && "*".equals(conf.confs.get(0)))
{
                             confs = md.getConfigurationsNames();
@@ -205,7 +222,7 @@
                                     .getConfigurationResolveReportInCache(
                                         ResolveOptions.getDefaultResolveId(md), confs[i]);
                             boolean resolved = false;
-                            if (report.exists()) {
+                            if (report.exists() && !conf.isResolveInWorkspace())
{
                                 // found a report, try to parse it.
                                 try {
                                     XmlReportParser parser = new XmlReportParser();
@@ -229,6 +246,7 @@
                                                 .toArray(new String[conf.confs.size()])));
                                 all.addAll(Arrays.asList(r.getArtifactsReports(null, false)));
                                 confs = r.getConfigurations();
+                                dependencies = listDependencies(r);
                                 problemMessages.addAll(r.getAllProblemMessages());
                                 maybeRetrieve(md, confs);
 
@@ -245,6 +263,8 @@
                             false)));
                         confs = report.getConfigurations();
 
+                        dependencies = listDependencies(report);
+
                         if (_monitor.isCanceled()) {
                             status[0] = Status.CANCEL_STATUS;
                             return;
@@ -255,7 +275,7 @@
 
                     warnIfDuplicates(all);
 
-                    classpathEntries[0] = artifacts2ClasspathEntries(all);
+                    classpathEntries[0] = artifacts2ClasspathEntries(all, dependencies);
                 } catch (ParseException e) {
                     String errorMsg = "Error while parsing the ivy file " + conf.ivyXmlPath
+ "\n"
                             + e.getMessage();
@@ -386,26 +406,86 @@
         }
     }
 
-    private IClasspathEntry[] artifacts2ClasspathEntries(Collection all) {
+    private IClasspathEntry[] artifacts2ClasspathEntries(Collection all, Map dependencies)
{
         IClasspathEntry[] classpathEntries;
         Collection paths = new LinkedHashSet();
+
+        Map idToJProject = new HashMap();
+        if (conf.isResolveInWorkspace()) {
+            try {
+                IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())
+                        .getJavaProjects();
+                for (int i = 0; i < projects.length; i++) {
+                    IJavaProject javaProject = projects[i];
+                    ModuleDescriptor md = findModuleDescriptor(javaProject);
+                    if (md != null) {
+                        idToJProject.put(md.getModuleRevisionId().getModuleId(), javaProject);
+                    }
+                }
+            } catch (JavaModelException e) {
+                IvyPlugin.log(IStatus.ERROR, "Error while listing the java projects,"
+                        + " dependencies between java projects won't be used", e);
+            }
+        }
+
         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));
+
+            boolean usedProject = false;
+            if (conf.isResolveInWorkspace()) {
+                ModuleId moduleId = artifact.getArtifact().getModuleRevisionId().getModuleId();
+                String moduleName = moduleId.getName();
+                ModuleRevisionId moduleRevisionId = (ModuleRevisionId) dependencies.get(moduleName);
+                if (moduleRevisionId != null) {
+                    IJavaProject project = (IJavaProject) idToJProject.get(moduleId);
+                    if (project != null && project.exists() && project.isOpen())
{
+                        IClasspathEntry entry = JavaCore.newProjectEntry(project.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()]);
 
         return classpathEntries;
     }
 
+    /*
+     * Finds and parses the ivy.xml file for the supplied project's classpath container
+     */
+    private ModuleDescriptor findModuleDescriptor(IJavaProject javaProject) {
+        IvyClasspathContainer cp = IvyClasspathUtil.getIvyClasspathContainer(javaProject);
+        if (cp == null) {
+            return null;
+        }
+        try {
+            return cp.getConf().getModuleDescriptor(ivy);
+        } catch (MalformedURLException e) {
+            IvyPlugin.log(IStatus.WARNING, "The path of the ivy.xml of the project " + javaProject
+ " is not a valid URL", e);
+        } catch (ParseException e) {
+            IvyPlugin.log(IStatus.WARNING, "The ivy.xml of the project " + javaProject +
" has a syntax error: ", e);
+        } catch (IOException e) {
+            IvyPlugin.log(IStatus.WARNING, "The ivy.xml of the project " + javaProject +
" could not be read: ", e);
+        }
+        return null;
+    }
+
     private Path getSourcesArtifactPath(ArtifactDownloadReport adr, Collection all) {
         Artifact artifact = adr.getArtifact();
         _monitor.subTask("searching sources for " + artifact);

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java?rev=682179&r1=682178&r2=682179&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java
Sun Aug  3 07:37:25 2008
@@ -105,6 +105,8 @@
 
     Button alphaOrderCheck;
 
+    Button resolveInWorkspaceCheck;
+
     Button projectSpecificButton;
 
     Button browse;
@@ -160,6 +162,7 @@
             conf.retrievePattern = retrievePatternText.getText();
             conf.retrieveSync = retrieveSyncButton.getSelection();
             conf.alphaOrder = alphaOrderCheck.getSelection();
+            conf.resolveInWorkspace = resolveInWorkspaceCheck.getSelection();
         } else {
             conf.ivySettingsPath = null;
         }
@@ -515,6 +518,13 @@
         alphaOrderCheck
                 .setToolTipText("Order alphabetically the artifacts in the classpath container");
 
+        resolveInWorkspaceCheck = new Button(this.configComposite, SWT.CHECK);
+        resolveInWorkspaceCheck.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
true,
+                false, 2, 1));
+        resolveInWorkspaceCheck.setText("Resolve dependencies in workspace");
+        resolveInWorkspaceCheck
+                .setToolTipText("Will replace jars on the classpath with workspace projects");
+
         return composite;
     }
 
@@ -538,6 +548,7 @@
             retrievePatternText.setText(conf.retrievePattern);
             retrieveSyncButton.setSelection(conf.retrieveSync);
             alphaOrderCheck.setSelection(conf.alphaOrder);
+            resolveInWorkspaceCheck.setSelection(this.conf.resolveInWorkspace);
         } else {
             projectSpecificButton.setSelection(false);
             IvyDEPreferenceStoreHelper helper = IvyPlugin.getPreferenceStoreHelper();
@@ -551,6 +562,7 @@
             retrievePatternText.setText(helper.getRetrievePattern());
             retrieveSyncButton.setSelection(helper.getRetrieveSync());
             alphaOrderCheck.setSelection(helper.isAlphOrder());
+            resolveInWorkspaceCheck.setSelection(helper.isResolveInWorkspace());
         }
 
         updateFieldsStatus();
@@ -570,6 +582,7 @@
         retrievePatternText.setEnabled(doRetrieveButton.getSelection() && projectSpecific);
         retrieveSyncButton.setEnabled(doRetrieveButton.getSelection() && projectSpecific);
         alphaOrderCheck.setEnabled(projectSpecific);
+        resolveInWorkspaceCheck.setEnabled(projectSpecific);
     }
 
     File getFile(File startingDirectory) {

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyDEPreferenceStoreHelper.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyDEPreferenceStoreHelper.java?rev=682179&r1=682178&r2=682179&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyDEPreferenceStoreHelper.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyDEPreferenceStoreHelper.java
Sun Aug  3 07:37:25 2008
@@ -61,6 +61,7 @@
 
         prefStore.setDefault(PreferenceConstants.RETRIEVE_SYNC, false);
         prefStore.setDefault(PreferenceConstants.ALPHABETICAL_ORDER, false);
+        prefStore.setDefault(PreferenceConstants.RESOLVE_IN_WORKSPACE, false);
     }
 
     public String getIvyOrg() {
@@ -111,4 +112,8 @@
         return prefStore.getBoolean(PreferenceConstants.ALPHABETICAL_ORDER);
     }
 
+    public boolean isResolveInWorkspace() {
+        return prefStore.getBoolean(PreferenceConstants.RESOLVE_IN_WORKSPACE);
+    }
+
 }

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyPreferencePage.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyPreferencePage.java?rev=682179&r1=682178&r2=682179&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyPreferencePage.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/IvyPreferencePage.java
Sun Aug  3 07:37:25 2008
@@ -216,6 +216,17 @@
         spacerData.horizontalSpan = 3;
         spacer.setLayoutData(spacerData);
 
+        BooleanFieldEditor resolveInWorkspace = new BooleanFieldEditor(
+                PreferenceConstants.RESOLVE_IN_WORKSPACE,
+                "Resolve dependencies to workspace projects",
+                fieldParent);
+        addField(resolveInWorkspace);
+
+        spacer = new Label(fieldParent, SWT.NONE);
+        spacerData = new GridData();
+        spacerData.horizontalSpan = 3;
+        spacer.setLayoutData(spacerData);
+
         spacer = new Label(fieldParent, SWT.NONE);
         spacerData = new GridData();
         spacerData.horizontalSpan = 3;

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/PreferenceConstants.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/PreferenceConstants.java?rev=682179&r1=682178&r2=682179&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/PreferenceConstants.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/preferences/PreferenceConstants.java
Sun Aug  3 07:37:25 2008
@@ -56,4 +56,6 @@
 
     public static final String ALPHABETICAL_ORDER = "order.alphabetical";
 
+    public static final String RESOLVE_IN_WORKSPACE = "resolveInWorkspace";
+
 }



Mime
View raw message