ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jschnei...@apache.org
Subject svn commit: r885779 - /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/revdepexplorer/SyncIvyFilesJob.java
Date Tue, 01 Dec 2009 14:58:00 GMT
Author: jschneider
Date: Tue Dec  1 14:58:00 2009
New Revision: 885779

URL: http://svn.apache.org/viewvc?rev=885779&view=rev
Log:
IVYDE-223.  Fix Reverse Dependency bug that inlines configuration includes and defaultconfmappings
on synch.

Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/revdepexplorer/SyncIvyFilesJob.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/revdepexplorer/SyncIvyFilesJob.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/revdepexplorer/SyncIvyFilesJob.java?rev=885779&r1=885778&r2=885779&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/revdepexplorer/SyncIvyFilesJob.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/revdepexplorer/SyncIvyFilesJob.java
Tue Dec  1 14:58:00 2009
@@ -17,19 +17,32 @@
  */
 package org.apache.ivyde.eclipse.revdepexplorer;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.IOException;
-import java.text.ParseException;
-import java.util.ArrayList;
+import java.net.MalformedURLException;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
+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.plugins.namespace.Namespace;
+import org.apache.ivy.plugins.namespace.NamespaceTransformer;
+import org.apache.ivy.plugins.parser.xml.UpdateOptions;
+import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater;
 import org.apache.ivyde.eclipse.IvyDEException;
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
-import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainerConfiguration;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.WorkspaceJob;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -37,6 +50,7 @@
 import org.eclipse.core.runtime.MultiStatus;
 import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.core.runtime.Status;
+import org.xml.sax.SAXException;
 
 /**
  * This job synchronizes all ivy files in a workspace according to the new revisions specified
in
@@ -46,10 +60,47 @@
 
     private MultiRevisionDependencyDescriptor[] multiRevisionDependencies;
 
+    /**
+     * FIXME Here we seriously abuse the Ivy core API to allow us to preserve an info element
+     * containing no revision attribute.  Ivy code should be altered to allow us to preserve
+     * revision (including the lack of its definition!).
+     */
+    private class RevisionPreservingNamespace extends Namespace {
+        private class NullableRevisionModuleRevisionId extends ModuleRevisionId {
+            private String revision;
+            
+            public NullableRevisionModuleRevisionId(ModuleId moduleId, String revision) {
+                super(moduleId, revision);
+                this.revision = revision;
+            }
+
+            public String getRevision() {
+                return revision;
+            }            
+        }
+        
+        private class RevisionPreservingNamespaceTransformer implements NamespaceTransformer
{
+            public boolean isIdentity() {
+                return false;
+            }
+    
+            public ModuleRevisionId transform(ModuleRevisionId mrid) {
+                if(mrid.getRevision().contains("working@")) {
+                    return new NullableRevisionModuleRevisionId(mrid.getModuleId(), null);
+                }
+                return new ModuleRevisionId(mrid.getModuleId(), mrid.getRevision());
+            }        
+        }
+
+        public NamespaceTransformer getToSystemTransformer() {
+            return new RevisionPreservingNamespaceTransformer();
+        }
+    }
+    
     public SyncIvyFilesJob(MultiRevisionDependencyDescriptor[] multiRevisionDependencies)
{
         super("Synchronizing Ivy Files");
         this.multiRevisionDependencies = multiRevisionDependencies;
-    }
+    }    
 
     protected IStatus executeJob(IProgressMonitor monitor) {
         MultiStatus errorStatuses = new MultiStatus(IvyPlugin.ID, IStatus.ERROR,
@@ -59,10 +110,9 @@
         for (int i = 0; i < containers.length; i++) {
             IvyClasspathContainer container = containers[i];
 
-            EditableModuleDescriptor moduleDescriptor;
+            ModuleDescriptor moduleDescriptor;
             try {
-                moduleDescriptor = new EditableModuleDescriptor(container.getState()
-                        .getModuleDescriptor());
+                moduleDescriptor = container.getState().getModuleDescriptor();
             } catch (IvyDEException e) {
                 errorStatuses
                         .add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
@@ -70,36 +120,47 @@
                                         + container.getConf().getIvyXmlPath(), e));
                 continue;
             }
-            Collection/* <MultiRevisionDependencyDescriptor> */newRevisions = getNewRevisions(container);
-
-            Iterator multiRevisionIter = newRevisions.iterator();
-            while (multiRevisionIter.hasNext()) {
-                MultiRevisionDependencyDescriptor newRevision = (MultiRevisionDependencyDescriptor)
multiRevisionIter
-                        .next();
-
-                DependencyDescriptor dependencyDescriptors[] = moduleDescriptor.getDependencies();
-                for (int j = 0; j < dependencyDescriptors.length; j++) {
-                    DependencyDescriptor dependencyDescriptor = dependencyDescriptors[j];
-                    if (newRevision.getModuleId().equals(dependencyDescriptor.getDependencyId()))
{
-                        EditableDependencyDescriptor editableDependencyDescriptor = new EditableDependencyDescriptor(
-                                dependencyDescriptor);
-                        editableDependencyDescriptor.setRevision(newRevision.getNewRevision());
-                        moduleDescriptor.removeDependency(dependencyDescriptor);
-                        moduleDescriptor.addDependency(editableDependencyDescriptor);
+            
+            Map/*<ModuleRevisionId, String> */ newRevisions = new HashMap/*<ModuleRevisionId,
String>*/();
+            
+            DependencyDescriptor[] dependencies = moduleDescriptor.getDependencies();   
        
+            for(int j = 0; j < dependencies.length; j++) {
+                for (int k = 0; k < multiRevisionDependencies.length; k++) {
+                    MultiRevisionDependencyDescriptor multiRevision = multiRevisionDependencies[k];
+                    ModuleRevisionId dependencyRevisionId = dependencies[j].getDependencyRevisionId();

+                    if (dependencies[j].getDependencyId().equals(multiRevision.getModuleId())
&&
+                            multiRevision.hasNewRevision() && multiRevision.isForContainer(container))
{
+                        newRevisions.put(dependencyRevisionId, multiRevisionDependencies[k].getNewRevision());
+                        break; // move on to the next dependency
                     }
                 }
             }
-
-            try {
-                IvyClasspathUtil.toIvyFile(moduleDescriptor, container);
-            } catch (ParseException e) {
+            
+            UpdateOptions updateOptions = new UpdateOptions()
+                .setResolvedRevisions(newRevisions)
+                .setReplaceInclude(false)
+                .setGenerateRevConstraint(false)
+                .setNamespace(new RevisionPreservingNamespace());
+            File ivyFile = container.getState().getIvyFile();
+            
+            File ivyTempFile = new File(ivyFile.toString() + ".temp");
+            try {                
+                XmlModuleDescriptorUpdater.update(ivyFile.toURI().toURL(), ivyTempFile, updateOptions);
+                saveChanges(container, ivyFile, ivyTempFile);
+            } catch (MalformedURLException e) {
                 errorStatuses.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
-                        "Failed to write Ivy file " + container.getState().getIvyFile().getPath(),
-                        e));
+                        "Failed to write Ivy file " + container.getState().getIvyFile().getPath()
+                                + " (malformed URL)", e));
             } catch (IOException e) {
                 errorStatuses.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
                         "Failed to write Ivy file " + container.getState().getIvyFile().getPath(),
                         e));
