revisited. The original patch wouldn't pass Unzip's new testPatternSetIncludeAndExclude test. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274017 13f79535-47bb-0310-9956-ffa450edef68master
@@ -4,6 +4,9 @@ | |||||
<target name="cleanup"> | <target name="cleanup"> | ||||
<delete file="asf-logo.gif" /> | <delete file="asf-logo.gif" /> | ||||
<delete file="unziptest.zip"/> | |||||
<delete dir="unziptestin"/> | |||||
<delete dir="unziptestout"/> | |||||
</target> | </target> | ||||
<target name="test1"> | <target name="test1"> | ||||
@@ -28,4 +31,36 @@ | |||||
<unzip src="expected/asf-logo.gif.zip" dest="." /> | <unzip src="expected/asf-logo.gif.zip" dest="." /> | ||||
</target> | </target> | ||||
<target name="prepareTestZip"> | |||||
<mkdir dir="unziptestin/1"/> | |||||
<mkdir dir="unziptestin/2"/> | |||||
<touch file="unziptestin/1/foo"/> | |||||
<touch file="unziptestin/2/bar"/> | |||||
<zip destfile="unziptest.zip" basedir="unziptestin"/> | |||||
</target> | |||||
<target name="testPatternSetExcludeOnly" depends="prepareTestZip"> | |||||
<unzip dest="unziptestout" src="unziptest.zip"> | |||||
<patternset> | |||||
<exclude name="1/**"/> | |||||
</patternset> | |||||
</unzip> | |||||
</target> | |||||
<target name="testPatternSetIncludeOnly" depends="prepareTestZip"> | |||||
<unzip dest="unziptestout" src="unziptest.zip"> | |||||
<patternset> | |||||
<include name="2/**"/> | |||||
</patternset> | |||||
</unzip> | |||||
</target> | |||||
<target name="testPatternSetIncludeAndExclude" depends="prepareTestZip"> | |||||
<unzip dest="unziptestout" src="unziptest.zip"> | |||||
<patternset> | |||||
<include name="2/**"/> | |||||
<exclude name="2/**"/> | |||||
</patternset> | |||||
</unzip> | |||||
</target> | |||||
</project> | </project> |
@@ -182,17 +182,25 @@ public class Expand extends Task { | |||||
String name = entryName; | String name = entryName; | ||||
boolean included = false; | boolean included = false; | ||||
for (int v = 0; v < patternsets.size(); v++) { | for (int v = 0; v < patternsets.size(); v++) { | ||||
included = true; | |||||
PatternSet p = (PatternSet) patternsets.elementAt(v); | PatternSet p = (PatternSet) patternsets.elementAt(v); | ||||
String[] incls = p.getIncludePatterns(getProject()); | String[] incls = p.getIncludePatterns(getProject()); | ||||
if (incls != null) { | |||||
for (int w = 0; w < incls.length; w++) { | |||||
included = DirectoryScanner.match(incls[w], name); | |||||
if (included) { | |||||
break; | |||||
} | |||||
if (incls == null || incls.length == 0) { | |||||
// no include pattern implicitly means includes="**" | |||||
incls = new String[] {"**"}; | |||||
} | |||||
for (int w = 0; w < incls.length; w++) { | |||||
included = DirectoryScanner.match(incls[w], name); | |||||
if (included) { | |||||
break; | |||||
} | } | ||||
} | } | ||||
if (!included) { | |||||
break; | |||||
} | |||||
String[] excls = p.getExcludePatterns(getProject()); | String[] excls = p.getExcludePatterns(getProject()); | ||||
if (excls != null) { | if (excls != null) { | ||||
for (int w = 0; w < excls.length; w++) { | for (int w = 0; w < excls.length; w++) { | ||||
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
* | * | ||||
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights | |||||
* Copyright (c) 2000-2001,2003 The Apache Software Foundation. All rights | |||||
* reserved. | * reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
@@ -101,4 +101,37 @@ public class UnzipTest extends BuildFileTest { | |||||
project.resolveFile("asf-logo.gif"))); | project.resolveFile("asf-logo.gif"))); | ||||
} | } | ||||
/* | |||||
* PR 11100 | |||||
*/ | |||||
public void testPatternSetExcludeOnly() { | |||||
executeTarget("testPatternSetExcludeOnly"); | |||||
assertTrue("1/foo is excluded", | |||||
!getProject().resolveFile("unziptestout/1/foo").exists()); | |||||
assertTrue("2/bar is not excluded", | |||||
getProject().resolveFile("unziptestout/2/bar").exists()); | |||||
} | |||||
/* | |||||
* PR 11100 | |||||
*/ | |||||
public void testPatternSetIncludeOnly() { | |||||
executeTarget("testPatternSetIncludeOnly"); | |||||
assertTrue("1/foo is not included", | |||||
!getProject().resolveFile("unziptestout/1/foo").exists()); | |||||
assertTrue("2/bar is included", | |||||
getProject().resolveFile("unziptestout/2/bar").exists()); | |||||
} | |||||
/* | |||||
* PR 11100 | |||||
*/ | |||||
public void testPatternSetIncludeAndExclude() { | |||||
executeTarget("testPatternSetIncludeAndExclude"); | |||||
assertTrue("1/foo is not included", | |||||
!getProject().resolveFile("unziptestout/1/foo").exists()); | |||||
assertTrue("2/bar is excluded", | |||||
!getProject().resolveFile("unziptestout/2/bar").exists()); | |||||
} | |||||
} | } |