Codebase list ant / 2992beb
New upstream version 1.9.8 Emmanuel Bourg 7 years ago
230 changed file(s) with 3194 addition(s) and 904 deletion(s). Raw diff Collapse all Expand all
5050 Cedomir Igaly
5151 Charles Hudak
5252 Charlie Hubbard
53 Chris Hegarty
5354 Chris Povirk
5455 Christian Knorr
5556 Christian Schmidt
7677 Dale Anson
7778 Dale Sherwood
7879 Dan Armbrust
80 Dana Dahlstrom
7981 Daniel Henrique
8082 Daniel Ribagnac
8183 Daniel Spilker
135137 Gero Vermaas
136138 Gerrit Riessen
137139 Gilbert Rebhan
140 Gilles Querret
138141 Gilles Scokart
139142 Glenn McAllister
140143 Glenn Twiggs
250253 Matthew Inger
251254 Matthew Kuperus Heun
252255 Matthew Watson
256 Matthew Yanos
253257 Matthias Bhend
254258 Michael Bayne
255259 Michael Clarke
399403 Victor Toni
400404 Vimil Saju
401405 Vincent Legoll
406 Vincent Privat
402407 Vitold Sedyshev
403408 Volker Leidl
404409 Waldek Herka
0 Changes from Ant 1.9.7 TO Ant 1.9.8
1 ===================================
2
3 Changes that could break older environments:
4 -------------------------------------------
5
6 * <fileset>/<zipfileset>/<tarfileset> exhibited undefined
7 behavior when both the dir and file attribute have been used on the
8 same instance. This will now cause the build to fail.
9 Bugzilla Report 59402
10
11 * The ant.java.version property will now hold the value "9" rather
12 than "1.9" if running on Java 9.
13
14 * <rmic> will no longer allow the -Xnew option (or xmic compiler) to
15 be used when running on Java 9 since this option has been removed.
16 Bugzilla Report 59906
17
18 Fixed bugs:
19 -----------
20
21 * setDynamicAttribute on MacroInstance now lower-cases the attribute
22 name in order to allow users of the API to use the attributes names
23 they have specified.
24 Bugzilla Report 59339
25
26 * <get>'s quiet attribute was broken, it didn't suppress any messages.
27 Bugzilla Report 59379
28
29 * <zip>'s check whether an archive is already up-to-date failed on
30 NTFS filesystems and re-created archives more often than necessary.
31 Bugzilla Report 59562
32
33 * AntClassLoader didn't delegate to the parent loader for classes in
34 the "jdk" package or one of its subpackages. This hierarchy has
35 been introduced with Java 7.
36 Bugzilla Report 59556
37
38 * The ant wrapper script used on Unix-like operating systems only
39 worked on OSes where sed is GNU sed.
40 Bugzilla Report 59898
41
42 * <touch>'s default pattern as well as the default patterns used by
43 the <date> (resource) selectors depended on the JDK being used - or
44 rather the locale provider being used and the default locale
45 provider changed with Java 9.
46 They are now fixed and the documentation has been updated to
47 reflect the real patterns used rather than a non-formal description
48 of the expected format.
49 Bugzilla Report 59909
50
51 * Clarified the documentation of <get>'s retries attribute.
52 Bugzilla Report 59930
53
54 * The ant wrapper script failed if backticks were passed on the
55 command line.
56 Bugzilla Report 60150, 59445
57
58 * The report generated by <junitreport> could contain duplicate
59 characters in stack traces.
60 Bugzilla Report 58661
61
62 Other changes:
63 --------------
64
65 * <junit> now initializes the cause of the AssertionFailedError when
66 converting from AssertionError.
67 Bugzilla Report 58982
68
69 * <scp> now supports compression via the optional compressed attribute.
70 Bugzilla Report 47552
71
72 * <junit> now supports JDK9 modules
73 Github Pull Request #18
74
75 * a new implementation "builtin" has been added to <native2ascii> and
76 is the default when running on JDK9+ since the tool itself has been
77 removed from the JDK.
78 Bugzilla Report 59855
79
80 * added a new <native2asciifilter> filter that can perform non-ASCII
81 to Unicode-escape conversions.
82
83 * <rmic> defaults to the "forking" compiler on JDK 9+ as the
84 implementation class of rmic is not exported by its containing
85 module and thus not accessible to Ant without applying -XaddExports
86 magic.
87 Bugzilla Report 59860
88
89 * a new implementation "forking" has been added to <javah> and is
90 used as default when running on JDK9.
91
92 * support for javac's -h switch has been added with the
93 nativeheaderdir attribute.
94 Bugzilla Report 59905
95
96 * it is now possible to set features of the TraX factory used by <xslt>
97 and <junitreport>.
98
99 * it is now possible to use references to Ant types and classloaders
100 built around Ant <path>s as values for TraX factory attributes.
101
102 * <junitreport> now enables the feature
103 http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions
104 when run on Java 9 so the redirect extension function can be used
105 if when a SecurityManager is active.
106 Bugzilla Report 60060
107
108 * support for javac's --release switch introduced with Java9 has been
109 added.
110 Bugzilla Report 60172
111
0112 Changes from Ant 1.9.6 TO Ant 1.9.7
1113 ===================================
2114
5252 echo JAVA=%JAVA%
5353 echo JAVAC=%JAVAC%
5454 echo CLASSPATH=%CLASSPATH%
55 echo ANT_HOME=%ANT_HOME%
5556
5657 if "%OS%" == "Windows_NT" if exist %CLASSDIR%\nul rmdir/s/q %CLASSDIR%
5758 if not "%OS%" == "Windows_NT" if exist %CLASSDIR%\nul deltree/y %CLASSDIR%
3333 <property name="name" value="ant"/>
3434 <!-- this is the groupId of ant in the Maven repository -->
3535 <property name="groupid" value="org/apache/ant"/>
36 <property name="project.version" value="1.9.7"/>
36 <property name="project.version" value="1.9.8"/>
3737 <!-- pom.version is used when doing a distribution and must match with what is checked in under src/etc/poms -->
38 <property name="pom.version" value="1.9.7"/>
39 <property name="manifest-version" value="1.9.7"/>
38 <property name="pom.version" value="1.9.8"/>
39 <property name="manifest-version" value="1.9.8"/>
4040 <property name="bootstrap.jar" value="ant-bootstrap.jar"/>
4141
4242 <property name="ant.package" value="org/apache/tools/ant"/>
377377 <available property="jdk1.6+" classname="java.net.CookieStore"/>
378378 <available property="jdk1.7+" classname="java.nio.file.FileSystem"/>
379379 <available property="jdk1.8+" classname="java.lang.reflect.Executable"/>
380 <condition property="jdk1.9+">
381 <contains string="${java.version}" substring="1.9."/>
382 </condition>
380 <available property="jdk9+" classname="java.lang.module.ModuleDescriptor"/>
383381 <available property="kaffe" classname="kaffe.util.NotImplemented"/>
384382 <available property="harmony"
385383 classname="org.apache.harmony.luni.util.Base64"/>
226226 </name>
227227 <name>
228228 <first>Chris</first>
229 <last>Hegarty</last>
230 </name>
231 <name>
232 <first>Chris</first>
229233 <last>Povirk</last>
230234 </name>
231235 <name>
331335 <last>Armbrust</last>
332336 </name>
333337 <name>
338 <first>Dana</first>
339 <last>Dahlstrom</last>
340 </name>
341 <name>
334342 <first>Daniel</first>
335343 <last>Henrique</last>
336344 </name>
569577 </name>
570578 <name>
571579 <first>Gilles</first>
580 <last>Querret</last>
581 </name>
582 <name>
583 <first>Gilles</first>
572584 <last>Scokart</last>
573585 </name>
574586 <name>
10331045 <last>Watson</last>
10341046 </name>
10351047 <name>
1048 <first>Matthew</first>
1049 <last>Yanos</last>
1050 </name>
1051 <name>
10361052 <first>Michael</first>
10371053 <last>Bayne</last>
10381054 </name>
16041620 <last>Legoll</last>
16051621 </name>
16061622 <name>
1623 <first>Vincent</first>
1624 <last>Privat</last>
1625 </name>
1626 <name>
16071627 <first>Vimil</first>
16081628 <last>Saju</last>
16091629 </name>
5656 regexp.version=1.3
5757 servlet-api.version=2.3
5858 which.version=1.0
59 xalan.version=2.7.1
59 xalan.version=2.7.2
6060 xml-resolver.version=1.2
6161 mail.version=1.4
6262 #paired
106106 </tr>
107107 <tr>
108108 <td valign="top">retries</td>
109 <td valign="top">the per download number of retries on error<br/>
109 <td valign="top">The number of attempts to make for opening the URI.<br/>
110 The name of the attribute is misleading as a value of 1 means
111 "don't retry on error" and a value of 0 meant don't even try to
112 reach the URI at all.<br/>
110113 <em>since Ant 1.8.0</em></td>
111114 <td align="center" valign="top">No; default "3"</td>
112115 </tr>
7878 <code>javac1.6</code> and
7979 <code>javac1.7</code> (<em>since Ant 1.8.2</em>) and
8080 <code>javac1.8</code> (<em>since Ant 1.8.3</em>) and</li>
81 <code>javac1.9</code> (<em>since Ant 1.9.5</em>) can be used as aliases.</li>
81 <code>javac1.9</code> (<em>since Ant 1.9.5</em>) and</li>
82 <code>javac9</code> (<em>since Ant 1.9.8</em>) can be used as aliases.</li>
8283 <li><code>jikes</code> (the <a
8384 href="http://jikes.sourceforge.net/" target="_top">Jikes</a>
8485 compiler).</li>
123124 The side effect of this is that you will not be able to delete or move
124125 those files later on in the build. The workaround is to fork when
125126 invoking the compiler.</p>
127 <p>If you are using Java 8 or above and your source contains native
128 methods or fields annotated with the <code>@Native</code> annotation
129 you can set the <code>nativeheaderdir</code> attribute in order to
130 use the <code>-h</code> switch of <code>javac</code> to generate the
131 native header files. Note that the logic Ant uses to determine which
132 files to compile does not take native headers into account, i.e. if
133 the <code>.class</code> is more recent than the
134 corresponding <code>.java</code> file the file will not get compiled
135 even if a native header file generated for it would be outdated.</p>
126136 <h3>Parameters</h3>
127137 <table border="1" cellpadding="2" cellspacing="0">
128138 <tr>
501511 <td valign="top">
502512 The upgrademodulepath to use, given as <a href="../using.html#references">reference</a> to a PATH defined elsewhere.
503513 <em>since Ant 1.9.7</em></td>
514 <td align="center" valign="top">No</td>
515 </tr>
516 <tr>
517 <td valign="top">nativeheaderdir</td>
518 <td valign="top">
519 Specify where to place generated native header files. Ignored
520 when running on JDK &lt; 8.
521 <em>Since Ant 1.9.8</em>.
522 <td align="center" valign="top">No</td>
523 </tr>
524 <tr>
525 <td valign="top">release</td>
526 <td valign="top">
527 Specify the value for the <code>--release</code> switch.Ignored
528 when running on JDK &lt; 9.<br>
529 When set and running on JDK &gt;= 9 the source and target
530 attributes as well as the bootclasspath will be ignored.
531 <em>Since Ant 1.9.8</em>.
504532 <td align="center" valign="top">No</td>
505533 </tr>
506534 </table>
3232 or <a href="http://java.sun.com/products/jdk/1.1/docs/tooldocs/win32/javah.html">pre-JDK1.2</a>
3333 systems are used.</p>
3434
35 <p>If you are building with Java 8 or above consider
36 using <a href="javac.html"><code>javac</code></a>'s <code>nativeheaderdir</code>
37 attribute instead which allows you to compile the classes and
38 generate the native header files with a single step.</p>
39
40 <p><b>Note</b> the <code>javah</code> has been deprecated as of Java 9
41 and is scheduled to be removed with Java 10.</p>
42
3543 <p>It is possible to use different compilers. This can be selected
3644 with the <code>implementation</code> attribute or a nested element. <a
3745 name="implementationvalues">Here are the choices of the attribute</a>:</p>
3846 <ul>
39 <li>default - the default compiler (kaffeh or sun) for the platform.</li>
40 <li>sun (the standard compiler of the JDK)</li>
47 <li>default - the default compiler for the platform.</li>
48 <li>sun (the standard compiler of the JDK) - default when not
49 running on Kaffee or gcj/gij or Java9.</li>
4150 <li>kaffeh (the native standard compiler of <a href="http://www.kaffe.org" target="_top">Kaffe</a>)</li>
4251 <li>gcjh (the native standard compiler
4352 of <a href="http://gcc.gnu.org/java/"
44 target="_top">gcj and gij</a>) <em>since Apache Ant 1.8.2</em></li>
53 target="_top">gcj and gij</a>) <em>since Apache Ant 1.8.2</em></li>
54 <li>forking - runs the javah executable via its command line
55 interface in a separate process. Default when running on
56 Java9. <em>since Ant 1.9.8</em></li>
4557 </ul>
4658
4759 <p><b>Note:</b> if you are using this task to work on multiple files
369369 <p>Assertion statements are currently ignored in non-forked mode.</p>
370370
371371 <p><em>since Ant 1.6.</em></p>
372
373 <h4>modulepath</h4>
374
375 <p>The location of modules can be specified using this <a href="../using.html#path">PATH like structure</a>.<br/>
376 The modulepath requires <i>fork</i> to be set to <code>true</code>.
377
378 <p><em>since Ant 1.9.8</em></p>
379
380 <h4>upgrademodulepath</h4>
381
382 <p>The location of modules that replace upgradeable modules in the runtime image
383 can be specified using this <a href="../using.html#path">PATH like structure</a>.<br/>
384 The upgrademodulepath requires <i>fork</i> to be set to <code>true</code>.
385
386 <p><em>since Ant 1.9.8</em></p>
372387
373388 <h4>formatter</h4>
374389
795810 The two nested formatters are for displaying (for the user) and for updating the collector
796811 class.
797812 </p>
798
799
813 <pre>
814 &lt;junit fork="true"
815 jvm="${platform.java}"&gt;
816 &lt;jvmarg line="--patch-module ${module.name}=${build.test.classes}"/&gt;
817 &lt;jvmarg line="--add-modules ${module.name}"/&gt;
818 &lt;jvmarg line="--add-reads ${module.name}=ALL-UNNAMED"/&gt;
819 &lt;jvmarg line="--add-exports ${module.name}/my.test=ALL-UNNAMED"/&gt;
820 &lt;classpath&gt;
821 &lt;pathelement path="${libs.junit}"/&gt;
822 &lt;/classpath&gt;
823 &lt;modulepath&gt;
824 &lt;pathelement path="${modules}:${build.classes}"/&gt;
825 &lt;/modulepath&gt;
826 &lt;formatter type="plain"/&gt;
827 &lt;test name="my.test.TestCase"/&gt;
828 &lt;/junit&gt;
829 </pre>
830 <p>Runs my.test.TestCase as a white-box test in the forked VM given by the <code>platform.java</code> property.
831 The junit library is a part of an unnamed module while the tested project and required modules are on the module path. The tests
832 do not have module-info file and are executed in the project module given by <code>module.name</code> property.<br/>
833 The <code>--patch-module</code> java option executes the tests built into <code>${build.test.classes}</code> in a module given
834 by <code>module.name</code> property.<br/>
835 The <code>--add-modules</code> java option enables the tested module.<br/>
836 The <code>--add-reads</code> java option makes the unnamed module containing the junit readable by tested module.<br/>
837 The <code>--add-exports</code> java option makes the non-exported test package <code>my.test</code> accessible from the unnamed module containing the junit.<br/>
838 <pre>
839 &lt;junit fork="true"
840 jvm="${platform.java}"&gt;
841 &lt;jvmarg line="--add-modules ${test.module.name}"/&gt;
842 &lt;jvmarg line="--add-exports ${test.module.name}/my.test=junit,ALL-UNNAMED"/&gt;
843 &lt;modulepath&gt;
844 &lt;pathelement path="${modules}:${build.classes}:${libs.junit}"/&gt;
845 &lt;/modulepath&gt;
846 &lt;formatter type="plain"/&gt;
847 &lt;test name="my.test.TestCase"/&gt;
848 &lt;/junit&gt;
849 </pre>
850 <p>Runs my.test.TestCase as a black-box test in the forked VM given by the <code>platform.java</code> property.
851 The junit library is used as an automatic module. The tests module-info requires the tested module and junit.<br/>
852 The <code>--add-modules</code> java option enables the test module.<br/>
853 The <code>--add-exports</code> java option makes the non-exported test package <code>my.test</code> accessible from the junit module and Ant's test runner.
854 Another possibility is to export the test package in the tests module-info by <code>exports my.test</code> directive.<br/>
800855 </body>
801856 </html>
6060 with the <code>implementation</code> attribute or a nested element.
6161 <a name="implementationvalues">Here are the choices of the attribute</a>:</p>
6262 <ul>
63 <li>default - the default converter (kaffe or sun) for the platform.</li>
64 <li>sun (the standard converter of the JDK)</li>
65 <li>kaffe (the standard converter of <a href="http://www.kaffe.org" target="_top">Kaffe</a>)</li>
63 <li>default - the default converter for the platform - kaffee
64 when run on Kaffee, builtin if JDK9 or newer is detected, sun
65 otherwise.</li>
66 <li>sun (the standard converter of the JDK < 9)</li>
67 <li>kaffe (the standard converter
68 of <a href="http://www.kaffe.org" target="_top">Kaffe</a>)</li>
69 <li>builtin - Ant's internal implementation used for
70 JDK9+. <em>since ant 1.9.8</em></li>
6671 </ul>
6772
6873 <table border="1" cellpadding="2" cellspacing="0">
7580 <td>reverse</td>
7681 <td>Reverse the sense of the conversion,
7782 i.e. convert from ASCII to native <b>only supported by the
78 sun converter</b></td>
83 sun and builtin converters</b></td>
7984 <td align="center">No</td>
8085 </tr>
8186 <tr>
5151 attribute. or a nested element.
5252 <a name="compilervalues">Here are the choices</a>:</p>
5353 <ul>
54 <li>default -the default compiler (kaffe or sun) for the platform.
55 <li>sun (the standard compiler of the JDK)</li>
54 <li>default -the default compiler (kaffe, sun or forking) for the platform.
55 <li>sun (the standard compiler of the JDK &lt; JDK 9)</li>
5656 <li>kaffe (the standard compiler of <a href="http://www.kaffe.org" target="_top">Kaffe</a>)</li>
5757 <li>weblogic</li>
58 <li>forking - the sun compiler forked into a separate process (since Apache Ant 1.7)</li>
58 <li>forking - the sun compiler forked into a separate process (since
59 Apache Ant 1.7). Starting with Ant 1.9.8 this is the default when
60 running on JDK 9+.</li>
5961 <li>xnew - the sun compiler forked into a separate process,
6062 with the -Xnew option (since Ant 1.7).
61 This is the most reliable way to use -Xnew</li>
63 This is the most reliable way to use -Xnew.
64 <br></br>JDK9 has removed support for -Xnew and starting with Ant
65 1.9.8 this option will be rejected by ant when running on JDK9.</li>
6266 <li> "" (empty string). This has the same behaviour as not setting the compiler attribute.
6367 First the value of <tt>build.rmic</tt> is used if defined, and if not, the default
6468 for the platform is chosen. If build.rmic is set to this, you get the default.
215215 used if serverAliveIntervalSeconds is not 0.
216216 <em>since Ant 1.9.7</em></td>
217217 <td align="center" valign="top">No, defaults to 3</td>
218 </tr>
219 <tr>
220 <td valign="top">compressed</td>
221 <td valign="top">Whether to enable compression during transfer.
222 <em>since Ant 1.9.8</em></td>
223 <td align="center" valign="top">No, defaults to false</td>
218224 </tr>
219225 </table>
220226 <h3>Parameters specified as nested elements</h3>
6868 to an <code>&lt;xsl:param&gt;</code> declaration.</p>
6969 <p>This task supports the use of a nested <a href="../Types/xmlcatalog.html">xmlcatalog</a>
7070 element which is used to perform Entity and URI resolution.</p>
71
72 <p><b>Note on XSLT extension functions</b>: when using the default
73 TraX implementation of the Java class library and
74 a <code>SecurityManager</code> is active - e.g. when running from
75 within an IDE - XSLT extension functions cannot be used as "secure
76 processing" is active in Java 7 and above. Ant contains a special
77 "hack" that allows XSLT extensions to be used in Java 7 and 8, but
78 this hack fails for Java 9. If you want to use extensions like the
79 redirect extension that are provided by the Java class library
80 itself, you can allow them by enabling the
81 feature <code>http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions</code>
82 in Java 9 and above. If you need to use an extension function not
83 provided by Java itself you can set the
84 attribute <code>jdk.xml.transform.extensionClassLoader</code> to a
85 classloader (reference to an Ant PATH-like structure).</p>
86
7187 <h3>Parameters</h3>
7288 <table border="1" cellpadding="2" cellspacing="0">
7389 <tr>
394410 </tr>
395411 </table>
396412 <h3>Parameters specified as nested elements</h3>
397 <h4>attribute </h4>
413 <h4>attribute</h4>
398414 <p>Used to specify settings of the processor factory.
399415 The attribute names and values are entirely processor specific
400416 so you must be aware of the implementation to figure them out.
430446 <tr>
431447 <td valign="top">value</td>
432448 <td valign="top">value of the attribute.</td>
449 <td align="center" valign="middle" rowspan="3">Exactly one of these</td>
450 </tr>
451 <tr>
452 <td valign="top">valueref</td>
453 <td valign="top">value of the attribute is the value of the
454 project reference with the given id. <em>since Ant 1.9.8</em></td>
455 </tr>
456 <tr>
457 <td valign="top">classloaderforpath</td>
458 <td valign="top">value of the attribute is a classloader that uses
459 the classpath specified by a path that is the project reference
460 with the given id. <em>since Ant 1.9.8</em></td>
461 </tr>
462 </table>
463
464 <h4>Examples</h4>
465
466 <pre>
467 &lt;path id="extension-path"&gt;
468 ...
469 &lt;/path&gt;
470
471
472 &lt;xslt ...&gt;
473 &lt;factory&gt;
474 &lt;attribute name="jdk.xml.transform.extensionClassLoader"
475 classloaderforpath="extension-path"/&gt;
476 &lt;/factory&gt;
477 &lt;/xslt ...&gt;
478 </pre>
479 <p>Sets the classloader to use when loading extension functions to a
480 classloader using the <code>path</code> with the
481 id <code>extension-path</code>.
482 </blockquote>
483 <h4>feature</h4>
484 <p><em>since Ant 1.9.8</em></p>
485 <p>Used to specify settings of the processor factory. The feature
486 names are mostly processor specific so you must be aware of the
487 implementation to figure them out. Read the documentation of your
488 processor. The only feature all implementations are required to
489 support
490 is <code>http://javax.xml.XMLConstants/feature/secure-processing</code>.
491 <blockquote>
492 <h4>Parameters</h4>
493 <table width="60%" border="1" cellpadding="2" cellspacing="0">
494 <tr>
495 <td valign="top"><b>Attribute</b></td>
496 <td valign="top"><b>Description</b></td>
497 <td align="center" valign="top"><b>Required</b></td>
498 </tr>
499 <tr>
500 <td valign="top">name</td>
501 <td valign="top">Name of the feature</td>
433502 <td align="center" valign="top">Yes</td>
503 </tr>
504 <tr>
505 <td valign="top">value</td>
506 <td valign="top">value of the feature. A boolean value
507 (i.e. permitted values are true,false,yes,no,on,off).</td>
508 <td align="center" valign="top">No, defaults to false</td>
434509 </tr>
435510 </table>
436511 </blockquote>
7373 </tr>
7474 <tr>
7575 <td valign="top">pattern</td>
76 <td valign="top">SimpleDateFormat-compatible pattern string.
77 Defaults to MM/DD/YYYY HH:MM AM_or_PM or MM/DD/YYYY HH:MM:SS AM_or_PM.
76 <td valign="top">SimpleDateFormat-compatible pattern string using
77 the current locale.
78 Defaults to "MM/dd/YYYY hh:mm a" or "MM/dd/yyyy hh:mm:ss a"
79 using the US locale.
7880 <b>Since Ant 1.6.3</b></td>
7981 <td valign="top" align="center">No</td>
8082 </tr>
4949 <tr>
5050 <td valign="top">dir</td>
5151 <td valign="top">the root of the directory tree of this FileSet.</td>
52 <td valign="middle" align="center" rowspan="2">Either dir or file must be specified</td>
52 <td valign="middle" align="center" rowspan="2">Exactly one of dir or file must be specified</td>
5353 </tr>
5454 <tr>
5555 <td valign="top">file</td>
11421142 <a href="#ignoreblank">IgnoreBlank</a><br>
11431143 <a href="#filterdeletecharacters">DeleteCharacters</a><br>
11441144 <a href="#uniqfilter">UniqFilter</a><br>
1145 <a href="#native2asciifilter">Native2AsciiFilter</a><br>
11451146 </p>
11461147
11471148 The following string filters are provided by the optional distribution.
14831484 <blockquote><pre>
14841485 &lt;tokenfilter&gt;
14851486 &lt;uniqfilter/&gt;
1487 &lt;/tokenfilter&gt;
1488 </pre></blockquote>
1489
1490 <p><b><em><a name="native2asciifilter">Native2AsciiFilter</a></em></b></p>
1491
1492 <p>Uses the "builtin" implementation of
1493 the <a href="../Tasks/native2ascii.html">native2ascii</a> task.</p>
1494
1495 <p>Replaces non-ascii characters by their Unicode-escapes or
1496 vice-versa. <em>Since Ant 1.9.8</em>.</p>
1497
1498 <p>This filter may be used directly within a filterchain.</p>
1499
1500 <table cellSpacing=0 cellPadding=2 border=1>
1501 <tr>
1502 <td vAlign=top><b>Attribute</b></td>
1503 <td vAlign=top><b>Description</b></td>
1504 <td vAlign=top align="center"><b>Required</b></td>
1505 </tr>
1506 <tr>
1507 <td vAlign=top>reverse</td>
1508 <td vAlign=top>Reverse the sense of the conversion,
1509 i.e. convert from ASCII to native.</td>
1510 <td vAlign=top align="center">No</td>
1511 </tr>
1512 </table>
1513
1514 <h4>Example:</h4>
1515
1516 <p>This replaces all non-ASCII characters by their Unicode-escapes.</p>
1517 <blockquote><pre>
1518 &lt;tokenfilter&gt;
1519 &lt;native2asciifilter/&gt;
14861520 &lt;/tokenfilter&gt;
14871521 </pre></blockquote>
14881522
640640 <tr>
641641 <td valign="top">pattern</td>
642642 <td valign="top">SimpleDateFormat-compatible pattern
643 for use with the <code>datetime</code> attribute</td>
643 for use with the <code>datetime</code> attribute using the
644 current locale</td>
644645 <td align="center" valign="top">
645 No, default is "MM/DD/YYYY HH:MM AM_or_PM"</td>
646 No, default is "MM/dd/yyyy hh:mm a" using the US locale</td>
646647 </tr>
647648 <tr>
648649 <td valign="top">granularity</td>
172172 <tr>
173173 <td valign="top">datetime</td>
174174 <td valign="top">Specifies the date and time to test for.
175 Should be in the format MM/DD/YYYY HH:MM AM_or_PM, or
176 an alternative pattern specified via the <i>pattern</i>
177 attribute.
175 Should be in the format "MM/dd/yyyy hh:mm a" using the US
176 locale, or an alternative pattern specified via
177 the <i>pattern</i> attribute.
178178 </td>
179179 <td valign="top" align="center" rowspan="2">At least one of the two.</td>
180180 </tr>
211211 <tr>
212212 <td valign="top">pattern</td>
213213 <td valign="top">The <CODE>SimpleDateFormat</CODE>-compatible pattern
214 to use when interpreting the <i>datetime</i> attribute.
214 to use when interpreting the <i>datetime</i> attribute using
215 the current locale.
215216 <i>Since Ant 1.6.2</i>
216217 </td>
217218 <td valign="top" align="center">No</td>
1818 <head>
1919 <meta http-equiv="Content-Language" content="en-us">
2020 <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
21 <title>Apache Ant 1.9.7 User Manual</title>
21 <title>Apache Ant 1.9.8 User Manual</title>
2222 </head>
2323
2424 <body bgcolor="#FFFFFF">
2525 <div align="center">
2626 <h1><img src="images/ant_logo_large.gif" width="190" height="120"></h1>
27 <h1>Apache Ant&trade; 1.9.7 Manual</h1>
28 <p align="left">This is the manual for version 1.9.7 of
27 <h1>Apache Ant&trade; 1.9.8 Manual</h1>
28 <p align="left">This is the manual for version 1.9.8 of
2929 <a target="_top" href="http://ant.apache.org/index.html">Apache Ant</a>.
3030 If your version
3131 of Ant (as verified with <tt>ant -version</tt>) is older or newer than this
6161 </ul>
6262
6363 <center>
64 <p>Version: 1.9.7</p>
64 <p>Version: 1.9.8</p>
6565 </center>
6666
6767
8383 will contain the project's default target in this
8484 case for tasks nested into targets..
8585 ant.java.version the JVM version Ant detected; currently it can hold
86 the values &quot;1.9&quot;, &quot;1.8&quot;,
86 the values &quot;9&quot;, &quot;1.8&quot;,
8787 &quot;1.7&quot;, &quot;1.6&quot;, &quot;1.5&quot;,
8888 &quot;1.4&quot;, &quot;1.3&quot; and
89 &quot;1.2&quot;. ant.core.lib the absolute path
90 of the <code>ant.jar</code> file.
89 &quot;1.2&quot;.
90 ant.core.lib the absolute path of the <code>ant.jar</code> file.
9191 </pre>
9292
9393 <p>There is also another property, but this is set by the launcher
929929 <xsl:template name="br-replace">
930930 <xsl:param name="word"/>
931931 <xsl:param name="splitlimit">32</xsl:param>
932 <xsl:variable name="secondhalflen" select="(string-length($word)+(string-length($word) mod 2)) div 2"/>
933 <xsl:variable name="secondhalfword" select="substring($word, $secondhalflen)"/>
932 <xsl:variable name="secondhalfstartindex" select="(string-length($word)+(string-length($word) mod 2)) div 2"/>
933 <xsl:variable name="secondhalfword" select="substring($word, $secondhalfstartindex)"/>
934934 <!-- When word is very big, a recursive replace is very heap/stack expensive, so subdivide on line break after middle of string -->
935935 <xsl:choose>
936936 <xsl:when test="(string-length($word) > $splitlimit) and (contains($secondhalfword, '&#xa;'))">
937937 <xsl:variable name="secondhalfend" select="substring-after($secondhalfword, '&#xa;')"/>
938 <xsl:variable name="firsthalflen" select="string-length($word) - $secondhalflen"/>
938 <xsl:variable name="firsthalflen" select="string-length($word) - string-length($secondhalfword)"/>
939939 <xsl:variable name="firsthalfword" select="substring($word, 1, $firsthalflen)"/>
940940 <xsl:variable name="firsthalfend" select="substring-before($secondhalfword, '&#xa;')"/>
941941 <xsl:call-template name="br-replace">
469469 <xsl:template name="br-replace">
470470 <xsl:param name="word"/>
471471 <xsl:param name="splitlimit">32</xsl:param>
472 <xsl:variable name="secondhalflen" select="(string-length($word)+(string-length($word) mod 2)) div 2"/>
473 <xsl:variable name="secondhalfword" select="substring($word, $secondhalflen)"/>
472 <xsl:variable name="secondhalfstartindex" select="(string-length($word)+(string-length($word) mod 2)) div 2"/>
473 <xsl:variable name="secondhalfword" select="substring($word, $secondhalfstartindex)"/>
474474 <!-- When word is very big, a recursive replace is very heap/stack expensive, so subdivide on line break after middle of string -->
475475 <xsl:choose>
476476 <xsl:when test="(string-length($word) > $splitlimit) and (contains($secondhalfword, '&#xa;'))">
477477 <xsl:variable name="secondhalfend" select="substring-after($secondhalfword, '&#xa;')"/>
478 <xsl:variable name="firsthalflen" select="string-length($word) - $secondhalflen"/>
478 <xsl:variable name="firsthalflen" select="string-length($word) - string-length($secondhalfword)"/>
479479 <xsl:variable name="firsthalfword" select="substring($word, 1, $firsthalflen)"/>
480480 <xsl:variable name="firsthalfend" select="substring-before($secondhalfword, '&#xa;')"/>
481481 <xsl:call-template name="br-replace">
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant Core</name>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant-launcher</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-antlr</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant + ANTLR</name>
3737 <description>antlr specific task.
3838 The implementation forks a java process, therefore the antlr jar file is only needed at runtime</description>
4040 <dependency>
4141 <groupId>org.apache.ant</groupId>
4242 <artifactId>ant</artifactId>
43 <version>1.9.7</version>
43 <version>1.9.8</version>
4444 <optional>true</optional>
4545 <scope>compile</scope>
4646 </dependency>
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-apache-bcel</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant + BCEL</name>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-apache-bsf</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant + BSF</name>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-apache-log4j</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + Log4J</name>
3636 <dependencies>
3737 <dependency>
3838 <groupId>org.apache.ant</groupId>
3939 <artifactId>ant</artifactId>
40 <version>1.9.7</version>
40 <version>1.9.8</version>
4141 <scope>compile</scope>
4242 </dependency>
4343 <dependency>
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-apache-oro</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant + Apache Oro</name>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-apache-regexp</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + Apache Regexp</name>
3636 <dependencies>
3737 <dependency>
3838 <groupId>org.apache.ant</groupId>
3939 <artifactId>ant</artifactId>
40 <version>1.9.7</version>
40 <version>1.9.8</version>
4141 <scope>compile</scope>
4242 </dependency>
4343 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-apache-resolver</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + Apache Resolver</name>
3636 <dependencies>
3737 <dependency>
3838 <groupId>org.apache.ant</groupId>
3939 <artifactId>ant</artifactId>
40 <version>1.9.7</version>
40 <version>1.9.8</version>
4141 <scope>compile</scope>
4242 </dependency>
4343 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-apache-xalan2</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + Xalan 2</name>
3636 <description>contains Xalan2-specific features</description>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-commons-logging</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + Commons Logging</name>
3636 <description>Ant Listener based on commons-logging</description>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-commons-net</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + Commons Net</name>
3636 <description>ftp, rexec and telnet tasks</description>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-jai</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant + JAI</name>
3737 <description>image task and corresponding types.
3838 </description>
4040 <dependency>
4141 <groupId>org.apache.ant</groupId>
4242 <artifactId>ant</artifactId>
43 <version>1.9.7</version>
43 <version>1.9.8</version>
4444 <scope>compile</scope>
4545 </dependency>
4646 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-javamail</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + JavaMail</name>
3636 <description>implementation of the mail task based on javamail.
3737 Required to send emails to SMTP servers using user/password combinations
4040 <dependency>
4141 <groupId>org.apache.ant</groupId>
4242 <artifactId>ant</artifactId>
43 <version>1.9.7</version>
43 <version>1.9.8</version>
4444 <scope>compile</scope>
4545 </dependency>
4646 <dependency>
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-jdepend</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant + JDepend</name>
3737 <description>task jdepend invoking the jdepend parser. There is also a version 2.9.1 of the
3838 jdepend parser available on the maven repository</description>
4040 <dependency>
4141 <groupId>org.apache.ant</groupId>
4242 <artifactId>ant</artifactId>
43 <version>1.9.7</version>
43 <version>1.9.8</version>
4444 <scope>compile</scope>
4545 </dependency>
4646 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-jmf</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + JMF</name>
3636 <description>contains the sound task and a soundplayer listener
3737 download the dependency from http://java.sun.com/products/java-media/jmf/</description>
3939 <dependency>
4040 <groupId>org.apache.ant</groupId>
4141 <artifactId>ant</artifactId>
42 <version>1.9.7</version>
42 <version>1.9.8</version>
4343 <scope>compile</scope>
4444 </dependency>
4545 </dependencies>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-jsch</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + JSch</name>
3636 <description>contains the sshexec and scp tasks
3737 </description>
3939 <dependency>
4040 <groupId>org.apache.ant</groupId>
4141 <artifactId>ant</artifactId>
42 <version>1.9.7</version>
42 <version>1.9.8</version>
4343 <scope>compile</scope>
4444 </dependency>
4545 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-junit</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + JUnit</name>
3636 <description>contains the junit and junirreport tasks</description>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-junit4</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + JUnit 4</name>
3636 <description>contains JUnit 4.x support</description>
3737 <dependencies>
3838 <dependency>
3939 <groupId>org.apache.ant</groupId>
4040 <artifactId>ant</artifactId>
41 <version>1.9.7</version>
41 <version>1.9.8</version>
4242 <scope>compile</scope>
4343 </dependency>
4444 <dependency>
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-launcher</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant Launcher</name>
3737 <build>
3838 <plugins>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
2727 <relativePath>../pom.xml</relativePath>
28 <version>1.9.7</version>
28 <version>1.9.8</version>
2929 </parent>
3030 <modelVersion>4.0.0</modelVersion>
3131 <url>http://ant.apache.org/</url>
3232 <groupId>org.apache.ant</groupId>
3333 <artifactId>ant-netrexx</artifactId>
34 <version>1.9.7</version>
34 <version>1.9.8</version>
3535 <name>Apache Ant + NetRexx</name>
3636 <description>NetRexxC task
3737 dependency can be downloaded from http://www.ibm.com/software/awdtools/netrexx/download.html</description>
3939 <dependency>
4040 <groupId>org.apache.ant</groupId>
4141 <artifactId>ant</artifactId>
42 <version>1.9.7</version>
42 <version>1.9.8</version>
4343 <scope>compile</scope>
4444 </dependency>
4545 <!-- Processed too early, before maven-antrun-plugin gets a chance to work:
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-swing</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant + Swing</name>
3737 <description>a listener and a splash task based on Swing</description>
3838 <dependencies>
3939 <dependency>
4040 <groupId>org.apache.ant</groupId>
4141 <artifactId>ant</artifactId>
42 <version>1.9.7</version>
42 <version>1.9.8</version>
4343 <scope>compile</scope>
4444 </dependency>
4545 </dependencies>
2626 <groupId>org.apache.ant</groupId>
2727 <artifactId>ant-parent</artifactId>
2828 <relativePath>../pom.xml</relativePath>
29 <version>1.9.7</version>
29 <version>1.9.8</version>
3030 </parent>
3131 <modelVersion>4.0.0</modelVersion>
3232 <url>http://ant.apache.org/</url>
3333 <groupId>org.apache.ant</groupId>
3434 <artifactId>ant-testutil</artifactId>
35 <version>1.9.7</version>
35 <version>1.9.8</version>
3636 <name>Apache Ant Test Utilities</name>
3737 <description>test utility classes</description>
3838 <dependencies>
3939 <dependency>
4040 <groupId>org.apache.ant</groupId>
4141 <artifactId>ant</artifactId>
42 <version>1.9.7</version>
42 <version>1.9.8</version>
4343 <scope>compile</scope>
4444 </dependency>
4545 <dependency>
2424 <modelVersion>4.0.0</modelVersion>
2525 <groupId>org.apache.ant</groupId>
2626 <artifactId>ant-parent</artifactId>
27 <version>1.9.7</version>
27 <version>1.9.8</version>
2828 <packaging>pom</packaging>
2929 <description>master POM</description>
3030 <licenses>
3131 <fail>
3232 <condition>
3333 <not>
34 <antversion exactly="1.9.7" />
34 <antversion exactly="1.9.8" />
3535 </not>
3636 </condition>
37 Should be exactly 1.9.7
37 Should be exactly 1.9.8
3838
3939 </fail>
4040 </target>
4444 <fail>
4545 <condition>
4646 <not>
47 <antversion atleast="1.9.7" />
47 <antversion atleast="1.9.8" />
4848 </not>
4949 </condition>
50 Should be at least 1.9.7
50 Should be at least 1.9.8
5151 </fail>
5252 </target>
5353
5656 <fail>
5757 <condition>
5858 <not>
59 <antversion exactly="1.9.7" />
59 <antversion exactly="1.9.8" />
6060 </not>
6161 </condition>
62 Should be exactly 1.9.7
62 Should be exactly 1.9.8
6363 </fail>
6464 </target>
6565 </project>
199199
200200 <target name="probe-rmic">
201201 <available property="kaffe.present" classname="jkaffe.rmi.rmic.RMIC"/>
202 <available property="rmic.present" classname="sun.rmi.rmic.Main"/>
202 <condition property="rmic.present">
203 <or>
204 <available classname="sun.rmi.rmic.Main"/>
205 <!-- we'll use forking as default for Java9 -->
206 <available classname="java.lang.module.ModuleDescriptor"/>
207 </or>
208 </condition>
209 <condition property="rmic.compiler" value="forking">
210 <available classname="java.lang.module.ModuleDescriptor"/>
211 </condition>
212 <property name="rmic.compiler" value="sun"/>
203213 <available property="wlrmic.present" classname="weblogic.rmic"/>
204 <condition property="rmic5.present">
205 <and>
206 <isset property="rmic.present"/>
207 <available classname="java.net.Proxy"/>
208 </and>
209 </condition>
210214 <condition property="rmic6.present">
211215 <and>
212216 <isset property="rmic.present"/>
268272 </target>
269273
270274 <target name="testRmic" if="rmic.present" depends="init">
271 <base-rmic compiler="sun"/>
275 <base-rmic compiler="${rmic.compiler}"/>
272276 <assertBaseCompiled/>
273277 </target>
274278
275279 <target name="testRmicDest" if="rmic.present" depends="init">
276 <dest-rmic compiler="sun"/>
280 <dest-rmic compiler="${rmic.compiler}"/>
277281 <assertBaseCompiledInDest/>
278282 </target>
279283
280284 <target name="testRmicJArg" if="rmic.present" depends="init">
281 <base-rmic compiler="sun">
285 <base-rmic compiler="${rmic.compiler}">
282286 <compilerarg value="-J-mx256m" />
283287 </base-rmic>
284288 <assertBaseCompiled/>
285289 </target>
286290
287291 <target name="testRmicJArgDest" if="rmic.present" depends="init">
288 <dest-rmic compiler="sun">
292 <dest-rmic compiler="${rmic.compiler}">
289293 <compilerarg value="-J-mx256m" />
290294 </dest-rmic>
291295 <assertBaseCompiledInDest/>
327331 <assertBaseCompiled/>
328332 </target>
329333
330 <target name="testBadName" if="rmic.present" depends="init">
334 <target name="testBadName" depends="init">
331335 <base-rmic
332336 compiler="no-such-compiler"
333337 />
335339
336340 <target name="testExplicitClass" if="rmic.present" depends="init">
337341 <base-rmic
338 compiler="org.apache.tools.ant.taskdefs.rmic.SunRmic"
342 compiler="org.apache.tools.ant.taskdefs.rmic.ForkingSunRmic"
339343 />
340344 <assertBaseCompiled/>
341345 </target>
342346
343 <target name="testWrongClass" if="rmic.present" depends="init">
347 <target name="testWrongClass" depends="init">
344348 <base-rmic
345349 compiler="org.apache.tools.ant.BuildException"
346350 />
394398 <assertAntCompiledInDest/>
395399 </target>
396400
397 <target name="testForkingAntClasspath" if="rmic.present" depends="compileAntTimestamp">
401 <target name="testForkingAntClasspath" depends="compileAntTimestamp">
398402 <base-rmic
399403 compiler="forking"
400404 />
401405 <assertAntCompiled />
402406 </target>
403407
404 <target name="testForkingAntClasspathDest" if="rmic.present" depends="compileAntTimestamp">
408 <target name="testForkingAntClasspathDest" depends="compileAntTimestamp">
405409 <dest-rmic
406410 compiler="forking"
407411 />
433437 <!--
434438 This test stamps on the XML parser settings on java6, so it is disabled.
435439 -->
436 <target name="testXnew" if="rmic5.present" unless="rmic6.present" depends="init">
437 <base-rmic compiler="sun">
440 <target name="testXnew" if="rmic.present" unless="rmic6.present" depends="init">
441 <base-rmic compiler="${rmic.compiler}">
438442 <compilerarg value="-Xnew"/>
439443 </base-rmic>
440444 <assertBaseCompiled/>
441445 </target>
442446
443 <target name="testXnewDest" if="rmic5.present" unless="rmic6.present" depends="init">
444 <dest-rmic compiler="sun">
447 <target name="testXnewDest" if="rmic.present" unless="rmic6.present" depends="init">
448 <dest-rmic compiler="${rmic.compiler}">
445449 <compilerarg value="-Xnew"/>
446450 </dest-rmic>
447451 <assertBaseCompiledInDest/>
448452 </target>
449453
450 <target name="testXnewForked" if="rmic5.present" depends="init">
454 <target name="testXnewForked" if="rmic.present" depends="init">
451455 <base-rmic compiler="forking">
452456 <compilerarg value="-Xnew"/>
453457 </base-rmic>
454458 <assertBaseCompiled/>
455459 </target>
456460
457 <target name="testXnewForkedDest" if="rmic5.present" depends="init">
461 <target name="testXnewForkedDest" if="rmic.present" depends="init">
458462 <dest-rmic compiler="forking">
459463 <compilerarg value="-Xnew"/>
460464 </dest-rmic>
461465 <assertBaseCompiledInDest/>
462466 </target>
463467
464 <target name="testXnewCompiler" if="rmic5.present" depends="init">
468 <target name="testXnewCompiler" if="rmic.present" depends="init">
465469 <base-rmic compiler="xnew">
466470 </base-rmic>
467471 <assertBaseCompiled/>
468472 </target>
469473
470 <target name="testXnewCompilerDest" if="rmic5.present" depends="init">
474 <target name="testXnewCompilerDest" if="rmic.present" depends="init">
471475 <dest-rmic compiler="xnew">
472476 </dest-rmic>
473477 <assertBaseCompiledInDest/>
282282 <zip destFile="${output}/test3.zip" basedir="${output}/ziptest" update="true"/>
283283 </target>
284284
285 <target name="testRegexpMapper1">
286 <mkdir dir="${output}/regexp.src"/>
287 <touch file="${output}/regexp.src/file1"/>
288 <zip destFile="${output}/regexp.zip">
289 <mappedresources>
290 <fileset dir="${output}/regexp.src" includes="file1" />
291 <regexpmapper from="^(([a-z][a-z]).*)" to="\2/\1.r" />
292 </mappedresources>
293 </zip>
294 </target>
295 <target name="testRegexpMapper2">
296 <sleep seconds="3" />
297 <zip destFile="${output}/regexp.zip">
298 <mappedresources>
299 <fileset dir="${output}/regexp.src" includes="file1" />
300 <regexpmapper from="^(([a-z][a-z]).*)" to="\2/\1.r" />
301 </mappedresources>
302 </zip>
303 </target>
285304
286305 </project>
4848 import org.apache.tools.ant.util.FileUtils;
4949 import org.apache.tools.ant.util.JavaEnvUtils;
5050 import org.apache.tools.ant.util.LoaderUtils;
51 import org.apache.tools.ant.util.StringUtils;
5152 import org.apache.tools.ant.util.VectorSet;
5253 import org.apache.tools.zip.ZipLong;
5354
400401 protected void log(final String message, final int priority) {
401402 if (project != null) {
402403 project.log(message, priority);
404 } else if (priority < Project.MSG_INFO) {
405 System.err.println(message);
403406 }
404407 }
405408
10191022 final String msg = "CLASSPATH element " + file
10201023 + " is not a JAR.";
10211024 log(msg, Project.MSG_WARN);
1022 System.err.println(msg);
10231025 return null;
10241026 }
10251027 jarFile = new JarFile(file);
10421044 } catch (final Exception e) {
10431045 final String msg = "Unable to obtain resource from " + file + ": ";
10441046 log(msg + e, Project.MSG_WARN);
1045 System.err.println(msg);
1046 e.printStackTrace();
1047 log(StringUtils.getStackTrace(e), Project.MSG_WARN);
10471048 }
10481049 return null;
10491050 }
12091210 *
12101211 * @return the entry's certificates or null is the container is
12111212 * not a jar or it has no certificates.
1212 *
1213 * @exception IOException if the manifest cannot be read.
1214 */
1215 private Certificate[] getCertificates(final File container, final String entry)
1216 throws IOException {
1213 */
1214 private Certificate[] getCertificates(final File container, final String entry) {
12171215 if (container.isDirectory()) {
12181216 return null;
12191217 }
8383 }
8484
8585 InputStream systemResource = ClassLoader.getSystemResourceAsStream(SERVICE_ID);
86 if (systemResource != null) {
86 if (systemResource != null) { //NOSONAR
8787 ArgumentProcessor processor = getProcessorByService(systemResource);
8888 registerArgumentProcessor(processor);
8989 }
9292 + SERVICE_ID + " (" + e.getClass().getName() + ": "
9393 + e.getMessage() + ")");
9494 if (DEBUG) {
95 e.printStackTrace(System.err);
95 e.printStackTrace(System.err); //NOSONAR
9696 }
9797 }
9898 }
970970 Throwable t = ex.getTargetException();
971971 out.println("Cause: The constructor threw the exception");
972972 out.println(t.toString());
973 t.printStackTrace(out);
973 t.printStackTrace(out); //NOSONAR
974974 } catch (NoClassDefFoundError ncdfe) {
975975 jars = true;
976976 out.println("Cause: A class needed by class " + classname
470470 // report error if something weird happens...this is diagnostic.
471471 if (error != null) {
472472 out.println("Error while running org.apache.env.Which");
473 error.printStackTrace();
473 error.printStackTrace(out); //NOSONAR
474474 }
475475 }
476476
145145 * method instead.
146146 */
147147 @Deprecated
148 protected static final String[] DEFAULTEXCLUDES = {
148 protected static final String[] DEFAULTEXCLUDES = { //NOSONAR
149149 // Miscellaneous typical temporary files
150150 SelectorUtils.DEEP_TREE_MATCH + "/*~",
151151 SelectorUtils.DEEP_TREE_MATCH + "/#*#",
406406 + " doesn't support the \"" + attributeName + "\" attribute.";
407407 throw new UnsupportedAttributeException(msg, attributeName);
408408 }
409 try {
410 as.setObject(p, element, value);
411 } catch (final IllegalAccessException ie) {
412 // impossible as getMethods should only return public methods
413 throw new BuildException(ie);
414 } catch (final InvocationTargetException ite) {
415 throw extractBuildException(ite);
409 if (as != null) { // possible if value == null
410 try {
411 as.setObject(p, element, value);
412 } catch (final IllegalAccessException ie) {
413 // impossible as getMethods should only return public methods
414 throw new BuildException(ie);
415 } catch (final InvocationTargetException ite) {
416 throw extractBuildException(ite);
417 }
416418 }
417419 }
418420
8080 private File buildFile; /* null */
8181
8282 /** Stream to use for logging. */
83 private static PrintStream out = System.out;
83 private PrintStream out = System.out;
8484
8585 /** Stream that we are using for logging error messages. */
86 private static PrintStream err = System.err;
86 private PrintStream err = System.err;
8787
8888 /** The build targets. */
8989 private final Vector<String> targets = new Vector<String>();
142142 * Whether or not a logfile is being used. This is used to
143143 * check if the output streams must be closed.
144144 */
145 private static boolean isLogFileUsed = false;
145 private boolean isLogFileUsed = false;
146146
147147 /**
148148 * optional thread priority
245245 printMessage(be);
246246 }
247247 } catch (final Throwable exc) {
248 exc.printStackTrace();
248 exc.printStackTrace(); //NOSONAR
249249 printMessage(exc);
250250 } finally {
251251 handleLogfile();
268268 *
269269 * @since Ant 1.6
270270 */
271 private static void handleLogfile() {
271 private void handleLogfile() {
272272 if (isLogFileUsed) {
273273 FileUtils.close(out);
274274 FileUtils.close(err);
354354 try {
355355 final File logFile = new File(args[i + 1]);
356356 i++;
357 logTo = new PrintStream(new FileOutputStream(logFile));
357 // life-cycle of FileOutputStream is controlled by
358 // logTo which becomes "out" and is closed in
359 // handleLogfile
360 logTo = new PrintStream(new FileOutputStream(logFile)); //NOSONAR
358361 isLogFileUsed = true;
359362 } catch (final IOException ioe) {
360363 final String msg = "Cannot write on the specified log file. "
877880 // but if we don't, we lose valuable information
878881 System.err.println("Caught an exception while logging the"
879882 + " end of the build. Exception was:");
880 t.printStackTrace();
883 t.printStackTrace(); //NOSONAR
881884 if (error != null) {
882885 System.err.println("There has been an error prior to"
883886 + " that:");
884 error.printStackTrace();
887 error.printStackTrace(); //NOSONAR
885888 }
886 throw new BuildException(t);
889 throw new BuildException(t); //NOSONAR
887890 }
888891 } else if (error != null) {
889892 project.log(error.toString(), Project.MSG_ERR);
974977 project.setInputHandler(handler);
975978 }
976979
977 // TODO: (Jon Skeet) Any reason for writing a message and then using a bare
978 // RuntimeException rather than just using a BuildException here? Is it
979 // in case the message could end up being written to no loggers (as the
980 // loggers could have failed to be created due to this failure)?
981980 /**
982981 * Creates the default build logger for sending build events to the ant
983982 * log.
999998 System.err.println("The specified logger class "
1000999 + loggerClassname
10011000 + " could not be used because " + e.getMessage());
1002 throw new RuntimeException();
1001 throw e;
10031002 }
10041003 } else {
10051004 logger = new DefaultLogger();
872872 try {
873873 setBasedir(".");
874874 } catch (final BuildException ex) {
875 ex.printStackTrace();
875 ex.printStackTrace(); //NOSONAR
876876 }
877877 }
878878 return baseDir;
14291429 "Target '" + curtarget.getName()
14301430 + "' failed with message '"
14311431 + thrownException.getMessage() + "'.", MSG_ERR);
1432 thrownException.printStackTrace(System.err);
1432 thrownException.printStackTrace(System.err); //NOSONAR
14331433 if (buildException == null) {
14341434 buildException =
14351435 new BuildException(thrownException);
18351835 if (st == null) {
18361836 tsort(root[i], targetTable, state, visiting, ret);
18371837 } else if (st == VISITING) {
1838 throw new RuntimeException("Unexpected node in visiting state: "
1838 throw new BuildException("Unexpected node in visiting state: "
18391839 + root[i]);
18401840 }
18411841 }
18541854 if (st == null) {
18551855 tsort(curTarget, targetTable, state, visiting, complete);
18561856 } else if (st == VISITING) {
1857 throw new RuntimeException("Unexpected node in visiting state: "
1857 throw new BuildException("Unexpected node in visiting state: "
18581858 + curTarget);
18591859 }
18601860 }
19401940 }
19411941 final String p = visiting.pop();
19421942 if (root != p) {
1943 throw new RuntimeException("Unexpected internal error: expected to "
1943 throw new BuildException("Unexpected internal error: expected to "
19441944 + "pop " + root + " but got " + p);
19451945 }
19461946 state.put(root, VISITED);
6161 PROJECTHELPER2_CONSTRUCTOR = ProjectHelper2.class.getConstructor();
6262 } catch (Exception e) {
6363 // ProjectHelper2 must be available
64 throw new RuntimeException(e);
64 throw new BuildException(e);
6565 }
6666 }
6767
107107 + e.getClass().getName()
108108 + ": " + e.getMessage() + ")");
109109 if (DEBUG) {
110 e.printStackTrace(System.err);
110 e.printStackTrace(System.err); //NOSONAR
111111 }
112112 }
113113 }
174174 + ProjectHelper.HELPER_PROPERTY + " ("
175175 + e.getMessage() + ")");
176176 if (DEBUG) {
177 e.printStackTrace(System.err);
177 e.printStackTrace(System.err); //NOSONAR
178178 }
179179 }
180180 return null;
202202 System.out.println("Unable to load ProjectHelper from service "
203203 + ProjectHelper.SERVICE_ID + " (" + e.getMessage() + ")");
204204 if (DEBUG) {
205 e.printStackTrace(System.err);
205 e.printStackTrace(System.err); //NOSONAR
206206 }
207207 }
208208 return null;
262262 return helper;
263263 }
264264 }
265 throw new RuntimeException("BUG: at least the ProjectHelper2 should "
265 throw new BuildException("BUG: at least the ProjectHelper2 should "
266266 + "have supported the file " + buildFile);
267267 }
268268
285285 return helper;
286286 }
287287 }
288 throw new RuntimeException("BUG: at least the ProjectHelper2 should "
288 throw new BuildException("BUG: at least the ProjectHelper2 should "
289289 + "have supported the file " + antlib);
290290 }
291291
5151 private String elementTag = null;
5252
5353 /** List of child element wrappers. */
54 private List<RuntimeConfigurable> children = null;
54 // picking ArrayList rather than List as arrayList is Serializable
55 private ArrayList<RuntimeConfigurable> children = null;
5556
5657 /** The element to configure. It is only used during
5758 * maybeConfigure.
588589
589590 // Children (this is a shadow of UnknownElement#children)
590591 if (r.children != null) {
591 List<RuntimeConfigurable> newChildren = new ArrayList<RuntimeConfigurable>();
592 ArrayList<RuntimeConfigurable> newChildren = new ArrayList<RuntimeConfigurable>();
592593 newChildren.addAll(r.children);
593594 if (children != null) {
594595 newChildren.addAll(children);
645645 return false;
646646 }
647647 for (int i = 0; i < childrenSize; ++i) {
648 UnknownElement child = (UnknownElement) children.get(i);
648 // children cannot be null childrenSize would have been 0
649 UnknownElement child = (UnknownElement) children.get(i); //NOSONAR
649650 if (!child.similar(other.children.get(i))) {
650651 return false;
651652 }
263263 if (!threadStack.empty()) {
264264 TimedElement poppedStack = threadStack.pop();
265265 if (poppedStack != targetElement) {
266 throw new RuntimeException("Mismatch - popped element = " + poppedStack
266 throw new RuntimeException("Mismatch - popped element = " + poppedStack //NOSONAR
267267 + " finished target element = " + targetElement);
268268 }
269269 if (!threadStack.empty()) {
315315 Task task = event.getTask();
316316 TimedElement taskElement = tasks.get(task);
317317 if (taskElement == null) {
318 throw new RuntimeException("Unknown task " + task + " not in " + tasks);
318 throw new RuntimeException("Unknown task " + task + " not in " + tasks); //NOSONAR
319319 }
320320 long totalTime = System.currentTimeMillis() - taskElement.startTime;
321321 taskElement.element.setAttribute(TIME_ATTR, DefaultLogger.formatTime(totalTime));
333333 if (!threadStack.empty()) {
334334 TimedElement poppedStack = threadStack.pop();
335335 if (poppedStack != taskElement) {
336 throw new RuntimeException("Mismatch - popped element = " + poppedStack
336 throw new RuntimeException("Mismatch - popped element = " + poppedStack //NOSONAR
337337 + " finished task element = " + taskElement);
338338 }
339339 }
139139 classname="org.apache.tools.ant.filters.SortFilter"/>
140140 <componentdef name="uniqfilter" onerror="ignore"
141141 classname="org.apache.tools.ant.filters.UniqFilter"/>
142 <componentdef name="native2asciifilter" onerror="ignore"
143 classname="org.apache.tools.ant.filters.Native2AsciiFilter"/>
142144 </antlib>
143145
0 /*
1 * Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.apache.tools.ant.filters;
18
19 import org.apache.tools.ant.util.Native2AsciiUtils;
20
21 /**
22 * A filter that performs translations from characters to their
23 * Unicode-escape sequences and vice-versa.
24 *
25 * @since Ant 1.9.8
26 */
27 public class Native2AsciiFilter extends TokenFilter.ChainableReaderFilter {
28 private boolean reverse;
29
30 /**
31 * Flag the conversion to run in the reverse sense,
32 * that is Ascii to Native encoding.
33 *
34 * @param reverse True if the conversion is to be reversed,
35 * otherwise false;
36 */
37 public void setReverse(boolean reverse) {
38 this.reverse = reverse;
39 }
40
41 public String filter(String line) {
42 return reverse
43 ? Native2AsciiUtils.ascii2native(line)
44 : Native2AsciiUtils.native2ascii(line);
45 }
46 }
2626 import java.util.SortedMap;
2727 import java.util.TreeMap;
2828
29 import org.apache.tools.ant.Project;
2930 import org.apache.tools.ant.types.Parameter;
3031 import org.apache.tools.ant.types.Resource;
3132 import org.apache.tools.ant.types.resources.FileResource;
243244 in = resource.getInputStream();
244245 props.load(in);
245246 } catch (IOException ioe) {
246 ioe.printStackTrace();
247 if (getProject() != null) {
248 getProject().log("getProperties failed, " + ioe.getMessage(), Project.MSG_ERR);
249 } else {
250 ioe.printStackTrace(); //NOSONAR
251 }
247252 } finally {
248253 FileUtils.close(in);
249254 }
361361 if (reverse) {
362362 Collections.sort(lines, new Comparator<String>() {
363363 public int compare(String s1, String s2) {
364 return (-s1.compareTo(s2));
364 return (-s1.compareTo(s2)); //NOSONAR
365365 }
366366 });
367367 } else {
3030 private String lastLine = null;
3131
3232 public String filter(String string) {
33 return lastLine == null || !lastLine.equals(string)
34 ? (lastLine = string) : null;
33 if (lastLine == null || !lastLine.equals(string)) {
34 lastLine = string;
35 return lastLine;
36 }
37 return null;
3538 }
3639 }
599599 private static void handleElement(ProjectHelperImpl helperImpl, DocumentHandler parent,
600600 Target target, String elementName, AttributeList attrs) throws SAXParseException {
601601 if (elementName.equals("description")) {
602 new DescriptionHandler(helperImpl, parent);
602 // created for side effect
603 new DescriptionHandler(helperImpl, parent); //NOSONAR
603604 } else if (helperImpl.project.getDataTypeDefinitions().get(elementName) != null) {
604605 new DataTypeHandler(helperImpl, parent, target).init(elementName, attrs);
605606 } else {
4747 public void handleInput(InputRequest request) throws BuildException {
4848 String prompt = getPrompt(request);
4949 BufferedReader r = null;
50 boolean success = false;
5051 try {
5152 r = new BufferedReader(new InputStreamReader(getInputStream()));
5253 do {
6061 + " Console.", e);
6162 }
6263 } while (!request.isInputValid());
64 success = true;
6365 } finally {
6466 if (r != null) {
6567 try {
6668 r.close();
6769 } catch (IOException e) {
68 throw new BuildException("Failed to close input.", e);
70 if (success) { // don't hide inner exception
71 throw new BuildException("Failed to close input.", e); //NOSONAR
72 }
6973 }
7074 }
7175 }
6464 /**
6565 * launch diagnostics flag; for debugging trouble at launch time.
6666 */
67 public static boolean launchDiag = false;
67 public boolean launchDiag = false;
6868
6969 /**
7070 * The location of a per-user library directory.
106106 */
107107 public static void main(final String[] args) {
108108 int exitCode;
109 boolean launchDiag = false;
109110 try {
110111 final Launcher launcher = new Launcher();
111112 exitCode = launcher.run(args);
113 launchDiag = launcher.launchDiag;
112114 } catch (final LaunchException e) {
113115 exitCode = EXIT_CODE_ERROR;
114116 System.err.println(e.getMessage());
115117 } catch (final Throwable t) {
116118 exitCode = EXIT_CODE_ERROR;
117 t.printStackTrace(System.err);
119 t.printStackTrace(System.err); //NOSONAR
118120 }
119121 if (exitCode != 0) {
120122 if (launchDiag) {
294296 "Failed to locate" + mainClassname);
295297 thrown = cnfe;
296298 } catch (final Throwable t) {
297 t.printStackTrace(System.err);
299 t.printStackTrace(System.err); //NOSONAR
298300 thrown=t;
299301 }
300302 if(thrown!=null) {
176176 }
177177 } catch (Exception e) {
178178 System.out.println("MailLogger failed to send e-mail!");
179 e.printStackTrace(System.err);
179 e.printStackTrace(System.err); //NOSONAR
180180 }
181181 }
182182
326326 * property is not present in properties.
327327 */
328328 private String getValue(Hashtable<String, Object> properties, String name,
329 String defaultValue) throws Exception {
329 String defaultValue) {
330330 String propertyName = "MailLogger." + name;
331331 String value = (String) properties.get(propertyName);
332332
335335 }
336336
337337 if (value == null) {
338 throw new Exception("Missing required parameter: " + propertyName);
338 throw new RuntimeException("Missing required parameter: " + propertyName); //NOSONAR
339339 }
340340
341341 return value;
381381 FileSet sourceJar = new FileSet();
382382 sourceJar.setProject(getProject());
383383 sourceJar.setFile(jar);
384 sourceJar.setDir(jar.getParentFile());
385384 sources.add(sourceJar);
386385 }
387386 return sources;
3535 import org.apache.tools.ant.TaskContainer;
3636 import org.apache.tools.ant.types.EnumeratedAttribute;
3737 import org.apache.tools.ant.types.Reference;
38 import org.apache.tools.ant.util.FileUtils;
3839
3940 /**
4041 * Creates a partial DTD for Ant from the currently known tasks.
8384
8485 PrintWriter out = null;
8586 try {
87 FileOutputStream fos = null;
8688 try {
87 out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF8"));
89 fos = new FileOutputStream(output);
90 out = new PrintWriter(new OutputStreamWriter(fos, "UTF8"));
8891 } catch (final UnsupportedEncodingException ue) {
92 FileUtils.close(fos);
8993 /*
9094 * Plain impossible with UTF8, see
9195 * http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html
385389 } catch (final IllegalAccessException ie) {
386390 sb.append("CDATA ");
387391 }
388 } else if (type.getSuperclass() != null
389 && type.getSuperclass().getName().equals("java.lang.Enum")) {
392 } else if (Enum.class.isAssignableFrom(type)) {
390393 try {
391394 final Object[] values = (Object[]) type.getMethod("values", (Class[]) null)
392395 .invoke(null, (Object[]) null);
1818 package org.apache.tools.ant.taskdefs;
1919
2020 import java.io.File;
21 import java.io.InputStream;
2122
2223 import org.apache.tools.ant.AntClassLoader;
2324 import org.apache.tools.ant.BuildException;
420421 * Check if a given resource can be loaded.
421422 */
422423 private boolean checkResource(String resource) {
423 if (loader != null) {
424 return (loader.getResourceAsStream(resource) != null);
425 } else {
426 ClassLoader cL = this.getClass().getClassLoader();
427 if (cL != null) {
428 return (cL.getResourceAsStream(resource) != null);
424 InputStream is = null;
425 try {
426 if (loader != null) {
427 is = loader.getResourceAsStream(resource);
429428 } else {
430 return
431 (ClassLoader.getSystemResourceAsStream(resource) != null);
432 }
429 ClassLoader cL = this.getClass().getClassLoader();
430 if (cL != null) {
431 is = cL.getResourceAsStream(resource);
432 } else {
433 is = ClassLoader.getSystemResourceAsStream(resource);
434 }
435 }
436 return is != null;
437 } finally {
438 FileUtils.close(is);
433439 }
434440 }
435441
2626 import org.apache.tools.ant.Task;
2727 import org.apache.tools.ant.types.Path;
2828 import org.apache.tools.ant.types.Reference;
29 import org.apache.tools.ant.util.StringUtils;
2930
3031 /**
3132 * EXPERIMENTAL
237238 // TODO add exceptions
238239
239240 } catch (Exception ex) {
240 ex.printStackTrace();
241 log(StringUtils.getStackTrace(ex), Project.MSG_ERR);
241242 }
242243 }
243244 }
382382 private ConcatResource(ResourceCollection c) {
383383 this.c = c;
384384 }
385 public InputStream getInputStream() throws IOException {
385 public InputStream getInputStream() {
386386 if (binary) {
387387 ConcatResourceInputStream result = new ConcatResourceInputStream(c);
388388 result.setManagingComponent(this);
112112 procEnvironment = System.getenv();
113113 return procEnvironment;
114114 } catch (Exception x) {
115 x.printStackTrace();
115 x.printStackTrace(); //NOSONAR
116116 }
117117 }
118118
161161 procEnvironment.put(var.substring(0, eq), var.substring(eq + 1));
162162 }
163163 } catch (java.io.IOException exc) {
164 exc.printStackTrace();
164 exc.printStackTrace(); //NOSONAR
165165 // Just try to see how much we got
166166 }
167167 return procEnvironment;
5252 private Long timeout = null;
5353 private volatile Throwable caught = null;
5454 private volatile boolean timedOut = false;
55 private boolean done = false;
5556 private Thread thread = null;
5657
5758 /**
149150 + " is not declared static");
150151 }
151152 if (timeout == null) {
152 run();
153 run(); //NOSONAR
153154 } else {
154155 thread = new Thread(this, "ExecuteJava");
155156 Task currentThreadTask
167168 thread.start();
168169 w.start();
169170 try {
170 wait();
171 while (!done) {
172 wait();
173 }
171174 } catch (InterruptedException e) {
172175 // ignore
173176 }
227230 perm.restoreSecurityManager();
228231 }
229232 synchronized (this) {
233 done = true;
230234 notifyAll();
231235 }
232236 }
242246 timedOut = true;
243247 thread.interrupt();
244248 }
249 done = true;
245250 notifyAll();
246251 }
247252
190190 log("extracting " + ze.getName(), Project.MSG_DEBUG);
191191 try {
192192 extractFile(fileUtils, srcF, dir,
193 is = zf.getInputStream(ze),
193 is = zf.getInputStream(ze), //NOSONAR
194194 ze.getName(), new Date(ze.getTime()),
195195 ze.isDirectory(), mapper);
196196 } finally {
134134 }
135135 }
136136
137 //set up logging
138 final int logLevel = Project.MSG_INFO;
139 DownloadProgress progress = null;
140 if (verbose) {
141 progress = new VerboseProgress(System.out);
142 }
143
144 //execute the get
145 try {
146 doGet(source, dest, logLevel, progress);
147 } catch (final IOException ioe) {
148 log("Error getting " + source + " to " + dest);
149 if (!ignoreErrors) {
150 throw new BuildException(ioe, getLocation());
151 }
152 }
137 //set up logging
138 final int logLevel = Project.MSG_INFO;
139 DownloadProgress progress = null;
140 if (verbose) {
141 progress = new VerboseProgress(System.out);
142 }
143
144 //execute the get
145 try {
146 doGet(source, dest, logLevel, progress);
147 } catch (final IOException ioe) {
148 log("Error getting " + source + " to " + dest);
149 if (!ignoreErrors) {
150 throw new BuildException(ioe, getLocation());
151 }
152 }
153153 }
154154 }
155155
258258
259259 @Override
260260 public void log(final String msg, final int msgLevel) {
261 if (!quiet || msgLevel >= Project.MSG_ERR) {
261 if (!quiet || msgLevel <= Project.MSG_ERR) {
262262 super.log(msg, msgLevel);
263263 }
264264 }
412412 }
413413
414414 /**
415 * The number of retries to attempt upon error, defaults to 3.
416 *
417 * @param r retry count
415 * The number of attempts to make for opening the URI, defaults to 3.
416 *
417 * <p>The name of the method is misleading as a value of 1 means
418 * "don't retry on error" and a value of 0 meant don't even try to
419 * reach the URI at all.</p>
420 *
421 * @param r number of attempts to make
418422 *
419423 * @since Ant 1.8.0
420424 */
421425 public void setRetries(final int r) {
426 if (r <= 0) {
427 log("Setting retries to " + r
428 + " will make the task not even try to reach the URI at all",
429 Project.MSG_WARN);
430 }
422431 this.numberRetries = r;
423432 }
424433
4242 public class HostInfo extends Task {
4343 private static final String DEF_REM_ADDR6 = "::";
4444
45 private static final String DEF_REM_ADDR4 = "0.0.0.0";
45 private static final String DEF_REM_ADDR4 = "0.0.0.0"; //NOSONAR
4646
4747 private static final String DEF_LOCAL_ADDR6 = "::1";
4848
49 private static final String DEF_LOCAL_ADDR4 = "127.0.0.1";
49 private static final String DEF_LOCAL_ADDR4 = "127.0.0.1"; //NOSONAR
5050
5151 private static final String DEF_LOCAL_NAME = "localhost";
5252 private static final String DEF_DOMAIN = "localdomain";
412412 */
413413 public void setFilesetmanifest(FilesetManifestConfig config) {
414414 filesetManifestConfig = config;
415 mergeManifestsMain = "merge".equals(config.getValue());
415 mergeManifestsMain = config != null && "merge".equals(config.getValue());
416416
417417 if (filesetManifestConfig != null
418418 && !filesetManifestConfig.getValue().equals("skip")) {
10351035 * @since Ant 1.6.2
10361036 */
10371037 protected final void writeIndexLikeList(List<String> dirs, List<String> files,
1038 PrintWriter writer)
1039 throws IOException {
1038 PrintWriter writer) {
10401039 // JarIndex is sorting the directories by ascending order.
10411040 // it has no value but cosmetic since it will be read into a
10421041 // hashtable by the classloader, but we'll do so anyway.
3939 import org.apache.tools.ant.types.RedirectorElement;
4040 import org.apache.tools.ant.types.Reference;
4141 import org.apache.tools.ant.util.KeepAliveInputStream;
42 import org.apache.tools.ant.util.StringUtils;
4243
4344 /**
4445 * Launcher for Java applications. Allows use of
996997 * @since 1.6.2
997998 */
998999 private void log(Throwable t) {
999 StringWriter sw = new StringWriter();
1000 PrintWriter w = new PrintWriter(sw);
1001 t.printStackTrace(w);
1002 w.close();
1003 log(sw.toString(), Project.MSG_ERR);
1000 log(StringUtils.getStackTrace(t), Project.MSG_ERR);
10041001 }
10051002
10061003 /**
6666 * <li>includejavaruntime
6767 * <li>source
6868 * <li>compiler
69 * <li>release
6970 * </ul>
7071 * Of these arguments, the <b>sourcedir</b> and <b>destdir</b> are required.
7172 * <p>
8485 private static final String FAIL_MSG
8586 = "Compile failed; see the compiler error output for details.";
8687
88 private static final String JAVAC9 = "javac9";
8789 private static final String JAVAC19 = "javac1.9";
8890 private static final String JAVAC18 = "javac1.8";
8991 private static final String JAVAC17 = "javac1.7";
106108
107109 private Path src;
108110 private File destDir;
111 private File nativeHeaderDir;
109112 private Path compileClasspath;
110113 private Path modulepath;
111114 private Path upgrademodulepath;
118121 private boolean depend = false;
119122 private boolean verbose = false;
120123 private String targetAttribute;
124 private String release;
121125 private Path bootclasspath;
122126 private Path extdirs;
123127 private Boolean includeAntRuntime;
165169 return JAVAC17;
166170 } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) {
167171 return JAVAC18;
168 } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_9)) {
169 return JAVAC19;
172 } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_9)) {
173 return JAVAC9;
170174 } else {
171175 return CLASSIC;
172176 }
284288 }
285289
286290 /**
291 * Set the destination directory into which the generated native
292 * header files should be placed.
293 * @param nhDir where to place generated native header files
294 * @since Ant 1.9.8
295 */
296 public void setNativeHeaderDir(final File nhDir) {
297 this.nativeHeaderDir = nhDir;
298 }
299
300 /**
301 * Gets the destination directory into which the generated native
302 * header files should be placed.
303 * @return where to place generated native header files
304 * @since Ant 1.9.8
305 */
306 public File getNativeHeaderDir() {
307 return nativeHeaderDir;
308 }
309
310 /**
287311 * Set the sourcepath to be used for this compilation.
288312 * @param sourcepath the source path
289313 */
762786 return targetAttribute != null
763787 ? targetAttribute
764788 : getProject().getProperty(MagicNames.BUILD_JAVAC_TARGET);
789 }
790
791 /**
792 * Sets the version to use for the {@code --release} switch that
793 * combines {@code source}, {@code target} and setting the
794 * bootclasspath.
795 *
796 * Values depend on the compiler, for jdk 9 the valid values are
797 * "6", "7", "8", "9".
798 * @param release the value of the release attribute
799 * @since Ant 1.9.8
800 */
801 public void setRelease(final String release) {
802 this.release = release;
803 }
804
805 /**
806 * Gets the version to use for the {@code --release} switch that
807 * combines {@code source}, {@code target} and setting the
808 * bootclasspath.
809 *
810 * @return the value of the release attribute
811 * @since Ant 1.9.8
812 */
813 public String getRelease() {
814 return release;
765815 }
766816
767817 /**
911961 }
912962
913963 private String getAltCompilerName(final String anImplementation) {
914 if (JAVAC19.equalsIgnoreCase(anImplementation)
964 if (JAVAC9.equalsIgnoreCase(anImplementation)
965 || JAVAC19.equalsIgnoreCase(anImplementation)
915966 || JAVAC18.equalsIgnoreCase(anImplementation)
916967 || JAVAC17.equalsIgnoreCase(anImplementation)
917968 || JAVAC16.equalsIgnoreCase(anImplementation)
926977 }
927978 if (MODERN.equalsIgnoreCase(anImplementation)) {
928979 final String nextSelected = assumedJavaVersion();
929 if (JAVAC19.equalsIgnoreCase(nextSelected)
980 if (JAVAC9.equalsIgnoreCase(nextSelected)
930981 || JAVAC18.equalsIgnoreCase(nextSelected)
931982 || JAVAC17.equalsIgnoreCase(nextSelected)
932983 || JAVAC16.equalsIgnoreCase(nextSelected)
11931244 * @param compilerImpl the name of the compiler implementation
11941245 * @return true if compilerImpl is "modern", "classic",
11951246 * "javac1.1", "javac1.2", "javac1.3", "javac1.4", "javac1.5",
1196 * "javac1.6", "javac1.7", "javac1.8" or "javac1.9".
1247 * "javac1.6", "javac1.7", "javac1.8", "javac1.9" or "javac9".
11971248 */
11981249 protected boolean isJdkCompiler(final String compilerImpl) {
11991250 return MODERN.equals(compilerImpl)
12001251 || CLASSIC.equals(compilerImpl)
1201 || JAVAC19.equals(compilerImpl)
1252 || JAVAC9.equals(compilerImpl)
12021253 || JAVAC18.equals(compilerImpl)
12031254 || JAVAC17.equals(compilerImpl)
12041255 || JAVAC16.equals(compilerImpl)
13121312 * cannot be static in inner classes.) The first letter
13131313 * from each element is used to build up the scope string.
13141314 */
1315 static final String[] SCOPE_ELEMENTS = {
1315 static final String[] SCOPE_ELEMENTS = { //NOSONAR
13161316 "overview", "packages", "types", "constructors",
13171317 "methods", "fields"
13181318 };
17711771 useExternalFile, tmpList, srcListWriter);
17721772
17731773 if (useExternalFile) {
1774 srcListWriter.flush();
1774 srcListWriter.flush(); //NOSONAR
17751775 }
17761776 } catch (final IOException e) {
1777 tmpList.delete();
1777 if (tmpList != null) {
1778 tmpList.delete();
1779 }
17781780 throw new BuildException("Error creating temporary file",
17791781 e, getLocation());
17801782 } finally {
20232025 // is the href a valid URL
20242026 try {
20252027 final URL base = new URL("file://.");
2026 new URL(base, la.getHref());
2028 // created for the side effect of throwing a MalformedURLException
2029 new URL(base, la.getHref()); //NOSONAR
20272030 link = la.getHref();
20282031 } catch (final MalformedURLException mue) {
20292032 // ok - just skip
2727 import java.util.StringTokenizer;
2828
2929 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.Project;
3031 import org.apache.tools.ant.Task;
3132 import org.apache.tools.ant.util.FileUtils;
33 import org.apache.tools.ant.util.StringUtils;
3234
3335 /**
3436 * Keyword substitution. Input file is written to output file.
7981 }
8082 bw.flush();
8183 } catch (IOException ioe) {
82 ioe.printStackTrace();
84 log(StringUtils.getStackTrace(ioe), Project.MSG_ERR);
8385 } finally {
8486 FileUtils.close(bw);
8587 FileUtils.close(br);
152154 System.out.println(KeySubst.replace("$f ${VERSION} f ${b} jj $",
153155 hash));
154156 } catch (Exception e) {
155 e.printStackTrace();
157 e.printStackTrace(); //NOSONAR
156158 }
157159 }
158160
246246
247247 /** EnumeratedAttribute operation mode */
248248 public static class FileMode extends EnumeratedAttribute {
249 static final String[] MODES = new String[] {EACH, ALL};
249 static final String[] MODES = new String[] {EACH, ALL}; //NOSONAR
250250
251251 /**
252252 * Return the possible values for FileMode.
7676 super.processBuffer();
7777 } catch (IOException e) {
7878 // impossible since *our* processLine doesn't throw an IOException
79 throw new RuntimeException("Impossible IOException caught: " + e);
79 throw new RuntimeException("Impossible IOException caught: " + e); //NOSONAR
8080 }
8181 }
8282
182182 ret.setTaskName("sequential");
183183 ret.setNamespace("");
184184 ret.setQName("sequential");
185 new RuntimeConfigurable(ret, "sequential");
185 // stores RuntimeConfigurable as "RuntimeConfigurableWrapper"
186 // in ret as side effect
187 new RuntimeConfigurable(ret, "sequential"); //NOSONAR
186188 final int size = nestedSequential.getNested().size();
187189 for (int i = 0; i < size; ++i) {
188190 UnknownElement e =
8080 * @param value the value of the attribute
8181 */
8282 public void setDynamicAttribute(String name, String value) {
83 map.put(name, value);
83 map.put(name.toLowerCase(Locale.ENGLISH), value);
8484 }
8585
8686 /**
196196 }
197197 break;
198198 case STATE_EXPECT_NAME:
199 // macroName cannot be null as this state is only
200 // ever reached from STATE_EXPECT_BRACKET after it
201 // has been set
199202 if (ch == '}') {
200203 state = STATE_NORMAL;
201 String name = macroName.toString().toLowerCase(Locale.ENGLISH);
204 String name = macroName.toString().toLowerCase(Locale.ENGLISH); //NOSONAR
202205 String value = (String) macroMapping.get(name);
203206 if (value == null) {
204207 ret.append("@{");
209212 }
210213 macroName = null;
211214 } else {
212 macroName.append(ch);
215 macroName.append(ch); //NOSONAR
213216 }
214217 break;
215218 default:
223226 ret.append('@');
224227 break;
225228 case STATE_EXPECT_NAME:
229 // macroName cannot be null as this state is only
230 // ever reached from STATE_EXPECT_BRACKET after it
231 // has been set
226232 ret.append("@{");
227 ret.append(macroName.toString());
233 ret.append(macroName.toString()); //NOSONAR
228234 break;
229235 default:
230236 break;
10651065 try {
10661066 write(new PrintWriter(sw));
10671067 } catch (IOException e) {
1068 return null;
1068 return "";
10691069 }
10701070 return sw.toString();
10711071 }
311311 Thread timeoutThread = new Thread() {
312312 public synchronized void run() {
313313 try {
314 wait(timeout);
314 final long start = System.currentTimeMillis();
315 final long end = start + timeout;
316 long now = System.currentTimeMillis();
317 while (now < end) {
318 wait(end - now);
319 now = System.currentTimeMillis();
320 }
315321 synchronized (semaphore) {
316322 stillRunning = false;
317323 timedOut = true;
351357 // System.out.println("Thread " + i + " is still
352358 // alive ");
353359 // still running - wait for it
354 semaphore.wait();
360 semaphore.wait(); //NOSONAR
355361 continue outer2;
356362 }
357363 }
8383 } catch (NoSuchMethodException e) {
8484 // it just won't be added as a shutdown hook... :(
8585 } catch (Exception e) {
86 e.printStackTrace();
86 e.printStackTrace(); //NOSONAR
8787 }
8888 }
8989
9999 addShutdownHookMethod.invoke(Runtime.getRuntime(), args);
100100 added = true;
101101 } catch (IllegalAccessException e) {
102 e.printStackTrace();
102 e.printStackTrace(); //NOSONAR
103103 } catch (InvocationTargetException e) {
104104 Throwable t = e.getTargetException();
105105 if (t != null && t.getClass() == IllegalStateException.class) {
106106 // shutdown already is in progress
107107 running = true;
108108 } else {
109 e.printStackTrace();
109 e.printStackTrace(); //NOSONAR
110110 }
111111 }
112112 }
128128 System.err.println("Could not remove shutdown hook");
129129 }
130130 } catch (IllegalAccessException e) {
131 e.printStackTrace();
131 e.printStackTrace(); //NOSONAR
132132 } catch (InvocationTargetException e) {
133133 Throwable t = e.getTargetException();
134134 if (t != null && t.getClass() == IllegalStateException.class) {
135135 // shutdown already is in progress
136136 running = true;
137137 } else {
138 e.printStackTrace();
138 e.printStackTrace(); //NOSONAR
139139 }
140140 }
141141 // start the hook thread, a unstarted thread may not be
110110 } else {
111111 out.println(StringUtils.LINE_SEP + "BUILD FAILED"
112112 + StringUtils.LINE_SEP);
113 error.printStackTrace(out);
113 error.printStackTrace(out); //NOSONAR
114114 }
115115 }
116116 cleanup();
136136 if (autoflush) {
137137 os.flush();
138138 }
139 if (finish) {
139 if (finish) { //NOSONAR
140140 break;
141141 }
142142 }
3333 import org.apache.tools.ant.types.PropertySet;
3434 import org.apache.tools.ant.types.Reference;
3535 import org.apache.tools.ant.types.ResourceCollection;
36
36 import org.apache.tools.ant.util.StringUtils;
3737
3838 /**
3939 * Calls a given target for all defined sub-builds. This is an extension
254254 log("Target '" + file
255255 + "' failed with message '"
256256 + thrownException.getMessage() + "'.", Project.MSG_ERR);
257 thrownException.printStackTrace(System.err);
257 log(StringUtils.getStackTrace(thrownException), Project.MSG_ERR);
258258 if (buildException == null) {
259259 buildException =
260260 new BuildException(thrownException);
402402 if (resources == null) {
403403 Restrict r = new Restrict();
404404 r.add(new Exists());
405 r.add(resources = new Resources());
405 resources = new Resources();
406 r.add(resources);
406407 myCopy.add(r);
407408 }
408409 resources.add(rc);
6060
6161 public static final DateFormatFactory DEFAULT_DF_FACTORY
6262 = new DateFormatFactory() {
63 /*
64 * The initial version used DateFormat.SHORT for the
65 * time format, which ignores seconds. If we want
66 * seconds as well, we need DateFormat.MEDIUM, which
67 * in turn would break all old build files.
68 *
69 * First try to parse with DateFormat.SHORT and if
70 * that fails with MEDIUM - throw an exception if both
71 * fail.
72 */
63
64 private ThreadLocal<DateFormat> primary =
65 new ThreadLocal<DateFormat>() {
66 @Override
67 protected DateFormat initialValue() {
68 return new SimpleDateFormat("MM/dd/yyyy hh:mm a",
69 Locale.US);
70 }
71 };
72 private ThreadLocal<DateFormat> fallback =
73 new ThreadLocal<DateFormat>() {
74 @Override
75 protected DateFormat initialValue() {
76 return new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a",
77 Locale.US);
78 }
79 };
80
7381 public DateFormat getPrimaryFormat() {
74 return DateFormat.getDateTimeInstance(DateFormat.SHORT,
75 DateFormat.SHORT, Locale.US);
82 return primary.get();
7683 }
7784 public DateFormat getFallbackFormat() {
78 return DateFormat.getDateTimeInstance(DateFormat.SHORT,
79 DateFormat.MEDIUM, Locale.US);
85 return fallback.get();
8086 }
8187 };
8288 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
166166 }
167167 RandomAccessFile raf = null;
168168 try {
169 raf = new RandomAccessFile(f, READ_WRITE);
169 raf = new RandomAccessFile(f, READ_WRITE); //NOSONAR
170170 } catch (Exception e) {
171171 throw new BuildException("Could not open " + f + " for writing", e);
172172 }
4343 * @throws Exception thrown if any problems happens.
4444 * @since Ant 1.4
4545 */
46 void setStylesheet(File stylesheet) throws Exception;
46 void setStylesheet(File stylesheet) throws Exception; //NOSONAR
4747
4848 /**
4949 * Add a parameter to be set during the XSL transformation.
5353 * @see XSLTLiaison4#addParam(java.lang.String, java.lang.Object)
5454 * @since Ant 1.3
5555 */
56 void addParam(String name, String expression) throws Exception;
56 void addParam(String name, String expression) throws Exception; //NOSONAR
5757
5858 /**
5959 * Perform the transformation of a file into another.
6363 * @see #setStylesheet(File)
6464 * @since Ant 1.4
6565 */
66 void transform(File infile, File outfile) throws Exception;
66 void transform(File infile, File outfile) throws Exception; //NOSONAR
6767
6868 } //-- XSLTLiaison
3838 import org.apache.tools.ant.DirectoryScanner;
3939 import org.apache.tools.ant.DynamicConfigurator;
4040 import org.apache.tools.ant.Project;
41 import org.apache.tools.ant.ProjectComponent;
4142 import org.apache.tools.ant.PropertyHelper;
4243 import org.apache.tools.ant.types.CommandlineJava;
4344 import org.apache.tools.ant.types.Environment;
5253 import org.apache.tools.ant.types.resources.FileResource;
5354 import org.apache.tools.ant.types.resources.Resources;
5455 import org.apache.tools.ant.types.resources.Union;
56 import org.apache.tools.ant.util.ClasspathUtils;
5557 import org.apache.tools.ant.util.FileNameMapper;
5658 import org.apache.tools.ant.util.FileUtils;
5759 import org.apache.tools.ant.util.ResourceUtils;
60 import org.apache.tools.ant.util.StringUtils;
5861
5962 /**
6063 * Processes a set of XML documents via XSLT. This is
717720 * @return the requested class.
718721 * @exception Exception if the class could not be loaded.
719722 */
720 private Class loadClass(final String classname) throws Exception {
723 private Class loadClass(final String classname) throws ClassNotFoundException {
721724 setupLoader();
722725 if (loader == null) {
723726 return Class.forName(classname);
828831 if (outFileName == null || outFileName.length == 0) {
829832 log("Skipping " + inFile + " it cannot get mapped to output.", Project.MSG_VERBOSE);
830833 return;
831 } else if (outFileName == null || outFileName.length > 1) {
834 } else if (outFileName.length > 1) {
832835 log("Skipping " + inFile + " its mapping is ambiguos.", Project.MSG_VERBOSE);
833836 return;
834837 }
949952 try {
950953 resolveProcessor(PROCESSOR_TRAX);
951954 } catch (final Throwable e1) {
952 e1.printStackTrace();
955 log(StringUtils.getStackTrace(e1), Project.MSG_ERR);
953956 handleError(e1);
954957 }
955958 }
13761379 * @since Ant 1.7
13771380 */
13781381 private void setLiaisonDynamicFileParameters(
1379 final XSLTLiaison liaison, final File inFile) throws Exception {
1382 final XSLTLiaison liaison, final File inFile) throws Exception { //NOSONAR
13801383 if (fileNameParameter != null) {
13811384 liaison.addParam(fileNameParameter, inFile.getName());
13821385 }
14611464 /**
14621465 * the list of factory attributes to use for TraXLiaison
14631466 */
1464 private final Vector attributes = new Vector();
1467 private final List<Attribute> attributes = new ArrayList<Attribute>();
1468
1469 /**
1470 * the list of factory features to use for TraXLiaison
1471 */
1472 private final List<Feature> features = new ArrayList<Feature>();
14651473
14661474 /**
14671475 * @return the name of the factory.
14831491 * @param attr the newly created factory attribute
14841492 */
14851493 public void addAttribute(final Attribute attr) {
1486 attributes.addElement(attr);
1494 attributes.add(attr);
14871495 }
14881496
14891497 /**
14911499 * @return the enumeration of attributes
14921500 */
14931501 public Enumeration getAttributes() {
1494 return attributes.elements();
1502 return Collections.enumeration(attributes);
1503 }
1504
1505 /**
1506 * Create an instance of a factory feature.
1507 * @param feature the newly created feature
1508 * @since Ant 1.9.8
1509 */
1510 public void addFeature(final Feature feature) {
1511 features.add(feature);
1512 }
1513
1514 /**
1515 * The configured features.
1516 * @since Ant 1.9.8
1517 */
1518 public Iterable<Feature> getFeatures() {
1519 return features;
14951520 }
14961521
14971522 /**
15021527 * <li>http://xml.apache.org/xalan/features/incremental (true|false) </li>
15031528 * </ul>
15041529 */
1505 public static class Attribute implements DynamicConfigurator {
1530 public static class Attribute
1531 extends ProjectComponent
1532 implements DynamicConfigurator {
15061533
15071534 /** attribute name, mostly processor specific */
15081535 private String name;
15181545 }
15191546
15201547 /**
1521 * @return the output property value.
1548 * @return the attribute value.
15221549 */
15231550 public Object getValue() {
15241551 return value;
15591586 this.value = value;
15601587 }
15611588 }
1589 } else if ("valueref".equalsIgnoreCase(name)) {
1590 this.value = getProject().getReference(value);
1591 } else if ("classloaderforpath".equalsIgnoreCase(name)) {
1592 this.value =
1593 ClasspathUtils.getClassLoaderForPath(getProject(),
1594 new Reference(getProject(),
1595 value));
15621596 } else {
15631597 throw new BuildException("Unsupported attribute: " + name);
15641598 }
15651599 }
15661600 } // -- class Attribute
1601
1602 /**
1603 * A feature for the TraX factory.
1604 * @since Ant 1.9.8
1605 */
1606 public static class Feature {
1607 private String name;
1608 private boolean value;
1609
1610 public Feature() { }
1611 public Feature(String name, boolean value) {
1612 this.name = name;
1613 this.value = value;
1614 }
1615
1616 /**
1617 * @param name the feature name.
1618 */
1619 public void setName(String name) {
1620 this.name = name;
1621 }
1622
1623 /**
1624 * @param value the feature value.
1625 */
1626 public void setValue(boolean value) {
1627 this.value = value;
1628 }
1629
1630 /**
1631 * @return the feature name.
1632 */
1633 public String getName() {
1634 return name;
1635 }
1636
1637 /**
1638 * @return the feature value.
1639 */
1640 public boolean getValue() {
1641 return value;
1642 }
1643 }
15671644 } // -- class Factory
15681645
15691646 /**
383383 if (containingPath != null && nodeName.equals(PATH)) {
384384 // A "path" attribute for a node within a Path object.
385385 containingPath.setPath(attributeValue);
386 } else if (container instanceof Path && nodeName.equals(REF_ID)) {
386 } else if (containingPath != null
387 && container instanceof Path && nodeName.equals(REF_ID)) {
387388 // A "refid" attribute for a node within a Path object.
388389 containingPath.setPath(attributeValue);
389 } else if (container instanceof Path && nodeName.equals(LOCATION)) {
390 } else if (containingPath != null && container instanceof Path
391 && nodeName.equals(LOCATION)) {
390392 // A "location" attribute for a node within a
391393 // Path object.
392394 containingPath.setLocation(resolveFile(attributeValue));
7777 */
7878 public class Zip extends MatchingTask {
7979 private static final int BUFFER_SIZE = 8 * 1024;
80 private static final int ROUNDUP_MILLIS = 1999; // 2 seconds - 1
80 /**
81 * The granularity of timestamps inside a ZIP archive.
82 */
83 private static final int ZIP_FILE_TIMESTAMP_GRANULARITY = 2000;
84 private static final int ROUNDUP_MILLIS = ZIP_FILE_TIMESTAMP_GRANULARITY - 1;
8185 // CheckStyle:VisibilityModifier OFF - bc
8286
8387 protected File zipFile;
10211025 * Determine a Resource's Unix mode or return the given default
10221026 * value if not available.
10231027 */
1024 private int getUnixMode(final Resource r, final ZipFile zf, final int defaultMode)
1025 throws IOException {
1028 private int getUnixMode(final Resource r, final ZipFile zf, final int defaultMode) {
10261029
10271030 int unixMode = defaultMode;
10281031 if (zf != null) {
15471550 final Resource[] rs = selectFileResources(initial);
15481551 Resource[] result =
15491552 ResourceUtils.selectOutOfDateSources(this, rs, mapper,
1550 getZipScanner());
1553 getZipScanner(),
1554 ZIP_FILE_TIMESTAMP_GRANULARITY);
15511555 if (!doFilesonly) {
15521556 final Union u = new Union();
15531557 u.addAll(Arrays.asList(selectDirectoryResources(initial)));
121121 || compilerType.equalsIgnoreCase("javac1.6")
122122 || compilerType.equalsIgnoreCase("javac1.7")
123123 || compilerType.equalsIgnoreCase("javac1.8")
124 || compilerType.equalsIgnoreCase("javac1.9")) {
124 || compilerType.equalsIgnoreCase("javac1.9")
125 || compilerType.equalsIgnoreCase("javac9")) {
125126 // does the modern compiler exist?
126127 if (doesModernCompilerExist()) {
127128 return new Javac13();
6969 protected boolean depend = false;
7070 protected boolean verbose = false;
7171 protected String target;
72 protected String release;
7273 protected Path bootclasspath;
7374 protected Path extdirs;
7475 protected Path compileClasspath;
110111 depend = attributes.getDepend();
111112 verbose = attributes.getVerbose();
112113 target = attributes.getTarget();
114 release = attributes.getRelease();
113115 bootclasspath = attributes.getBootclasspath();
114116 extdirs = attributes.getExtdirs();
115117 compileList = attributes.getFileList();
320322 cmd.createArgument().setValue("-sourcepath");
321323 cmd.createArgument().setPath(sourcepath);
322324 }
323 if (target != null) {
324 cmd.createArgument().setValue("-target");
325 cmd.createArgument().setValue(target);
326 }
327
328 final Path bp = getBootClassPath();
329 if (bp.size() > 0) {
330 cmd.createArgument().setValue("-bootclasspath");
331 cmd.createArgument().setPath(bp);
325 if (release == null || !assumeJava19()) {
326 if (target != null) {
327 cmd.createArgument().setValue("-target");
328 cmd.createArgument().setValue(target);
329 }
330
331 final Path bp = getBootClassPath();
332 if (bp.size() > 0) {
333 cmd.createArgument().setValue("-bootclasspath");
334 cmd.createArgument().setPath(bp);
335 }
332336 }
333337
334338 if (extdirs != null && extdirs.size() > 0) {
389393 setupJavacCommandlineSwitches(cmd, true);
390394 if (!assumeJava13()) { // -source added with JDK 1.4
391395 final String t = attributes.getTarget();
392 if (attributes.getSource() != null) {
393 cmd.createArgument().setValue("-source");
394 cmd.createArgument()
395 .setValue(adjustSourceValue(attributes.getSource()));
396
397 } else if (t != null && mustSetSourceForTarget(t)) {
398 setImplicitSourceSwitch(cmd, t, adjustSourceValue(t));
396 final String s = attributes.getSource();
397 if (release == null || !assumeJava19()) {
398 if (release != null) {
399 attributes.log("Support for javac --release has been added"
400 + " in Java9 ignoring it");
401 }
402 if (s != null) {
403 cmd.createArgument().setValue("-source");
404 cmd.createArgument().setValue(adjustSourceValue(s));
405
406 } else if (t != null && mustSetSourceForTarget(t)) {
407 setImplicitSourceSwitch(cmd, t, adjustSourceValue(t));
408 }
409 } else { // Java 9+ and release has been set
410 if (t != null || s != null || getBootClassPath().size() > 0) {
411 attributes.log("Ignoring source, target and bootclasspath"
412 + " as release has been set",
413 Project.MSG_WARN);
414 }
415 cmd.createArgument().setValue("--release");
416 cmd.createArgument().setValue(release);
399417 }
400418 }
401419 final Path msp = getModulesourcepath();
402420 if (msp.size() > 0) {
403 cmd.createArgument().setValue("-modulesourcepath");
421 cmd.createArgument().setValue("--module-source-path");
404422 cmd.createArgument().setPath(msp);
405423 }
406424 final Path mp = getModulepath();
407425 if (mp.size() > 0) {
408 cmd.createArgument().setValue("-modulepath");
426 cmd.createArgument().setValue("--module-path");
409427 cmd.createArgument().setPath(mp);
410428 }
411429 final Path ump = getUpgrademodulepath();
412430 if (ump.size() > 0) {
413 cmd.createArgument().setValue("-upgrademodulepath");
431 cmd.createArgument().setValue("--upgrade-module-path");
414432 cmd.createArgument().setPath(ump);
433 }
434 if (attributes.getNativeHeaderDir() != null) {
435 if (assumeJava13() || assumeJava14() || assumeJava15()
436 || assumeJava16() || assumeJava17()) {
437 attributes.log("Support for javac -h has been added in Java8,"
438 + " ignoring it");
439 } else {
440 cmd.createArgument().setValue("-h");
441 cmd.createArgument().setFile(attributes.getNativeHeaderDir());
442 }
415443 }
416444 return cmd;
417445 }
671699 }
672700
673701 /**
674 * Shall we assume JDK 1.9 command line switches?
675 * @return true if JDK 1.9
702 * Shall we assume JDK 9 command line switches?
703 * @return true if JDK 9
676704 * @since Ant 1.9.4
705 * @deprecated use #assumeJava9 instead
677706 */
678707 protected boolean assumeJava19() {
679 return assumeJavaXY("javac1.9", JavaEnvUtils.JAVA_1_9);
708 return assumeJavaXY("javac1.9", JavaEnvUtils.JAVA_9)
709 || assumeJavaXY("javac9", JavaEnvUtils.JAVA_9);
710 }
711
712 /**
713 * Shall we assume JDK 9 command line switches?
714 * @return true if JDK 9
715 * @since Ant 1.9.8
716 */
717 protected boolean assumeJava9() {
718 return assumeJava19();
680719 }
681720
682721 /**
685724 */
686725 private boolean assumeJavaXY(final String javacXY, final String javaEnvVersionXY) {
687726 return javacXY.equals(attributes.getCompilerVersion())
688 || ("classic".equals(attributes.getCompilerVersion())
689 && JavaEnvUtils.isJavaVersion(javaEnvVersionXY))
690 || ("modern".equals(attributes.getCompilerVersion())
691 && JavaEnvUtils.isJavaVersion(javaEnvVersionXY))
692 || ("extJavac".equals(attributes.getCompilerVersion())
693 && JavaEnvUtils.isJavaVersion(javaEnvVersionXY));
727 || (JavaEnvUtils.isJavaVersion(javaEnvVersionXY) &&
728 ("classic".equals(attributes.getCompilerVersion())
729 || "modern".equals(attributes.getCompilerVersion())
730 || "extJavac".equals(attributes.getCompilerVersion())));
694731 }
695732
696733 /**
754791 if (assumeJava18()) {
755792 return "1.8 in JDK 1.8";
756793 }
757 if (assumeJava19()) {
758 return "1.9 in JDK 1.9";
794 if (assumeJava9()) {
795 return "9 in JDK 9";
759796 }
760797 return "";
761798 }
781818 && !assumeJava15() && !assumeJava16())
782819 || (t.equals("7") && !assumeJava17())
783820 || (t.equals("8") && !assumeJava18())
784 || (t.equals("9") && !assumeJava19());
821 || (t.equals("9") && !assumeJava9());
785822 }
786823
787824
7777 }
7878 if (atLeast != null) {
7979 try {
80 new DeweyDecimal(atLeast);
80 // only created for side effect
81 new DeweyDecimal(atLeast); //NOSONAR
8182 } catch (NumberFormatException e) {
8283 throw new BuildException(
8384 "The 'atleast' attribute is not a Dewey Decimal eg 1.1.0 : "
8586 }
8687 } else {
8788 try {
88 new DeweyDecimal(exactly);
89 // only created for side effect
90 new DeweyDecimal(exactly); //NOSONAR
8991 } catch (NumberFormatException e) {
9092 throw new BuildException(
9193 "The 'exactly' attribute is not a Dewey Decimal eg 1.1.0 : "
4343 private static final int GET_REVISION = 4;
4444 private static final int GET_PREVIOUS_REV = 5;
4545
46 // FIXME formatters are not thread-safe
47
4846 /** input format for dates read in from cvs log */
49 private static final SimpleDateFormat INPUT_DATE
47 private final SimpleDateFormat inputDate
5048 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
5149 /**
5250 * New formatter used to parse CVS date/timestamp.
5351 */
54 private static final SimpleDateFormat CVS1129_INPUT_DATE =
52 private final SimpleDateFormat cvs1129InputDate =
5553 new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US);
5654
5755 static {
58 TimeZone utc = TimeZone.getTimeZone("UTC");
59 INPUT_DATE.setTimeZone(utc);
60 CVS1129_INPUT_DATE.setTimeZone(utc);
6156 }
6257
6358 //The following is data used while processing stdout of CVS command
10196 for (int i = 0; i < moduleNames.length; i++) {
10297 moduleNameLengths[i] = moduleNames[i].length();
10398 }
99
100 TimeZone utc = TimeZone.getTimeZone("UTC");
101 inputDate.setTimeZone(utc);
102 cvs1129InputDate.setTimeZone(utc);
104103 }
105104
106105 /**
296295 */
297296 private Date parseDate(final String date) {
298297 try {
299 return INPUT_DATE.parse(date);
298 return inputDate.parse(date);
300299 } catch (ParseException e) {
301300 try {
302 return CVS1129_INPUT_DATE.parse(date);
301 return cvs1129InputDate.parse(date);
303302 } catch (ParseException e2) {
304303 throw new IllegalStateException("Invalid date format: " + date);
305304 }
3333 */
3434 public class ChangeLogWriter {
3535 /** output format for dates written to xml file */
36 private static final SimpleDateFormat OUTPUT_DATE
36 private final SimpleDateFormat outputDate
3737 = new SimpleDateFormat("yyyy-MM-dd");
3838 /** output format for times written to xml file */
39 private static final SimpleDateFormat OUTPUT_TIME
39 private SimpleDateFormat outputTime
4040 = new SimpleDateFormat("HH:mm");
4141 /** stateless helper for writing the XML document */
4242 private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();
4343
44 static {
44 public ChangeLogWriter() {
4545 TimeZone utc = TimeZone.getTimeZone("UTC");
46 OUTPUT_DATE.setTimeZone(utc);
47 OUTPUT_TIME.setTimeZone(utc);
46 outputDate.setTimeZone(utc);
47 outputTime.setTimeZone(utc);
4848 }
4949
5050 /**
8686 final CVSEntry entry) throws IOException {
8787 Element ent = doc.createElement("entry");
8888 DOMUtils.appendTextElement(ent, "date",
89 OUTPUT_DATE.format(entry.getDate()));
89 outputDate.format(entry.getDate()));
9090 DOMUtils.appendTextElement(ent, "time",
91 OUTPUT_TIME.format(entry.getDate()));
91 outputTime.format(entry.getDate()));
9292 DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor());
9393
9494 final Enumeration enumeration = entry.getFiles().elements();
298298 BufferedReader reader = null;
299299
300300 try {
301 reader = new BufferedReader(new FileReader(tmpFile));
301 reader = new BufferedReader(new FileReader(tmpFile)); //NOSONAR
302302
303303 // entries are of the form:
304304 //CVS 1.11
439439 Tuple that = (Tuple) o;
440440 return key.compareTo(that.key);
441441 }
442
443 @Override
444 public boolean equals(Object o) {
445 if (o == this) {
446 return true;
447 }
448 if (o == null || o.getClass() != getClass()) {
449 return false;
450 }
451 Tuple that = (Tuple) o;
452 return (key == null ? that.key == null : key.equals(that.key))
453 && (value == null ? that.value == null : value.equals(that.value));
454 }
455
456 @Override
457 public int hashCode() {
458 return key != null ? key.hashCode() : 0;
459 }
442460 }
443461
444462 private List sortProperties(Properties props) {
867867 PrintWriter w = null;
868868 int rc =
869869 COM.ibm.netrexx.process.NetRexxC.main(new Rexx(compileArgs),
870 w = new PrintWriter(out));
870 w = new PrintWriter(out)); //NOSONAR
871871 String sdir = srcDir.getAbsolutePath();
872872 String ddir = destDir.getAbsolutePath();
873873 boolean doReplace = !(sdir.equals(ddir));
259259 throw new BuildException(x, getLocation());
260260 }
261261 try {
262 OutputStream os = new FileOutputStream(propertyfile);
262 OutputStream os = new FileOutputStream(propertyfile); //NOSONAR
263263 try {
264264 try {
265265 os.write(baos.toByteArray());
400400 } catch (NullPointerException npe) {
401401 // Default to string type
402402 // which means do nothing
403 npe.printStackTrace();
403 npe.printStackTrace(); //NOSONAR
404404 }
405405
406406 if (newValue == null) {
148148 }
149149 } else {
150150 if (output != null) {
151 FileOutputStream fos = null;
151152 try {
152 BufferedOutputStream bos
153 = new BufferedOutputStream(new FileOutputStream(output));
153 fos = new FileOutputStream(output); //NOSONAR
154 BufferedOutputStream bos = new BufferedOutputStream(fos);
154155 outputstream = new PrintStream(bos);
155156 } catch (IOException e) {
157 FileUtils.close(fos);
156158 throw new BuildException(e, getLocation());
157159 }
158160 } else if (!quiet) {
161163 outputstream = new LogOutputStream(this, Project.MSG_DEBUG);
162164 }
163165 if (error != null) {
166 FileOutputStream fos = null;
164167 try {
165 BufferedOutputStream bos
166 = new BufferedOutputStream(new FileOutputStream(error));
168 fos = new FileOutputStream(error);
169 BufferedOutputStream bos = new BufferedOutputStream(fos);
167170 errorstream = new PrintStream(bos);
168171 } catch (IOException e) {
172 FileUtils.close(fos);
169173 throw new BuildException(e, getLocation());
170174 }
171175 } else if (!quiet) {
2727 import java.io.OutputStream;
2828 import java.lang.reflect.Field;
2929 import java.net.URL;
30 import java.util.ArrayList;
3031 import java.util.Enumeration;
32 import java.util.HashMap;
3133 import java.util.Hashtable;
34 import java.util.List;
35 import java.util.Map;
3236 import java.util.Vector;
3337
3438 import javax.xml.parsers.ParserConfigurationException;
5963 import org.apache.tools.ant.types.resources.URLProvider;
6064 import org.apache.tools.ant.util.FileUtils;
6165 import org.apache.tools.ant.util.JAXPUtils;
66 import org.apache.tools.ant.util.JavaEnvUtils;
6267 import org.xml.sax.EntityResolver;
6368 import org.xml.sax.InputSource;
6469 import org.xml.sax.SAXException;
122127 private final Hashtable<String, Object> params = new Hashtable<String, Object>();
123128
124129 /** factory attributes */
125 private final Vector attributes = new Vector();
130 private final List<Object[]> attributes = new ArrayList<Object[]>();
131
132 /** factory features */
133 private final Map<String, Boolean> features = new HashMap<String, Boolean>();
126134
127135 /** whether to suppress warnings */
128136 private boolean suppressWarnings = false;
134142 * Constructor for TraXLiaison.
135143 * @throws Exception never
136144 */
137 public TraXLiaison() throws Exception {
145 public TraXLiaison() throws Exception { //NOSONAR
138146 }
139147
140148 /**
313321 * @see #addParam(java.lang.String, java.lang.String)
314322 * @see #setOutputProperty(java.lang.String, java.lang.String)
315323 */
316 private void createTransformer() throws Exception {
324 private void createTransformer()
325 throws IOException, ParserConfigurationException, SAXException, TransformerException {
317326 if (templates == null) {
318327 readTemplates();
319328 }
332341 }
333342
334343 if (traceConfiguration != null) {
335 if ("org.apache.xalan.transformer.TransformerImpl"
344 if ("org.apache.xalan.transformer.TransformerImpl" //NOSONAR
336345 .equals(transformer.getClass().getName())) {
337346 try {
338347 final Class traceSupport =
420429 }
421430 }
422431
423 try { // #51668, #52382
424 final Field _isNotSecureProcessing = tfactory.getClass().getDeclaredField("_isNotSecureProcessing");
425 _isNotSecureProcessing.setAccessible(true);
426 _isNotSecureProcessing.set(tfactory, Boolean.TRUE);
427 } catch (final Exception x) {
428 if (project != null) {
429 project.log(x.toString(), Project.MSG_DEBUG);
430 }
431 }
432 applyReflectionHackForExtensionMethods();
432433
433434 tfactory.setErrorListener(this);
434435
435436 // specific attributes for the transformer
436437 final int size = attributes.size();
437438 for (int i = 0; i < size; i++) {
438 final Object[] pair = (Object[]) attributes.elementAt(i);
439 final Object[] pair = attributes.get(i);
439440 tfactory.setAttribute((String) pair[0], pair[1]);
441 }
442
443 for (Map.Entry<String, Boolean> feature : features.entrySet()) {
444 try {
445 tfactory.setFeature(feature.getKey(), feature.getValue());
446 } catch (TransformerConfigurationException ex) {
447 throw new BuildException(ex);
448 }
440449 }
441450
442451 if (uriResolver != null) {
444453 }
445454 return tfactory;
446455 }
447
448456
449457 /**
450458 * Set the factory name to use instead of JAXP default lookup.
465473 */
466474 public void setAttribute(final String name, final Object value) {
467475 final Object[] pair = new Object[]{name, value};
468 attributes.addElement(pair);
476 attributes.add(pair);
477 }
478
479 /**
480 * Set a custom feature for the JAXP factory implementation.
481 * @param name the feature name.
482 * @param value the value of the feature
483 * @since Ant 1.9.8
484 */
485 public void setFeature(final String name, final boolean value) {
486 features.put(name, value);
469487 }
470488
471489 /**
624642 (XSLTProcess.Factory.Attribute) attrs.nextElement();
625643 setAttribute(attr.getName(), attr.getValue());
626644 }
645 for (final XSLTProcess.Factory.Feature feature
646 : factory.getFeatures()) {
647 setFeature(feature.getName(), feature.getValue());
648 }
627649 }
628650
629651 final XMLCatalog xmlCatalog = xsltTask.getXMLCatalog();
646668
647669 traceConfiguration = xsltTask.getTraceConfiguration();
648670 }
671
672 private void applyReflectionHackForExtensionMethods() {
673 // Jigsaw doesn't allow reflection to work, so we can stop trying
674 if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_7)
675 && !JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
676 try { // #51668, #52382
677 final Field _isNotSecureProcessing = tfactory.getClass().getDeclaredField("_isNotSecureProcessing");
678 _isNotSecureProcessing.setAccessible(true);
679 _isNotSecureProcessing.set(tfactory, Boolean.TRUE);
680 } catch (final Exception x) {
681 if (project != null) {
682 project.log(x.toString(), Project.MSG_DEBUG);
683 }
684 }
685 }
686 }
687
649688 }
2929 import org.apache.tools.ant.taskdefs.Execute;
3030 import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
3131 import org.apache.tools.ant.types.Commandline;
32
32 import org.apache.tools.ant.util.StringUtils;
3333
3434 /**
3535 * Creates new Continuus ccm task and sets it as the default.
321321 } // end of if ()
322322 } catch (NullPointerException npe) {
323323 log("error procession stream , null pointer exception", Project.MSG_ERR);
324 npe.printStackTrace();
324 log(StringUtils.getStackTrace(npe), Project.MSG_ERR);
325325 throw new BuildException(npe.getClass().getName());
326326 } catch (Exception e) {
327327 log("error procession stream " + e.getMessage(), Project.MSG_ERR);
4848 private String mClearToolDir = "";
4949 private String mviewPath = null;
5050 private String mobjSelect = null;
51 private static int pcnt = 0;
51 private int pcnt = 0;
5252 private boolean mFailonerr = true;
5353 /**
5454 * Set the directory where the cleartool executable is located.
196196 dependencyList = new Vector();
197197 className = line.substring(prependLength);
198198 dependencyMap.put(className, dependencyList);
199 } else {
199 } else if (dependencyList != null) {
200200 dependencyList.addElement(line);
201201 }
202202 }
132132 FileInputStream inFileStream
133133 = new FileInputStream(element);
134134
135 if (element.getName().endsWith(".class")) {
135 try {
136 if (element.getName().endsWith(".class")) {
136137
137 // create a data input stream from the jar
138 // input stream
139 ClassFile javaClass = new ClassFile();
138 // create a data input stream from the jar
139 // input stream
140 ClassFile javaClass = new ClassFile();
140141
141 javaClass.read(inFileStream);
142 javaClass.read(inFileStream);
142143
143 nextElement = javaClass;
144 nextElement = javaClass;
145 }
146 } finally {
147 inFileStream.close();
144148 }
145149 }
146150 } else {
2020 import java.io.InputStream;
2121 import java.util.zip.ZipEntry;
2222 import java.util.zip.ZipInputStream;
23
24 import org.apache.tools.ant.BuildException;
2325
2426 /**
2527 * A class file iterator which iterates through the contents of a Java jar
7880 text += ": " + message;
7981 }
8082
81 throw new RuntimeException("Problem reading JAR file: " + text);
83 throw new BuildException("Problem reading JAR file: " + text);
8284 }
8385
8486 return nextElement;
4242 import org.xml.sax.SAXException;
4343
4444 import org.apache.tools.ant.util.FileUtils;
45 import org.apache.tools.ant.util.StringUtils;
4546
4647 /**
4748 * Compiles EJB stubs and skeletons for the iPlanet Application
309310 // SAXException or ParserConfigurationException may be thrown
310311 System.out.println("An exception was generated while trying to ");
311312 System.out.println("create a new SAXParser.");
312 e.printStackTrace();
313 e.printStackTrace(); //NOSONAR
313314 return;
314315 }
315316
442443 p.destroy();
443444 } catch (IOException e) {
444445 log("An IOException has occurred while trying to execute ejbc.");
445 e.printStackTrace();
446 log(StringUtils.getStackTrace(e));
446447 } catch (InterruptedException e) {
447448 // Do nothing
448449 }
726727 } else {
727728 location = (String) fileDtds.get(publicId);
728729 if (location != null) {
729 inputStream = new FileInputStream(location);
730 // closed when the InputSource is closed
731 inputStream = new FileInputStream(location); //NOSONAR
730732 }
731733 }
732734 } catch (IOException e) {
14821484 System.out.println(text);
14831485 }
14841486 } catch (IOException e) {
1485 e.printStackTrace();
1487 e.printStackTrace(); //NOSONAR
14861488 } finally {
14871489 FileUtils.close(reader);
14881490 }
129129 final boolean includeImpl,
130130 final boolean includeURL)
131131 throws BuildException {
132 JarFile jarFile = null;
132133 try {
133 final JarFile jarFile = new JarFile(file);
134 jarFile = new JarFile(file);
134135 final Extension[] extensions =
135136 Extension.getAvailable(jarFile.getManifest());
136137 for (int i = 0; i < extensions.length; i++) {
139140 }
140141 } catch (final Exception e) {
141142 throw new BuildException(e.getMessage(), e);
143 } finally {
144 close(jarFile);
142145 }
143146 }
144147
200203 */
201204 static Manifest getManifest(final File file)
202205 throws BuildException {
206 JarFile jarFile = null;
203207 try {
204 final JarFile jarFile = new JarFile(file);
208 jarFile = new JarFile(file);
205209 Manifest m = jarFile.getManifest();
206210 if (m == null) {
207211 throw new BuildException(file + " doesn't have a MANIFEST");
209213 return m;
210214 } catch (final IOException ioe) {
211215 throw new BuildException(ioe.getMessage(), ioe);
216 } finally {
217 close(jarFile);
218 }
219 }
220
221 private static void close(JarFile device) {
222 if (null != device) {
223 try {
224 device.close();
225 } catch (IOException e) {
226 //ignore
227 }
212228 }
213229 }
214230 }
3939 import org.apache.tools.ant.util.FileNameMapper;
4040 import org.apache.tools.ant.util.FileUtils;
4141 import org.apache.tools.ant.util.IdentityMapper;
42 import org.apache.tools.ant.util.StringUtils;
4243
4344 import com.sun.media.jai.codec.FileSeekableStream;
4445
391392 }
392393
393394 } catch (Exception err) {
394 err.printStackTrace();
395 log(StringUtils.getStackTrace(err), Project.MSG_ERR);
395396 throw new BuildException(err.getMessage());
396397 }
397398 }
7676 protected static final int TASKDEF_TYPE_JJTREE = 2;
7777 protected static final int TASKDEF_TYPE_JJDOC = 3;
7878
79 protected static final String[] ARCHIVE_LOCATIONS =
79 protected static final String[] ARCHIVE_LOCATIONS = //NOSONAR
8080 new String[] {
8181 "JavaCC.zip",
8282 "bin/lib/JavaCC.zip",
8484 "javacc.jar", // used by jpackage for JavaCC 3.x
8585 };
8686
87 protected static final int[] ARCHIVE_LOCATIONS_VS_MAJOR_VERSION =
87 protected static final int[] ARCHIVE_LOCATIONS_VS_MAJOR_VERSION = //NOSONAR
8888 new int[] {
8989 1,
9090 2,
0 /*
1 * Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.apache.tools.ant.taskdefs.optional.javah;
18
19 import java.io.IOException;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.taskdefs.Execute;
24 import org.apache.tools.ant.taskdefs.LogStreamHandler;
25 import org.apache.tools.ant.taskdefs.optional.Javah;
26 import org.apache.tools.ant.types.Commandline;
27 import org.apache.tools.ant.util.JavaEnvUtils;
28
29 /**
30 * This implementation runs the javah executable in a separate process.
31 *
32 * @since Ant 1.9.8
33 */
34 public class ForkingJavah implements JavahAdapter {
35
36 /**
37 * the name of this adapter for users to select
38 */
39 public static final String IMPLEMENTATION_NAME = "forking";
40
41 /**
42 * Performs the actual compilation.
43 * @param javah the calling javah task.
44 * @return true if the compilation was successful.
45 * @throws BuildException if there is an error.
46 */
47 public boolean compile(Javah javah) throws BuildException {
48 Commandline cmd = SunJavah.setupJavahCommand(javah);
49 Project project = javah.getProject();
50 String executable = JavaEnvUtils.getJdkExecutable("javah");
51 javah.log("Running " + executable, Project.MSG_VERBOSE);
52 cmd.setExecutable(executable);
53
54 //set up the args
55 String[] args = cmd.getCommandline();
56
57 try {
58 Execute exe = new Execute(new LogStreamHandler(javah,
59 Project.MSG_INFO,
60 Project.MSG_WARN));
61 exe.setAntRun(project);
62 exe.setWorkingDirectory(project.getBaseDir());
63 exe.setCommandline(args);
64 exe.execute();
65 return !exe.isFailure();
66 } catch (IOException exception) {
67 throw new BuildException("Error running " + executable
68 + " -maybe it is not on the path", exception);
69 }
70 }
71 }
4343 return Kaffeh.IMPLEMENTATION_NAME;
4444 } else if (JavaEnvUtils.isGij()) {
4545 return Gcjh.IMPLEMENTATION_NAME;
46 } else if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
47 return ForkingJavah.IMPLEMENTATION_NAME;
4648 }
4749 return SunJavah.IMPLEMENTATION_NAME;
4850 }
8688 } else if ((JavaEnvUtils.isGij() && choice == null)
8789 || Gcjh.IMPLEMENTATION_NAME.equals(choice)) {
8890 return new Gcjh();
91 } else if ((JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)
92 && choice == null)
93 || ForkingJavah.IMPLEMENTATION_NAME.equals(choice)) {
94 return new ForkingJavah();
8995 } else if (SunJavah.IMPLEMENTATION_NAME.equals(choice)) {
9096 return new SunJavah();
9197 } else if (choice != null) {
6868 return ej.fork(javah) == 0;
6969 }
7070
71 private Commandline setupJavahCommand(Javah javah) {
71 static Commandline setupJavahCommand(Javah javah) {
7272 Commandline cmd = new Commandline();
7373
7474 if (javah.getDestdir() != null) {
458458 PrintWriter pw = null;
459459 if (getOutputFile() != null) {
460460 try {
461 fw = new FileWriter(getOutputFile().getPath());
461 fw = new FileWriter(getOutputFile().getPath()); //NOSONAR
462462 } catch (IOException e) {
463463 String msg = "JDepend Failed when creating the output file: "
464464 + e.getMessage();
552552 }
553553
554554 jdepend.analyze();
555 if (pw.checkError()) {
555 if (pw != null && pw.checkError()) {
556556 throw new IOException("Encountered an error writing JDepend"
557557 + " output");
558558 }
143143 * a rational manner to outfile.
144144 * @throws Exception on error.
145145 */
146 public void link() throws Exception {
146 public void link() throws Exception { //NOSONAR
147147 ZipOutputStream output = new ZipOutputStream(new FileOutputStream(outfile));
148148
149149 if (compression) {
222222 return;
223223 }
224224 ZipFile zipf = new ZipFile(f);
225 Enumeration entries = zipf.entries();
226
227 while (entries.hasMoreElements()) {
228 ZipEntry inputEntry = (ZipEntry) entries.nextElement();
229 //Ignore manifest entries. They're bound to cause conflicts between
230 //files that are being merged. User should supply their own
231 //manifest file when doing the merge.
232 String inputEntryName = inputEntry.getName();
233 int index = inputEntryName.indexOf("META-INF");
234
235 if (index < 0) {
236 //META-INF not found in the name of the entry. Go ahead and process it.
237 try {
238 output.putNextEntry(processEntry(zipf, inputEntry));
239 } catch (ZipException ex) {
240 //If we get here, it could be because we are trying to put a
241 //directory entry that already exists.
242 //For example, we're trying to write "com", but a previous
243 //entry from another mergefile was called "com".
244 //In that case, just ignore the error and go on to the
245 //next entry.
246 String mess = ex.getMessage();
247
248 if (mess.indexOf("duplicate") >= 0) {
249 //It was the duplicate entry.
250 continue;
251 } else {
252 // I hate to admit it, but we don't know what happened
253 // here. Throw the Exception.
254 throw ex;
225 try {
226 Enumeration entries = zipf.entries();
227
228 while (entries.hasMoreElements()) {
229 ZipEntry inputEntry = (ZipEntry) entries.nextElement();
230 //Ignore manifest entries. They're bound to cause conflicts between
231 //files that are being merged. User should supply their own
232 //manifest file when doing the merge.
233 String inputEntryName = inputEntry.getName();
234 int index = inputEntryName.indexOf("META-INF");
235
236 if (index < 0) {
237 //META-INF not found in the name of the entry. Go ahead and process it.
238 try {
239 output.putNextEntry(processEntry(zipf, inputEntry));
240 } catch (ZipException ex) {
241 //If we get here, it could be because we are trying to put a
242 //directory entry that already exists.
243 //For example, we're trying to write "com", but a previous
244 //entry from another mergefile was called "com".
245 //In that case, just ignore the error and go on to the
246 //next entry.
247 String mess = ex.getMessage();
248
249 if (mess.indexOf("duplicate") >= 0) {
250 //It was the duplicate entry.
251 continue;
252 } else {
253 // I hate to admit it, but we don't know what happened
254 // here. Throw the Exception.
255 throw ex;
256 }
255257 }
258
259 InputStream in = zipf.getInputStream(inputEntry);
260 int len = buffer.length;
261 int count = -1;
262
263 while ((count = in.read(buffer, 0, len)) > 0) {
264 output.write(buffer, 0, count);
265 }
266 in.close();
267 output.closeEntry();
256268 }
257
258 InputStream in = zipf.getInputStream(inputEntry);
259 int len = buffer.length;
260 int count = -1;
261
262 while ((count = in.read(buffer, 0, len)) > 0) {
263 output.write(buffer, 0, count);
264 }
265 in.close();
266 output.closeEntry();
267 }
268 }
269 zipf.close();
269 }
270 } finally {
271 zipf.close();
272 }
270273 }
271274
272275
3232 /**
3333 * this is the list of keywords which can not be used as classnames
3434 */
35 public static final String[] keywords = {
35 public static final String[] keywords = { //NOSONAR
3636 "assert",
3737 "abstract", "boolean", "break", "byte",
3838 "case", "catch", "char", "class",
2828
2929 import javax.xml.parsers.DocumentBuilder;
3030 import javax.xml.parsers.DocumentBuilderFactory;
31 import javax.xml.transform.TransformerFactory;
32 import javax.xml.transform.TransformerFactoryConfigurationError;
3133
3234 import org.apache.tools.ant.BuildException;
3335 import org.apache.tools.ant.Project;
4244 import org.apache.tools.ant.types.resources.URLResource;
4345 import org.apache.tools.ant.util.FileUtils;
4446 import org.apache.tools.ant.util.JAXPUtils;
47 import org.apache.tools.ant.util.JavaEnvUtils;
4548 import org.w3c.dom.Document;
4649
4750 /**
97100 private XSLTProcess xsltTask;
98101
99102 /**
103 * The JAXP factory used for the internal XSLT task.
104 */
105 private XSLTProcess.Factory xsltFactory;
106
107 /**
100108 * Instance of a utility class to use for file operations.
101109 *
102110 * @since Ant 1.7
106114 /**
107115 * Used to ensure the uniqueness of a property
108116 */
109 private static int counter = 0;
117 private volatile static int counter = 0;
110118
111119 /** the format to use for the report. Must be <tt>FRAMES</tt> or <tt>NOFRAMES</tt> */
112120 protected String format = FRAMES;
230238 * @since Ant 1.9.5
231239 */
232240 public XSLTProcess.Factory createFactory() {
233 return xsltTask.createFactory();
241 if (xsltFactory == null) {
242 xsltFactory = xsltTask.createFactory();
243 }
244 return xsltFactory;
234245 }
235246
236247 /**
250261 xsltTask.setIn(((XMLResultAggregator) task).getDestinationFile());
251262 File outputFile = null;
252263 if (format.equals(FRAMES)) {
253 String tempFileProperty = getClass().getName() + String.valueOf(counter++);
264 String tempFileProperty = getClass().getName() + String.valueOf(counter++); //NOSONAR
254265 File tmp = FILE_UTILS.resolveFile(project.getBaseDir(), project
255266 .getProperty("java.io.tmpdir"));
256267 tempFileTask.setDestDir(tmp);
265276 paramx.setProject(task.getProject());
266277 paramx.setName("output.dir");
267278 paramx.setExpression(toDir.getAbsolutePath());
279 configureForRedirectExtension();
268280 final long t0 = System.currentTimeMillis();
269281 try {
270282 xsltTask.execute();
342354 return JAXPUtils.getSystemId(file);
343355 }
344356
357 private static final String JDK_INTERNAL_FACTORY = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
358
359 /**
360 * If we end up using the JDK's own TraX factory on Java 9+, then
361 * set the features and attributes necessary to allow redirect
362 * extensions to be used.
363 * @since Ant 1.9.8
364 */
365 protected void configureForRedirectExtension() {
366 XSLTProcess.Factory factory = createFactory();
367 String factoryName = factory.getName();
368 if (factoryName == null) {
369 try {
370 factoryName = TransformerFactory.newInstance().getClass().getName();
371 } catch (TransformerFactoryConfigurationError exc) {
372 throw new BuildException(exc);
373 }
374 }
375 if (JDK_INTERNAL_FACTORY.equals(factoryName)
376 && JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
377 factory.addFeature(new XSLTProcess.Factory.Feature("http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions",
378 true));
379 }
380 }
345381 }
3737 import org.apache.tools.ant.Project;
3838 import org.apache.tools.ant.ProjectComponent;
3939 import org.apache.tools.ant.util.FileUtils;
40 import org.apache.tools.ant.util.StringUtils;
4041
4142 /**
4243 * <p>Collects all failing test <i>cases</i> and creates a new JUnit test class containing
9697 * Location and name of the generated JUnit class.
9798 * Lazy instantiated via getLocationName().
9899 */
99 private static String locationName;
100 private String locationName;
100101
101102 /**
102103 * Returns the (lazy evaluated) location for the collector class.
259260 createClassFooter();
260261
261262 } catch (IOException e) {
262 e.printStackTrace();
263 log(StringUtils.getStackTrace(e));
263264 } finally {
264265 FileUtils.close(writer);
265266 }
2020 import java.io.BufferedReader;
2121 import java.io.BufferedWriter;
2222 import java.io.File;
23 import java.io.FilenameFilter;
2324 import java.io.FileOutputStream;
2425 import java.io.FileReader;
2526 import java.io.FileWriter;
3738 import java.util.Hashtable;
3839 import java.util.Iterator;
3940 import java.util.List;
41 import java.util.Locale;
4042 import java.util.Map;
4143 import java.util.Properties;
4244 import java.util.Vector;
6062 import org.apache.tools.ant.util.FileUtils;
6163 import org.apache.tools.ant.util.LoaderUtils;
6264 import org.apache.tools.ant.util.SplitClassLoader;
65 import org.apache.tools.ant.util.StringUtils;
6366
6467 /**
6568 * Runs JUnit tests.
510513 }
511514
512515 /**
516 * Add a path to the modulepath.
517 *
518 * @return created modulepath.
519 * @since 1.9.8
520 */
521 public Path createModulepath() {
522 return getCommandline().createModulepath(getProject()).createPath();
523 }
524
525 /**
526 * Add a path to the upgrademodulepath.
527 *
528 * @return created upgrademodulepath.
529 * @since 1.9.8
530 */
531 public Path createUpgrademodulepath() {
532 return getCommandline().createUpgrademodulepath(getProject()).createPath();
533 }
534
535 /**
513536 * Adds an environment variable; used when forking.
514537 *
515538 * <p>Will be ignored if we are not forking a new VM.</p>
678701 /**
679702 * Creates a new JUnitRunner and enables fork of a new Java VM.
680703 *
681 * @throws Exception under ??? circumstances
704 * @throws Exception never
682705 * @since Ant 1.2
683706 */
684 public JUnitTask() throws Exception {
707 public JUnitTask() throws Exception { //NOSONAR
685708 }
686709
687710 /**
748771 loader.loadClass("junit.framework.Test"); // sanity check
749772 } catch (final ClassNotFoundException e) {
750773 throw new BuildException(
751 "The <classpath> for <junit> must include junit.jar "
774 "The <classpath> or <modulepath> for <junit> must include junit.jar "
752775 + "if not in Ant's own classpath",
753776 e, task.getLocation());
754777 }
776799 if (splitJUnit) {
777800 final Path path = new Path(getProject());
778801 path.add(antRuntimeClasses);
779 final Path extra = getCommandline().getClasspath();
802 Path extra = getCommandline().getClasspath();
780803 if (extra != null) {
781804 path.add(extra);
805 }
806 extra = getCommandline().getModulepath();
807 if (extra != null && !hasJunit(path)) {
808 path.add(expandModulePath(extra));
782809 }
783810 mirrorLoader = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
784811 public Object run() {
817844 @Override
818845 public void execute() throws BuildException {
819846 checkMethodLists();
820
847 checkModules();
821848 setupJUnitDelegate();
822849
823850 final List<List> testLists = new ArrayList<List>();
12521279 checkForkedPath(cmd);
12531280
12541281 final TestResultHolder result = new TestResultHolder();
1282 boolean success = false;
12551283 try {
12561284 result.exitCode = execute.execute();
1285 success = true;
12571286 } catch (final IOException e) {
12581287 throw new BuildException("Process fork failed.", e, getLocation());
12591288 } finally {
12701299 + " testcase not started or mixing ant versions?";
12711300 }
12721301 } catch (final Exception e) {
1273 e.printStackTrace();
1302 log(StringUtils.getStackTrace(e), Project.MSG_INFO);
12741303 // ignored.
12751304 } finally {
12761305 FileUtils.close(br);
12951324 }
12961325
12971326 if (!FILE_UTILS.tryHardToDelete(propsFile)) {
1298 throw new BuildException("Could not delete temporary "
1299 + "properties file '"
1300 + propsFile.getAbsolutePath() + "'.");
1327 String msg = "Could not delete temporary properties file '"
1328 + propsFile.getAbsolutePath() + "'.";
1329 if (success) {
1330 throw new BuildException(msg); //NOSONAR
1331 } else { // don't hide inner exception
1332 log(msg, Project.MSG_ERR);
1333 }
13011334 }
13021335 }
13031336
16971730 }
16981731
16991732 /**
1733 * Checks a validity of module specific options.
1734 * @since 1.9.8
1735 */
1736 private void checkModules() {
1737 if (hasPath(getCommandline().getModulepath()) ||
1738 hasPath(getCommandline().getUpgrademodulepath())) {
1739 for (int i = 0, count = batchTests.size(); i < count; i++) {
1740 if(!batchTests.elementAt(i).getFork()) {
1741 throw new BuildException("The module path requires fork attribute to be set to true.");
1742 }
1743 }
1744 for (int i = 0, count = tests.size(); i < count; i++) {
1745 if (!tests.elementAt(i).getFork()) {
1746 throw new BuildException("The module path requires fork attribute to be set to true.");
1747 }
1748 }
1749 }
1750 }
1751
1752 /**
1753 * Checks is a junit is on given path.
1754 * @param path the {@link Path} to check
1755 * @return true when given {@link Path} contains junit
1756 * @since 1.9.8
1757 */
1758 private boolean hasJunit(final Path path) {
1759 AntClassLoader loader = null;
1760 try {
1761 loader = AntClassLoader.newAntClassLoader(
1762 null,
1763 getProject(),
1764 path,
1765 true);
1766 try {
1767 loader.loadClass("junit.framework.Test");
1768 return true;
1769 } catch (final Exception ex) {
1770 return false;
1771 }
1772 } finally {
1773 if (loader != null) {
1774 loader.close();
1775 }
1776 }
1777 }
1778
1779 /**
1780 * Expands a module path to flat path of jars and root folders usable by classloader.
1781 * @param modulePath to be expanded
1782 * @return the expanded path
1783 * @since 1.9.8
1784 */
1785 private Path expandModulePath(Path modulePath) {
1786 final Path expanded = new Path(getProject());
1787 for (String path : modulePath.list()) {
1788 final File modulePathEntry = getProject().resolveFile(path);
1789 if (modulePathEntry.isDirectory() && !hasModuleInfo(modulePathEntry)) {
1790 final File[] modules = modulePathEntry.listFiles(new FilenameFilter() {
1791 public boolean accept(File dir, String name) {
1792 return name.toLowerCase(Locale.ENGLISH).endsWith(".jar");
1793 }
1794 });
1795 if (modules != null) {
1796 for (File module : modules) {
1797 expanded.add(new Path(getProject(), String.format(
1798 "%s%s%s", //NOI18N
1799 path,
1800 File.separator,
1801 module.getName())));
1802 }
1803 }
1804 } else {
1805 expanded.add(new Path(getProject(), path));
1806 }
1807 }
1808 return expanded;
1809 }
1810
1811 /**
17001812 * return an enumeration listing each test, then each batchtest
17011813 * @return enumeration
17021814 * @since Ant 1.3
18912003 */
18922004 private void createClassLoader() {
18932005 final Path userClasspath = getCommandline().getClasspath();
1894 if (userClasspath != null) {
2006 final Path userModulepath = getCommandline().getModulepath();
2007 if (userClasspath != null || userModulepath != null) {
18952008 if (reloading || classLoader == null) {
18962009 deleteClassLoader();
1897 final Path classpath = (Path) userClasspath.clone();
2010 final Path path = new Path(getProject());
2011 if (userClasspath != null) {
2012 path.add((Path) userClasspath.clone());
2013 }
2014 if (userModulepath != null && !hasJunit(path)) {
2015 path.add(expandModulePath(userModulepath));
2016 }
18982017 if (includeAntRuntime) {
18992018 log("Implicitly adding " + antRuntimeClasses
19002019 + " to CLASSPATH", Project.MSG_VERBOSE);
1901 classpath.append(antRuntimeClasses);
2020 path.append(antRuntimeClasses);
19022021 }
1903 classLoader = getProject().createClassLoader(classpath);
2022 classLoader = getProject().createClassLoader(path);
19042023 if (getClass().getClassLoader() != null
19052024 && getClass().getClassLoader() != Project.class.getClassLoader()) {
19062025 classLoader.setParent(getClass().getClassLoader());
22792398 w.newLine();
22802399 s.println(text);
22812400 }
2401
2402 /**
2403 * Checks if a path exists and is non empty.
2404 * @param path to be checked
2405 * @return true if the path is non <code>null</code> and non empty.
2406 * @since 1.9.8
2407 */
2408 private static boolean hasPath(final Path path) {
2409 return path != null && path.size() > 0;
2410 }
2411
2412 /**
2413 * Checks if a given folder is an unpacked module.
2414 * @param root the fodler to be checked
2415 * @return true if the root is an unpacked module
2416 * @since 1.9.8
2417 */
2418 private static boolean hasModuleInfo(final File root) {
2419 return new File(root, "module-info.class").exists(); //NOI18N
2420 }
22822421 }
10221022 }
10231023 }
10241024 } catch (final IOException e) {
1025 e.printStackTrace();
1025 e.printStackTrace(); //NOSONAR
10261026 }
10271027 } else {
10281028 final JUnitTest t = new JUnitTest(args[0]);
12391239 final String msg = t.getMessage();
12401240 final AssertionFailedError failure = msg != null
12411241 ? new AssertionFailedError(msg) : new AssertionFailedError();
1242 failure.initCause(t.getCause());
12421243 failure.setStackTrace(t.getStackTrace());
12431244 testListener.addFailure(test, failure);
12441245 } else {
116116 * @throws BuildException if unable to write the output
117117 */
118118 public void endTestSuite(JUnitTest suite) throws BuildException {
119 boolean success = false;
119120 try {
120121 StringBuffer sb = new StringBuffer("Tests run: ");
121122 sb.append(suite.runCount());
157158 throw new BuildException("Unable to write output", ioex);
158159 }
159160 }
161 success = true;
160162 } finally {
161163 if (out != null) {
162164 try {
163165 wri.close();
164166 } catch (IOException ioex) {
165 throw new BuildException("Unable to flush output", ioex);
167 if (success) {
168 throw new BuildException("Unable to flush output", ioex); //NOSONAR
169 }
166170 } finally {
167171 if (out != System.out && out != System.err) {
168172 FileUtils.close(out);
0 /*
1 * Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.apache.tools.ant.taskdefs.optional.native2ascii;
18
19 import java.io.BufferedReader;
20 import java.io.BufferedWriter;
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.FileReader;
25 import java.io.FileWriter;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28 import java.io.OutputStreamWriter;
29 import java.io.Writer;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
33 import org.apache.tools.ant.util.FileUtils;
34 import org.apache.tools.ant.util.Native2AsciiUtils;
35 import org.apache.tools.ant.util.StringUtils;
36
37 /**
38 * Encapsulates the built-in Native2Ascii implementation.
39 *
40 * @since Ant 1.9.8
41 */
42 public class BuiltinNative2Ascii implements Native2AsciiAdapter {
43
44 static final String IMPLEMENTATION_NAME = "builtin";
45
46 public final boolean convert(Native2Ascii args, File srcFile,
47 File destFile) throws BuildException {
48 boolean reverse = args.getReverse();
49 String encoding = args.getEncoding();
50 BufferedReader input = null;
51 try {
52 input = getReader(srcFile, encoding, reverse);
53 try {
54 Writer output = getWriter(destFile, encoding, reverse);
55 try {
56 translate(input, output, reverse);
57 } finally {
58 FileUtils.close(output);
59 }
60 } finally {
61 FileUtils.close(input);
62 }
63 return true;
64 } catch (IOException ex) {
65 throw new BuildException("Exception trying to translate data", ex);
66 }
67 }
68
69 private BufferedReader getReader(File srcFile, String encoding,
70 boolean reverse) throws IOException {
71 if (!reverse && encoding != null) {
72 return new BufferedReader(new InputStreamReader(
73 new FileInputStream(srcFile), encoding));
74 }
75 return new BufferedReader(new FileReader(srcFile));
76 }
77
78 private Writer getWriter(File destFile, String encoding,
79 boolean reverse) throws IOException {
80 if (!reverse) {
81 encoding = "ASCII";
82 }
83 if (encoding != null) {
84 return new BufferedWriter(
85 new OutputStreamWriter(new FileOutputStream(destFile),
86 encoding));
87 }
88 return new BufferedWriter(new FileWriter(destFile));
89 }
90
91 private void translate(BufferedReader input, Writer output,
92 boolean reverse) throws IOException {
93 String line = null;
94 while ((line = input.readLine()) != null) {
95 if (!reverse) {
96 output.write(Native2AsciiUtils.native2ascii(line));
97 } else {
98 output.write(Native2AsciiUtils.ascii2native(line));
99 }
100 output.write(StringUtils.LINE_SEP);
101 }
102 }
103 }
3939 * vendor
4040 */
4141 public static String getDefault() {
42 if (JavaEnvUtils.isKaffe() || JavaEnvUtils.isClasspathBased()) {
42 if (shouldUseKaffee()) {
4343 return KaffeNative2Ascii.IMPLEMENTATION_NAME;
4444 }
45 return SunNative2Ascii.IMPLEMENTATION_NAME;
45 if (shouldUseSun()) {
46 return SunNative2Ascii.IMPLEMENTATION_NAME;
47 }
48 return BuiltinNative2Ascii.IMPLEMENTATION_NAME;
4649 }
4750
4851 /**
7881 ProjectComponent log,
7982 Path classpath)
8083 throws BuildException {
81 if (((JavaEnvUtils.isKaffe() || JavaEnvUtils.isClasspathBased()) && choice == null)
84 if ((shouldUseKaffee() && choice == null)
8285 || KaffeNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
8386 return new KaffeNative2Ascii();
84 } else if (SunNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
87 } else if ((shouldUseSun() && choice == null)
88 || SunNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
8589 return new SunNative2Ascii();
90 } else if (BuiltinNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
91 return new BuiltinNative2Ascii();
8692 } else if (choice != null) {
8793 return resolveClassName(choice,
8894 // Memory leak in line below
9096 .createClassLoader(classpath));
9197 }
9298
93 // This default has been good enough until Ant 1.6.3, so stick
94 // with it
95 return new SunNative2Ascii();
99 return new BuiltinNative2Ascii();
96100 }
97101
98102 /**
112116 Native2AsciiAdapterFactory.class.getClassLoader(),
113117 Native2AsciiAdapter.class);
114118 }
119
120 private static final boolean shouldUseKaffee() {
121 return JavaEnvUtils.isKaffe() || JavaEnvUtils.isClasspathBased();
122 }
123
124 private static final boolean shouldUseSun() {
125 return JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)
126 || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)
127 || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_7)
128 || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8);
129 }
115130 }
143143 private String initialSiteCommand = null;
144144 private boolean enableRemoteVerification = true;
145145
146 protected static final String[] ACTION_STRS = {
146 protected static final String[] ACTION_STRS = { //NOSONAR
147147 "sending",
148148 "getting",
149149 "deleting",
154154 "site"
155155 };
156156
157 protected static final String[] COMPLETED_ACTION_STRS = {
157 protected static final String[] COMPLETED_ACTION_STRS = { //NOSONAR
158158 "sent",
159159 "retrieved",
160160 "deleted",
165165 "site command executed"
166166 };
167167
168 protected static final String[] ACTION_TARGET_STRS = {
168 protected static final String[] ACTION_TARGET_STRS = { //NOSONAR
169169 "files",
170170 "files",
171171 "files",
746746 try {
747747 ftp.changeWorkingDirectory(directory);
748748 } catch (IOException ioe) {
749 throw new BuildException(ioe, getLocation());
749 throw new BuildException(ioe, getLocation()); //NOSONAR
750750 }
751751 }
752752 getProject().log("remote system is case sensitive : " + remoteSystemCaseSensitive,
11541154 Project.MSG_ERR);
11551155 } finally {
11561156 if (!comeback) {
1157 throw new BuildException("could not cd back to " + dir
1157 throw new BuildException("could not cd back to " + dir //NOSONAR
11581158 + " while checking a symlink");
11591159 }
11601160 }
107107 private ClassLoader mirrorLoader;
108108 private FTPTaskMirror delegate = null;
109109
110 public static final String[] ACTION_STRS = {
110 public static final String[] ACTION_STRS = { //NOSONAR
111111 "sending",
112112 "getting",
113113 "deleting",
118118 "site"
119119 };
120120
121 public static final String[] COMPLETED_ACTION_STRS = {
121 public static final String[] COMPLETED_ACTION_STRS = { //NOSONAR
122122 "sent",
123123 "retrieved",
124124 "deleted",
129129 "site command executed"
130130 };
131131
132 public static final String[] ACTION_TARGET_STRS = {
132 public static final String[] ACTION_TARGET_STRS = { //NOSONAR
133133 "files",
134134 "files",
135135 "files",
647647 try {
648648 ftp.changeWorkingDirectory(directory);
649649 } catch (IOException ioe) {
650 throw new BuildException(ioe, task.getLocation());
650 throw new BuildException(ioe, task.getLocation()); //NOSONAR
651651 }
652652 }
653653 task.log("remote system is case sensitive : "
10601060 Project.MSG_ERR);
10611061 } finally {
10621062 if (!comeback) {
1063 throw new BuildException("could not cd back to " + dir
1063 throw new BuildException("could not cd back to " + dir //NOSONAR
10641064 + " while checking a symlink");
10651065 }
10661066 }
353353
354354 /** Create the telnet client object */
355355 AntRExecClient rexec = null;
356 boolean success = false;
356357 try {
357358 rexec = new AntRExecClient();
358359 try {
360361 } catch (IOException e) {
361362 throw new BuildException("Can't connect to " + server);
362363 }
363 if (userid != null && password != null && command != null
364 if (userid != null && password != null && command != null //NOSONAR
364365 && rexecTasks.size() == 0) {
365366 // simple one-shot execution
366367 rexec.rexec(userid, password, command);
371372
372373 /** Keep reading input stream until end of it or time-out */
373374 rexec.waitForEOF(defaultTimeout);
375 success = true;
374376 } catch (IOException e) {
375377 throw new BuildException("Error r-executing command", e);
376378 } finally {
378380 try {
379381 rexec.disconnect();
380382 } catch (IOException e) {
381 throw new BuildException("Error disconnecting from "
382 + server);
383 String msg = "Error disconnecting from " + server;
384 if (success) {
385 throw new BuildException(msg); //NOSONAR
386 } else { // don't hide inner exception
387 log(msg, Project.MSG_ERR);
388 }
383389 }
384390 }
385391 }
9797
9898 /** Create the telnet client object */
9999 AntTelnetClient telnet = null;
100 boolean success = false;
100101 try {
101102 telnet = new AntTelnetClient();
102103 try {
105106 throw new BuildException("Can't connect to " + server);
106107 }
107108 /** Login if userid and password were specified */
108 if (userid != null && password != null) {
109 if (userid != null && password != null) { //NOSONAR
109110 login(telnet);
110111 }
111112 /** Process each sub command */
117118 }
118119 task.execute(telnet);
119120 }
121 success = true;
120122 } finally {
121123 if (telnet != null && telnet.isConnected()) {
122124 try {
123125 telnet.disconnect();
124126 } catch (IOException e) {
125 throw new BuildException("Error disconnecting from "
126 + server);
127 String msg = "Error disconnecting from " + server;
128 if (success) {
129 throw new BuildException(msg); //NOSONAR
130 } else { // don't hide inner exception
131 log(msg, Project.MSG_ERR);
132 }
127133 }
128134 }
129135 }
4040
4141 private String sosCmdDir = null;
4242 private String sosUsername = null;
43 private String sosPassword = "";
43 private String sosPassword = null;
4444 private String projectPath = null;
4545 private String vssServerPath = null;
4646 private String sosServerPath = null;
268268 * @return empty string if it wasn't set.
269269 */
270270 protected String getPassword() {
271 return sosPassword;
271 return sosPassword == null ? "" : sosPassword;
272272 }
273273
274274 /**
5252 /** The username option */
5353 String FLAG_USERNAME = "-name";
5454 /** The password option */
55 String FLAG_PASSWORD = "-password";
55 String FLAG_PASSWORD = "-password"; //NOSONAR
5656 /** The log option */
5757 String FLAG_COMMENT = "-log";
5858 /** The workdir option */
108108 project.log("Audio format is not yet supported: "
109109 + uafe.getMessage());
110110 } catch (IOException ioe) {
111 ioe.printStackTrace();
111 ioe.printStackTrace(); //NOSONAR
112112 }
113113
114114 if (audioInputStream != null) {
116116 DataLine.Info info = new DataLine.Info(Clip.class, format,
117117 AudioSystem.NOT_SPECIFIED);
118118 try {
119 audioClip = (Clip) AudioSystem.getLine(info);
120 audioClip.addLineListener(this);
121 audioClip.open(audioInputStream);
122 } catch (LineUnavailableException e) {
123 project.log("The sound device is currently unavailable");
124 return;
125 } catch (IOException e) {
126 e.printStackTrace();
119 try {
120 audioClip = (Clip) AudioSystem.getLine(info);
121 audioClip.addLineListener(this);
122 audioClip.open(audioInputStream);
123 } catch (LineUnavailableException e) {
124 project.log("The sound device is currently unavailable");
125 return;
126 } catch (IOException e) {
127 e.printStackTrace(); //NOSONAR
128 }
129
130 if (duration != null) {
131 playClip(audioClip, duration.longValue());
132 } else {
133 playClip(audioClip, loops);
134 }
135 if (audioClip != null) {
136 audioClip.drain();
137 }
138 } finally {
139 if (audioClip != null) {
140 audioClip.close();
141 }
127142 }
128
129 if (duration != null) {
130 playClip(audioClip, duration.longValue());
131 } else {
132 playClip(audioClip, loops);
133 }
134 audioClip.drain();
135 audioClip.close();
136143 } else {
137144 project.log("Can't get data from file " + file.getName());
138145 }
5252 private String progressRegExp = null;
5353 private String displayText = null;
5454
55 // class instance so we'll never show two splash screens at the same time
5556 private static SplashScreen splash = null;
5657
5758 /**
162163 splash.setVisible(false);
163164 getProject().removeBuildListener(splash);
164165 splash.dispose();
165 splash = null;
166 splash = null; //NOSONAR
166167 }
167168
168169 log("Creating new SplashScreen", Project.MSG_VERBOSE);
247248
248249 try {
249250 ImageIcon img = new ImageIcon(bout.toByteArray());
250 splash = new SplashScreen(img, progressRegExp, displayText);
251 splash = new SplashScreen(img, progressRegExp, displayText); //NOSONAR
251252 success = true;
252253 } catch (Throwable e) {
253254 logHeadless(e);
261262 // swallow if there was an error before so that
262263 // original error will be passed up
263264 if (success) {
264 throw new BuildException(ioe);
265 throw new BuildException(ioe); //NOSONAR
265266 }
266267 }
267268 }
268269 } else {
269270 try {
270 splash = new SplashScreen("Image Unavailable.", progressRegExp,
271 splash = new SplashScreen("Image Unavailable.", progressRegExp, //NOSONAR
271272 displayText);
272273 success = true;
273274 } catch (Throwable e) {
3939
4040 private final Session session;
4141 private final boolean verbose;
42 private final boolean compressed;
4243 private LogListener listener = new LogListener() {
4344 public void log(final String message) {
4445 // do nothing;
6061 * @since Ant 1.6.2
6162 */
6263 public AbstractSshMessage(final boolean verbose, final Session session) {
64 this(verbose, false, session);
65 }
66
67 /**
68 * Constructor for AbstractSshMessage
69 * @param verbose if true do verbose logging
70 * @param compression if true use compression
71 * @param session the ssh session to use
72 * @since Ant 1.9.8
73 */
74 public AbstractSshMessage(boolean verbose, boolean compressed, Session session) {
6375 this.verbose = verbose;
76 this.compressed = compressed;
6477 this.session = session;
6578 }
6679
188201 */
189202 protected final boolean getVerbose() {
190203 return verbose;
204 }
205
206 /**
207 * Is the compressed attribute set.
208 * @return true if the compressed attribute is set
209 * @since Ant 1.9.8
210 */
211 protected final boolean getCompressed() {
212 return compressed;
191213 }
192214
193215 /**
5353 private String fromUri;
5454 private String toUri;
5555 private boolean preserveLastModified = false;
56 private boolean compressed = false;
5657 private List<ResourceCollection> rcs = null;
5758 private boolean isFromRemote, isToRemote;
5859 private boolean isSftp = false;
109110 setFromUri(aFromUri);
110111 this.isFromRemote = true;
111112 }
113
114 /**
115 * Sets flag to determine if compression should
116 * be used for the copy.
117 * @since Ant 1.9.8
118 */
119 public void setCompressed(boolean compressed) {
120 this.compressed = compressed;
121 }
112122
113123 /**
114124 * Similar to {@link #setTodir setTodir} but explicitly states
256266 } else {
257267 upload(fromUri, toUri);
258268 }
259 } else if (isFromRemote && isToRemote) {
269 } else if (isFromRemote && isToRemote) { //NOSONAR
260270 throw new BuildException(
261271 "Copying from a remote server to a remote server is not supported.");
262272 } else {
294304 new ScpFromMessage(getVerbose(), session, file,
295305 getProject().resolveFile(toPath),
296306 fromSshUri.endsWith("*"),
297 preserveLastModified);
307 preserveLastModified,
308 compressed);
298309 } else {
299310 message =
300311 new ScpFromMessageBySftp(getVerbose(), session, file,
338349 session = openSession();
339350 ScpToMessage message = null;
340351 if (!isSftp) {
341 message = new ScpToMessage(getVerbose(), session,
352 message = new ScpToMessage(getVerbose(), compressed, session,
342353 list, file, preserveLastModified);
343354 } else {
344355 message = new ScpToMessageBySftp(getVerbose(), session,
370381 ScpToMessage message = null;
371382 if (!isSftp) {
372383 message =
373 new ScpToMessage(getVerbose(), session,
384 new ScpToMessage(getVerbose(), compressed, session,
374385 getProject().resolveFile(fromPath), file,
375386 preserveLastModified);
376387 } else {
114114 final File aLocalFile,
115115 final boolean recursive,
116116 final boolean preserveLastModified) {
117 super(verbose, session);
117 this(verbose, session, aRemoteFile, aLocalFile, recursive, preserveLastModified, false);
118 }
119
120 /**
121 * Constructor for ScpFromMessage.
122 * @param verbose if true log extra information
123 * @param session the Scp session to use
124 * @param aRemoteFile the remote file name
125 * @param aLocalFile the local file
126 * @param recursive if true use recursion (-r option to scp)
127 * @param preserveLastModified whether to preserve file
128 * @param compressed if true use compression (-C option to scp)
129 * modification times
130 * @since Ant 1.9.8
131 */
132 public ScpFromMessage(boolean verbose,
133 Session session,
134 String aRemoteFile,
135 File aLocalFile,
136 boolean recursive,
137 boolean preserveLastModified,
138 boolean compressed) {
139 super(verbose, compressed, session);
118140 this.remoteFile = aRemoteFile;
119141 this.localFile = aLocalFile;
120142 this.isRecursive = recursive;
130152 String command = "scp -f ";
131153 if (isRecursive) {
132154 command += "-r ";
155 }
156 if (getCompressed()) {
157 command += "-C ";
133158 }
134159 command += remoteFile;
135160 final Channel channel = openExecChannel(command);
6060 * @since Ant 1.7
6161 */
6262 public ScpToMessage(final boolean verbose, final Session session) {
63 super(verbose, session);
63 this(verbose, false, session);
64 }
65
66 /**
67 * Constructor for ScpToMessage
68 * @param verbose if true do verbose logging
69 * @param compressed if true use compression
70 * @param session the ssh session to use
71 * @since Ant 1.9.8
72 */
73 public ScpToMessage(final boolean verbose, boolean compressed, final Session session) {
74 super(verbose, compressed, session);
6475 }
6576
6677 /**
7788 final File aLocalFile,
7889 final String aRemotePath,
7990 final boolean preserveLastModified) {
80 this(verbose, session, aRemotePath);
91 this(verbose, false, session, aLocalFile, aRemotePath, preserveLastModified);
92 }
93
94 /**
95 * Constructor for a local file to remote.
96 * @param verbose if true do verbose logging
97 * @param compressed if true use compression
98 * @param session the scp session to use
99 * @param aLocalFile the local file
100 * @param aRemotePath the remote path
101 * @param preserveLastModified whether to preserve the last modified timestamps
102 * @since Ant 1.9.8
103 */
104 public ScpToMessage(final boolean verbose,
105 final boolean compressed,
106 final Session session,
107 final File aLocalFile,
108 final String aRemotePath,
109 final boolean preserveLastModified) {
110 this(verbose, compressed, session, aRemotePath);
81111 this.localFile = aLocalFile;
82112 this.preserveLastModified = preserveLastModified;
83113 }
96126 final List aDirectoryList,
97127 final String aRemotePath,
98128 final boolean preserveLastModified) {
99 this(verbose, session, aRemotePath);
129 this(verbose, false, session, aDirectoryList, aRemotePath, preserveLastModified);
130 }
131
132 /**
133 * Constructor for a local directories to remote.
134 * @param verbose if true do verbose logging
135 * @param compressed whether to use compression
136 * @param session the scp session to use
137 * @param aDirectoryList a list of directories
138 * @param aRemotePath the remote path
139 * @param preserveLastModified whether to preserve the last modified timestamps
140 * @since Ant 1.9.8
141 */
142 public ScpToMessage(final boolean verbose,
143 final boolean compressed,
144 final Session session,
145 final List aDirectoryList,
146 final String aRemotePath,
147 final boolean preserveLastModified) {
148 this(verbose, compressed, session, aRemotePath);
100149 this.directoryList = aDirectoryList;
101150 this.preserveLastModified = preserveLastModified;
102151 }
141190 private ScpToMessage(final boolean verbose,
142191 final Session session,
143192 final String aRemotePath) {
144 super(verbose, session);
193 this(verbose, false, session, aRemotePath);
194 }
195
196 /**
197 * Constructor for ScpToMessage.
198 * @param verbose if true do verbose logging
199 * @param compressed if true use compression
200 * @param session the scp session to use
201 * @param aRemotePath the remote path
202 * @since Ant 1.9.8
203 */
204 private ScpToMessage(final boolean verbose,
205 final boolean compressed,
206 final Session session,
207 final String aRemotePath) {
208 super(verbose, compressed, session);
145209 this.remotePath = aRemotePath;
146210 }
147211
186250 }
187251
188252 private void doSingleTransfer() throws IOException, JSchException {
189 final String cmd = "scp -t " + (getPreserveLastModified() ? "-p " : "") + remotePath;
253 StringBuilder sb = new StringBuilder("scp -t ");
254 if (getPreserveLastModified()) {
255 sb.append("-p ");
256 }
257 if (getCompressed()) {
258 sb.append("-C ");
259 }
260 sb.append(remotePath);
261 final String cmd = sb.toString();
190262 final Channel channel = openExecChannel(cmd);
191263 try {
192264
205277 }
206278
207279 private void doMultipleTransfer() throws IOException, JSchException {
208 final Channel channel =
209 openExecChannel("scp -r -d -t "
210 + (getPreserveLastModified() ? "-p " : "")
211 + remotePath);
280 StringBuilder sb = new StringBuilder("scp -r -d -t ");
281 if (getPreserveLastModified()) {
282 sb.append("-p ");
283 }
284 if (getCompressed()) {
285 sb.append("-C ");
286 }
287 sb.append(remotePath);
288 final Channel channel = openExecChannel(sb.toString());
212289 try {
213290 final OutputStream out = channel.getOutputStream();
214291 final InputStream in = channel.getInputStream();
377377 *
378378 * @param path A string containing the path of the symlink to delete.
379379 *
380 * @throws FileNotFoundException When the path results in a
381 * <code>File</code> that doesn't exist.
382380 * @throws IOException If calls to <code>File.rename</code>
383381 * or <code>File.delete</code> fail.
384382 * @deprecated use
387385 */
388386 @Deprecated
389387 public static void deleteSymlink(String path)
390 throws IOException, FileNotFoundException {
388 throws IOException {
391389 SYMLINK_UTILS.deleteSymbolicLink(new File(path), null);
392390 }
393391
486486 //make sure m_LocalDir exists, create it if it doesn't
487487 File dir = getProject().resolveFile(localPath);
488488 if (!dir.exists()) {
489 boolean done = dir.mkdirs();
489 boolean done = dir.mkdirs() || dir.exists();
490490 if (!done) {
491491 String msg = "Directory " + localPath + " creation was not "
492492 + "successful for an unknown reason";
2323 import java.util.Random;
2424 import java.util.Vector;
2525
26 import org.apache.tools.ant.BuildException;
2627 import org.apache.tools.ant.Project;
2728 import org.apache.tools.ant.taskdefs.Rmic;
2829 import org.apache.tools.ant.types.Commandline;
2930 import org.apache.tools.ant.types.Path;
3031 import org.apache.tools.ant.util.FileNameMapper;
32 import org.apache.tools.ant.util.JavaEnvUtils;
3133 import org.apache.tools.ant.util.StringUtils;
3234
3335 /**
246248 String[] compilerArgs = attributes.getCurrentCompilerArgs();
247249 compilerArgs = preprocessCompilerArgs(compilerArgs);
248250 cmd.addArguments(compilerArgs);
251
252 verifyArguments(cmd);
249253
250254 logAndAddFilesToCompile(cmd);
251255 return cmd;
346350 }
347351
348352 attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE);
353 }
354
355 private void verifyArguments(Commandline cmd) {
356 if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
357 for (String arg : cmd.getArguments()) {
358 if ("-Xnew".equals(arg)) {
359 throw new BuildException("JDK9 has removed support for -Xnew");
360 }
361 }
362 }
349363 }
350364
351365 /**
6666 }
6767
6868 cmd.setExecutable(c.getName());
69 if (!c.getName().equals(RMIC_CLASSNAMES[RMIC_CLASSNAMES.length - 1])) {
69 if (!c.getName().equals(RMIC_CLASSNAMES[RMIC_CLASSNAMES.length - 1])) { //NOSONAR
7070 // only supported since Kaffe 1.1.2
7171 cmd.createArgument().setValue("-verbose");
7272 getRmic().log(Commandline.describeCommand(cmd));
2121 import org.apache.tools.ant.Task;
2222 import org.apache.tools.ant.types.Path;
2323 import org.apache.tools.ant.util.ClasspathUtils;
24 import org.apache.tools.ant.util.JavaEnvUtils;
2425
2526 /**
2627 * Creates the necessary rmic adapter, given basic criteria.
9495 throws BuildException {
9596 //handle default specially by choosing the sun or kaffe compiler
9697 if (DEFAULT_COMPILER.equalsIgnoreCase(rmicType) || rmicType.length() == 0) {
97 rmicType = KaffeRmic.isAvailable()
98 ? KaffeRmic.COMPILER_NAME
99 : SunRmic.COMPILER_NAME;
98 if (KaffeRmic.isAvailable()) {
99 rmicType = KaffeRmic.COMPILER_NAME;
100 } else if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
101 rmicType = ForkingSunRmic.COMPILER_NAME;
102 } else {
103 rmicType = SunRmic.COMPILER_NAME;
104 }
100105 }
101106 if (SunRmic.COMPILER_NAME.equalsIgnoreCase(rmicType)) {
102107 return new SunRmic();
2626 import org.apache.tools.ant.Project;
2727 import org.apache.tools.ant.taskdefs.LogOutputStream;
2828 import org.apache.tools.ant.types.Commandline;
29 import org.apache.tools.ant.util.JavaEnvUtils;
2930
3031 /**
3132 * The implementation of the rmic for SUN's JDK.
5354 + "available. A common solution is to "
5455 + "set the environment variable "
5556 + "JAVA_HOME";
57 public static final String ERROR_NO_RMIC_ON_CLASSPATH_JAVA_9 = "Cannot use SUN rmic, as it is not "
58 + "available. The class we try to use is part of the jdk.rmic module which may not be. "
59 + "Please use the 'forking' compiler for JDK 9+";
5660 /** Error message to use when there is an error starting the sun rmic compiler */
5761 public static final String ERROR_RMIC_FAILED = "Error starting SUN rmic: ";
5862
7074 LogOutputStream logstr = new LogOutputStream(getRmic(),
7175 Project.MSG_WARN);
7276
77 boolean success = false;
7378 try {
7479 Class c = Class.forName(RMIC_CLASSNAME);
7580 Constructor cons
8186 Boolean ok =
8287 (Boolean) doRmic.invoke(rmic,
8388 (new Object[] {cmd.getArguments()}));
89 success = true;
8490 return ok.booleanValue();
8591 } catch (ClassNotFoundException ex) {
92 if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
93 throw new BuildException(ERROR_NO_RMIC_ON_CLASSPATH_JAVA_9,
94 getRmic().getLocation());
95 }
8696 throw new BuildException(ERROR_NO_RMIC_ON_CLASSPATH,
8797 getRmic().getLocation());
8898 } catch (Exception ex) {
96106 try {
97107 logstr.close();
98108 } catch (IOException e) {
99 throw new BuildException(e);
109 // swallow if there was an error before so that
110 // original error will be passed up
111 if (success) {
112 throw new BuildException(e); //NOSONAR
113 }
100114 }
101115 }
102116 }
6666 private List<FileSelector> selectors = new ArrayList<FileSelector>();
6767
6868 private File dir;
69 private boolean fileAttributeUsed;
6970 private boolean useDefaultExcludes = true;
7071 private boolean caseSensitive = true;
7172 private boolean followSymlinks = true;
130131 if (isReference()) {
131132 throw tooManyAttributes();
132133 }
134 if (fileAttributeUsed && !getDir().equals(dir)) {
135 throw dirAndFileAreMutuallyExclusive();
136 }
133137 this.dir = dir;
134138 directoryScanner = null;
135139 }
227231 if (isReference()) {
228232 throw tooManyAttributes();
229233 }
234 if (getDir() != null) {
235 throw dirAndFileAreMutuallyExclusive();
236 }
230237 setDir(file.getParentFile());
238 fileAttributeUsed = true;
231239 createInclude().setName(file.getName());
232240 }
233241
918926 setChecked(true);
919927 }
920928 }
929
930 private BuildException dirAndFileAreMutuallyExclusive() {
931 return new BuildException("you can only specify one of the dir and file attributes");
932 }
921933 }
2626 * An AntFilterReader is a wrapper class that encloses the classname
2727 * and configuration of a Configurable FilterReader.
2828 */
29 public final class AntFilterReader
30 extends DataType implements Cloneable {
29 public final class AntFilterReader extends DataType {
3130
3231 private String className;
3332
519519 }
520520 //module path
521521 if (haveModulepath()) {
522 listIterator.add("-modulepath");
522 listIterator.add("--module-path");
523523 listIterator.add(
524524 modulepath.concatSystemClasspath("ignore").toString());
525525 }
526526 //upgrade module path
527527 if (haveUpgrademodulepath()) {
528 listIterator.add("-upgrademodulepath");
528 listIterator.add("--upgrade-module-path");
529529 listIterator.add(
530530 upgrademodulepath.concatSystemClasspath("ignore").toString());
531531 }
4444 * FilterChain may contain a chained set of filter readers.
4545 *
4646 */
47 public class FilterChain extends DataType
48 implements Cloneable {
47 public class FilterChain extends DataType {
4948
5049 private Vector<Object> filterReaders = new Vector<Object>();
5150
2929 * Element to define a FileNameMapper.
3030 *
3131 */
32 public class Mapper extends DataType implements Cloneable {
32 public class Mapper extends DataType {
3333 // CheckStyle:VisibilityModifier OFF - bc
3434
3535 protected MapperType type = null;
6666 // CheckStyle:VisibilityModifier OFF - bc
6767
6868 /** The system classpath as a Path object */
69 public static Path systemClasspath =
69 public static final Path systemClasspath =
7070 new Path(null, System.getProperty("java.class.path"));
7171
7272
7575 *
7676 * @since Ant 1.6.2
7777 */
78 public static Path systemBootClasspath =
78 public static final Path systemBootClasspath =
7979 new Path(null, System.getProperty("sun.boot.class.path"));
8080
8181 // CheckStyle:VisibilityModifier OFF - bc
301301 * @param perm The permission to check against.
302302 */
303303 boolean matches(final java.security.Permission perm) {
304 if (!className.equals(perm.getClass().getName())) {
304 if (!className.equals(perm.getClass().getName())) { //NOSONAR
305305 return false;
306306 }
307307 if (name != null) {
118118 *
119119 */
120120 public class XMLCatalog extends DataType
121 implements Cloneable, EntityResolver, URIResolver {
121 implements EntityResolver, URIResolver {
122122
123123 /** helper for some File.toURL connversions */
124124 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
215215 if (isReference()) {
216216 return getCheckedRef().equals(another);
217217 }
218 if (another == null || !(another.getClass().equals(getClass()))) {
218 if (another == null || another.getClass() != getClass()) {
219219 return false;
220220 }
221221 ArchiveResource r = (ArchiveResource) another;
9494 */
9595 @Override
9696 public boolean equals(Object other) {
97 if (other == null || !other.getClass().equals(getClass())) {
97 if (other == null || other.getClass() != getClass()) {
9898 return false;
9999 }
100100 MappedResource m = (MappedResource) other;
7373 * Get the name of the resource.
7474 * @return the name of the wrapped resource.
7575 */
76 @Override
7677 public String getName() {
7778 return getResource().getName();
7879 }
8182 * The exists attribute tells whether a file exists.
8283 * @return true if this resource exists.
8384 */
85 @Override
8486 public boolean isExists() {
8587 return getResource().isExists();
8688 }
9193 * @return 0 if the resource does not exist to mirror the behavior
9294 * of {@link java.io.File File}.
9395 */
96 @Override
9497 public long getLastModified() {
9598 return getResource().getLastModified();
9699 }
99102 * Tells if the resource is a directory.
100103 * @return boolean flag indicating if the resource is a directory.
101104 */
105 @Override
102106 public boolean isDirectory() {
103107 return getResource().isDirectory();
104108 }
108112 * @return the size, as a long, 0 if the Resource does not exist (for
109113 * compatibility with java.io.File), or UNKNOWN_SIZE if not known.
110114 */
115 @Override
111116 public long getSize() {
112117 return getResource().getSize();
113118 }
120125 * @throws UnsupportedOperationException if InputStreams are not
121126 * supported for this Resource type.
122127 */
128 @Override
123129 public InputStream getInputStream() throws IOException {
124130 return getResource().getInputStream();
125131 }
132138 * @throws UnsupportedOperationException if OutputStreams are not
133139 * supported for this Resource type.
134140 */
141 @Override
135142 public OutputStream getOutputStream() throws IOException {
136143 return getResource().getOutputStream();
137144 }
140147 * Fulfill the ResourceCollection contract.
141148 * @return whether this Resource is a FileProvider.
142149 */
150 @Override
143151 public boolean isFilesystemOnly() {
144152 return as(FileProvider.class) != null;
145153 }
148156 * Overrides the base version.
149157 * @param r the Reference to set.
150158 */
159 @Override
151160 public void setRefid(Reference r) {
152161 if (resource != null) {
153162 throw noChildrenAllowed();
158167 /**
159168 * {@inheritDoc}
160169 */
170 @Override
161171 public <T> T as(Class<T> clazz) {
162172 return getResource().as(clazz);
163173 }
165175 /**
166176 * {@inheritDoc}
167177 */
178 @Override
168179 public int compareTo(Resource other) {
169180 if (other == this) {
170181 return 0;
180191 * Get the hash code for this Resource.
181192 * @return hash code as int.
182193 */
183 public int hashCode() {
194 @Override
195 public int hashCode() { // NOSONAR
196 // super.equals + compareTo are consistent with this implementation
184197 return (getClass().hashCode() << 4) | getResource().hashCode();
185198 }
186199
266279 throw new BuildException("you can't change the size of a "
267280 + getDataTypeName());
268281 }
282
269283 }
194194 crh.setPrimaryReader(input);
195195 crh.setFilterChains(filterChains);
196196 crh.setProject(getProject());
197 Union streamResources = new Union();
197198 BufferedReader reader = new BufferedReader(crh.getAssembledReader());
198
199 Union streamResources = new Union();
200 streamResources.setCache(true);
201
202 String line = null;
203 while ((line = reader.readLine()) != null) {
204 streamResources.add(parse(line));
199 try {
200 streamResources.setCache(true);
201
202 String line = null;
203 while ((line = reader.readLine()) != null) {
204 streamResources.add(parse(line));
205 }
206 } finally {
207 reader.close();
205208 }
206209
207210 return streamResources;
7070 * Enforce String immutability.
7171 * @param s the new name/value for this StringResource.
7272 */
73 @Override
7374 public synchronized void setName(String s) {
7475 if (getName() != null) {
7576 throw new BuildException(new ImmutableResourceException());
8990 * Synchronize access.
9091 * @return the name/value of this StringResource.
9192 */
93 @Override
9294 public synchronized String getName() {
9395 return super.getName();
9496 }
106108 *
107109 * @return true if this resource exists.
108110 */
111 @Override
109112 public boolean isExists() {
110113 return getValue() != null;
111114 }
143146 * @return the size, as a long, 0 if the Resource does not exist (for
144147 * compatibility with java.io.File), or UNKNOWN_SIZE if not known.
145148 */
149 @Override
146150 public synchronized long getSize() {
147151 return isReference() ? ((Resource) getCheckedRef()).getSize()
148152 : getContent().length();
152156 * Get the hash code for this Resource.
153157 * @return hash code as int.
154158 */
155 public synchronized int hashCode() {
159 @Override
160 public synchronized int hashCode() { //NOSONAR
161 // super.equals + super.compareTo are consistent with this implementation
156162 if (isReference()) {
157163 return getCheckedRef().hashCode();
158164 }
165171 * @return the string contents of the resource.
166172 * @since Ant 1.7
167173 */
174 @Override
168175 public String toString() {
169176 return String.valueOf(getContent());
170177 }
177184 * @throws UnsupportedOperationException if InputStreams are not
178185 * supported for this Resource type.
179186 */
187 @Override
180188 public synchronized InputStream getInputStream() throws IOException {
181189 if (isReference()) {
182190 return ((Resource) getCheckedRef()).getInputStream();
197205 * @throws UnsupportedOperationException if OutputStreams are not
198206 * supported for this Resource type.
199207 */
208 @Override
200209 public synchronized OutputStream getOutputStream() throws IOException {
201210 if (isReference()) {
202211 return ((Resource) getCheckedRef()).getOutputStream();
211220 * Overrides the super version.
212221 * @param r the Reference to set.
213222 */
223 @Override
214224 public void setRefid(Reference r) {
215225 if (encoding != DEFAULT_ENCODING) {
216226 throw tooManyAttributes();
249259 baos = (ByteArrayOutputStream) out;
250260 }
251261
262 @Override
252263 public void close() throws IOException {
253264 super.close();
254265 String result = encoding == null
5959 ConcatResourceInputStream cat = new ConcatResourceInputStream(rc);
6060 cat.setManagingComponent(this);
6161
62 InputStreamReader rdr = null;
6263 try {
63 InputStreamReader rdr = null;
6464 if (encoding == null) {
6565 rdr = new InputStreamReader(cat);
6666 } else {
8080 } catch (IOException e) {
8181 throw new BuildException("Error reading tokens", e);
8282 } finally {
83 FileUtils.close(rdr);
8384 FileUtils.close(cat);
8485 }
8586 }
312312 if (isReference()) {
313313 return getCheckedRef().equals(another);
314314 }
315 if (another == null || !(another.getClass().equals(getClass()))) {
315 if (another == null || another.getClass() != getClass()) {
316316 return false;
317317 }
318318 URLResource otheru = (URLResource) another;
136136 throw new BuildException(MILLIS_OR_DATETIME);
137137 }
138138 if (millis == null) {
139 DateFormat df = ((pattern == null)
140 ? DateFormat.getDateTimeInstance(
141 DateFormat.SHORT, DateFormat.SHORT, Locale.US)
142 : new SimpleDateFormat(pattern));
139 String p = pattern == null ? "MM/dd/yyyy hh:mm a" : pattern;
140 DateFormat df = pattern == null
141 ? new SimpleDateFormat(p, Locale.US)
142 : new SimpleDateFormat(p);
143143 try {
144144 long m = df.parse(dateTime).getTime();
145145 if (m < 0) {
150150 setMillis(m);
151151 } catch (ParseException pe) {
152152 throw new BuildException("Date of " + dateTime
153 + " Cannot be parsed correctly. It should be in"
154 + (pattern == null
155 ? " MM/DD/YYYY HH:MM AM_PM" : pattern) + " format.");
153 + " Cannot be parsed correctly. It should be in '"
154 + p + "' format.");
156155 }
157156 }
158157 return when.evaluate(r.getLastModified(), millis.longValue(), granularity);
3333 public abstract class BaseSelector extends DataType implements FileSelector {
3434
3535 private String errmsg = null;
36
36 private Throwable cause;
3737
3838 /**
3939 * Do nothing constructor.
5050 public void setError(String msg) {
5151 if (errmsg == null) {
5252 errmsg = msg;
53 }
54 }
55
56 /**
57 * Allows all selectors to indicate a setup error. Note that only
58 * the first error message is recorded.
59 *
60 * @param msg The error message any BuildException should throw.
61 */
62 public void setError(String msg, Throwable cause) {
63 if (errmsg == null) {
64 errmsg = msg;
65 this.cause = cause;
5366 }
5467 }
5568
8699 verifySettings();
87100 }
88101 if (getError() != null) {
89 throw new BuildException(errmsg);
102 throw new BuildException(errmsg, cause);
90103 }
91104 if (!isReference()) {
92105 dieOnCircularReference();
183183 }
184184
185185 try {
186 in = new BufferedReader(new InputStreamReader(r.getInputStream()));
186 in = new BufferedReader(new InputStreamReader(r.getInputStream())); //NOSONAR
187187 } catch (Exception e) {
188188 throw new BuildException("Could not get InputStream from "
189189 + r.toLongString(), e);
190190 }
191 boolean success = false;
191192 try {
192193 teststr = in.readLine();
193194
201202 }
202203 teststr = in.readLine();
203204 }
204
205 success = true;
205206 return false;
206207 } catch (IOException ioe) {
207208 throw new BuildException("Could not read " + r.toLongString());
209210 try {
210211 in.close();
211212 } catch (Exception e) {
212 throw new BuildException("Could not close "
213 + r.toLongString());
213 if (success) {
214 throw new BuildException("Could not close " //NOSONAR
215 + r.toLongString());
216 }
214217 }
215218 }
216219 }
186186 BufferedReader in = null;
187187 try {
188188 if (encoding != null) {
189 in = new BufferedReader(new InputStreamReader(r.getInputStream(), encoding));
189 in = new BufferedReader(new InputStreamReader(r.getInputStream(), encoding)); //NOSONAR
190190 } else {
191 in = new BufferedReader(new InputStreamReader(r.getInputStream()));
191 in = new BufferedReader(new InputStreamReader(r.getInputStream())); //NOSONAR
192192 }
193193 } catch (Exception e) {
194194 throw new BuildException("Could not get InputStream from "
208208 setError("You must provide a datetime or the number of "
209209 + "milliseconds.");
210210 } else if (millis < 0 && dateTime != null) {
211 // check millis and only set it once.
212 DateFormat df = ((pattern == null)
213 ? DateFormat.getDateTimeInstance(
214 DateFormat.SHORT, DateFormat.SHORT, Locale.US)
215 : new SimpleDateFormat(pattern));
211 String p = pattern == null ? "MM/dd/yyyy hh:mm a" : pattern;
212 DateFormat df = pattern == null
213 ? new SimpleDateFormat(p, Locale.US)
214 : new SimpleDateFormat(p);
216215
217216 try {
218217 setMillis(df.parse(dateTime).getTime());
223222 }
224223 } catch (ParseException pe) {
225224 setError("Date of " + dateTime
226 + " Cannot be parsed correctly. It should be in"
227 + ((pattern == null)
228 ? " MM/DD/YYYY HH:MM AM_PM" : pattern) + " format.");
225 + " Cannot be parsed correctly. It should be in '"
226 + p + "' format.", pe);
229227 }
230228 }
231229 }
136136 cache.load(bis);
137137 bis.close();
138138 } catch (Exception e) {
139 e.printStackTrace();
139 e.printStackTrace(); //NOSONAR
140140 }
141141 }
142142 // after loading the cache is up to date with the file
163163 bos.flush();
164164 bos.close();
165165 } catch (Exception e) {
166 e.printStackTrace();
166 e.printStackTrace(); //NOSONAR
167167 }
168168 }
169169 cacheDirty = false;
4848
4949 // CheckStyle:ConstantNameCheck OFF - bc
5050 /** Provided for BC purposes */
51 public static final char[] alphabet = ALPHABET;
51 public static final char[] alphabet = ALPHABET; //NOSONAR
5252 // CheckStyle:ConstantNameCheck ON
5353
5454
3535 */
3636 public class CollectionUtils {
3737
38 /**
39 * Collections.emptyList() is Java5+.
40 */
4138 @SuppressWarnings("rawtypes")
4239 @Deprecated
43 public static final List EMPTY_LIST = Collections.EMPTY_LIST;
40 public static final List EMPTY_LIST = Collections.EMPTY_LIST; //NOSONAR
4441
4542 /**
4643 * Please use Vector.equals() or List.equals().
493493 try {
494494 encodedata(out, value);
495495 } catch (IOException ex) {
496 throw new RuntimeException(ex);
496 throw new RuntimeException(ex); //NOSONAR
497497 }
498498 return out.toString();
499499 }
16021602 *
16031603 * @since Ant 1.7
16041604 */
1605 public static String getRelativePath(File fromFile, File toFile) throws Exception {
1605 public static String getRelativePath(File fromFile, File toFile) throws Exception { //NOSONAR
16061606 String fromPath = fromFile.getCanonicalPath();
16071607 String toPath = toFile.getCanonicalPath();
16081608
17071707 */
17081708 public String getDefaultEncoding() {
17091709 InputStreamReader is = new InputStreamReader(
1710 new InputStream() {
1710 new InputStream() { //NOSONAR
17111711 public int read() {
17121712 return -1;
17131713 }
5454 /** floating version of the JVM */
5555 private static int javaVersionNumber;
5656
57 /** Version of currently running VM. */
58 private static final DeweyDecimal parsedJavaVersion;
59
5760 /** Version constant for Java 1.0 */
5861 public static final String JAVA_1_0 = "1.0";
5962 /** Number Version constant for Java 1.0 */
99102 /** Number Version constant for Java 1.8 */
100103 public static final int VERSION_1_8 = 18;
101104
102 /** Version constant for Java 1.9 */
105 /**
106 * Version constant for Java 1.9
107 * @deprecated use #JAVA_9 instead
108 */
103109 public static final String JAVA_1_9 = "1.9";
104 /** Number Version constant for Java 1.9 */
110 /**
111 * Number Version constant for Java 1.9
112 * @deprecated use #VERSION_9 instead
113 */
105114 public static final int VERSION_1_9 = 19;
115
116 /**
117 * Version constant for Java 9
118 * @since Ant 1.9.8
119 */
120 public static final String JAVA_9 = "9";
121 /**
122 * Number Version constant for Java 9
123 * @since Ant 1.9.8
124 */
125 public static final int VERSION_9 = 90;
106126
107127 /** Whether this is the Kaffe VM */
108128 private static boolean kaffeDetected;
157177 Class.forName("java.lang.reflect.Executable");
158178 javaVersion = JAVA_1_8;
159179 javaVersionNumber++;
160 checkForJava9();
161 javaVersion = JAVA_1_9;
162 javaVersionNumber++;
180 Class.forName("java.lang.module.ModuleDescriptor");
181 javaVersion = JAVA_9;
182 javaVersionNumber = VERSION_9;
163183 } catch (Throwable t) {
164184 // swallow as we've hit the max class version that
165185 // we have
166186 }
187 parsedJavaVersion = new DeweyDecimal(javaVersion);
167188 kaffeDetected = false;
168189 try {
169190 Class.forName("kaffe.util.NotImplemented");
196217
197218 /**
198219 * Returns the version of Java this class is running under.
199 * @return the version of Java as a String, e.g. "1.6"
220 *
221 * <p>Up until Java 8 Java version numbers were 1.VERSION -
222 * e.g. 1.8.x for Java 8, starting with Java 9 it became 9.x.</p>
223 *
224 * @return the version of Java as a String, e.g. "1.6" or "9"
200225 */
201226 public static String getJavaVersion() {
202227 return javaVersion;
204229
205230
206231 /**
207 * Checks for a give Java 9 runtime.
208 * At the time of writing the actual version of the JDK was 1.9.0_b06.
209 * Searching for new classes gave no hits, so we need another aproach.
210 * Searching for changes (grep -r -i -n "@since 1.9" .) in the sources gave
211 * only one hit: a new constant in the class SourceVersion.
212 * So we have to check that ...
213 *
214 * @throws Exception if we can't load the class or don't find the new constant.
215 * This is the behavior when searching for new features on older versions.
216 * @since Ant 1.9.4
217 */
218 private static void checkForJava9() throws Exception {
219 Class<?> clazz = Class.forName("javax.lang.model.SourceVersion");
220 clazz.getDeclaredField("RELEASE_9");
221 }
222
223
224 /**
225232 * Returns the version of Java this class is running under.
226 * This number can be used for comparisons; it will always be
233 * <p>This number can be used for comparisons.</p>
227234 * @return the version of Java as a number 10x the major/minor,
228 * e.g Java1.5 has a value of 15
235 * e.g Java1.5 has a value of 15 and Java9 the value 90 - major
236 * will be 1 for all versions of Java prior to Java 9, minor will
237 * be 0 for all versions of Java starting with Java 9.
238 * @deprecated use #getParsedJavaVersion instead
229239 */
230240 public static int getJavaVersionNumber() {
231241 return javaVersionNumber;
242 }
243
244 /**
245 * Returns the version of Java this class is running under.
246 * <p>This number can be used for comparisons.</p>
247 * @return the version of Java as major.minor, e.g Java1.5 has a
248 * value of 1.5 and Java9 the value 9 - major will be 1 for all
249 * versions of Java prior to Java 9, minor will be 0 for all
250 * versions of Java starting with Java 9.
251 */
252 public static DeweyDecimal getParsedJavaVersion() {
253 return parsedJavaVersion;
232254 }
233255
234256 /**
242264 * @since Ant 1.5
243265 */
244266 public static boolean isJavaVersion(String version) {
245 return javaVersion.equals(version);
267 return javaVersion.equals(version)
268 || (javaVersion.equals(JAVA_9) && JAVA_1_9.equals(version));
246269 }
247270
248271 /**
257280 * @since Ant 1.7
258281 */
259282 public static boolean isAtLeastJavaVersion(String version) {
260 return javaVersion.compareTo(version) >= 0;
283 return parsedJavaVersion.compareTo(new DeweyDecimal(version)) >= 0;
261284 }
262285
263286 /**
384407 // fall back to JRE bin directory, also catches JDK 1.0 and 1.1
385408 // where java.home points to the root of the JDK and Mac OS X where
386409 // the whole directory layout is different from Sun's
387 // and also catches JDK 1.9 (and probably later) which
410 // and also catches JDK 9 (and probably later) which
388411 // merged JDK and JRE dirs
389412 return getJreExecutable(command);
390413 }
426449 private static void buildJrePackages() {
427450 jrePackages = new Vector<String>();
428451 switch(javaVersionNumber) {
429 case VERSION_1_9:
452 case VERSION_9:
430453 case VERSION_1_8:
431454 case VERSION_1_7:
455 jrePackages.addElement("jdk");
456 // fall through
432457 case VERSION_1_6:
433458 case VERSION_1_5:
434459 //In Java1.5, the apache stuff moved.
479504 Vector<String> tests = new Vector<String>();
480505 tests.addElement("java.lang.Object");
481506 switch(javaVersionNumber) {
482 case VERSION_1_9:
507 case VERSION_9:
483508 case VERSION_1_8:
484509 case VERSION_1_7:
510 tests.addElement("jdk.net.Sockets");
511 // fall through
485512 case VERSION_1_6:
486513 case VERSION_1_5:
487514 tests.addElement(
699699 dolly = super.clone();
700700 } catch (final CloneNotSupportedException e) {
701701 // should be fine
702 e.printStackTrace();
702 e.printStackTrace(); //NOSONAR
703703 }
704704 return dolly;
705705 }
0 /*
1 * Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.apache.tools.ant.util;
18
19 /**
20 * Contains helper methods for Ant's built-in implementation of native2ascii.
21 *
22 * @since Ant 1.9.8
23 */
24 public class Native2AsciiUtils {
25
26 private static final int MAX_ASCII = 127;
27
28 /**
29 * Replaces non-ASCII characters with their Unicode-Escapes.
30 * <p>Expects to be called once per line if applied to a file.</p>
31 * @param line the input line
32 * @return the translated line
33 */
34 public static String native2ascii(String line) {
35 StringBuilder sb = new StringBuilder();
36 for (char c : line.toCharArray()) {
37 if (c <= MAX_ASCII) {
38 sb.append(c);
39 } else {
40 sb.append("\\u");
41 String encoded = Integer.toHexString(c);
42 for (int i = encoded.length(); i < 4; i++) {
43 sb.append("0");
44 }
45 sb.append(encoded);
46 }
47 }
48 return sb.toString();
49 }
50
51 /**
52 * Replaces Unicode-Escapes.
53 * <p>Expects to be called once per line if applied to a file.</p>
54 * @param line the input line
55 * @return the translated line
56 */
57 public static String ascii2native(String line) {
58 StringBuilder sb = new StringBuilder();
59 int inputLen = line.length();
60 for (int i = 0; i < inputLen; i++) {
61 char c = line.charAt(i);
62 if (c != '\\' || i >= inputLen - 5) {
63 sb.append(c);
64 } else { // backslash with enough remaining characters
65 char u = line.charAt(++i);
66 if (u == 'u') {
67 int unescaped = tryParse(line, i + 1);
68 if (unescaped >= 0) {
69 sb.append((char) unescaped);
70 i += 4;
71 continue;
72 }
73 }
74 // not a unicode escape
75 sb.append(c).append(u);
76 }
77 }
78 return sb.toString();
79 }
80
81 private static int tryParse(String line, int startIdx) {
82 try {
83 return Integer.parseInt(line.substring(startIdx, startIdx + 4), 16);
84 } catch (NumberFormatException ex) {
85 return -1;
86 }
87 }
88 }
142142 if (!funnel.closed) {
143143 try {
144144 if (timeoutMillis > 0) {
145 final long start = System.currentTimeMillis();
146 final long end = start + timeoutMillis;
147 long now = System.currentTimeMillis();
145148 try {
146 wait(timeoutMillis);
149 while (now < end) {
150 wait(end - now);
151 now = System.currentTimeMillis();
152 }
147153 } catch (InterruptedException eyeEx) {
148154 //ignore
149155 }
5656 /** the http proxy username property */
5757 public static final String HTTP_PROXY_USERNAME = "http.proxyUser";
5858 /** the http proxy password property */
59 public static final String HTTP_PROXY_PASSWORD = "http.proxyPassword";
59 public static final String HTTP_PROXY_PASSWORD = "http.proxyPassword"; //NOSONAR
6060 /** the socks proxy host property */
6161 public static final String SOCKS_PROXY_HOST = "socksProxyHost";
6262 /** the socks proxy port property */
6464 /** the socks proxy username property */
6565 public static final String SOCKS_PROXY_USERNAME = "java.net.socks.username";
6666 /** the socks proxy password property */
67 public static final String SOCKS_PROXY_PASSWORD = "java.net.socks.password";
67 public static final String SOCKS_PROXY_PASSWORD = "java.net.socks.password"; //NOSONAR
6868
6969 /**
7070 * create a proxy setup class bound to this project
147147 try {
148148 in.mark(limit);
149149 } catch (IOException ioe) {
150 throw new RuntimeException(ioe.getMessage());
150 throw new RuntimeException(ioe.getMessage()); //NOSONAR
151151 }
152152 }
153153
7171 */
7272 public static final String ISO_8859_1 = "ISO-8859-1";
7373
74 private static final long MAX_IO_CHUNK_SIZE = 16*1024*1024; // 16 MB
74 private static final long MAX_IO_CHUNK_SIZE = 16*1024*1024l; // 16 MB
7575
7676 /**
7777 * Tells which source files should be reprocessed based on the
629629 }
630630 expected = in1.readLine();
631631 }
632 return in2.readLine() == null ? 0 : -1;
632 return in2.readLine() == null ? 0 : -1; //NOSONAR
633633 } finally {
634634 FileUtils.close(in1);
635635 FileUtils.close(in2);
9292 public static String getStackTrace(Throwable t) {
9393 StringWriter sw = new StringWriter();
9494 PrintWriter pw = new PrintWriter(sw, true);
95 t.printStackTrace(pw);
95 t.printStackTrace(pw); //NOSONAR
9696 pw.flush();
9797 pw.close();
9898 return sw.toString();
194194 * @throws Exception if there is a problem.
195195 * @since Ant 1.7
196196 */
197 public static long parseHumanSizes(String humanSize) throws Exception {
197 public static long parseHumanSizes(String humanSize) throws Exception { //NOSONAR
198198 long factor = 1L;
199199 char s = humanSize.charAt(0);
200200 switch (s) {
253253 }
254254
255255 boolean renamedTarget = false;
256 boolean success = false;
256257 try {
257258 try {
258259 FILE_UTILS.rename(target, temp);
269270 + " (was it a real file? is this "
270271 + "not a UNIX system?)");
271272 }
273 success = true;
272274 } finally {
273275 if (renamedTarget) {
274276 // return the resource to its original name:
275277 try {
276278 FILE_UTILS.rename(temp, target);
277279 } catch (final IOException e) {
278 throw new IOException("Couldn't return resource "
279 + temp
280 + " to its original name: "
281 + target.getAbsolutePath()
282 + ". Reason: " + e.getMessage()
283 + "\n THE RESOURCE'S NAME ON DISK"
284 + " HAS BEEN CHANGED BY THIS"
285 + " ERROR!\n");
280 String msg = "Couldn't return resource "
281 + temp
282 + " to its original name: "
283 + target.getAbsolutePath()
284 + ". Reason: " + e.getMessage()
285 + "\n THE RESOURCE'S NAME ON DISK"
286 + " HAS BEEN CHANGED BY THIS"
287 + " ERROR!\n";
288 if (success) {
289 throw new IOException(msg); //NOSONAR
290 } else {
291 System.err.println(msg);
292 }
286293 }
287294 }
288295 }
8080 /**
8181 * Encode a string to the output.
8282 */
83 private void encodeString(String n) throws IOException {
83 private void encodeString(String n) {
8484 PrintStream writer = new PrintStream(out);
8585 writer.print(n);
8686 writer.flush();
116116 * @throws InterruptedException if the execution was interrupted
117117 */
118118 public void waitUntilFinished(long timeout) throws InterruptedException {
119 final long start = System.currentTimeMillis();
120 final long end = start + timeout;
119121 synchronized (notify) {
120 if (!finished) {
121 notify.wait(timeout);
122 long now = System.currentTimeMillis();
123 while (!finished && now < end) {
124 notify.wait(end - now);
125 now = System.currentTimeMillis();
122126 }
123127 }
124128 }
2121 import java.util.Vector;
2222 import java.util.zip.ZipFile;
2323
24 import org.apache.tools.ant.BuildException;
2425 import org.apache.tools.ant.types.Path;
2526 import org.apache.tools.ant.util.VectorSet;
2627
7980 */
8081 public Enumeration<File> getFileDependencies() {
8182 if (!supportsFileDependencies()) {
82 throw new RuntimeException("File dependencies are not supported "
83 throw new BuildException("File dependencies are not supported "
8384 + "by this analyzer");
8485 }
8586 if (!determined) {
4141 public AncestorAnalyzer() {
4242 // force BCEL classes to load now
4343 try {
44 new ClassParser("force");
44 new ClassParser("force"); //NOSONAR
4545 } catch (Exception e) {
4646 // all released versions of BCEL may throw an IOException
4747 // here, but BCEL's trunk does no longer declare to do so
4040 public FullAnalyzer() {
4141 // force BCEL classes to load now
4242 try {
43 new ClassParser("force");
43 new ClassParser("force"); //NOSONAR
4444 } catch (Exception e) {
4545 // all released versions of BCEL may throw an IOException
4646 // here, but BCEL's trunk does no longer declare to do so
125125 }
126126 }
127127
128 private ReflectWrapper createEngine() throws Exception {
128 private ReflectWrapper createEngine() {
129129 if (engine != null) {
130130 return engine;
131131 }
5151 * <p>FIXME: This array should be in a private or package private
5252 * location, since it could be modified by malicious code.</p>
5353 */
54 int[] rNums = {
54 int[] rNums = { //NOSONAR
5555 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
5656 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
5757 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
444444 private int[] eclass;
445445
446446 private int[] getEclass() {
447 return eclass == null
448 ? (eclass = new int[quadrant.length / 2]) : eclass;
447 if (eclass == null) {
448 eclass = new int[quadrant.length / 2];
449 }
450 return eclass;
449451 }
450452
451453 /*
641643 HAMMER: while (true) {
642644 if (onceRunned) {
643645 fmap[j] = a;
644 if ((j -= h) <= mj) {
646 if ((j -= h) <= mj) { //NOSONAR
645647 break HAMMER;
646648 }
647649 } else {
659661 if (block[i1 + 3] == block[i2 + 3]) {
660662 if (block[i1 + 4] == block[i2 + 4]) {
661663 if (block[i1 + 5] == block[i2 + 5]) {
662 if (block[(i1 += 6)] == block[(i2 += 6)]) {
664 if (block[(i1 += 6)] == block[(i2 += 6)]) { //NOSONAR
663665 int x = lastShadow;
664666 X: while (x > 0) {
665667 x -= 4;
672674 if (quadrant[i1 + 2] == quadrant[i2 + 2]) {
673675 if (block[i1 + 4] == block[i2 + 4]) {
674676 if (quadrant[i1 + 3] == quadrant[i2 + 3]) {
675 if ((i1 += 4) >= lastPlus1) {
677 if ((i1 += 4) >= lastPlus1) { //NOSONAR
676678 i1 -= lastPlus1;
677679 }
678 if ((i2 += 4) >= lastPlus1) {
680 if ((i2 += 4) >= lastPlus1) { //NOSONAR
679681 i2 -= lastPlus1;
680682 }
681683 workDoneShadow++;
972974 runningOrder[i] = i;
973975 }
974976
975 for (int h = 364; h != 1;) {
977 for (int h = 364; h != 1;) { //NOSONAR
976978 h /= 3;
977979 for (int i = h; i <= 255; i++) {
978980 final int vv = runningOrder[i];
2929 *
3030 */
3131 final class CRC {
32 static final int crc32Table[] = {
32 static final int crc32Table[] = { //NOSONAR
3333 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
3434 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
3535 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
332332 * @return True if the entries are equal.
333333 */
334334 public boolean equals(TarEntry it) {
335 return getName().equals(it.getName());
335 return it != null && getName().equals(it.getName());
336336 }
337337
338338 /**
845845 writeEntryHeader(outbuf, TarUtils.FALLBACK_ENCODING, false);
846846 } catch (IOException ex2) {
847847 // impossible
848 throw new RuntimeException(ex2);
848 throw new RuntimeException(ex2); //NOSONAR
849849 }
850850 }
851851 }
931931 parseTarHeader(header, TarUtils.DEFAULT_ENCODING, true);
932932 } catch (IOException ex2) {
933933 // not really possible
934 throw new RuntimeException(ex2);
934 throw new RuntimeException(ex2); //NOSONAR
935935 }
936936 }
937937 }
10941094 try {
10951095 buffer1 = expected.getBytes("ASCII");
10961096 } catch (UnsupportedEncodingException e) {
1097 throw new RuntimeException(e); // Should not happen
1097 // Should not happen
1098 throw new RuntimeException(e); //NOSONAR
10981099 }
10991100 return isEqual(buffer1, 0, buffer1.length, buffer, offset, length,
11001101 false);
275275 while (numToSkip > 0) {
276276 long skipped = skip(numToSkip);
277277 if (skipped <= 0) {
278 throw new RuntimeException("failed to skip current tar"
278 throw new IOException("failed to skip current tar"
279279 + " entry");
280280 }
281281 numToSkip -= skipped;
585585
586586 private void failForBigNumber(String field, long value, long maxValue, String additionalMsg) {
587587 if (value < 0 || value > maxValue) {
588 throw new RuntimeException(field + " '" + value
588 throw new RuntimeException(field + " '" + value //NOSONAR
589589 + "' is too big ( > "
590590 + maxValue + " )");
591591 }
637637 write(0); // NUL terminator
638638 closeEntry();
639639 } else if (longFileMode != LONGFILE_TRUNCATE) {
640 throw new RuntimeException(fieldName + " '" + name
640 throw new RuntimeException(fieldName + " '" + name //NOSONAR
641641 + "' is too long ( > "
642642 + TarConstants.NAMELEN + " bytes)");
643643 }
190190 if (negative) {
191191 // 2's complement
192192 val--;
193 val ^= (long) Math.pow(2, (length - 1) * 8) - 1;
193 val ^= (long) Math.pow(2, (length - 1) * 8.0) - 1;
194194 }
195195 return negative ? -val : val;
196196 }
264264 return parseName(buffer, offset, length, FALLBACK_ENCODING);
265265 } catch (final IOException ex2) {
266266 // impossible
267 throw new RuntimeException(ex2);
267 throw new RuntimeException(ex2); //NOSONAR
268268 }
269269 }
270270 }
323323 FALLBACK_ENCODING);
324324 } catch (final IOException ex2) {
325325 // impossible
326 throw new RuntimeException(ex2);
326 throw new RuntimeException(ex2); //NOSONAR
327327 }
328328 }
329329 }
5353 try {
5454 unicodeName = text.getBytes("UTF-8");
5555 } catch (final UnsupportedEncodingException e) {
56 throw new RuntimeException("FATAL: UTF-8 encoding not supported.",
56 throw new RuntimeException("FATAL: UTF-8 encoding not supported.", //NOSONAR
5757 e);
5858 }
5959 }
345345 return cloned;
346346 } catch (CloneNotSupportedException cnfe) {
347347 // impossible
348 throw new RuntimeException(cnfe);
348 throw new RuntimeException(cnfe); //NOSONAR
349349 }
350350 }
351351 }
6262 ZipExtraField ze = (ZipExtraField) c.newInstance();
6363 implementations.put(ze.getHeaderId(), c);
6464 } catch (ClassCastException cc) {
65 throw new RuntimeException(c + " doesn\'t implement ZipExtraField");
65 throw new RuntimeException(c + " doesn\'t implement ZipExtraField"); //NOSONAR
6666 } catch (InstantiationException ie) {
67 throw new RuntimeException(c + " is not a concrete class");
67 throw new RuntimeException(c + " is not a concrete class"); //NOSONAR
6868 } catch (IllegalAccessException ie) {
69 throw new RuntimeException(c + "\'s no-arg constructor is not public");
69 throw new RuntimeException(c + "\'s no-arg constructor is not public"); //NOSONAR
7070 }
7171 }
7272
187187 return super.clone();
188188 } catch (CloneNotSupportedException ex) {
189189 // impossible
190 throw new RuntimeException("GeneralPurposeBit is not Cloneable?", ex);
190 throw new RuntimeException("GeneralPurposeBit is not Cloneable?", ex); //NOSONAR
191191 }
192192 }
193193 }
2727 public class UnsupportedZipFeatureException extends ZipException {
2828
2929 private final Feature reason;
30 private final ZipEntry entry;
31 private static final long serialVersionUID = 4430521921766595597L;
30 private transient final ZipEntry entry;
31 private static final long serialVersionUID = 20161221L;
3232
3333 /**
3434 * Creates an exception.
6060 /**
6161 * ZIP Features that may or may not be supported.
6262 */
63 public static class Feature {
63 public static class Feature implements java.io.Serializable {
6464 /**
6565 * The entry is encrypted.
6666 */
516516 mergeExtraFields(local, true);
517517 } catch (final ZipException e) {
518518 // actually this is not be possible as of Ant 1.8.1
519 throw new RuntimeException("Error parsing extra fields for entry: "
519 throw new RuntimeException("Error parsing extra fields for entry: " //NOSONAR
520520 + getName() + " - " + e.getMessage(), e);
521521 }
522522 }
543543 ExtraFieldUtils.UnparseableExtraField.READ);
544544 mergeExtraFields(central, false);
545545 } catch (final ZipException e) {
546 throw new RuntimeException(e.getMessage(), e);
546 throw new RuntimeException(e.getMessage(), e); //NOSONAR
547547 }
548548 }
549549
369369 final OffsetEntry offsetEntry = ((Entry) ze).getOffsetEntry();
370370 ZipUtil.checkRequestedFeatures(ze);
371371 final long start = offsetEntry.dataOffset;
372 // doesn't get closed if the method is not supported, but
373 // doesn't hold any resources either
372374 final BoundedInputStream bis =
373 new BoundedInputStream(start, ze.getCompressedSize());
375 new BoundedInputStream(start, ze.getCompressedSize()); //NOSONAR
374376 switch (ze.getMethod()) {
375377 case ZipEntry.STORED:
376378 return bis;
10351037 @Override
10361038 public boolean equals(final Object other) {
10371039 if (super.equals(other)) {
1038 // super.equals would return false if other were not an Entry
1040 // super.equals would return false if other were null or not an Entry
10391041 final Entry otherEntry = (Entry) other;
10401042 return offsetEntry.headerOffset
1041 == otherEntry.offsetEntry.headerOffset
1043 == otherEntry.offsetEntry.headerOffset //NOSONAR
10421044 && offsetEntry.dataOffset
1043 == otherEntry.offsetEntry.dataOffset;
1045 == otherEntry.offsetEntry.dataOffset; //NOSONAR
10441046 }
10451047 return false;
10461048 }
189189 return super.clone();
190190 } catch (CloneNotSupportedException cnfe) {
191191 // impossible
192 throw new RuntimeException(cnfe);
192 throw new RuntimeException(cnfe); //NOSONAR
193193 }
194194 }
195195
962962 *
963963 * @since 1.1
964964 */
965 protected static final byte[] LFH_SIG = ZipLong.LFH_SIG.getBytes();
965 protected static final byte[] LFH_SIG = ZipLong.LFH_SIG.getBytes(); //NOSONAR
966966 /**
967967 * data descriptor signature
968968 *
969969 * @since 1.1
970970 */
971 protected static final byte[] DD_SIG = ZipLong.DD_SIG.getBytes();
971 protected static final byte[] DD_SIG = ZipLong.DD_SIG.getBytes(); //NOSONAR
972972 /**
973973 * central file header signature
974974 *
975975 * @since 1.1
976976 */
977 protected static final byte[] CFH_SIG = ZipLong.CFH_SIG.getBytes();
977 protected static final byte[] CFH_SIG = ZipLong.CFH_SIG.getBytes(); //NOSONAR
978978 /**
979979 * end of central dir signature
980980 *
981981 * @since 1.1
982982 */
983 protected static final byte[] EOCD_SIG = ZipLong.getBytes(0X06054B50L);
983 protected static final byte[] EOCD_SIG = ZipLong.getBytes(0X06054B50L); //NOSONAR
984984 /**
985985 * ZIP64 end of central dir signature
986986 */
987 static final byte[] ZIP64_EOCD_SIG = ZipLong.getBytes(0X06064B50L);
987 static final byte[] ZIP64_EOCD_SIG = ZipLong.getBytes(0X06064B50L); //NOSONAR
988988 /**
989989 * ZIP64 end of central dir locator signature
990990 */
991 static final byte[] ZIP64_EOCD_LOC_SIG = ZipLong.getBytes(0X07064B50L);
991 static final byte[] ZIP64_EOCD_LOC_SIG = ZipLong.getBytes(0X07064B50L); //NOSONAR
992992
993993 /**
994994 * Writes next block of compressed data to the output stream.
154154 return super.clone();
155155 } catch (CloneNotSupportedException cnfe) {
156156 // impossible
157 throw new RuntimeException(cnfe);
157 throw new RuntimeException(cnfe); //NOSONAR
158158 }
159159 }
160160
2020 use_jikes_default=false
2121 ant_exec_debug=false
2222 show_help=false
23
24 esc_tool=sed
25
26 # if awk esc_tool is chosen, use nawk when available
27 if [ "$esc_tool" = "awk" ]
28 then
29 awk_exec=awk
30 # Solaris_awk does not support gsub, but Solaris_nawk does
31 # `command -v` behavior is part of posix spec
32 command -v nawk >/dev/null && awk_exec=nawk
33 fi
34
2335 for arg in "$@" ; do
2436 if [ "$arg" = "--noconfig" ] ; then
2537 no_config=true
3446 if [ my"$arg" = my"-h" -o my"$arg" = my"-help" ] ; then
3547 show_help=true
3648 fi
37 # wrap all arguments as "" strings, escape any internal back-slash or double-quote characters
38 ant_exec_args="$ant_exec_args \"$(printf '%s' "$arg" | sed -e 's@"\|\\@\\\0@g' )\""
49
50 # wrap all arguments as "" strings, escape any internal back-slash, double-quote, $, or back-tick characters
51 # use printf to avoid echo interpretation behaviors such as escapes and line continuation
52 # pad the value with X to protect leading/trailing whitespace from subshell output trimming
53 esc_arg="X${arg}X"
54 case "$esc_tool" in
55 'sed')
56 # Mac bsd_sed does not support group-0, so pattern uses group-1
57 # Solaris sed only proceses lines with trailing newline, passing in an extra newline
58 # subshell assignment will trim the added trailing newline
59 esc_arg="$(printf '%s\n' "$esc_arg" | sed -e 's@\([$"\\`]\)@\\\1@g')"
60 ;;
61 'awk')
62 esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\\/, "\\\\"); print }' )"
63 esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\$/, "\\$"); print }' )"
64 esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\"/, "\\\""); print }' )"
65 esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/`/, "\\`"); print }' )"
66 ;;
67 # 'bash')
68 # # does not depend upon `sed` or `echo` quirks
69 # # tested with bash `[ -n "${BASH_VERSION}" ]`
70 # # tested with zsh `[ -n "${ZSH_NAME}" ]`
71 # # tested with ksh93+ `ksh_ver="$(echo "$KSH_VERSION" | grep -m 1 -o '[0-9]\+' | head -n 1)"; [ "$ksh_ver" -gt 88 ]`
72 # # fails in ksh88, dash, ash
73 # esc_arg="${esc_arg//\\/\\\\}" # must be first since later patterns introduce backslash chars
74 # esc_arg="${esc_arg//\$/\\\$}"
75 # esc_arg="${esc_arg//\"/\\\"}"
76 # esc_arg="${esc_arg//\`/\\\`}"
77 # ;;
78 '*')
79 echo "could not determine escaping tool"
80 exit 1
81 ;;
82 esac
83 # remove the padding Xs added above
84 esc_arg="${esc_arg#X}"
85 esc_arg="${esc_arg%X}"
86 quoted_arg="\"$esc_arg\""
87
88 if $ant_exec_debug
89 then
90 # using printf to avoid echo line continuation and escape interpretation
91 printf "arg : %s\n" "$arg"
92 printf "quoted_arg: %s\n" "$quoted_arg"
93 fi
94 ant_exec_args="$ant_exec_args $quoted_arg"
3995 fi
4096 done
4197
331387 fi
332388 ant_exec_command="exec \"\$JAVACMD\" $ANT_OPTS -classpath \"\$LOCALCLASSPATH\" -Dant.home=\"\$ANT_HOME\" -Dant.library.dir=\"\$ANT_LIB\" $ant_sys_opts org.apache.tools.ant.launch.Launcher $ANT_ARGS -cp \"\$CLASSPATH\""
333389 if $ant_exec_debug ; then
334 echo $ant_exec_command $ant_exec_args
335 fi
336
337 eval $ant_exec_command $ant_exec_args
390 echo "$ant_exec_command $ant_exec_args"
391 fi
392
393 eval "$ant_exec_command $ant_exec_args"
2626 <property name="test3.jar" location="${antunit.tmpdir}/test3.jar"/>
2727 <property name="test4.jar" location="${antunit.tmpdir}/test4.jar"/>
2828 <property name="test5.jar" location="${antunit.tmpdir}/test5.jar"/>
29 <condition property="jdk1.9+">
30 <contains string="${java.version}" substring="1.9."/>
31 </condition>
29 <available property="jdk9+" classname="java.lang.module.ModuleDescriptor"/>
3230 <available property="jdk1.8+" classname="java.lang.reflect.Executable"/>
3331 <available property="jdk1.7+" classname="java.nio.file.FileSystem"/>
3432 <available property="jdk1.6+" classname="java.net.CookieStore"/>
0 <?xml version="1.0"?>
1 <!--
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 -->
17 <project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
18 <import file="../antunit-base.xml" />
19
20 <target name="testForward">
21 <au:assertTrue>
22 <resourcesmatch>
23 <string value="\u00e4\u00f6\u00fc=\u00c4\u00d6\u00dc
24 \u00df=\u20ac"/>
25 <concat encoding="UTF-8" outputencoding="UTF-8">
26 <string value="äöü=ÄÖÜ
27 ß=€"/>
28 <filterchain>
29 <native2asciifilter/>
30 </filterchain>
31 </concat>
32 </resourcesmatch>
33 </au:assertTrue>
34 </target>
35
36 <target name="testReverse">
37 <au:assertTrue>
38 <resourcesmatch>
39 <string value="äöü=ÄÖÜ
40 ß=€"/>
41 <concat encoding="UTF-8" outputencoding="UTF-8">
42 <string value="\u00e4\u00f6\u00fc=\u00c4\u00d6\u00dc
43 \u00df=\u20ac"/>
44 <filterchain>
45 <native2asciifilter reverse="true"/>
46 </filterchain>
47 </concat>
48 </resourcesmatch>
49 </au:assertTrue>
50 </target>
51
52 </project>
1717 <project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
1818 <import file="../antunit-base.xml" />
1919
20 <property name="javac-dir" location="${output}/javac-dir" />
21 <property name="build-dir" location="${javac-dir}/build" />
22
23 <target name="test-includeDestClasses">
20 <target name="setup">
21 <property name="javac-dir" location="${output}/javac-dir" />
22 <property name="build-dir" location="${javac-dir}/build" />
23 <presetdef name="testJavac">
24 <javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes"
25 includeantruntime="false"/>
26 </presetdef>
27 </target>
28
29 <target name="test-includeDestClasses" depends="setup">
2430 <property name="DATE" value="09/10/1999 4:30 pm" />
2531 <delete dir="${javac-dir}/src" />
2632 <mkdir dir="${javac-dir}/src" />
5359 </au:assertFalse>
5460 </target>
5561
56 <target name="test-updated-property">
62 <target name="test-updated-property" depends="setup">
5763 <delete quiet="yes" dir="${build-dir}" />
5864 <mkdir dir="${build-dir}" />
5965 <javac srcdir="javac-dir/good-src" destdir="${build-dir}" updatedProperty="classes-updated" />
6672 </au:assertFalse>
6773 </target>
6874
69 <target name="test-error-property">
75 <target name="test-error-property" depends="setup">
7076 <delete quiet="yes" dir="${build-dir}" />
7177 <mkdir dir="${build-dir}" />
7278 <javac srcdir="javac-dir/good-src" destdir="${build-dir}" failOnError="false" errorProperty="compile-failed" />
7985 </au:assertTrue>
8086 </target>
8187
82 <target name="setUpForPackageInfoJava">
88 <target name="setUpForPackageInfoJava" depends="setup">
8389 <mkdir dir="${javac-dir}/src/a" />
8490 <mkdir dir="${build-dir}" />
8591 <echo file="${javac-dir}/src/a/package-info.java">
150156 <au:assertFileDoesntExist file="${build-dir}/a/package-info.class"/>
151157 </target>
152158
153 <target name="-create-javac-adapter">
159 <target name="-create-javac-adapter" depends="setup">
154160 <property name="adapter.dir" location="${output}/adapter" />
155161 <mkdir dir="${input}/org/example" />
156162 <echo file="${input}/org/example/Adapter.java">
197203 <au:assertLogContains text="adapter called" />
198204 </target>
199205
200 <target name="testSourceAttributes" xmlns:if="ant:if" xmlns:unless="ant:unless">
206 <target name="testSourceAttributes" depends="setup"
207 xmlns:if="ant:if" xmlns:unless="ant:unless">
201208 <delete dir="${javac-dir}/src" />
202209 <mkdir dir="${javac-dir}/src" />
203210 <mkdir dir="${javac-dir}/classes" />
204211 <echo file="${javac-dir}/src/A.java">
205212 public class A { }
206213 </echo>
207 <presetdef name="testJavac">
208 <javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" includeantruntime="false"/>
209 </presetdef>
210214
211215 <au:expectfailure>
212216 <testJavac source="notValid"/>
213217 </au:expectfailure>
214218
215 <sequential unless:set="jdk1.9+">
219 <sequential unless:set="jdk9+">
216220 <echo>JDK 1.4+</echo>
217221 <testJavac source="1.4"/>
218222 <delete dir="${javac-dir}/classes"/>
219223 <mkdir dir="${javac-dir}/classes"/>
220224 </sequential>
221225
222 <sequential unless:set="jdk1.9+">
226 <sequential unless:set="jdk9+">
223227 <echo>JDK 1.5+</echo>
224228 <testJavac source="1.5"/>
225229 <delete dir="${javac-dir}/classes"/>
247251 <mkdir dir="${javac-dir}/classes"/>
248252 </sequential>
249253
250 <sequential if:set="jdk1.9+">
251 <echo>JDK 1.9+</echo>
252 <testJavac source="1.9"/>
254 <sequential if:set="jdk9+">
255 <echo>JDK 9+</echo>
256 <testJavac source="9"/>
253257 <delete dir="${javac-dir}/classes"/>
254258 <mkdir dir="${javac-dir}/classes"/>
255259 </sequential>
256260 </target>
257261
258 <target name="testTargetAttributes" xmlns:if="ant:if" xmlns:unless="ant:unless">
262 <target name="testTargetAttributes" depends="setup"
263 xmlns:if="ant:if" xmlns:unless="ant:unless">
259264 <delete dir="${javac-dir}/src" />
260265 <mkdir dir="${javac-dir}/src" />
261266 <mkdir dir="${javac-dir}/classes" />
262267 <echo file="${javac-dir}/src/A.java">
263268 public class A { }
264269 </echo>
265 <presetdef name="testJavac">
266 <javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" includeantruntime="false"/>
267 </presetdef>
268270
269271 <au:expectfailure>
270272 <testJavac target="notValid"/>
271273 </au:expectfailure>
272274
273 <sequential unless:set="jdk1.9+">
275 <sequential unless:set="jdk9+">
274276 <echo>JDK 1.4+</echo>
275277 <testJavac source="1.4" target="1.4"/>
276278 <delete dir="${javac-dir}/classes"/>
277279 <mkdir dir="${javac-dir}/classes"/>
278280 </sequential>
279281
280 <sequential unless:set="jdk1.9+">
282 <sequential unless:set="jdk9+">
281283 <echo>JDK 1.5+</echo>
282284 <testJavac source="1.5" target="1.5"/>
283285 <delete dir="${javac-dir}/classes"/>
305307 <mkdir dir="${javac-dir}/classes"/>
306308 </sequential>
307309
308 <sequential if:set="jdk1.9+">
309 <echo>JDK 1.9+</echo>
310 <testJavac source="1.9" target="1.9"/>
310 <sequential if:set="jdk9+">
311 <echo>JDK 9+</echo>
312 <testJavac source="9" target="9"/>
311313 <delete dir="${javac-dir}/classes"/>
312314 <mkdir dir="${javac-dir}/classes"/>
313315 </sequential>
314316 </target>
317
318 <target name="testJavacWithNativeHeaderGeneration" if="jdk1.8+" depends="setup">
319 <mkdir dir="${javac-dir}/src/org/example" />
320 <mkdir dir="${javac-dir}/classes"/>
321 <mkdir dir="${javac-dir}/headers"/>
322 <echo file="${javac-dir}/src/org/example/Foo.java">
323 <![CDATA[
324 package org.example;
325 public class Foo {
326 public Foo() {}
327 public native String bar(Object baz);
328 }
329 ]]></echo>
330 <echo file="${javac-dir}/src/org/example/Bar.java">
331 <![CDATA[
332 package org.example;
333 public class Bar {
334 public Bar() {}
335 public String xyzzy(Object baz) {
336 return new Foo().bar(baz);
337 }
338 }
339 ]]></echo>
340 <testJavac nativeheaderdir="${javac-dir}/headers"/>
341 <au:assertFileExists file="${javac-dir}/headers/org_example_Foo.h"/>
342 <au:assertFileDoesntExist file="${javac-dir}/headers/org_example_Bar.h"/>
343 </target>
315344 </project>
6161 </javah>
6262 <au:assertLogContains text="adapter called" />
6363 </target>
64
65 <target name="-setupForRealJavahTests">
66 <condition property="sunjavah.present">
67 <or>
68 <available classname="com.sun.tools.javah.oldjavah.Main"/>
69 <available classname="com.sun.tools.javah.Main"/>
70 </or>
71 </condition>
72 <mkdir dir="${input}/org/example"/>
73 <mkdir dir="${output}/org/example"/>
74 <echo file="${input}/org/example/Foo.java">
75 <![CDATA[
76 package org.example;
77 public class Foo {
78 public Foo() {}
79 public native String bar(Object baz);
80 }
81 ]]></echo>
82 <javac srcdir="${input}" destdir="${output}"/>
83 <presetdef name="javah-single">
84 <javah destdir="${output}">
85 <class name="org.example.Foo"/>
86 <classpath>
87 <pathelement location="${output}"/>
88 </classpath>
89 </javah>
90 </presetdef>
91 <presetdef name="javah-fileset">
92 <javah destdir="${output}">
93 <fileset dir="${output}">
94 <include name="**/*.class"/>
95 </fileset>
96 <classpath>
97 <pathelement location="${output}"/>
98 </classpath>
99 </javah>
100 </presetdef>
101 </target>
102
103 <target name="testSimpleCompile" depends="-setupForRealJavahTests">
104 <javah-single/>
105 <au:assertFileExists file="${output}/org_example_Foo.h"/>
106 </target>
107
108 <target name="testCompileUsingFileset" depends="-setupForRealJavahTests">
109 <javah-fileset/>
110 <au:assertFileExists file="${output}/org_example_Foo.h"/>
111 </target>
112
113 <target name="testSimpleCompileSun" depends="-setupForRealJavahTests"
114 if="sunjavah.present">
115 <javah-single implementation="sun"/>
116 <au:assertFileExists file="${output}/org_example_Foo.h"/>
117 </target>
118
119 <target name="testCompileUsingFilesetSun" depends="-setupForRealJavahTests"
120 if="sunjavah.present">
121 <javah-fileset implementation="sun"/>
122 <au:assertFileExists file="${output}/org_example_Foo.h"/>
123 </target>
124
125 <target name="testSimpleCompileForking" depends="-setupForRealJavahTests">
126 <javah-single implementation="forking"/>
127 <au:assertFileExists file="${output}/org_example_Foo.h"/>
128 </target>
129
130 <target name="testCompileUsingFilesetForking" depends="-setupForRealJavahTests">
131 <javah-fileset implementation="forking"/>
132 <au:assertFileExists file="${output}/org_example_Foo.h"/>
133 </target>
64134 </project>
6464 </native2ascii>
6565 <au:assertLogContains text="adapter called"/>
6666 </target>
67
68 <target name="-real-test-macros">
69 <macrodef name="assertTranslatedOutput">
70 <attribute name="file"/>
71 <attribute name="expected"/>
72 <attribute name="encoding"/>
73 <sequential>
74 <loadfile srcFile="${output}/@{file}" encoding="@{encoding}"
75 property="@{file}.actual">
76 <filterchain>
77 <striplinebreaks/>
78 </filterchain>
79 </loadfile>
80 <au:assertEquals expected="@{expected}" actual="${@{file}.actual}"/>
81 </sequential>
82 </macrodef>
83 <presetdef name="native2ascii-def">
84 <native2ascii src="${input}" dest="${output}" encoding="UTF-8"
85 includes="**/*.properties"/>
86 </presetdef>
87 </target>
88
89 <target name="-setup-UTF8-To-ASCII" depends="-real-test-macros">
90 <mkdir dir="${input}"/>
91 <mkdir dir="${output}"/>
92 <echo file="${input}/umlauts.properties" encoding="UTF-8">äöü=ÄÖÜ</echo>
93 <property name="umlauts.expected"
94 value="\u00e4\u00f6\u00fc=\u00c4\u00d6\u00dc"/>
95 </target>
96
97 <target name="testUTF8-To-ASCII-sun" depends="-setup-UTF8-To-ASCII"
98 description="https://bz.apache.org/bugzilla/show_bug.cgi?id=59855"
99 unless="jdk9+">
100 <native2ascii-def implementation="sun"/>
101 <assertTranslatedOutput file="umlauts.properties" encoding="ASCII"
102 expected="${umlauts.expected}"/>
103 </target>
104
105 <target name="testUTF8-To-ASCII-builtin" depends="-setup-UTF8-To-ASCII"
106 description="https://bz.apache.org/bugzilla/show_bug.cgi?id=59855">
107 <native2ascii-def implementation="builtin"/>
108 <assertTranslatedOutput file="umlauts.properties" encoding="ASCII"
109 expected="${umlauts.expected}"/>
110 </target>
111
112 <target name="-setup-ASCII-To-UTF8" depends="-real-test-macros">
113 <mkdir dir="${input}"/>
114 <mkdir dir="${output}"/>
115 <echo file="${input}/umlauts.properties" encoding="ASCII">\u00e4\u00f6\u00fc=\u00c4\u00d6\u00dc</echo>
116 <property name="umlauts.expected" value="äöü=ÄÖÜ"/>
117 </target>
118
119 <target name="testASCII-To-UTF8-sun" depends="-setup-ASCII-To-UTF8"
120 description="https://bz.apache.org/bugzilla/show_bug.cgi?id=59855"
121 unless="jdk9+">
122 <native2ascii-def implementation="sun" reverse="true"/>
123 <assertTranslatedOutput file="umlauts.properties" encoding="UTF-8"
124 expected="${umlauts.expected}"/>
125 </target>
126
127 <target name="testASCII-To-UTF8-builtin" depends="-setup-ASCII-To-UTF8"
128 description="https://bz.apache.org/bugzilla/show_bug.cgi?id=59855">
129 <native2ascii-def implementation="builtin" reverse="true"/>
130 <assertTranslatedOutput file="umlauts.properties" encoding="UTF-8"
131 expected="${umlauts.expected}"/>
132 </target>
133
67134 </project>
6363 <au:assertLogContains text="fileset-test.xml"/>
6464 </target>
6565
66 <target name="test-fileset-dir-and-file-exception">
67 <mkdir dir="${output}"/>
68 <au:expectfailure expectedmessage="you can only specify one of the dir and file attributes">
69 <copy todir="${output}">
70 <fileset dir="foo" file="bar" />
71 </copy>
72 </au:expectfailure>
73 </target>
74
75 <target name="test-fileset-file-and-dir-exception">
76 <mkdir dir="${output}"/>
77 <au:expectfailure expectedmessage="you can only specify one of the dir and file attributes">
78 <copy todir="${output}">
79 <fileset file="bar" dir="foo"/>
80 </copy>
81 </au:expectfailure>
82 </target>
83
6684 </project>
194194 int startMessage = log.indexOf("CLASSPATH element ");
195195 assertTrue(startMessage >= 0);
196196 assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0);
197 log = errBuffer.toString();
198 startMessage = log.indexOf("CLASSPATH element ");
199 assertTrue(startMessage >= 0);
200 assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0);
201197 } finally {
202198 System.setErr(sysErr);
203199 }
2323 import org.apache.tools.ant.BuildException;
2424 import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory;
2525 import org.apache.tools.ant.taskdefs.rmic.DefaultRmicAdapter;
26 import org.apache.tools.ant.util.JavaEnvUtils;
2627 import org.junit.Before;
2728 import org.junit.Ignore;
2829 import org.junit.Rule;
2930 import org.junit.Test;
3031
32 import static org.junit.Assert.assertEquals;
3133 import static org.junit.Assert.fail;
3234
3335 /**
136138 * test weblogic
137139 */
138140 @Test
139 @Ignore("WLRmin tests don't work")
141 @Ignore("WLRmic tests don't work")
140142 public void XtestWlrmic() throws Exception {
141143 buildRule.executeTarget("testWlrmic");
142144 }
145147 * test weblogic's stripping of -J args
146148 */
147149 @Test
148 @Ignore("WLRmin tests don't work")
150 @Ignore("WLRmic tests don't work")
149151 public void XtestWlrmicJArg() throws Exception {
150152 buildRule.executeTarget("testWlrmicJArg");
151153 }
154156 * test the forking compiler
155157 */
156158 @Test
157 @Ignore("WLRmin tests don't work")
158 public void NotestForking() throws Exception {
159 public void testForking() throws Exception {
159160 buildRule.executeTarget("testForking");
160161 }
161162
352353 */
353354 @Test
354355 public void testXnew() throws Exception {
356 // skipped via unless attribute for JDK > 6
355357 buildRule.executeTarget("testXnew");
356358 }
357359
362364 */
363365 @Test
364366 public void testXnewDest() throws Exception {
367 // skipped via unless attribute for JDK > 6
365368 buildRule.executeTarget("testXnewDest");
366369 }
367370
372375 */
373376 @Test
374377 public void testXnewForked() throws Exception {
375 buildRule.executeTarget("testXnewForked");
378 xnewTest("testXnewForked");
376379 }
377380
378381 /**
382385 */
383386 @Test
384387 public void testXnewForkedDest() throws Exception {
385 buildRule.executeTarget("testXnewForkedDest");
388 xnewTest("testXnewForkedDest");
386389 }
387390
388391 /**
392395 */
393396 @Test
394397 public void testXnewCompiler() throws Exception {
395 buildRule.executeTarget("testXnewCompiler");
398 xnewTest("testXnewCompiler");
396399 }
397400
398401 /**
402405 */
403406 @Test
404407 public void testXnewCompilerDest() throws Exception {
405 buildRule.executeTarget("testXnewCompilerDest");
408 xnewTest("testXnewCompilerDest");
406409 }
407410
408411 /**
443446 @Test
444447 public void testIIOPDest() throws Exception {
445448 buildRule.executeTarget("testIIOPDest");
449 }
450
451 private void xnewTest(String target) {
452 if (!JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
453 buildRule.executeTarget(target);
454 } else {
455 try {
456 buildRule.executeTarget(target);
457 fail("Target should have thrown a BuildException");
458 } catch (BuildException ex) {
459 assertEquals("JDK9 has removed support for -Xnew", ex.getMessage());
460 }
461 }
446462 }
447463
448464 /**
296296 }
297297 }
298298
299 @Test
300 public void testRegexpMapper() throws IOException {
301 buildRule.executeTarget("testRegexpMapper1");
302 File testFile = new File(buildRule.getOutputDir(), "regexp.zip");
303 long l = testFile.lastModified();
304 buildRule.executeTarget("testRegexpMapper2");
305 assertEquals(l, testFile.lastModified());
306 }
299307 }
5656 boolean debug) {
5757 return cmd;
5858 }
59
60 public boolean execute() { return false; }
61
62 /**
63 * public to avoid classloader issues.
64 */
65 public Commandline setupModernJavacCommandlineSwitches(Commandline cmd) {
66 return super.setupModernJavacCommandlineSwitches(cmd);
67 }
68 }
69
70 private static class SourceTargetHelperNoOverride extends DefaultCompilerAdapter {
5971
6072 public boolean execute() { return false; }
6173
182194 + " -source 8", "8");
183195 testSource(null, "javac1.9", "", "1.9");
184196 testSource(null, "javac1.9", "", "9");
197 }
198
199 @Test
200 public void testImplicitSourceForJava9() {
201 commonSourceDowngrades("javac9");
202 testSource("1.5", "javac9",
203 "If you specify -target 1.5 you now must also specify"
204 + " -source 1.5", "1.5");
205 testSource("1.6", "javac1.9",
206 "If you specify -target 1.6 you now must also specify"
207 + " -source 1.6", "1.6");
208 testSource("1.7", "javac9",
209 "If you specify -target 1.7 you now must also specify"
210 + " -source 1.7", "1.7");
211 testSource("1.8", "javac9",
212 "If you specify -target 1.8 you now must also specify"
213 + " -source 1.8", "1.8");
214 testSource("5", "javac9",
215 "If you specify -target 5 you now must also specify"
216 + " -source 5", "5");
217 testSource("6", "javac9",
218 "If you specify -target 6 you now must also specify"
219 + " -source 6", "6");
220 testSource("7", "javac9",
221 "If you specify -target 7 you now must also specify"
222 + " -source 7", "7");
223 testSource("8", "javac9",
224 "If you specify -target 8 you now must also specify"
225 + " -source 8", "8");
226 testSource(null, "javac9", "", "1.9");
227 testSource(null, "javac9", "", "9");
185228 }
186229
187230 @Test
217260 Assert.assertNotNull(cmd[0]);
218261 final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline());
219262 //No modulesourcepath
220 assertEquals(-1, cmdLine.indexOf("-modulesourcepath"));
263 assertEquals(-1, cmdLine.indexOf("--module-source-path"));
221264 //The -sourcepath has to be followed by src
222265 int index = cmdLine.indexOf("-sourcepath");
223266 Assert.assertTrue(index != -1 && index < cmdLine.size() - 1);
224267 assertEquals(src.getAbsolutePath(), cmdLine.get(index + 1));
225 //The -modulepath has to be followed by modules
226 index = cmdLine.indexOf("-modulepath");
268 //The --module-path has to be followed by modules
269 index = cmdLine.indexOf("--module-path");
227270 Assert.assertTrue(index != -1 && index < cmdLine.size() - 1);
228271 assertEquals(modules.getAbsolutePath(), cmdLine.get(index + 1));
229272 //J1.java & J2.java has to be in files list
276319 final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline());
277320 //No sourcepath
278321 assertEquals(-1, cmdLine.indexOf("-sourcepath"));
279 //The -modulesourcepath has to be followed by the pattern
280 int index = cmdLine.indexOf("-modulesourcepath");
322 //The --module-source-path has to be followed by the pattern
323 int index = cmdLine.indexOf("--module-source-path");
281324 Assert.assertTrue(index != -1 && index < cmdLine.size() - 1);
282325 String expectedModSrcPath = String.format("%s/%s",
283326 workDir.getAbsolutePath(),
285328 .replace('/', File.separatorChar)
286329 .replace('\\', File.separatorChar);
287330 assertEquals(expectedModSrcPath, cmdLine.get(index + 1));
288 //The -modulepath has to be followed by modules
289 index = cmdLine.indexOf("-modulepath");
331 //The --module-path has to be followed by modules
332 index = cmdLine.indexOf("--module-path");
290333 Assert.assertTrue(index != -1 && index < cmdLine.size() - 1);
291334 assertEquals(modules.getAbsolutePath(), cmdLine.get(index + 1));
292335 //J1.java, J2.java & J3.java has to be in files list
352395 }
353396 }
354397
398 @Test
399 public void releaseIsIgnoredForJava8() {
400 LogCapturingJavac javac = new LogCapturingJavac();
401 Project p = new Project();
402 javac.setProject(p);
403 javac.setCompiler("javac8");
404 javac.setSource("6");
405 javac.setTarget("6");
406 javac.setRelease("6");
407 javac.setSourcepath(new Path(p));
408 SourceTargetHelperNoOverride sth = new SourceTargetHelperNoOverride();
409 sth.setJavac(javac);
410 Commandline cmd = new Commandline();
411 sth.setupModernJavacCommandlineSwitches(cmd);
412 assertContains("Support for javac --release has been added in "
413 + "Java9 ignoring it", javac.getLog());
414 String[] args = cmd.getCommandline();
415 assertEquals(7, args.length);
416 assertEquals("-classpath", args[0]);
417 assertEquals("-target", args[2]);
418 assertEquals("6", args[3]);
419 assertEquals("-g:none", args[4]);
420 assertEquals("-source", args[5]);
421 assertEquals("6", args[6]);
422 }
423
424 @Test
425 public void releaseIsUsedForJava9() {
426 LogCapturingJavac javac = new LogCapturingJavac();
427 Project p = new Project();
428 javac.setProject(p);
429 javac.setCompiler("javac9");
430 javac.setSource("6");
431 javac.setTarget("6");
432 javac.setRelease("6");
433 javac.setSourcepath(new Path(p));
434 SourceTargetHelperNoOverride sth = new SourceTargetHelperNoOverride();
435 sth.setJavac(javac);
436 Commandline cmd = new Commandline();
437 sth.setupModernJavacCommandlineSwitches(cmd);
438 assertContains("Ignoring source, target and bootclasspath as "
439 + "release has been set", javac.getLog());
440 String[] args = cmd.getCommandline();
441 assertEquals(5, args.length);
442 assertEquals("-classpath", args[0]);
443 assertEquals("-g:none", args[2]);
444 assertEquals("--release", args[3]);
445 assertEquals("6", args[4]);
446 }
447
355448 private void commonSourceDowngrades(String javaVersion) {
356449 testSource("1.3", javaVersion,
357450 "If you specify -target 1.1 you now must also specify"
0 package org.apache.tools.ant.taskdefs.optional;
1
2 import static org.junit.Assert.assertTrue;
3
4 import java.io.ByteArrayInputStream;
5 import java.io.File;
6 import java.io.InputStream;
7 import java.security.Permission;
8
9 import junit.framework.AssertionFailedError;
10
11 import org.apache.tools.ant.BuildException;
12 import org.apache.tools.ant.taskdefs.XSLTLiaison;
13 import org.apache.tools.ant.taskdefs.XSLTLogger;
14 import org.apache.tools.ant.util.JAXPUtils;
15 import org.junit.After;
16 import org.junit.Assume;
17 import org.junit.Test;
18
190 /*
201 * Licensed to the Apache Software Foundation (ASF) under one or more
212 * contributor license agreements. See the NOTICE file distributed with
3415 *
3516 */
3617
18 package org.apache.tools.ant.taskdefs.optional;
19
20 import static org.junit.Assert.assertTrue;
21
22 import java.io.ByteArrayInputStream;
23 import java.io.File;
24 import java.io.InputStream;
25 import java.security.Permission;
26 import javax.xml.transform.TransformerFactory;
27 import javax.xml.transform.TransformerFactoryConfigurationError;
28
29 import junit.framework.AssertionFailedError;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.taskdefs.XSLTLiaison;
33 import org.apache.tools.ant.taskdefs.XSLTLogger;
34 import org.apache.tools.ant.util.JAXPUtils;
35 import org.junit.After;
36 import org.junit.Assume;
37 import org.junit.Test;
38
3739 /**
3840 * TraX XSLTLiaison testcase
3941 */
4143 implements XSLTLogger {
4244
4345
44 @After
46 @After
4547 public void tearDown() {
4648 File f = new File("xalan2-redirect-out.tmp");
4749 if (f.exists()) {
5658 }
5759
5860 @Test
59 public void testXalan2Redirect() throws Exception {
60 try {
61 getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect");
62 } catch (Exception exc) {
63 Assume.assumeNoException("xalan redirect is not on the classpath", exc);
64 }
61 public void testXalan2RedirectViaJDKFactory() throws Exception {
62 try {
63 getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect");
64 } catch (Exception exc) {
65 Assume.assumeNoException("xalan redirect is not on the classpath", exc);
66 }
67 try {
68 String factoryName = TransformerFactory.newInstance().getClass().getName();
69 Assume.assumeFalse("TraxFactory is Xalan",
70 "org.apache.xalan.processor.TransformerFactoryImpl"
71 .equals(factoryName));
72 } catch (TransformerFactoryConfigurationError exc) {
73 throw new RuntimeException(exc);
74 }
6575 File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
6676 liaison.setStylesheet(xsl);
77 ((TraXLiaison) liaison)
78 .setFeature("http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions", true);
6779 File out = new File("xalan2-redirect-out-dummy.tmp");
6880 File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
6981 ClassLoader orig = Thread.currentThread().getContextClassLoader();
8597 } finally {
8698 out.delete();
8799 Thread.currentThread().setContextClassLoader(orig);
100 System.setSecurityManager(null);
101 }
102 }
103
104 @Test
105 public void testXalan2RedirectViaXalan() throws Exception {
106 try {
107 getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect");
108 } catch (Exception exc) {
109 Assume.assumeNoException("xalan redirect is not on the classpath", exc);
110 }
111 try {
112 String factoryName = TransformerFactory.newInstance().getClass().getName();
113 Assume.assumeTrue("TraxFactory is " + factoryName + " and not Xalan",
114 "org.apache.xalan.processor.TransformerFactoryImpl"
115 .equals(factoryName));
116 } catch (TransformerFactoryConfigurationError exc) {
117 throw new RuntimeException(exc);
118 }
119 File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
120 liaison.setStylesheet(xsl);
121 File out = new File("xalan2-redirect-out-dummy.tmp");
122 File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
123 try {
124 liaison.addParam("xalan-version", "2");
125 System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
126 liaison.transform(in, out);
127 } finally {
128 out.delete();
88129 System.setSecurityManager(null);
89130 }
90131 }
2222 import static org.apache.tools.ant.AntAssert.assertContains;
2323 import static org.junit.Assert.fail;
2424
25 import java.io.ByteArrayInputStream;
2526 import java.io.File;
2627 import java.io.FileReader;
2728 import java.io.InputStream;
29 import java.io.IOException;
2830 import java.net.URL;
31 import java.security.Permission;
32 import javax.xml.transform.TransformerFactory;
33 import javax.xml.transform.TransformerFactoryConfigurationError;
2934
3035 import org.apache.tools.ant.BuildFileRule;
3136 import org.apache.tools.ant.util.FileUtils;
37 import org.junit.Assume;
3238 import org.junit.Before;
3339 import org.junit.Rule;
3440 import org.junit.Test;
3945 *
4046 */
4147 public class JUnitReportTest {
42
43 @Rule
44 public BuildFileRule buildRule = new BuildFileRule();
45
46 @Before
48
49 @Rule
50 public BuildFileRule buildRule = new BuildFileRule();
51
52 @Before
4753 public void setUp() {
4854 buildRule.configureProject("src/etc/testcases/taskdefs/optional/junitreport.xml");
4955 }
5359 * output is selected via the default.
5460 * Needs reports1 task from junitreport.xml.
5561 */
56 @Test
62 @Test
5763 public void testNoFileJUnitNoFrames() {
5864 buildRule.executeTarget("reports1");
5965 assertFalse("No file junit-noframes.html expected", (new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html").exists()));
60
66
6167 }
6268
6369 public void assertIndexCreated() {
64 if (!new File(buildRule.getProject().getProperty("output"), "html/index.html").exists()) {
65 fail("No file index file found");
66 }
67
68 }
69
70
71 @Test
72 public void testEmptyFile() throws Exception {
73 buildRule.executeTarget("testEmptyFile");
74 assertIndexCreated();
75 assertContains("Required text not found in log", XMLResultAggregator.WARNING_EMPTY_FILE, buildRule.getLog());
76 }
77
78 @Test
79 public void testIncompleteFile() throws Exception {
80 buildRule.executeTarget("testIncompleteFile");
81 assertIndexCreated();
82 assertContains("Required text not found in log", XMLResultAggregator.WARNING_IS_POSSIBLY_CORRUPTED, buildRule.getLog());
83 }
84
85 @Test
86 public void testWrongElement() throws Exception {
87 buildRule.executeTarget("testWrongElement");
88 assertIndexCreated();
89 assertContains("Required text not found in log", XMLResultAggregator.WARNING_INVALID_ROOT_ELEMENT, buildRule.getLog());
90 }
91
92 // Bugzilla Report 34963
93 @Test
94 public void testStackTraceLineBreaks() throws Exception {
95 buildRule.executeTarget("testStackTraceLineBreaks");
96 assertIndexCreated();
97 FileReader r = null;
98 try {
99 r = new FileReader(new File(buildRule.getOutputDir(), "html/sampleproject/coins/0_CoinTest.html"));
100 String report = FileUtils.readFully(r);
101 assertContains("output must contain <br>:\n" + report, "junit.framework.AssertionFailedError: DOEG<br>", report);
102 assertContains("#51049: output must translate line breaks:\n" + report, "cur['line.separator'] = '\\r\\n';", report);
103 } finally {
104 FileUtils.close(r);
105 }
106 }
107
108
109 // Bugzilla Report 38477
110 @Test
111 public void testSpecialSignsInSrcPath() throws Exception {
112 buildRule.executeTarget("testSpecialSignsInSrcPath");
70 try {
71 commonIndexFileAssertions();
72 } catch (IOException ex) {
73 throw new RuntimeException(ex);
74 }
75 }
76
77 private File commonIndexFileAssertions() throws IOException {
11378 File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
79 commonIndexFileAssertions(reportFile);
80 return reportFile;
81 }
82
83 private void commonIndexFileAssertions(File reportFile) throws IOException {
11484 // tests one the file object
11585 assertTrue("No index.html present. Not generated?", reportFile.exists() );
11686 assertTrue("Cant read the report file.", reportFile.canRead() );
11888 // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
11989 URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
12090 InputStream reportStream = reportUrl.openStream();
121 assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
91 try {
92 assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
93 } finally {
94 FileUtils.getFileUtils().close(reportStream);
95 }
96 }
97
98 @Test
99 public void testEmptyFile() throws Exception {
100 buildRule.executeTarget("testEmptyFile");
101 assertIndexCreated();
102 assertContains("Required text not found in log", XMLResultAggregator.WARNING_EMPTY_FILE, buildRule.getLog());
103 }
104
105 @Test
106 public void testIncompleteFile() throws Exception {
107 buildRule.executeTarget("testIncompleteFile");
108 assertIndexCreated();
109 assertContains("Required text not found in log", XMLResultAggregator.WARNING_IS_POSSIBLY_CORRUPTED, buildRule.getLog());
110 }
111
112 @Test
113 public void testWrongElement() throws Exception {
114 buildRule.executeTarget("testWrongElement");
115 assertIndexCreated();
116 assertContains("Required text not found in log", XMLResultAggregator.WARNING_INVALID_ROOT_ELEMENT, buildRule.getLog());
117 }
118
119 // Bugzilla Report 34963
120 @Test
121 public void testStackTraceLineBreaks() throws Exception {
122 buildRule.executeTarget("testStackTraceLineBreaks");
123 assertIndexCreated();
124 FileReader r = null;
125 try {
126 r = new FileReader(new File(buildRule.getOutputDir(), "html/sampleproject/coins/0_CoinTest.html"));
127 String report = FileUtils.readFully(r);
128 assertContains("output must contain <br>:\n" + report, "junit.framework.AssertionFailedError: DOEG<br>", report);
129 assertContains("#51049: output must translate line breaks:\n" + report, "cur['line.separator'] = '\\r\\n';", report);
130 } finally {
131 FileUtils.close(r);
132 }
133 }
134
135
136 // Bugzilla Report 38477
137 @Test
138 public void testSpecialSignsInSrcPath() throws Exception {
139 buildRule.executeTarget("testSpecialSignsInSrcPath");
140 commonIndexFileAssertions();
122141 }
123142
124143 @Test
125144 public void testSpecialSignsInHtmlPath() throws Exception {
126145 buildRule.executeTarget("testSpecialSignsInHtmlPath");
127146 File reportFile = new File(buildRule.getOutputDir(), "html# $%\u00A7&-!report/index.html");
128 // tests one the file object
129 assertTrue("No index.html present. Not generated?", reportFile.exists() );
130 assertTrue("Cant read the report file.", reportFile.canRead() );
131 assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
132 // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
133 URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
134 InputStream reportStream = reportUrl.openStream();
135 assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
147 commonIndexFileAssertions(reportFile);
136148 }
137149
138150 //Bugzilla Report 39708
139151 @Test
140152 public void testWithStyleFromDir() throws Exception {
141153 buildRule.executeTarget("testWithStyleFromDir");
142 File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
143 // tests one the file object
144 assertTrue("No index.html present. Not generated?", reportFile.exists() );
145 assertTrue("Cant read the report file.", reportFile.canRead() );
146 assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
147 // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
148 URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
149 InputStream reportStream = reportUrl.openStream();
150 assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
154 commonIndexFileAssertions();
151155 }
152156
153157 //Bugzilla Report 40021
155159 public void testNoFrames() throws Exception {
156160 buildRule.executeTarget("testNoFrames");
157161 File reportFile = new File(buildRule.getOutputDir(), "html/junit-noframes.html");
158 // tests one the file object
159 assertTrue("No junit-noframes.html present. Not generated?", reportFile.exists() );
160 assertTrue("Cant read the report file.", reportFile.canRead() );
161 assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
162 // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
163 URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
164 InputStream reportStream = reportUrl.openStream();
165 assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
166 }
162 commonIndexFileAssertions(reportFile);
163 }
164
167165 //Bugzilla Report 39708
168166 @Test
169167 public void testWithStyleFromDirAndXslImport() throws Exception {
170168 buildRule.executeTarget("testWithStyleFromDirAndXslImport");
171 File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
172 // tests one the file object
173 assertTrue("No index.html present. Not generated?", reportFile.exists() );
174 assertTrue("Cant read the report file.", reportFile.canRead() );
175 assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
176 // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
177 URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
178 InputStream reportStream = reportUrl.openStream();
179 assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
169 commonIndexFileAssertions();
180170 }
181171
182172 @Test
183173 public void testWithStyleFromClasspath() throws Exception {
184174 buildRule.executeTarget("testWithStyleFromClasspath");
185 File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
186 // tests one the file object
187 assertTrue("No index.html present. Not generated?", reportFile.exists() );
188 assertTrue("Cant read the report file.", reportFile.canRead() );
189 assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
190 // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
191 URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
192 InputStream reportStream = reportUrl.openStream();
193 assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
175 commonIndexFileAssertions();
194176 }
195177
196178 @Test
197179 public void testWithParams() throws Exception {
198 buildRule.executeTarget("testWithParams");
199 assertContains("key1=value1,key2=value2", buildRule.getLog());
200 File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
201 // tests one the file object
202 assertTrue("No index.html present. Not generated?", reportFile.exists() );
203 assertTrue("Cant read the report file.", reportFile.canRead() );
204 assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
205 // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
206 URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
207 InputStream reportStream = reportUrl.openStream();
208 assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
209 }
180 buildRule.executeTarget("testWithParams");
181 assertContains("key1=value1,key2=value2", buildRule.getLog());
182 commonIndexFileAssertions();
183 }
184
185 @Test
186 public void testWithSecurityManagerAndXalanFactory() throws Exception {
187 try {
188 String factoryName = TransformerFactory.newInstance().getClass().getName();
189 Assume.assumeTrue("TraxFactory is " + factoryName + " and not Xalan",
190 "org.apache.xalan.processor.TransformerFactoryImpl"
191 .equals(factoryName));
192 } catch (TransformerFactoryConfigurationError exc) {
193 throw new RuntimeException(exc);
194 }
195 try {
196 System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
197 buildRule.executeTarget("testWithStyleFromClasspath");
198 commonIndexFileAssertions();
199 } finally {
200 System.setSecurityManager(null);
201 }
202 }
203
204 @Test
205 public void testWithSecurityManagerAndJDKFactory() throws Exception {
206 ClassLoader orig = Thread.currentThread().getContextClassLoader();
207 try {
208 Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
209 public InputStream getResourceAsStream(String name) {
210 if (name.startsWith("META-INF/services/")) {
211 // work around JAXP #6723276 in JDK 6
212 return new ByteArrayInputStream(new byte[0]);
213 }
214 return super.getResourceAsStream(name);
215 }
216 });
217 System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
218 buildRule.executeTarget("testWithStyleFromClasspath");
219 commonIndexFileAssertions();
220 } finally {
221 System.setSecurityManager(null);
222 Thread.currentThread().setContextClassLoader(orig);
223 }
224 }
225
210226 }
2626 import static org.apache.tools.ant.AntAssert.assertContains;
2727
2828 import java.io.BufferedReader;
29 import java.io.ByteArrayInputStream;
30 import java.io.ByteArrayOutputStream;
2931 import java.io.File;
3032 import java.io.FileReader;
3133 import java.io.IOException;
34 import java.io.InputStream;
35 import java.io.OutputStream;
36 import java.util.Arrays;
37 import java.util.Collections;
38 import java.util.Set;
39 import java.util.TreeSet;
3240
3341 import javax.xml.parsers.DocumentBuilder;
3442 import javax.xml.parsers.DocumentBuilderFactory;
3543 import javax.xml.xpath.XPath;
3644 import javax.xml.xpath.XPathConstants;
3745 import javax.xml.xpath.XPathFactory;
46 import org.apache.tools.ant.BuildException;
3847
3948 import org.apache.tools.ant.BuildFileRule;
49 import org.apache.tools.ant.MagicNames;
50 import org.apache.tools.ant.Project;
51 import org.apache.tools.ant.taskdefs.launcher.CommandLauncher;
52 import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.ForkMode;
53 import org.apache.tools.ant.types.Path;
4054 import org.apache.tools.ant.util.JavaEnvUtils;
55 import org.apache.tools.ant.util.LoaderUtils;
4156 import org.junit.Assume;
4257 import org.junit.Before;
4358 import org.junit.Rule;
394409
395410 }
396411
412 @Test(expected = BuildException.class)
413 public void testModulePathNeedsFork() throws Exception {
414 final Project project = new Project();
415 project.init();
416 JUnitTask task = new JUnitTask();
417 task.setProject(project);
418 final Path p = new Path(project);
419 p.setPath("modules");
420 task.createModulepath().add(p);
421 task.addTest(new JUnitTest("org.apache.tools.ant.taskdefs.optional.junit.TestTest"));
422 task.execute();
423 }
424
425 @Test(expected = BuildException.class)
426 public void testUpgradeModulePathNeedsFork() throws Exception {
427 final Project project = new Project();
428 project.init();
429 JUnitTask task = new JUnitTask();
430 task.setProject(project);
431 final Path p = new Path(project);
432 p.setPath("modules");
433 task.createUpgrademodulepath().add(p);
434 task.addTest(new JUnitTest("org.apache.tools.ant.taskdefs.optional.junit.TestTest"));
435 task.execute();
436 }
437
438 @Test
439 public void testJunitOnCpArguments() throws Exception {
440 final File tmp = new File(System.getProperty("java.io.tmpdir")); //NOI18N
441 final File workDir = new File(tmp, String.format("%s_testJCP%d", //NOI18N
442 getClass().getName(),
443 System.currentTimeMillis()/1000));
444 workDir.mkdirs();
445 try {
446 final File modulesDir = new File(workDir,"modules"); //NOI18N
447 modulesDir.mkdirs();
448
449 final Project project = new Project();
450 project.init();
451 project.setBaseDir(workDir);
452 final MockCommandLauncher mockProcLauncher = new MockCommandLauncher();
453 project.addReference(
454 MagicNames.ANT_VM_LAUNCHER_REF_ID,
455 mockProcLauncher);
456 JUnitTask task = new JUnitTask();
457 task.setDir(workDir);
458 task.setFork(true);
459 task.setProject(project);
460 final File junit = LoaderUtils.getResourceSource(
461 JUnitTask.class.getClassLoader(),
462 "junit/framework/Test.class"); //NOI18N
463 final Path cp = new Path(project);
464 cp.setPath(junit.getAbsolutePath());
465 task.createClasspath().add(cp);
466 final Path mp = new Path(project);
467 mp.setPath(modulesDir.getName());
468 task.createModulepath().add(mp);
469 task.addTest(new JUnitTest("org.apache.tools.ant.taskdefs.optional.junit.TestTest"));
470 task.execute();
471 assertNotNull(mockProcLauncher.cmd);
472 String resCp = null;
473 String resMp = null;
474 Set<String> resExports = new TreeSet<String>();
475 for (int i = 1; i< mockProcLauncher.cmd.length; i++) {
476 if ("-classpath".equals(mockProcLauncher.cmd[i])) { //NOI18N
477 resCp = mockProcLauncher.cmd[++i];
478 } else if ("--module-path".equals(mockProcLauncher.cmd[i])) { //NOI18N
479 resMp = mockProcLauncher.cmd[++i];
480 } else if (mockProcLauncher.cmd[i].equals("--add-exports")) { //NOI18N
481 resExports.add(mockProcLauncher.cmd[++i]);
482 } else if (JUnitTestRunner.class.getName().equals(mockProcLauncher.cmd[i])) {
483 break;
484 }
485 }
486 assertTrue("No exports", resExports.isEmpty());
487 if (project.getProperty(MagicNames.BUILD_SYSCLASSPATH) == null
488 && System.getProperty(MagicNames.BUILD_SYSCLASSPATH) == null) {
489 assertEquals("Expected classpath", cp.toString(), resCp);
490 }
491 assertEquals("Expected modulepath", mp.toString(), resMp);
492 } finally {
493 delete(workDir);
494 }
495 }
496
497 @Test
498 public void testJunitOnMpArguments() throws Exception {
499 final File tmp = new File(System.getProperty("java.io.tmpdir")); //NOI18N
500 final File workDir = new File(tmp, String.format("%s_testJMP%d", //NOI18N
501 getClass().getName(),
502 System.currentTimeMillis()/1000));
503 workDir.mkdirs();
504 try {
505 final File modulesDir = new File(workDir,"modules"); //NOI18N
506 modulesDir.mkdirs();
507
508 final Project project = new Project();
509 project.init();
510 project.setBaseDir(workDir);
511 final MockCommandLauncher mockProcLauncher = new MockCommandLauncher();
512 project.addReference(
513 MagicNames.ANT_VM_LAUNCHER_REF_ID,
514 mockProcLauncher);
515 JUnitTask task = new JUnitTask();
516 task.setDir(workDir);
517 task.setFork(true);
518 task.setProject(project);
519 final File junit = LoaderUtils.getResourceSource(
520 JUnitTask.class.getClassLoader(),
521 "junit/framework/Test.class"); //NOI18N
522 final Path mp = new Path(project);
523 mp.add(new Path(project, junit.getAbsolutePath()));
524 mp.add(new Path(project, modulesDir.getName()));
525 task.createModulepath().add(mp);
526 task.addTest(new JUnitTest("org.apache.tools.ant.taskdefs.optional.junit.TestTest")); //NOI18N
527 task.execute();
528 assertNotNull(mockProcLauncher.cmd);
529 String resCp = null;
530 String resMp = null;
531 Set<String> resExports = new TreeSet<String>();
532 for (int i = 1; i< mockProcLauncher.cmd.length; i++) {
533 if ("-classpath".equals(mockProcLauncher.cmd[i])) { //NOI18N
534 resCp = mockProcLauncher.cmd[++i];
535 } else if ("--module-path".equals(mockProcLauncher.cmd[i])) { //NOI18N
536 resMp = mockProcLauncher.cmd[++i];
537 } else if (mockProcLauncher.cmd[i].equals("--add-exports")) { //NOI18N
538 resExports.add(mockProcLauncher.cmd[++i]);
539 } else if (JUnitTestRunner.class.getName().equals(mockProcLauncher.cmd[i])) {
540 break;
541 }
542 }
543 assertTrue("No exports", resExports.isEmpty());
544 if (project.getProperty(MagicNames.BUILD_SYSCLASSPATH) == null
545 && System.getProperty(MagicNames.BUILD_SYSCLASSPATH) == null) {
546 assertNull("No classpath", resCp);
547 }
548 assertEquals("Expected modulepath", mp.toString(), resMp);
549 } finally {
550 delete(workDir);
551 }
552 }
553
554 private void delete(File f) {
555 if (f.isDirectory()) {
556 final File[] clds = f.listFiles();
557 if (clds != null) {
558 for (File cld : clds) {
559 delete(cld);
560 }
561 }
562 }
563 f.delete();
564 }
565
566 private static final class MockCommandLauncher extends CommandLauncher {
567 private String[] cmd;
568
569 @Override
570 public Process exec(Project project, String[] cmd, String[] env, File workingDir) throws IOException {
571 this.cmd = new String[cmd.length];
572 System.arraycopy(cmd, 0, this.cmd, 0, cmd.length);
573 return new MockProcess();
574 }
575
576 private static class MockProcess extends Process {
577
578 @Override
579 public OutputStream getOutputStream() {
580 return new ByteArrayOutputStream();
581 }
582
583 @Override
584 public InputStream getInputStream() {
585 return new ByteArrayInputStream(new byte[0]);
586 }
587
588 @Override
589 public InputStream getErrorStream() {
590 return new ByteArrayInputStream(new byte[0]);
591 }
592
593 @Override
594 public int waitFor() throws InterruptedException {
595 return exitValue();
596 }
597
598 @Override
599 public int exitValue() {
600 return 0;
601 }
602
603 @Override
604 public void destroy() {
605 }
606 }
607 }
397608 }
113113 //assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode());
114114 //@fixme as of now does not report the original stacktrace.
115115 //assertTrue(error, error.indexOf("thrown on purpose") != -1);
116 }
117
118 // check that JUnit 4 synthetic AssertionFailedError gets message and cause from AssertionError
119 @Test
120 public void testJUnit4AssertionError(){
121 TestRunner runner = createRunnerForTestMethod(AssertionErrorTest.class,"throwsAssertionError");
122 runner.run();
123
124 AssertionFailedError failure = runner.getFormatter().getFailure();
125 assertEquals("failure message", failure.getMessage());
126
127 Throwable cause = failure.getCause();
128 assertEquals(RuntimeException.class, cause.getClass());
129 assertEquals("cause message", cause.getMessage());
116130 }
117131
118132 protected TestRunner createRunner(Class<?> clazz){
144158
145159 // dummy formatter just to catch the error
146160 private final static class ResultFormatter implements JUnitResultFormatter {
161 private AssertionFailedError failure;
147162 private Throwable error;
148163 public void setSystemOutput(String output){}
149164 public void setSystemError(String output){}
152167 public void setOutput(java.io.OutputStream out){}
153168 public void startTest(junit.framework.Test t) {}
154169 public void endTest(junit.framework.Test test) {}
155 public void addFailure(junit.framework.Test test, AssertionFailedError t) { }
170 public void addFailure(junit.framework.Test test, AssertionFailedError t) {
171 failure = t;
172 }
173 AssertionFailedError getFailure() {
174 return failure;
175 }
156176 public void addError(junit.framework.Test test, Throwable t) {
157177 error = t;
158178 }
212232 throw new NullPointerException("thrown on purpose");
213233 }
214234 }
235
236 public static class AssertionErrorTest {
237 @Test public void throwsAssertionError() {
238 AssertionError assertionError = new AssertionError("failure message");
239 assertionError.initCause(new RuntimeException("cause message"));
240 throw assertionError;
241 }
242 }
215243 }
216244
7272 } catch (BuildException be3) {
7373 assertEquals("Date of this is not a date"
7474 + " Cannot be parsed correctly. It should be in"
75 + " MM/DD/YYYY HH:MM AM_PM format.", be3.getMessage());
75 + " 'MM/dd/yyyy hh:mm a' format.", be3.getMessage());
7676 }
7777
7878 s = new DateSelector();
2727 import static org.junit.Assert.assertEquals;
2828 import static org.junit.Assert.assertFalse;
2929 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assume.assumeTrue;
3031
3132 /**
3233 * TestCase for JavaEnvUtils.
115116 j.startsWith(javaHomeParent));
116117
117118 if ((Os.isFamily("mac") && JavaEnvUtils.getJavaVersionNumber() <= JavaEnvUtils.VERSION_1_6)
118 || JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_9)) {
119 || JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
119120 assertTrue(j+" is normalized and in the JRE dir",
120121 j.startsWith(javaHome));
121122 } else {
135136 assertTrue(
136137 "Current java version is not at least the current java version...",
137138 JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.getJavaVersion()));
138 assertFalse(
139 "In case the current java version is higher than 9.0 definitely a new algorithem will be needed",
140 JavaEnvUtils.isAtLeastJavaVersion("9.0"));
141139 }
142140
141 @Test
142 public void isJavaVersionSupportsBothVersionsOfJava9() {
143 assumeTrue(JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_9));
144 assertTrue("JAVA_1_9 is not considered equal to JAVA_9",
145 JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_9));
146 }
147
143148 }
0 /*
1 * Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.apache.tools.ant.util;
18
19 import org.junit.Test;
20
21 import static org.junit.Assert.assertEquals;
22
23 public class Native2AsciiUtilsTest {
24
25 @Test
26 public void doesntTouchAscii() {
27 StringBuilder sb = new StringBuilder();
28 for (char i = 0; i < 128; i++) {
29 sb.append(i);
30 }
31 assertEquals(sb.toString(), Native2AsciiUtils.native2ascii(sb.toString()));
32 }
33
34 @Test
35 public void escapes() {
36 assertEquals("\\u00e4\\u00f6\\u00fc",
37 Native2AsciiUtils.native2ascii("\u00e4\u00f6\u00fc"));
38 }
39
40 @Test
41 public void pads() {
42 assertEquals("\\u00e4\\u01f6\\u12fc",
43 Native2AsciiUtils.native2ascii("\u00e4\u01f6\u12fc"));
44 }
45
46 @Test
47 public void doesntTouchNonEscapes() {
48 StringBuilder sb = new StringBuilder();
49 for (char i = 0; i < 128; i++) {
50 sb.append(i);
51 }
52 assertEquals(sb.toString(), Native2AsciiUtils.ascii2native(sb.toString()));
53 }
54
55 @Test
56 public void unescapes() {
57 assertEquals("\u00e4\u00f6\u00fc",
58 Native2AsciiUtils.ascii2native("\\u00e4\\u00f6\\u00fc"));
59 }
60
61 @Test
62 public void leavesNonUnicodeBackslashesAlone() {
63 assertEquals("\\abcdef", Native2AsciiUtils.ascii2native("\\abcdef"));
64 assertEquals("\\u012j", Native2AsciiUtils.ascii2native("\\u012j"));
65 }
66
67 @Test
68 public void dealsWithUnfinishedEscapes() {
69 assertEquals("\u00e4", Native2AsciiUtils.ascii2native("\\u00e4"));
70 assertEquals("\\u00e", Native2AsciiUtils.ascii2native("\\u00e"));
71 assertEquals("\\u00", Native2AsciiUtils.ascii2native("\\u00"));
72 assertEquals("\\u0", Native2AsciiUtils.ascii2native("\\u0"));
73 }
74
75 }