| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package net.sf.antcontrib; |
| 17 |
|
| 18 |
import java.io.File; |
| 19 |
import java.io.PrintWriter; |
| 20 |
import java.io.StringWriter; |
| 21 |
import java.net.URL; |
| 22 |
|
| 23 |
import org.apache.tools.ant.BuildException; |
| 24 |
import org.apache.tools.ant.BuildFileTest; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public abstract class BuildFileTestBase extends BuildFileTest { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public BuildFileTestBase( String name ) { |
| 40 |
super( name ); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
protected void expectBuildException( String target ) { |
| 49 |
expectSpecificBuildException( target, "no specific reason", null ); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
protected void expectLogNotContaining( String target, String log ) { |
| 60 |
executeTarget( target ); |
| 61 |
String realLog = getLog(); |
| 62 |
assertTrue( "expecting log to NOT contain \"" + log + "\" log was \"" |
| 63 |
+ realLog + "\"", |
| 64 |
realLog.indexOf( log ) < 0 ); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
protected void configureProject( String filename ) throws BuildException { |
| 80 |
|
| 81 |
File f = new File( filename ); |
| 82 |
if ( !f.exists() ) { |
| 83 |
URL url = getClass().getClassLoader().getResource( filename ); |
| 84 |
if ( url == null ) |
| 85 |
throw new BuildException( "Can't find " + filename ); |
| 86 |
f = new File( url.getPath() ); |
| 87 |
if ( !f.exists() ) |
| 88 |
throw new BuildException( "Can't find " + filename ); |
| 89 |
} |
| 90 |
super.configureProject(f.getAbsolutePath()); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
protected void expectBuildExceptionStackTraceContaining( String target, String cause, String contains ) { |
| 102 |
try { |
| 103 |
executeTarget( target ); |
| 104 |
} |
| 105 |
catch ( org.apache.tools.ant.BuildException ex ) { |
| 106 |
|
| 107 |
StringWriter stacktrace = new StringWriter(); |
| 108 |
PrintWriter writer = new PrintWriter( stacktrace, true ); |
| 109 |
ex.printStackTrace( writer ); |
| 110 |
String trace = stacktrace.toString(); |
| 111 |
if ( ( null != contains ) && ( trace.indexOf( contains ) == -1 ) ) { |
| 112 |
fail( "Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + trace + "' instead)" ); |
| 113 |
} |
| 114 |
return; |
| 115 |
} |
| 116 |
fail( "Should throw BuildException because: " + cause ); |
| 117 |
} |
| 118 |
} |
| 119 |
|