开发者

Ant unzip task - how can I exclude the archive name from extracted hierarchy?

开发者 https://www.devze.com 2023-01-06 02:50 出处:网络
How can I exclude the ar开发者_如何学编程chive name from the file hierarchy after an ant unzip task?

How can I exclude the ar开发者_如何学编程chive name from the file hierarchy after an ant unzip task?

For example, once ant's run the unzip task in the folder C:\temp, I want all the files from the archive archive, but instead I get C:\temp\t\file.tmp.

Can I effectively exclude the base directory inside the archive?


Use a mapper specify how the files should look in the destination directory:

<unzip src="t.zip" dest="temp">
    <globmapper from="t/*" to="*"/>
</unzip>


A better solution now is the cutdirsmapper:

<unzip src="t.zip" dest="temp">
    <cutdirsmapper dirs="1"/>
</unzip>


I use:

<mapper type="flatten" />   


See also https://www.safaribooksonline.com/library/view/ant-the-definitive/0596001843/ch04s10.html

The flatten mapper removes all path information from filenames.

For example in build.xml:

<target name="extract-xsd">
    <unzip src="./cache/nl.packagename.example/xx/jars/somepackage.jar" dest="repository">
        <mapper type="flatten" />
        <patternset>
            <include name="**/Example.xsd"/>
            <include name="**/Example.wsdl"/>
        </patternset>
    </unzip>
</target>

As a result, the Example.xsd and Example.wsdl are put in the repository folder directly.

0

精彩评论

暂无评论...
验证码 换一张
取 消