ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas Lalevée <nicolas.lale...@hibnet.org>
Subject Re: svn commit: r1075566 - in /ant/ivy/core/trunk: ./ doc/use/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/retrieve/
Date Wed, 02 Mar 2011 00:45:33 GMT
This feature looks great, but I'm starting now (it took me some time yeah :)) to have some
doubt on the implementation. I'll just raise them to get some other point of view.

Since retrieve is a post resolve task, it can accept nested <dependency> declaration.
Then addin the possibility to have a nested mapper, won't be any conflict. What happen if
a mapper get called "dependency" ? Ant would be confused right ?

And it seems than the Ant API is leaking into Ivy core here. RetrieveOption is depending on
FileNameMapper which is then depending on Mapper from Ant. Shouldn't we try to get Ivy loadable
without Ant ?

Nicolas

Le 28 févr. 2011 à 23:27, maartenc@apache.org a écrit :

> Author: maartenc
> Date: Mon Feb 28 22:27:20 2011
> New Revision: 1075566
> 
> URL: http://svn.apache.org/viewvc?rev=1075566&view=rev
> Log:
> IMPROVEMENT: ivy:retrieve now accepts a nested Ant <mapper> type.
> 
> Added:
>    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/MapperAdapter.java
>    ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/FileNameMapper.java
> Modified:
>    ant/ivy/core/trunk/CHANGES.txt
>    ant/ivy/core/trunk/doc/use/retrieve.html
>    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java
>    ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java
>    ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java
> 
> Modified: ant/ivy/core/trunk/CHANGES.txt
> URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1075566&r1=1075565&r2=1075566&view=diff
> ==============================================================================
> --- ant/ivy/core/trunk/CHANGES.txt (original)
> +++ ant/ivy/core/trunk/CHANGES.txt Mon Feb 28 22:27:20 2011
> @@ -122,6 +122,7 @@ for detailed view of each issue, please 
> - IMPROVEMENT: ivy:retrieve can now create a path or fileset containing the retrieved
artifacts (IVY-1235)
> - IMPROVEMENT: Improve diagnostics in ssh resolver (IVY-1267) (thanks to Stepan Koltsov)
> - IMPROVEMENT: ivy:retrieve can now convert 'dotted'-organisation names into a directory
tree.
> +- IMPROVEMENT: ivy:retrieve now accepts a nested mapper type.
> 
> - FIX: quiet="true" does not surpress download 'dots' on packager resolver (IVY-1269)
> - FIX: Dynamic version resolution result can be incorrect when ivy metadata contains
extra attributes (IVY-1236)
> 
> Modified: ant/ivy/core/trunk/doc/use/retrieve.html
> URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/retrieve.html?rev=1075566&r1=1075565&r2=1075566&view=diff
> ==============================================================================
> --- ant/ivy/core/trunk/doc/use/retrieve.html (original)
> +++ ant/ivy/core/trunk/doc/use/retrieve.html Mon Feb 28 22:27:20 2011
> @@ -38,6 +38,7 @@ Example:
> pattern: lib/[conf]/[artifact].[ext]
> root: lib
> 
> +<span class="since">since 2.3</span> A nested <a href="http://ant.apache.org/manual/Types/mapper.html">mapper</a>
element can be used to specify more complex filename transformations of the retrieved files.
See the examples below.
> 
> <table class="ant">
> <thead>
> @@ -172,6 +173,16 @@ lib
> <ivy:retrieve organisation="foo" module="bar" inline="true" pattern="${my.install.dir}/[artifact].[ext]"/>
> </code>
> Resolves and retrieve the latest version of the module bar and its dependencies in the
directory pointed by ${my.install.dir}.
> +<hr/>
> +<code type="xml">
> +<ivy:retrieve pattern="lib/[artifact]-[revision].[ext]">
> +    <firstmatchmapper>
> +        <globmapper from="lib/*-SNAPSHOT.jar" to="lib/snapshots/*-SNAPSHOT.jar" />
> +        <globmapper from="lib/*" to="lib/releases/*"/>
> +    </firstmatchmapper>
> +</ivy:retrieve>
> +</code>
> +Retrieves all dependencies of the last resolve call to a lib directory. The jar files
with a version equal to 'SNAPSHOT' are retrieved in a 'snapshots' directory. The other ones
are retrieved in a 'releases' directory.
> 	</textarea>
> <script type="text/javascript">xooki.postProcess();</script>
> </body>
> 
> Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java
> URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java?rev=1075566&r1=1075565&r2=1075566&view=diff
> ==============================================================================
> --- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java (original)
> +++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java Mon Feb 28 22:27:20
2011
> @@ -28,8 +28,10 @@ import org.apache.ivy.core.retrieve.Retr
> import org.apache.ivy.util.filter.Filter;
> import org.apache.tools.ant.BuildException;
> import org.apache.tools.ant.types.FileSet;
> +import org.apache.tools.ant.types.Mapper;
> import org.apache.tools.ant.types.Path;
> import org.apache.tools.ant.types.PatternSet;
> +import org.apache.tools.ant.util.FileNameMapper;
> 
> /**
>  * This task allow to retrieve dependencies from the cache to a local directory like
a lib dir.
> @@ -60,6 +62,8 @@ public class IvyRetrieve extends IvyPost
>     private String pathId = null;
> 
>     private String setId = null;
> +    
> +    private Mapper mapper = null;
> 
>     public String getPattern() {
>         return pattern;
> @@ -109,7 +113,8 @@ public class IvyRetrieve extends IvyPost
>                             .setDirMode(getDirMode())
>                             .setUseOrigin(isUseOrigin())
>                             .setMakeSymlinks(symlink)
> -                            .setResolveId(getResolveId()));
> +                            .setResolveId(getResolveId())
> +                            .setMapper(mapper == null ? null : new MapperAdapter(mapper)));
> 
>             int targetsCopied = report.getNbrArtifactsCopied();
>             boolean haveTargetsBeenCopied = targetsCopied > 0;
> @@ -193,6 +198,28 @@ public class IvyRetrieve extends IvyPost
>     public String getDirMode() {
>         return dirMode;
>     }
> +    
> +    /**
> +     * Add a mapper to convert the file names.
> +     *
> +     * @param mapper a <code>Mapper</code> value.
> +     */
> +    public void addMapper(Mapper mapper) {
> +        if (this.mapper != null) {
> +            throw new IllegalArgumentException("Cannot define more than one mapper");
> +        }
> +        this.mapper = mapper;
> +    }
> +
> +    /**
> +     * Add a nested filenamemapper.
> +     * @param fileNameMapper the mapper to add.
> +     */
> +    public void add(FileNameMapper fileNameMapper) {
> +        Mapper m = new Mapper(getProject());
> +        m.add(fileNameMapper);
> +        addMapper(m);
> +    }
> 
>     /**
>      * Returns the path of the file relative to the given base directory.
> 
> Added: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/MapperAdapter.java
> URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/MapperAdapter.java?rev=1075566&view=auto
> ==============================================================================
> --- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/MapperAdapter.java (added)
> +++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/MapperAdapter.java Mon Feb 28 22:27:20
2011
> @@ -0,0 +1,42 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one or more
> + *  contributor license agreements.  See the NOTICE file distributed with
> + *  this work for additional information regarding copyright ownership.
> + *  The ASF licenses this file to You under the Apache License, Version 2.0
> + *  (the "License"); you may not use this file except in compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing, software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + *  See the License for the specific language governing permissions and
> + *  limitations under the License.
> + *
> + */
> +package org.apache.ivy.ant;
> +
> +import org.apache.ivy.core.retrieve.FileNameMapper;
> +import org.apache.tools.ant.types.Mapper;
> +
> +class MapperAdapter implements FileNameMapper {
> +    
> +    private static final String[] EMPTY = new String[0];
> +    
> +    private Mapper mapper;
> +    
> +    MapperAdapter(Mapper mapper) {
> +        this.mapper = mapper;
> +    }
> +
> +    public String[] mapFileName(String fileName) {
> +        String[] result = mapper.getImplementation().mapFileName(fileName);
> +        if (result == null) {
> +            result = EMPTY;
> +        }
> +        
> +        return result;
> +    }
> +
> +}
> 
> Added: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/FileNameMapper.java
> URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/FileNameMapper.java?rev=1075566&view=auto
> ==============================================================================
> --- ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/FileNameMapper.java (added)
> +++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/FileNameMapper.java Mon
Feb 28 22:27:20 2011
> @@ -0,0 +1,24 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one or more
> + *  contributor license agreements.  See the NOTICE file distributed with
> + *  this work for additional information regarding copyright ownership.
> + *  The ASF licenses this file to You under the Apache License, Version 2.0
> + *  (the "License"); you may not use this file except in compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing, software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + *  See the License for the specific language governing permissions and
> + *  limitations under the License.
> + *
> + */
> +package org.apache.ivy.core.retrieve;
> +
> +public interface FileNameMapper {
> +
> +    String[] mapFileName(String fileName);
> +    
> +}
> 
> Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java
> URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java?rev=1075566&r1=1075565&r2=1075566&view=diff
> ==============================================================================
> --- ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java (original)
> +++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java Mon
Feb 28 22:27:20 2011
> @@ -307,7 +307,7 @@ public class RetrieveEngine {
>                 ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next();
>                 String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern
>                         : destFilePattern;
> -
> +                
>                 if (!"ivy".equals(artifact.getType())
>                         && !options.getArtifactFilter().accept(artifact.getArtifact()))
{
>                     continue; // skip this artifact, the filter didn't accept it!
> @@ -327,33 +327,41 @@ public class RetrieveEngine {
>                 } else {
>                     throw new IllegalArgumentException("Unsupported dirMode: " + options.getDirMode());
>                 }
> -
> +                
>                 Set dest = (Set) artifactsToCopy.get(artifact);
>                 if (dest == null) {
>                     dest = new HashSet();
>                     artifactsToCopy.put(artifact, dest);
>                 }
>                 String copyDest = settings.resolveFile(destFileName).getAbsolutePath();
> -                dest.add(copyDest);
> 
> -                Set conflicts = (Set) conflictsMap.get(copyDest);
> -                Set conflictsReports = (Set) conflictsReportsMap.get(copyDest);
> -                Set conflictsConf = (Set) conflictsConfMap.get(copyDest);
> -                if (conflicts == null) {
> -                    conflicts = new HashSet();
> -                    conflictsMap.put(copyDest, conflicts);
> -                }
> -                if (conflictsReports == null) {
> -                    conflictsReports = new HashSet();
> -                    conflictsReportsMap.put(copyDest, conflictsReports);
> -                }
> -                if (conflictsConf == null) {
> -                    conflictsConf = new HashSet();
> -                    conflictsConfMap.put(copyDest, conflictsConf);
> -                }
> -                if (conflicts.add(artifact.getArtifact().getId())) {
> -                    conflictsReports.add(artifact);
> -                    conflictsConf.add(conf);
> +                String[] destinations = new String[] {copyDest};
> +                if (options.getMapper() != null) {
> +                    destinations = options.getMapper().mapFileName(copyDest);
> +                }
> +
> +                for (int j = 0; j < destinations.length; j++) {
> +                    dest.add(destinations[j]);
> +
> +                    Set conflicts = (Set) conflictsMap.get(destinations[j]);
> +                    Set conflictsReports = (Set) conflictsReportsMap.get(destinations[j]);
> +                    Set conflictsConf = (Set) conflictsConfMap.get(destinations[j]);
> +                    if (conflicts == null) {
> +                        conflicts = new HashSet();
> +                        conflictsMap.put(destinations[j], conflicts);
> +                    }
> +                    if (conflictsReports == null) {
> +                        conflictsReports = new HashSet();
> +                        conflictsReportsMap.put(destinations[j], conflictsReports);
> +                    }
> +                    if (conflictsConf == null) {
> +                        conflictsConf = new HashSet();
> +                        conflictsConfMap.put(destinations[j], conflictsConf);
> +                    }
> +                    if (conflicts.add(artifact.getArtifact().getId())) {
> +                        conflictsReports.add(artifact);
> +                        conflictsConf.add(conf);
> +                    }
>                 }
>             }
>         }
> 
> Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java
> URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java?rev=1075566&r1=1075565&r2=1075566&view=diff
> ==============================================================================
> --- ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java (original)
> +++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java Mon
Feb 28 22:27:20 2011
> @@ -83,6 +83,8 @@ public class RetrieveOptions extends Log
>      * The id used to store the resolve information.
>      */
>     private String resolveId;
> +    
> +    private FileNameMapper mapper;
> 
>     public RetrieveOptions() {
>     }
> @@ -99,6 +101,7 @@ public class RetrieveOptions extends Log
>         this.makeSymlinks = options.makeSymlinks;
>         this.dirMode = options.dirMode;
>         this.resolveId = options.resolveId;
> +        this.mapper = options.mapper;
>     }
> 
>     public String getDestArtifactPattern() {
> @@ -191,4 +194,13 @@ public class RetrieveOptions extends Log
>         return this;
>     }
> 
> +    public FileNameMapper getMapper() {
> +        return mapper;
> +    }
> +
> +    public RetrieveOptions setMapper(FileNameMapper mapper) {
> +        this.mapper = mapper;
> +        return this;
> +    }
> +    
> }
> 
> 


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


Mime
View raw message