Return-Path: Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: (qmail 63730 invoked from network); 20 Sep 2010 15:52:01 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 20 Sep 2010 15:52:01 -0000 Received: (qmail 78176 invoked by uid 500); 20 Sep 2010 15:52:01 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 78091 invoked by uid 500); 20 Sep 2010 15:51:59 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 78082 invoked by uid 99); 20 Sep 2010 15:51:58 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Sep 2010 15:51:58 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Sep 2010 15:51:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6CA722388A40; Mon, 20 Sep 2010 15:51:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r998962 - in /ant/core/trunk: WHATSNEW docs/manual/Types/mapper.html src/main/org/apache/tools/ant/types/defaults.properties src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java src/tests/antunit/types/cutdirs-test.xml Date: Mon, 20 Sep 2010 15:51:19 -0000 To: notifications@ant.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100920155119.6CA722388A40@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Mon Sep 20 15:51:18 2010 New Revision: 998962 URL: http://svn.apache.org/viewvc?rev=998962&view=rev Log: Add a mapper similar to wget --cut-dirs, based on user-list discussion initiated by Michael Ludwig Added: ant/core/trunk/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java (with props) ant/core/trunk/src/tests/antunit/types/cutdirs-test.xml (with props) Modified: ant/core/trunk/WHATSNEW ant/core/trunk/docs/manual/Types/mapper.html ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=998962&r1=998961&r2=998962&view=diff ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Mon Sep 20 15:51:18 2010 @@ -203,6 +203,9 @@ Other changes: and singleline attributes. Bugzilla Report 49764. + * A new can be used like wget's --cut-dirs option to + strip leading directories from file names. + Changes from Ant 1.8.0 TO Ant 1.8.1 =================================== Modified: ant/core/trunk/docs/manual/Types/mapper.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/Types/mapper.html?rev=998962&r1=998961&r2=998962&view=diff ============================================================================== --- ant/core/trunk/docs/manual/Types/mapper.html (original) +++ ant/core/trunk/docs/manual/Types/mapper.html Mon Sep 20 15:51:18 2010 @@ -919,7 +919,44 @@ list of mapped names reset after every i <mapper type> attribute.

+

cutdirsmapper (since Ant 1.8.2)

+

This mapper strips a configured number of leading directories from + the source file name.

+ +Examples: +
+<cutdirsmapper dirs="1"/>
+
+ + + + + + + + + + +
Source file nameTarget file names
foo/bar/A.txtbar/A.txt
+ +

The cutdirsmapper has no +corresponding <mapper type> attribute.

+ + + + + + + + + + + + +
AttributeDescriptionRequired
dirs + Number of directories to strip (must be a positive number). + Yes
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties?rev=998962&r1=998961&r2=998962&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties Mon Sep 20 15:51:18 2010 @@ -46,6 +46,7 @@ compositemapper=org.apache.tools.ant.uti chainedmapper=org.apache.tools.ant.util.ChainedMapper filtermapper=org.apache.tools.ant.types.mappers.FilterMapper firstmatchmapper=org.apache.tools.ant.util.FirstMatchMapper +cutdirsmapper=org.apache.tools.ant.types.mappers.CutDirsMapper #this condition is in here because it is the sole #condition defined in Ant1.6 Added: ant/core/trunk/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java?rev=998962&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java Mon Sep 20 15:51:18 2010 @@ -0,0 +1,74 @@ +/* + * 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.tools.ant.types.mappers; + +import java.io.File; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.FileNameMapper; + +/** + * A mapper that strips of the a configurable number of leading + * directories from a file name. + * + *

This mapper was inspired by a user-list thread that mentioned + * wget's --cut-dirs option.

+ * + * @see http://mail-archives.apache.org/mod_mbox/ant-user/201009.mbox/%3C51772743BEA5D44A9EA5BF52AADDD6FB010E96F6@hammai008.delphi.local%3E + */ +public class CutDirsMapper implements FileNameMapper { + private int dirs = 0; + + /** + * The number of leading directories to cut. + */ + public void setDirs(int dirs) { + this.dirs = dirs; + } + + /** + * Empty implementation. + * @param ignore ignored. + */ + public void setFrom(String ignore) { + } + + /** + * Empty implementation. + * @param ignore ignored. + */ + public void setTo(String ignore) { + } + + /** {@inheritDoc}. */ + public String[] mapFileName(final String sourceFileName) { + if (dirs <= 0) { + throw new BuildException("dirs must be set to a positive number"); + } + char fileSep = File.separatorChar; + String fileSepCorrected = + sourceFileName.replace('/', fileSep).replace('\\', fileSep); + int nthMatch = fileSepCorrected.indexOf(fileSep); + for (int n = 1; nthMatch > -1 && n < dirs; n++) { + nthMatch = fileSepCorrected.indexOf(fileSep, nthMatch + 1); + } + if (nthMatch == -1) { + return null; + } + return new String[] { sourceFileName.substring(nthMatch + 1) }; + } +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/core/trunk/src/tests/antunit/types/cutdirs-test.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/cutdirs-test.xml?rev=998962&view=auto ============================================================================== --- ant/core/trunk/src/tests/antunit/types/cutdirs-test.xml (added) +++ ant/core/trunk/src/tests/antunit/types/cutdirs-test.xml Mon Sep 20 15:51:18 2010 @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Propchange: ant/core/trunk/src/tests/antunit/types/cutdirs-test.xml ------------------------------------------------------------------------------ svn:eol-style = native