Browse Source

Use a non-recursive (well, less recursive, max depth is 2) approach

for <linecontains>.

PR: 15528


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274106 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
c8b3893a88
4 changed files with 24 additions and 8 deletions
  1. +3
    -0
      src/etc/testcases/filters/expected/linecontains.test
  2. +5
    -1
      src/etc/testcases/filters/input/linecontains.test
  3. +13
    -5
      src/main/org/apache/tools/ant/filters/LineContains.java
  4. +3
    -2
      src/testcases/org/apache/tools/ant/filters/LineContainsTest.java

+ 3
- 0
src/etc/testcases/filters/expected/linecontains.test View File

@@ -1 +1,4 @@
This is line 2 with beta.
This is line 3 with beta.
This is line 5 with beta.
This is line 7 with beta.

+ 5
- 1
src/etc/testcases/filters/input/linecontains.test View File

@@ -1,3 +1,7 @@
This is line 1 with alpha.
This is line 2 with beta.
This is line 3 with gamma.
This is line 3 with beta.
This is line 4 with gamma.
This is line 5 with beta.
This is line 6 with delta.
This is line 7 with beta.

+ 13
- 5
src/main/org/apache/tools/ant/filters/LineContains.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -143,10 +143,9 @@ public final class LineContains
}
} else {
line = readLine();
if (line == null) {
ch = -1;
} else {
final int containsSize = contains.size();
final int containsSize = contains.size();

while (line != null) {
for (int i = 0; i < containsSize; i++) {
String containsStr = (String) contains.elementAt(i);
if (line.indexOf(containsStr) == -1) {
@@ -155,6 +154,15 @@ public final class LineContains
}
}

if (line == null) {
// line didn't match
line = readLine();
} else {
break;
}
}

if (line != null) {
return read();
}
}


+ 3
- 2
src/testcases/org/apache/tools/ant/filters/LineContainsTest.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -81,7 +81,8 @@ public class LineContainsTest extends BuildFileTest {
executeTarget("testLineContains");
File expected = getProject().resolveFile("expected/linecontains.test");
File result = getProject().resolveFile("result/linecontains.test");
assertTrue(FileUtils.newFileUtils().contentEquals(expected, result));
FileUtils fu = FileUtils.newFileUtils();
assertTrue(fu.contentEquals(expected, result));
}
}

Loading…
Cancel
Save