You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Nicolas Lalevée <ni...@hibnet.org> on 2009/12/04 15:23:11 UTC

Re: svn commit: r885779 - /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/revdepexplorer/SyncIvyFilesJob.java

With this change now IvyDE expects an Ivy 2.1.0. I have absolutely no problem 
with that, just to let you know. I just fixed the build on hudson regarding 
this dependency.

There was also a use of String.contains which comes with java 1.5. For now we 
kept the compatibility with 1.4 [1]. Some time ago I remember some user 
requiring it. We probably can dump now to 1.5. For now I just fixed it by 
using String.indexOf. Note also that hudson won't complain about the use of 
java 1.4 api as the build itself require java 1.6 (we need the javascript 
engine to generate the doc), and I don't know how to tell the headless 
eclipse to build with a bootstrap 1.4.

Nicolas


On Tuesday 01 December 2009 15:58:00 jschneider@apache.org wrote:
> 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/ecli
>pse/revdepexplorer/SyncIvyFilesJob.java
>
> Modified:
> ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/ecli
>pse/revdepexplorer/SyncIvyFilesJob.java URL:
> http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/s
>rc/java/org/apache/ivyde/eclipse/revdepexplorer/SyncIvyFilesJob.java?rev=885
>779&r1=885778&r2=885779&view=diff
> ===========================================================================
>=== ---
> ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/ecli
>pse/revdepexplorer/SyncIvyFilesJob.java (original) +++
> ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/ecli
>pse/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;
> -    }
> +    }
>  }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org