+            } catch (SAXException e) {
+                errorStatuses.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
+                    "Failed to write Ivy file " + container.getState().getIvyFile().getPath(),
+                    e));
+            } finally {
+                ivyTempFile.delete();
             }
         }
 
@@ -135,24 +196,20 @@
                 .size()]);
     }
 
-    /**
-     * Return the new revision changes for a given project <br>
-     * 
-     * @param project
-     *            project
-     * @return multiRevision descriptors
-     */
-    private Collection/* <MultiRevisionDependencyDescriptor> */getNewRevisions(
-            IvyClasspathContainer container) {
-        Collection/* <MultiRevisionDependencyDescriptor> */list = new ArrayList();
-
-        for (int i = 0; i < multiRevisionDependencies.length; i++) {
-            MultiRevisionDependencyDescriptor multiRevision = multiRevisionDependencies[i];
-            if (multiRevision.hasNewRevision() && multiRevision.isForContainer(container))
{
-                list.add(multiRevision);
+    private void saveChanges(IvyClasspathContainer container, File permanentSaveTarget, File
temporaryChanges) throws IOException {
+        IvyClasspathContainerConfiguration conf = container.getConf();
+        IFile virtualIvyFile = conf.getJavaProject().getProject().getFile(conf.getIvyXmlPath());
+        IStatus writable = virtualIvyFile.getWorkspace().validateEdit(new IFile[] {virtualIvyFile},
+            IWorkspace.VALIDATE_PROMPT);
+        if (writable.isOK()) {            
+            FileWriter writer = new FileWriter(permanentSaveTarget, false);            
+            BufferedReader reader = new BufferedReader(new FileReader(temporaryChanges));
+            while(reader.ready()) {
+                writer.write(reader.readLine() + "\n");
             }
+            writer.flush();
+            writer.close();
+            reader.close();
         }
-
-        return list;
-    }
+    }    
 }



Mime
View raw message