--[[ Copyright (c) 2022, Vsevolod Stakhov Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ]]-- local logger = require "rspamd_logger" local lua_util = require "lua_util" local rspamd_util = require "rspamd_util" -- Converts surbl module config to rbl module local function surbl_section_convert(cfg, section) local rbl_section = cfg.rbl.rbls local wl = section.whitelist if section.rules then for name, value in section.rules:pairs() do if rbl_section[name] then logger.warnx(rspamd_config, 'conflicting names in surbl and rbl rules: %s, prefer surbl rule!', name) end local converted = { urls = true, ignore_defaults = true, } if wl then converted.whitelist = wl end for k, v in value:pairs() do local skip = false -- Rename if k == 'suffix' then k = 'rbl' end if k == 'ips' then k = 'returncodes' end if k == 'bits' then k = 'returnbits' end if k == 'noip' then k = 'no_ip' end -- Crappy legacy if k == 'options' then if v == 'noip' or v == 'no_ip' then converted.no_ip = true skip = true end end if k:match('check_') then local n = k:match('check_(.*)') k = n end if k == 'dkim' and v then converted.dkim_domainonly = false converted.dkim_match_from = true end if k == 'emails' and v then -- To match surbl behaviour converted.emails_domainonly = true end if not skip then converted[k] = lua_util.deepcopy(v) end end rbl_section[name] = lua_util.override_defaults(rbl_section[name], converted) end end end -- Converts surbl module config to rbl module local function emails_section_convert(cfg, section) local rbl_section = cfg.rbl.rbls local wl = section.whitelist if section.rules then for name, value in section.rules:pairs() do if rbl_section[name] then logger.warnx(rspamd_config, 'conflicting names in emails and rbl rules: %s, prefer emails rule!', name) end local converted = { emails = true, ignore_defaults = true, } if wl then converted.whitelist = wl end for k, v in value:pairs() do local skip = false -- Rename if k == 'dnsbl' then k = 'rbl' end if k == 'check_replyto' then k = 'replyto' end if k == 'hashlen' then k = 'hash_len' end if k == 'encoding' then k = 'hash_format' end if k == 'domain_only' then k = 'emails_domainonly' end if k == 'delimiter' then k = 'emails_delimiter' end if k == 'skip_body' then skip = true if v then -- Hack converted.emails = false converted.replyto = true else converted.emails = true end end if k == 'expect_ip' then -- Another stupid hack if not converted.return_codes then converted.returncodes = {} end local symbol = value.symbol or name converted.returncodes[symbol] = { v } skip = true end if not skip then converted[k] = lua_util.deepcopy(v) end end rbl_section[name] = lua_util.override_defaults(rbl_section[name], converted) end end end local function group_transform(cfg, k, v) if v:at('name') then k = v:at('name'):unwrap() end local new_group = { symbols = {} } if v:at('enabled') then new_group.enabled = v:at('enabled'):unwrap() end if v:at('disabled') then new_group.disabled = v:at('disabled'):unwrap() end if v.max_score then new_group.max_score = v:at('max_score'):unwrap() end if v:at('symbol') then for sk, sv in v:at('symbol'):pairs() do if sv:at('name') then sk = sv:at('name'):unwrap() sv.name = nil -- Remove field end new_group.symbols[sk] = sv end end if not cfg:at('group') then cfg.group = {} end if cfg:at('group'):at(k) then cfg:at('group')[k] = lua_util.override_defaults(cfg:at('group')[k]:unwrap(), new_group) else cfg:at('group')[k] = new_group end logger.infox("overriding group %s from the legacy metric settings", k) end local function symbol_transform(cfg, k, v) local groups = cfg:at('group') -- first try to find any group where there is a definition of this symbol for gr_n, gr in groups:pairs() do local symbols = gr:at('symbols') if symbols and symbols:at(k) then -- We override group symbol with ungrouped symbol logger.infox("overriding group symbol %s in the group %s", k, gr_n) symbols[k] = lua_util.override_defaults(symbols:at(k):unwrap(), v:unwrap()) return end end -- Now check what Rspamd knows about this symbol local sym = rspamd_config:get_symbol(k) if not sym or not sym.group then -- Otherwise we just use group 'ungrouped' if not groups:at('ungrouped') then groups.ungrouped = { symbols = { [k] = v } } else groups:at('ungrouped'):at('symbols')[k] = v end logger.debugx("adding symbol %s to the group 'ungrouped'", k) end end local function convert_metric(cfg, metric) if metric:type() ~= 'object' then logger.errx('invalid metric definition: %s', metric) return end if metric:at('actions') then local existing_actions = cfg:at('actions') and cfg:at('actions'):unwrap() or {} cfg.actions = lua_util.override_defaults(existing_actions, metric:at('actions'):unwrap()) logger.infox("overriding actions from the legacy metric settings") end if metric:at('unknown_weight') then logger.infox("overriding unknown weight from the legacy metric settings") cfg:at('actions').unknown_weight = metric:at('unknown_weight'):unwrap() end if metric:at('subject') then logger.infox("overriding subject from the legacy metric settings") cfg:at('actions').subject = metric:at('subject'):unwrap() end if metric:at('group') then for k, v in metric:at('group'):pairs() do group_transform(cfg, k, v) end end if metric:at('symbol') then for k, v in metric:at('symbol'):pairs() do symbol_transform(cfg, k, v) end end end -- Checks configuration files for statistics local function check_statistics_sanity() local local_conf = rspamd_paths['LOCAL_CONFDIR'] local local_stat = string.format('%s/local.d/%s', local_conf, 'statistic.conf') local local_bayes = string.format('%s/local.d/%s', local_conf, 'classifier-bayes.conf') if rspamd_util.file_exists(local_stat) and rspamd_util.file_exists(local_bayes) then logger.warnx(rspamd_config, 'conflicting files %s and %s are found: ' .. 'Rspamd classifier configuration might be broken!', local_stat, local_bayes) end end return function(cfg) local ret = false if cfg:at('metric') then local metric = cfg:at('metric') -- There are two things that we can have (old `metric_pairs` logic) -- 1. A metric is a single metric definition like: metric { name = "default", ... } -- 2. A metric is a list of metrics like: metric { "default": ... } if metric:at('actions') or metric:at('name') then convert_metric(cfg, metric) else for _, v in cfg:at('metric'):pairs() do if v:type() == 'object' then logger.infox('converting metric element %s', v) convert_metric(cfg, v) end end end ret = true end if cfg:at('symbols') then for k, v in cfg:at('symbols'):pairs() do symbol_transform(cfg, k, v) end end check_statistics_sanity() if not cfg:at('actions') then logger.errx('no actions defined') else -- Perform sanity check for actions local actions_defs = { 'no action', 'no_action', -- In case if that's added 'greylist', 'add header', 'add_header', 'rewrite subject', 'rewrite_subject', 'quarantine', 'reject', 'discard' } local actions = cfg:at('actions') if not actions:at('no action') and not actions:at('no_action') and not actions:at('accept') then for _, d in ipairs(actions_defs) do if actions:at(d) then local action_score local act = actions:at(d) if act:type() ~= 'object' then action_score = act:unwrap() elseif act:type() == 'object' and act:at('score') then action_score = act:at('score'):unwrap() end if act:type() ~= 'object' and not action_score then actions[d] = nil elseif type(action_score) == 'number' and action_score < 0 then actions['no_action'] = actions:at(d):unwrap() - 0.001 logger.infox(rspamd_config, 'set no_action score to: %s, as action %s has negative score', actions:at('no_action'):unwrap(), d) break end end end end local actions_set = lua_util.list_to_hash(actions_defs) -- Now check actions section for garbage actions_set['unknown_weight'] = true actions_set['grow_factor'] = true actions_set['subject'] = true for k, _ in cfg:at('actions'):pairs() do if not actions_set[k] then logger.warnx(rspamd_config, 'unknown element in actions section: %s', k) end end -- Performs thresholds sanity -- We exclude greylist here as it can be set to whatever threshold in practice local actions_order = { 'no_action', 'add_header', 'rewrite_subject', 'quarantine', 'reject', 'discard' } for i = 1, (#actions_order - 1) do local act = actions_order[i] if actions:at(act) and actions:at(act):type() ~= 'object' then local score = actions:at(act):unwrap() for j = i + 1, #actions_order do local next_act = actions_order[j] if actions:at(next_act) and actions:at(next_act):type() == 'number' then local next_score = actions:at(next_act):unwrap() if next_score <= score then logger.errx(rspamd_config, 'invalid actions thresholds order: action %s (%s) must have lower ' .. 'score than action %s (%s)', act, score, next_act, next_score) ret = false end end end end end end -- DKIM signing/ARC legacy for _, mod in ipairs({ 'dkim_signing', 'arc' }) do if cfg:at(mod) then if cfg:at(mod):at('auth_only') then if cfg:at(mod):at('sign_authenticated') then logger.warnx(rspamd_config, 'both auth_only (%s) and sign_authenticated (%s) for %s are specified, prefer auth_only', cfg:at(mod):at('auth_only'):unwrap(), cfg:at(mod):at('sign_authenticated'):unwrap(), mod) end cfg:at(mod).sign_authenticated = cfg:at(mod):at('auth_only') end end end -- Deal with dkim settings if not cfg.dkim then cfg.dkim = {} else if cfg.dkim.sign_condition then -- We have an obsoleted sign condition, so we need to either add dkim_signing and move it -- there or just move sign condition there... if not cfg.dkim_signing then logger.warnx('obsoleted DKIM signing method used, converting it to "dkim_signing" module') cfg.dkim_signing = { sign_condition = cfg.dkim.sign_condition } else if not cfg.dkim_signing.sign_condition then logger.warnx('obsoleted DKIM signing method used, move it to "dkim_signing" module') cfg.dkim_signing.sign_condition = cfg.dkim.sign_condition else logger.warnx('obsoleted DKIM signing method used, ignore it as "dkim_signing" also defines condition!') end end end end -- Try to find some obvious issues with configuration for k, v in cfg:pairs() do if v:type() == 'object' and v:at(k) and v:at(k):type() == 'object' then logger.errx('nested section: %s { %s { ... } }, it is likely a configuration error', k, k) end end -- If neural network is enabled we MUST have `check_all_filters` flag if cfg:at('neural') then if cfg:at('options') then if not cfg:at('options'):at('check_all_filters') then logger.infox(rspamd_config, 'enable `options.check_all_filters` for neural network') cfg:at('options')['check_all_filters'] = true end end end if cfg.surbl then if not cfg.rbl then cfg.rbl = { rbls = {} } end if not cfg.rbl.rbls then cfg.rbl.rbls = {} end surbl_section_convert(cfg, cfg.surbl) logger.infox(rspamd_config, 'converted surbl rules to rbl rules') cfg.surbl = nil end if cfg.emails then if not cfg.rbl then cfg.rbl = { rbls = {} } end if not cfg.rbl.rbls then cfg.rbl.rbls = {} end emails_section_convert(cfg, cfg.emails) logger.infox(rspamd_config, 'converted emails rules to rbl rules') cfg.emails = nil end -- Common misprint options.upstreams -> options.upstream if type(cfg.options) == 'table' and type(cfg.options.upstreams) == 'table' and not cfg.options.upstream then cfg.options.upstream = cfg.options.upstreams end return ret, cfg end /a> 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516
<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- ===========================================================================

                           * ================== *
                           |  FOP build system  |
                           * ================== *

Building instructions
=====================

First, install Ant (http://ant.apache.org). Check that ant or ant.bat
is in your search path and that JAVA_HOME and ANT_HOME are properly set.
Next make sure your current working directory is where this very file is
located. Then type

  ant

If everything is right and all the required packages are visible, this action
will generate a file called "fop.jar" in the "./build" directory.

If you experience any problems with the build please visit the FOP website for
more information: http://xmlgraphics.apache.org/fop


Build targets
=============

The build system is not only responsible for compiling Fop into a jar file,
but is also responsible for creating the javadocs, distributions, examples
and a miscellaneous stuff. In fact, the file you have here is _exactly_ what
is used by fop maintainers to take care of nearly everything in the Fop
project, no less and no more.

Call the Ant (see above) with the parameter "-projecthelp" to get a
list of possible build targets.

============================================================================ -->
<project default="all" basedir="." name="fop">

  <!-- See build.properties and build-local.properties for overriding build settings. -->
  <!-- build-local.properties is not stored in SVN and overrides values from build.properties -->
  <property file="${basedir}/build-local.properties"/>
  <property file="${basedir}/build.properties"/>
  <property environment="env"/>

  <property name="optional.lib.dir" value="${basedir}/lib"/>

  <fileset dir="${basedir}" id="dist.bin">
    <include name="conf/**"/>
    <include name="examples/**"/>
    <include name="LICENSE"/>
    <include name="NOTICE"/>
    <include name="README"/>
    <include name="KEYS"/>
    <include name="status.xml"/>
    <include name="fop.bat"/>
    <include name="fop"/>
  </fileset>

  <fileset dir="${basedir}" id="dist.bin.lib">
    <patternset id="dist.lib">
      <include name="lib/avalon-framework*"/>
      <include name="lib/xmlgraphics-commons*"/>
      <include name="lib/batik*"/>
      <include name="lib/commons-io*"/>
      <include name="lib/commons-logging*"/>
      <include name="lib/README*"/>
      <include name="lib/serializer*"/>
      <include name="lib/xalan*"/>
      <include name="lib/xerces*"/>
      <include name="lib/xml-apis*"/>
    </patternset>
  </fileset>

  <fileset dir="${basedir}" id="dist.src">
    <include name="src/**"/>
    <include name="conf/**"/>
    <include name="hyph/hyphenation.dtd"/>
    <include name="hyph/readme"/>
    <patternset refid="dist.lib"/>
    <include name="lib/servlet*"/>
    <include name="test/**"/>
    <include name="examples/**"/>
    <include name="LICENSE"/>
    <include name="NOTICE"/>
    <include name="README"/>
    <include name="KEYS"/>
    <include name="known-issues.xml"/>
    <include name="status.xml"/>
    <include name="build.*"/>
    <include name="forrest.properties"/>
    <include name="fop.bat"/>
    <include name="fop"/>
  </fileset>

  <path id="libs-build-classpath">
    <fileset dir="${basedir}/lib">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${optional.lib.dir}">
      <include name="*.jar"/>
    </fileset>
  </path>

  <path id="libs-build-tools-classpath">
    <path refid="libs-build-classpath"/>
    <fileset dir="${basedir}/lib/build">
      <include name="*.jar"/>
    </fileset>
  </path>
  
  <path id="libs-run-classpath">
    <path refid="libs-build-classpath"/>
    <fileset dir="${basedir}/build">
      <include name="fop.jar"/>
      <include name="fop-hyph.jar" />
    </fileset>
  </path>

  <patternset id="exclude-jai">
    <exclude name="org/apache/fop/image/JAIImage.java" unless="jai.present"/>
    <exclude name="org/apache/fop/render/pcl/JAIMonochromeBitmapConverter.java" unless="jai.present"/>
  </patternset>

  <patternset id="exclude-jce-dependencies">
    <exclude name="org/apache/fop/pdf/PDFEncryptionJCE.java" unless="jce.present"/>
  </patternset>

  <property name="Name" value="Apache FOP"/>
  <property name="name" value="fop"/>
  <property name="NAME" value="FOP"/>
  <property name="version" value="svn-trunk"/>
  <property name="year" value="1999-2008"/>

  <property name="javac.debug" value="on"/>
  <property name="javac.optimize" value="off"/>
  <property name="javac.deprecation" value="on"/>
  <property name="javac.source" value="1.4"/>
  <property name="javac.target" value="1.4"/>
  <property name="javac.fork" value="no"/>

  <property name="junit.fork" value="on"/>
  <property name="junit.haltonfailure" value="off"/>

  <property name="javadoc.packages" value="org.apache.fop.*"/>
  
  <property name="src.dir" value="${basedir}/src"/>
  <property name="src.codegen.dir" value="${src.dir}/codegen"/>
  <property name="src.codegen.fonts.dir" value="${src.codegen.dir}/fonts"/>
  <property name="src.java.dir" value="${src.dir}/java"/>
  <property name="src.sandbox.dir" value="${src.dir}/sandbox"/>
  <property name="src.viewer.resources.dir" value="${src.java.dir}/org/apache/fop/render/awt/viewer/resources"/>
  <property name="src.viewer.images.dir" value="${src.java.dir}/org/apache/fop/render/awt/viewer/images"/>
  <property name="xdocs.dir" value="${src.dir}/documentation/content/xdocs"/>
  <property name="fo.examples.dir" value="${basedir}/examples/fo/basic"/>
  <property name="fo.examples.userconfig" value="conf/fop.xconf"/>
  <property name="fo.examples.include" value="**/*.fo"/>
  <property name="fo.examples.force" value="false"/>
  <property name="lib.dir" value="${basedir}/lib"/>
  <property name="user.hyph.dir" value="${basedir}/hyph"/>

  <property name="build.dir" value="${basedir}/build"/>
  <property name="build.gensrc.dir" value="${build.dir}/gensrc"/>
  <property name="build.classes.dir" value="${build.dir}/classes"/>
  <property name="build.sandbox-classes.dir" value="${build.dir}/sandbox-classes"/>
  <property name="build.codegen-classes.dir" value="${build.dir}/codegen-classes"/>
  <property name="build.javadocs.dir" value="${build.dir}/javadocs"/>
  <property name="build.examples.dir" value="${build.dir}/examples"/>

  <property name="build.viewer.resources.dir" value="${build.classes.dir}/org/apache/fop/render/awt/viewer/resources"/>
  <property name="build.viewer.images.dir" value="${build.classes.dir}/org/apache/fop/render/awt/viewer/images"/>

  <property name="build.property.examples.mime.type" value="application/pdf"/>

  <!--property name="layoutengine.disabled" value="test/layoutengine/disabled-testcases.txt"/-->
  <!--property name="fotree.disabled" value="test/fotree/disabled-testcases.txt"/-->
  <property name="layoutengine.disabled" value="test/layoutengine/disabled-testcases.xml"/>
  <property name="fotree.disabled" value="test/fotree/disabled-testcases.xml"/>

  <property name="dist.bin.dir" value="${basedir}/dist-bin"/>
  <property name="dist.src.dir" value="${basedir}/dist-src"/>
  <property name="dist.bin.result.dir" value="${dist.bin.dir}/${name}-${version}"/>
  <property name="dist.src.result.dir" value="${dist.src.dir}/${name}-${version}"/>
  <property name="samedir" value="${basedir}"/>
  
  <property name="junit.reports.dir" value="${build.dir}/test-reports"/>
  <property name="junit.html.reports.dir" value="${build.dir}/test-reports/html"/>

  <!-- Importing Apache Forrest for building the docs -->
  <!--
  <property environment="env"/>
  <property name="forrest.home" value="${env.FORREST_HOME}"/>
  <import file="${env.FORREST_HOME}/main/forrest.build.xml" optional="true"/>
  -->

  <!-- =================================================================== -->
  <!-- Initialization target                                               -->
  <!-- =================================================================== -->
  <target name="init" depends="init-avail">
  </target>

  <target name="init-avail">
    <echo message="------------------- ${Name} ${version} [${year}] ----------------"/>
    <echo message="See build.properties and build-local.properties for additional build settings"/>
    <echo message="${ant.version}"/>
    <echo message="VM: ${java.vm.version}, ${java.vm.vendor}"/>
    <echo message="JAVA_HOME: ${env.JAVA_HOME}"/>

    <available property="jai.present" classname="javax.media.jai.JAI"
        classpathref="libs-build-classpath"/>
    <condition property="jai.message" value="JAI Support PRESENT">
      <equals arg1="${jai.present}" arg2="true"/>
    </condition>
    <condition property="jai.message" value="JAI Support NOT Present">
      <not>
        <equals arg1="${jai.present}" arg2="true"/>
      </not>
    </condition>
    <echo message="${jai.message}"/>

    <available property="jce.present" classname="javax.crypto.Cipher"
        classpathref="libs-build-classpath"/>
    <condition property="jce.message" value="JCE Support PRESENT">
      <equals arg1="${jce.present}" arg2="true"/>
    </condition>
    <condition property="jce.message" value="JCE Support NOT Present">
      <not>
        <equals arg1="${jce.present}" arg2="true"/>
      </not>
    </condition>
    <echo message="${jce.message}"/>

    <available property="jdk14.present" classname="java.lang.CharSequence"/>
    <fail message="${Name} requires at least Java 1.4!" unless="jdk14.present"/>
    
    <available property="junit.present" classname="junit.framework.TestCase"
        classpathref="libs-build-classpath"/>
    <condition property="junit.message" value="JUnit Support PRESENT">
      <equals arg1="${junit.present}" arg2="true"/>
    </condition>
    <condition property="junit.message" value="JUnit Support NOT Present - Committers are required to have JUnit working">
      <not>
        <equals arg1="${junit.present}" arg2="true"/>
      </not>
    </condition>
    <echo message="${junit.message}"/>

    <condition property="xmlunit.present">
      <and>
        <available classname="org.custommonkey.xmlunit.XMLTestCase" classpathref="libs-build-classpath"/>
        <isset property="junit.present"/>
      </and>
    </condition>
    <condition property="xmlunit.message" value="XMLUnit Support PRESENT">
      <equals arg1="${xmlunit.present}" arg2="true"/>
    </condition>
    <condition property="xmlunit.message" value="XMLUnit Support NOT Present - you can get it from http://xmlunit.sourceforge.net">
      <not>
        <equals arg1="${xmlunit.present}" arg2="true"/>
      </not>
    </condition>
    <echo message="${xmlunit.message}"/>
   
  </target>

  <!-- =================================================================== -->
  <!-- Help on usage                                                       -->
  <!-- =================================================================== -->
  <target name="usage">
    <echo message="Use the -projecthelp option instead"/>
  </target>

  <!-- =================================================================== -->
  <!-- Generate the source code                                            -->
  <!-- =================================================================== -->
  <target name="codegen" depends="init" description="Generates the java files from the xml resources">
    <echo message="Generating the java files from xml resources"/>
    <mkdir dir="${build.gensrc.dir}"/>
    <mkdir dir="${build.gensrc.dir}/org/apache/fop/fonts/base14"/>

    <xslt in="${src.codegen.fonts.dir}/encodings.xml"
           style="${src.codegen.fonts.dir}/code-point-mapping.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/CodePointMapping.java"/>
    <!-- Task unrolled because of a bug in Xalan included in some
         JDK 1.4 releases
    <xslt basedir="src/codegen" includes="Helvetica*.xml,Times*.xml,Courier*.xml"
        style="${src.codegen.fonts.dir}/font-file.xsl"
        destdir="${build.gensrc.dir}/org/apache/fop/fonts/base14" extension=".java">
        <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    -->
    <xslt in="${src.codegen.fonts.dir}/Courier.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/Courier.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/CourierOblique.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/CourierOblique.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/CourierBold.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/CourierBold.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/CourierBoldOblique.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/CourierBoldOblique.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/Helvetica.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        destdir="${build.gensrc.dir}/org/apache/fop/fonts/base14"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/Helvetica.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/HelveticaBold.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/HelveticaBold.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/HelveticaOblique.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/HelveticaOblique.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/HelveticaBoldOblique.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/HelveticaBoldOblique.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/TimesRoman.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/TimesRoman.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/TimesItalic.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/TimesItalic.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/TimesBold.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/TimesBold.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/TimesBoldItalic.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/TimesBoldItalic.java">
      <param name="encoding" expression="WinAnsiEncoding"/>
    </xslt>
    <xslt in="${src.codegen.fonts.dir}/Symbol.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/Symbol.java"/>
    <xslt in="${src.codegen.fonts.dir}/ZapfDingbats.xml" style="${src.codegen.fonts.dir}/font-file.xsl"
        out="${build.gensrc.dir}/org/apache/fop/fonts/base14/ZapfDingbats.java"/>

  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source directory                                       -->
  <!-- =================================================================== -->
  <target name="compile-java" depends="init, codegen">
    <!-- create directories -->
    <mkdir dir="${build.classes.dir}"/>
    <javac destdir="${build.classes.dir}" fork="${javac.fork}" debug="${javac.debug}"
           deprecation="${javac.deprecation}" optimize="${javac.optimize}"
           source="${javac.source}" target="${javac.target}">
      <src path="${build.gensrc.dir}"/>
      <src path="${src.java.dir}"/>
      <patternset includes="**/*.java"/>
      <patternset refid="exclude-jce-dependencies"/>
      <patternset refid="exclude-jai"/>
      <classpath refid="libs-build-classpath"/>
    </javac>

    <mkdir dir="${build.sandbox-classes.dir}"/>
    <javac destdir="${build.sandbox-classes.dir}" fork="${javac.fork}" debug="${javac.debug}"
           deprecation="${javac.deprecation}" optimize="${javac.optimize}"
           source="${javac.source}" target="${javac.target}">
      <src path="${src.sandbox.dir}"/>
      <patternset includes="**/*.java"/>
      <patternset refid="exclude-jai"/>
      <classpath>
        <path refid="libs-build-classpath"/>
        <pathelement location="${build.classes.dir}"/>
      </classpath>
    </javac>
  </target>

  <target name="resourcegen" depends="compile-java">
    <mkdir dir="${build.codegen-classes.dir}"/>
    <javac destdir="${build.codegen-classes.dir}" fork="${javac.fork}" debug="${javac.debug}"
      deprecation="${javac.deprecation}" optimize="${javac.optimize}"
      source="${javac.source}" target="${javac.target}">
      <src path="${src.codegen.dir}/java"/>
      <patternset includes="**/*.java"/>
      <classpath>
        <path refid="libs-build-tools-classpath"/>
        <pathelement location="${build.classes.dir}"/>
      </classpath>
    </javac>
    <copy todir="${build.codegen-classes.dir}">
      <fileset dir="${src.codegen.dir}/java">
        <include name="**/*.xsl"/>
      </fileset>
    </copy>
    
    <taskdef name="eventResourceGenerator"
      classname="org.apache.fop.tools.EventProducerCollectorTask">
      <classpath>
        <path refid="libs-build-tools-classpath"/>
        <pathelement location="${build.classes.dir}"/>
        <pathelement location="${build.codegen-classes.dir}"/>
      </classpath>
    </taskdef>
  
    <eventResourceGenerator
        modelfile="${build.gensrc.dir}/org/apache/fop/events/event-model.xml"
        translationfile="${src.java.dir}/org/apache/fop/events/EventFormatter.xml">
      <fileset dir="${src.java.dir}">
        <include name="**/*.java"/>
        <exclude name="org/apache/fop/render/*/**/*.java"/>
      </fileset>
    </eventResourceGenerator>
    <fixcrlf file="${src.java.dir}/org/apache/fop/events/EventFormatter.xml" tab="remove" tablength="2"/>
    <eventResourceGenerator
      modelfile="${build.gensrc.dir}/org/apache/fop/render/afp/event-model.xml"
      translationfile="${src.java.dir}/org/apache/fop/render/afp/AFPEventProducer.xml">
      <fileset dir="${src.java.dir}">
        <include name="org/apache/fop/render/afp/**/*.java"/>
      </fileset>
    </eventResourceGenerator>
    <fixcrlf file="${src.java.dir}/org/apache/fop/render/afp/AFPEventProducer.xml" tab="remove" tablength="2"/>
    <eventResourceGenerator
      modelfile="${build.gensrc.dir}/org/apache/fop/render/bitmap/event-model.xml"
      translationfile="${src.java.dir}/org/apache/fop/render/bitmap/BitmapRendererEventProducer.xml">
      <fileset dir="${src.java.dir}">
        <include name="org/apache/fop/render/bitmap/**/*.java"/>
      </fileset>
    </eventResourceGenerator>
    <fixcrlf file="${src.java.dir}/org/apache/fop/render/bitmap/BitmapRendererEventProducer.xml" tab="remove" tablength="2"/>
    <eventResourceGenerator
      modelfile="${build.gensrc.dir}/org/apache/fop/render/pcl/event-model.xml"
      translationfile="${src.java.dir}/org/apache/fop/render/pcl/PCLEventProducer.xml">
      <fileset dir="${src.java.dir}">
        <include name="org/apache/fop/render/pcl/**/*.java"/>
      </fileset>
    </eventResourceGenerator>
    <fixcrlf file="${src.java.dir}/org/apache/fop/render/pcl/PCLEventProducer.xml" tab="remove" tablength="2"/>
    <eventResourceGenerator
      modelfile="${build.gensrc.dir}/org/apache/fop/render/pdf/event-model.xml"
      translationfile="${src.java.dir}/org/apache/fop/render/pdf/PDFEventProducer.xml">
      <fileset dir="${src.java.dir}">
        <include name="org/apache/fop/render/pdf/**/*.java"/>
      </fileset>
    </eventResourceGenerator>
    <fixcrlf file="${src.java.dir}/org/apache/fop/render/pdf/PDFEventProducer.xml" tab="remove" tablength="2"/>
    <eventResourceGenerator
      modelfile="${build.gensrc.dir}/org/apache/fop/render/ps/event-model.xml"
      translationfile="${src.java.dir}/org/apache/fop/render/ps/PSEventProducer.xml">
      <fileset dir="${src.java.dir}">
        <include name="org/apache/fop/render/ps/**/*.java"/>
      </fileset>
    </eventResourceGenerator>
    <fixcrlf file="${src.java.dir}/org/apache/fop/render/ps/PSEventProducer.xml" tab="remove" tablength="2"/>
    <eventResourceGenerator
      modelfile="${build.gensrc.dir}/org/apache/fop/render/rtf/event-model.xml"
      translationfile="${src.java.dir}/org/apache/fop/render/rtf/RTFEventProducer.xml">
      <fileset dir="${src.java.dir}">
        <include name="org/apache/fop/render/rtf/**/*.java"/>
      </fileset>
    </eventResourceGenerator>
    <fixcrlf file="${src.java.dir}/org/apache/fop/render/rtf/RTFEventProducer.xml" tab="remove" tablength="2"/>
  </target>
  
  <target name="compile-copy-resources" depends="resourcegen">
    <copy todir="${build.classes.dir}">
      <fileset dir="${src.java.dir}">
        <include name="META-INF/**"/>
        <include name="**/*.icm"/>
        <include name="**/*.xml"/>
        <include name="**/*.LICENSE.txt"/>
      </fileset>
      <fileset dir="${build.gensrc.dir}">
        <include name="**/*.xml"/>
      </fileset>
    </copy>
    <mkdir dir="${build.viewer.resources.dir}"/>
    <copy todir="${build.viewer.resources.dir}">
      <fileset dir="${src.viewer.resources.dir}"/>
    </copy>
    <mkdir dir="${build.viewer.images.dir}"/>
    <copy todir="${build.viewer.images.dir}">
      <fileset dir="${src.viewer.images.dir}"/>
    </copy>
    
    <!-- sandbox -->
    <copy todir="${build.sandbox-classes.dir}">
      <fileset dir="${src.sandbox.dir}">
        <include name="META-INF/**"/>
      </fileset>
    </copy>
    
  </target>
  
  <target name="compile" depends="compile-java, compile-copy-resources" description="Compiles the source code"/>

  <!-- =================================================================== -->
  <!-- compiles hyphenation patterns                                       -->
  <!-- =================================================================== -->
  <target name="compile-hyphenation" depends="compile">
    <path id="hyph-classpath">
      <path refid="libs-build-classpath"/>
      <pathelement location="${build.classes.dir}"/>
    </path>
    <taskdef name="serHyph" classname="org.apache.fop.tools.anttasks.SerializeHyphPattern" classpathref="hyph-classpath"/>
    <mkdir dir="${build.classes.dir}/hyph"/>
    <serHyph targetDir="${build.classes.dir}/hyph">
      <fileset dir="${user.hyph.dir}">
        <include name="*.xml"/>
      </fileset>
    </serHyph>
  </target>

  <target name="uptodate-jar-hyphenation" depends="compile-hyphenation">
    <uptodate property="jar.hyphenation.uptodate" targetfile="${build.dir}/fop-hyph.jar">
      <srcfiles dir="${build.classes.dir}/hyph"/>
    </uptodate>
  </target>

  <target name="jar-hyphenation" depends="compile-hyphenation,uptodate-jar-hyphenation" description="Generates the hyphenation jar file" unless="jar.hyphenation.uptodate">
    <tstamp>
      <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
    </tstamp>
    <jar jarfile="${build.dir}/fop-hyph.jar" basedir="${build.classes.dir}" includes="hyph/*.hyp">
      <manifest>
        <attribute name="Implementation-Title" value="${Name}"/>
        <attribute name="Implementation-Version" value="${version}"/>
        <attribute name="Implementation-Vendor" value="The Apache Software Foundation (http://xmlgraphics.apache.org/fop/)"/>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
    </jar>
  </target>

  <!-- =================================================================== -->
  <!-- main FOP JARs                                                       -->
  <!-- =================================================================== -->

  <target name="uptodate-jar-main" depends="compile">
    <uptodate property="jar.main.uptodate" targetfile="${build.dir}/fop.jar">
      <srcfiles dir= "${build.classes.dir}"/>
    </uptodate>
  </target>

  <target name="jar-main" depends="compile,uptodate-jar-main" description="Generates the main jar file" unless="jar.main.uptodate">
    <tstamp>
      <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
    </tstamp>
    
    <pathconvert property="manifest.classpath" dirsep="/" pathsep=" " refid="libs-build-classpath">
      <map from="${basedir}${file.separator}lib${file.separator}" to=""/>
      <map from="${optional.lib.dir}${file.separator}" to=""/>
    </pathconvert>

    <jar jarfile="${build.dir}/fop.jar" basedir="${build.classes.dir}">
      <manifest>
        <attribute name="Main-Class" value="org.apache.fop.cli.Main"/>
        <attribute name="Class-Path" value="${manifest.classpath}"/>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
        <section name="org/apache/fop/">
          <attribute name="Specification-Title" value="XSL-FO - Extensible Stylesheet Language"/>
          <attribute name="Specification-Version" value="1.0"/>
          <attribute name="Specification-Vendor" value="World Wide Web Consortium"/>
          <attribute name="Specification-URL" value="http://www.w3.org/TR/xsl"/>
          <attribute name="Implementation-Title" value="${Name}"/>
          <attribute name="Implementation-Version" value="${version}"/>
          <attribute name="Implementation-Vendor" value="The Apache Software Foundation (http://xmlgraphics.apache.org/fop/)"/>
        </section>
      </manifest>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
  </target>

  <target name="uptodate-jar-sandbox" depends="compile">
    <uptodate property="jar.sandbox.uptodate" targetfile="${build.dir}/fop-sandbox.jar">
      <srcfiles dir= "${build.sandbox-classes.dir}"/>
    </uptodate>
  </target>

  <target name="jar-sandbox" depends="compile,uptodate-jar-sandbox" description="Generates the sandbox jar file" unless="jar.sandbox.uptodate">
    <tstamp>
      <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
    </tstamp>
    <jar jarfile="${build.dir}/fop-sandbox.jar" basedir="${build.sandbox-classes.dir}">
      <manifest>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
  </target>

  <target name="uptodate-jar-sources" depends="codegen">
    <uptodate property="jar.sources.uptodate" targetfile="${build.dir}/fop-sources.jar">
      <srcfiles dir="${build.gensrc.dir}"/>
      <srcfiles dir="${src.java.dir}"/>
    </uptodate>
  </target>

  <target name="jar-sources" depends="codegen" description="Generates a jar file with all the sources" unless="jar.sources.uptodate">
    <tstamp>
      <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
    </tstamp>
    <patternset id="java-only">
      <include name="**/*.java"/>
    </patternset>
    <jar jarfile="${build.dir}/${name}-${version}-sources.jar">
      <fileset dir="${build.gensrc.dir}">
        <patternset refid="java-only"/>
      </fileset>
      <fileset dir="${src.java.dir}">
        <patternset refid="java-only"/>
      </fileset>
      <fileset dir="${src.java.version.dir}">
        <patternset refid="java-only"/>
      </fileset>
      <fileset dir="${basedir}">
        <include name="LICENSE"/>
        <include name="NOTICE"/>
      </fileset>
    </jar>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the class package                                           -->
  <!-- =================================================================== -->
  <target name="package" depends="jar-main,jar-hyphenation,jar-sandbox" description="Generates the jar files"/>
  
  <target name="servlet" depends="package" description="Generates the WAR with the sample FOP servlet">
    <echo message="Creating the WAR file"/>
    <war warfile="${build.dir}/fop.war" webxml="${src.dir}/conf/web.xml">
      <lib dir="${lib.dir}">
        <include name="avalon-framework*.jar"/>
        <include name="commons-logging*.jar"/>
        <include name="batik*.jar"/>
        <include name="commons-io*.jar"/>
        <include name="xmlgraphics*.jar"/>
      </lib>
      <lib dir="${build.dir}">
        <include name="fop.jar"/>
      </lib>
    </war>
  </target>

  <patternset id="transcoder-classes">
    <!-- General classes -->
    <patternset>
      <include name="org/apache/fop/Version.class"/>
      <include name="org/apache/fop/apps/Fop.class"/>
      <include name="org/apache/fop/apps/FOPException.class"/>
      <include name="org/apache/fop/fo/Constants.class"/>
      <include name="org/apache/fop/fo/FOTreeBuilder.class"/>
      <include name="org/apache/fop/area/AreaTreeControl*"/>
      <include name="org/apache/fop/svg/**"/>
      <include name="org/apache/fop/fonts/**"/>
      <include name="org/apache/fop/image/FopImag*.class"/>
      <include name="org/apache/fop/image/Jpeg*"/>
      <include name="org/apache/fop/image/EPS*"/>
      <include name="org/apache/fop/image/Abstract*"/>
      <include name="org/apache/fop/image/analyser/*.class"/>
      <include name="org/apache/fop/util/CMYKColorSpace*.class"/>
      <include name="org/apache/fop/util/Color*.class"/>
      <include name="org/apache/fop/util/ASCII*.class"/>
      <include name="org/apache/fop/util/*OutputStream.class"/>
      <include name="org/apache/fop/util/SubInputStream.class"/>
      <include name="org/apache/fop/util/Finalizable.class"/>
      <include name="org/apache/fop/util/CharUtilities.class"/>
    </patternset>
    <!-- PDF transcoder -->
    <patternset>
      <include name="org/apache/fop/render/pdf/**"/>
      <exclude name="org/apache/fop/render/pdf/PDFRenderer.class"/>
      <exclude name="org/apache/fop/render/pdf/PDFXMLHandler*"/>
      <include name="org/apache/fop/render/*RendererConfigurator**"/>
      <include name="org/apache/fop/pdf/**"/>
    </patternset>
    <!-- PS transcoder -->
    <patternset>
      <include name="org/apache/fop/render/ps/**"/>
      <exclude name="org/apache/fop/render/pdf/PSRenderer.class"/>
      <exclude name="org/apache/fop/render/pdf/PSXMLHandler*"/>
    </patternset>
  </patternset>

  <fileset dir="${build.classes.dir}" id="transcoder-classes-files">
    <patternset refid="transcoder-classes"/>
  </fileset>
  
  <fileset dir="${lib.dir}" id="transcoder-lib-files">
    <include name="commons-io*.jar"/>
    <include name="avalon-framework*.jar"/>
    <include name="commons-logging*.jar"/>
    <include name="xmlgraphics-commons*.jar"/>
  </fileset>
  
  <target name="uptodate-transcoder-pkg" depends="compile">
    <uptodate property="transcoder.pkg.uptodate" targetfile="${build.dir}/fop-transcoder.jar">
      <srcfiles refid="transcoder-classes-files"/>
      <srcfiles refid="transcoder-lib-files"/>
    </uptodate>
  </target>

  <target name="transcoder-pkg" depends="uptodate-transcoder-pkg, compile" description="Generates the jar for the transcoder package for Batik" unless="transcoder.pkg.uptodate">
    <echo message="Creating the jar file ${build.dir}/fop-transcoder.jar"/>

    <property name="fop-transcoder.name" value="FOP Transcoder Package"/>
    <property name="fop-transcoder.version" value="1.0beta2"/>
    <tstamp>
      <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
    </tstamp>

    <!-- lean transcoder jar -->
    <jar jarfile="${build.dir}/fop-transcoder.jar">
      <fileset refid="transcoder-classes-files"/>
      <manifest>
        <attribute name="Implementation-Title" value="${fop-transcoder.name}"/>
        <attribute name="Implementation-Version" value="${fop-transcoder.version}"/>
        <attribute name="Implementation-Vendor" value="The Apache Software Foundation (http://xmlgraphics.apache.org/fop/)"/>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>

    <!-- all-in-one transcoder jar -->
    <property name="transcoder-deps" value="${build.dir}/transcoder-dependencies"/>
    <mkdir dir="${transcoder-deps}"/>
    <unjar dest="${transcoder-deps}">
      <patternset>
        <include name="org/apache/avalon/framework/*"/>
        <include name="org/apache/avalon/framework/activity/*"/>
        <include name="org/apache/avalon/framework/configuration/*"/>
        <include name="org/apache/avalon/framework/container/*"/>
        <include name="org/apache/commons/logging/**"/>
        <include name="org/apache/commons/io/*.class"/>
        <include name="org/apache/commons/io/filefilter/*.class"/>
        <include name="org/apache/commons/io/output/*.class"/>
        <!-- TODO Remove the following lines once Batik switches over to using XML Graphics Commons -->
        <include name="org/apache/xmlgraphics/java2d/**"/>
        <include name="org/apache/xmlgraphics/ps/**"/>
        <include name="org/apache/xmlgraphics/fonts/**"/>
        <include name="org/apache/xmlgraphics/util/io/**"/>
      </patternset>
      <fileset refid="transcoder-lib-files"/>
    </unjar>
    <mkdir dir="${transcoder-deps}/legal"/>
    <copy todir="${transcoder-deps}/legal">
      <fileset dir="${lib.dir}">
        <include name="avalon.LICENSE.txt"/>
        <include name="commons-io.LICENSE.txt"/>
        <include name="commons-logging.LICENSE.txt"/>
      </fileset>
    </copy>
    <jar jarfile="${build.dir}/fop-transcoder-allinone.jar">
      <fileset refid="transcoder-classes-files"/>
      <fileset dir="${transcoder-deps}"/>
      <manifest>
        <attribute name="Implementation-Title" value="${fop-transcoder.name}"/>
        <attribute name="Implementation-Version" value="${fop-transcoder.version}"/>
        <attribute name="Implementation-Vendor" value="The Apache Software Foundation (http://xmlgraphics.apache.org/fop/)"/>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
  </target>

  <target name="all" depends="package, servlet, transcoder-pkg, junit"/> <!-- "all" target for us Makefile converts ;-) -->

  <!-- =================================================================== -->
  <!-- Testing                                                             -->
  <!-- =================================================================== -->
  <target name="junit-with-xmlunit" depends="init-avail" if="xmlunit.present">
    <patternset id="test-sources"/>
  </target>
  <target name="junit-without-xmlunit" depends="init-avail" unless="xmlunit.present">
    <patternset id="test-sources">
      <exclude name="**/intermediate/*"/>
    </patternset>
  </target>

  <target name="junit-compile-java" depends="package, transcoder-pkg, junit-with-xmlunit, junit-without-xmlunit" if="junit.present">
    <mkdir dir="${build.dir}/test-classes"/>
    <mkdir dir="${build.dir}/test-gensrc"/>
    <mkdir dir="${junit.reports.dir}"/>
    <javac destdir="${build.dir}/test-classes" fork="${javac.fork}"
           debug="${javac.debug}" deprecation="${javac.deprecation}"
           optimize="${javac.optimize}" source="${javac.source}"
           target="${javac.target}">
      <src path="${basedir}/test/java"/>
      <patternset refid="test-sources"/>
      <classpath>
        <path refid="libs-build-classpath"/>
        <fileset dir="${build.dir}">
          <include name="fop.jar"/>
        </fileset>
      </classpath>
    </javac>
    <copy todir="${build.dir}/test-classes">
      <fileset dir="${basedir}/test/java">
        <include name="**/*.xsl"/>
      </fileset>
    </copy>
  </target>

  <target name="junit-compile-copy-resources" if="junit.present">
    <eventResourceGenerator modelfile="${build.dir}/test-gensrc/org/apache/fop/events/test-event-model.xml">
      <fileset dir="${basedir}/test/java">
        <include name="**/*.java"/>
      </fileset>
    </eventResourceGenerator>
    <copy todir="${build.dir}/test-classes">
      <fileset dir="${basedir}/test/java">
        <include name="META-INF/**"/>
        <include name="**/*.xml"/>
      </fileset>
      <fileset dir="${build.dir}/test-gensrc">
        <include name="**/*.xml"/>
      </fileset>
    </copy>
  </target>

  <target name="junit-compile" depends="junit-compile-java, junit-compile-copy-resources" description="Compiles FOP's JUnit tests" if="junit.present"/>

  <target name="junit-transcoder" depends="junit-compile" description="Runs FOP's JUnit transcoder tests" if="junit.present">
    <echo message="Running basic functionality tests for fop-transcoder.jar"/>
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-build-classpath"/>
        <fileset dir="${build.dir}">
          <include name="fop-transcoder.jar"/>
        </fileset>
      </classpath>
      <test name="org.apache.fop.BasicTranscoderTestSuite" todir="${junit.reports.dir}" outfile="TEST-transcoder"/>
    </junit>
    <echo message="Running basic functionality tests for fop-transcoder-allinone.jar"/>
    <!-- These are the same tests as in the block above but testing the "allinone" JAR
         instead. Please don't add any additional paths other than the test classes, the
         allinone JAR and the any Batik JARs to the classpath. If this fails, but the
         previous test block succeeded it indicates that the packaging of the allinone
         JAR needs to be updated.
    -->
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-build-classpath"/>
        <fileset dir="build">
          <include name="fop-transcoder-allinone.jar"/>
        </fileset>
        <fileset dir="${lib.dir}">
          <include name="xml-apis*.jar"/>
          <include name="xerces*.jar"/>
          <include name="batik*.jar"/>
        </fileset>
      </classpath>
      <test name="org.apache.fop.BasicTranscoderTestSuite" todir="${junit.reports.dir}" outfile="TEST-transcoder-allinone"/>
    </junit>
  </target>

  <target name="junit-userconfig" depends="junit-compile" if="junit.present" description="Runs FOP's user config JUnit tests">
    <echo message="Running user config tests"/>
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
      <sysproperty key="fop.layoutengine.testset" value="standard"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-run-classpath"/>
      </classpath>
      <test name="org.apache.fop.config.UserConfigTestSuite" todir="${junit.reports.dir}" outfile="TEST-userconfig"/>
    </junit>
  </target>

  <target name="junit-basic" depends="junit-compile" description="Runs FOP's JUnit basic tests" if="junit.present">
    <echo message="Running basic functionality tests for fop.jar"/>
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-build-classpath"/>
        <fileset dir="build">
          <include name="fop.jar"/>
        </fileset>
      </classpath>
      <test name="org.apache.fop.StandardTestSuite" todir="${junit.reports.dir}"/>
    </junit>
  </target>

  <target name="hyphenation-present" depends="junit-compile" if="junit.present">
    <condition property="hyphenation.present">
      <and><!-- All the hyphenation files required by the layout test cases to be listed here -->
        <available resource="hyph/en.hyp" classpathref="libs-run-classpath"/>
        <available resource="hyph/de.hyp" classpathref="libs-run-classpath"/>
      </and>
    </condition>
    <condition property="hyphenation.message" value="Hyphenation Support PRESENT">
      <equals arg1="${hyphenation.present}" arg2="true"/>
    </condition>
    <condition property="hyphenation.message" value="Hyphenation Support NOT Present - Layout tests which require hyphenation are NOT being run!">
      <not>
        <equals arg1="${hyphenation.present}" arg2="true"/>
      </not>
    </condition>
    <echo message="${hyphenation.message}"/>
  </target>

  <target name="junit-layout-standard" depends="junit-compile, junit-fotree" if="junit.present" description="Runs FOP's standard JUnit layout tests">
    <echo message="Running standard layout engine tests"/>
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
      <sysproperty key="fop.layoutengine.testset" value="standard"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-run-classpath"/>
      </classpath>
      <test name="org.apache.fop.layoutengine.LayoutEngineTestSuite" todir="${junit.reports.dir}" outfile="TEST-layoutengine-standard"/>
    </junit>
  </target>

  <target name="junit-layout-hyphenation" depends="hyphenation-present, junit-compile" if="hyphenation.present" description="Runs FOP's JUnit hyphenation layout tests">
    <echo message="Running hyphenation layout engine tests"/>
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
      <sysproperty key="fop.layoutengine.testset" value="hyphenation"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-run-classpath"/>
      </classpath>
      <test name="org.apache.fop.layoutengine.LayoutEngineTestSuite" todir="${junit.reports.dir}" outfile="TEST-layoutengine-hyphenation"/>
    </junit>
  </target>

  <target name="junit-layout" depends="junit-layout-standard, junit-layout-hyphenation" description="Runs all FOP's JUnit layout tests" />
  
  <target name="junit-fotree" depends="junit-compile" description="Runs FOP's FO tree JUnit tests" if="junit.present">
    <echo message="Running fo tree tests"/>
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <sysproperty key="fop.layoutengine.disabled" value="${fotree.disabled}"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-build-classpath"/>
        <fileset dir="build">
          <include name="fop.jar"/>
        </fileset>
      </classpath>
      <test name="org.apache.fop.fotreetest.FOTreeTestSuite" todir="${junit.reports.dir}" outfile="TEST-FO-tree"/>
    </junit>
  </target>

  <target name="junit-intermediate-format" depends="junit-compile, junit-layout" description="Runs FOP's intermediate format JUnit tests" if="xmlunit.present">
    <echo message="Running intermediate format tests"/>
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
      <sysproperty key="fop.layoutengine.testset" value="standard"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-build-classpath"/>
        <fileset dir="build">
          <include name="fop.jar"/>
        </fileset>
      </classpath>
      <test name="org.apache.fop.intermediate.IntermediateFormatTestSuite" todir="${junit.reports.dir}" outfile="TEST-intermediate-format"/>
    </junit>
  </target>

  <target name="junit-text-linebreak" depends="junit-compile" description="Runs FOP's JUnit unicode linebreak tests" if="junit.present">
    <echo message="Running tests for Unicode UAX#14 support"/>
    <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
      <sysproperty key="basedir" value="${basedir}"/>
      <sysproperty key="jawa.awt.headless" value="true"/>
      <formatter type="brief" usefile="false"/>
      <formatter type="plain" usefile="true"/>
      <formatter type="xml" usefile="true"/>
      <classpath>
        <pathelement location="${build.dir}/test-classes"/>
        <path refid="libs-build-classpath"/>
        <fileset dir="build">
          <include name="fop.jar"/>
        </fileset>
      </classpath>
      <test name="org.apache.fop.text.linebreak.LineBreakStatusTest" todir="${junit.reports.dir}"/>
    </junit>
  </target>

  <target name="junit" depends="junit-userconfig, junit-basic, junit-transcoder, junit-text-linebreak, junit-layout, junit-fotree, junit-intermediate-format" description="Runs all of FOP's JUnit tests" if="junit.present">
    <fail>
      <condition>
        <or>
          <isset property="fop.junit.error"/>
          <isset property="fop.junit.failure"/>
          <not>
            <isset property="hyphenation.present"/>
          </not>
        </or>
      </condition>
NOTE:
**************************************************************************
* One or more of the Junit tests had Failures or Errors or were skipped! *
*         Please check the output above for relevant messages.           *
*    Or use the "junit-reports" target to generate HTML test reports.    *
**************************************************************************
    </fail>
    <echo>All Junit tests passed!</echo>
    <echo>Use the "junit-reports" target to generate HTML test reports</echo>
  </target>

  <!-- haven't made this dependent on "junit" as that would rerun all tests -->
  <target name="junit-reports" description="Generates HTML test reports">
    <mkdir dir="${junit.html.reports.dir}"/>
    <junitreport todir="${junit.reports.dir}">
      <fileset dir="${junit.reports.dir}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="frames" todir="${junit.html.reports.dir}"/>
    </junitreport>
    <echo>JUnit HTML test reports should be available in ${junit.html.reports.dir}</echo>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the API documentation                                       -->
  <!-- =================================================================== -->
  <target name="javadocs" depends="codegen" description="Generates javadocs">
    <!--condition property="javadoc.version.ok">
      <not>
        <or>
          <equals arg1="${ant.java.version}" arg2="1.1"/>
          <equals arg1="${ant.java.version}" arg2="1.2"/>
          <equals arg1="${ant.java.version}" arg2="1.3"/>
        </or>
      </not>
    </condition>
    <fail message="Building FOP javadocs requires at least Java 1.4" unless="javadoc.version.ok"/-->
    <property name="javadoc.public"  value="false"/>
    <property name="javadoc.package" value="false"/>
    <property name="javadoc.private" value="false"/>
    <condition property="javadoc.level" value=" (level: private)">
      <equals arg1="${javadoc.private}" arg2="true"/>
    </condition>
    <condition property="javadoc.level" value=" (level: package)">
      <equals arg1="${javadoc.package}" arg2="true"/>
    </condition>
    <condition property="javadoc.level" value=" (level: public)">
      <equals arg1="${javadoc.public}" arg2="true"/>
    </condition>
    <property name="javadoc.level" value=""/>
    <echo message="Producing the javadoc files${javadoc.level}"/>
    <mkdir dir="${build.javadocs.dir}"/>

    <javadoc
        packagenames="${javadoc.packages}"
        destdir="${build.javadocs.dir}"
        author="true"
        version="true"
        windowtitle="${Name} ${version} API"
        doctitle="Apache Formatting Objects Processor (FOP)"
        bottom="Copyright ${year} The Apache Software Foundation. All Rights Reserved."
        overview="${src.dir}/java/org/apache/fop/overview.html"
        use="true"
        failonerror="true"
        source="${javac.source}"
        public="${javadoc.public}"
        package="${javadoc.package}"
        private="${javadoc.private}">
      <header><![CDATA[${name} ${version}]]></header>
      <footer><![CDATA[${name} ${version}]]></footer>
      <classpath>
        <path refid="libs-build-classpath"/>
        <pathelement path="${java.class.path}"/>
      </classpath>
      <sourcepath>
        <pathelement path="${src.java.dir}"/>
        <pathelement path="${src.sandbox.dir}"/>
        <pathelement path="${build.gensrc.dir}"/>
      </sourcepath>
      <tag name="todo" scope="all" description="To do:"/>
      <group title="Control and Startup">
        <package name="org.apache.fop"/>
        <package name="org.apache.fop.apps"/>
        <package name="org.apache.fop.cli"/>
        <package name="org.apache.fop.configuration"/>
        <package name="org.apache.fop.messaging"/>
        <package name="org.apache.fop.servlet"/>
      </group>
      <group title="XSL-FO Tree">
        <package name="org.apache.fop.fo"/>
        <package name="org.apache.fop.fo.*"/>
        <package name="org.apache.fop.datatypes"/>
        <package name="org.apache.fop.extensions"/>
      </group>
      <group title="Layout">
        <package name="org.apache.fop.layoutmgr"/>
        <package name="org.apache.fop.layoutmgr.*"/>
      </group>
      <group title="Area Tree">
        <package name="org.apache.fop.area"/>
        <package name="org.apache.fop.area.*"/>
        <package name="org.apache.fop.traits"/>
      </group>
      <group title="Paginated Rendering">
        <package name="org.apache.fop.render"/>
        <package name="org.apache.fop.render.*"/>
      </group>
      <group title="Structural Rendering">
        <package name="org.apache.fop.render.rtf"/>
        <package name="org.apache.fop.render.mif"/>
      </group>
      <group title="Utility">
        <package name="org.apache.fop.hyphenation"/>
        <package name="org.apache.fop.pdf"/>
        <package name="org.apache.fop.tools"/>
        <package name="org.apache.fop.tools.*"/>
        <package name="org.apache.fop.svg"/>
        <package name="org.apache.fop.image"/>
        <package name="org.apache.fop.image.*"/>
        <package name="org.apache.fop.fonts"/>
        <package name="org.apache.fop.fonts.*"/>
        <package name="org.apache.fop.util"/>
      </group>
      <group title="RTFLib (formerly JFor) Subpackage Candidate">
        <package name="org.apache.fop.render.rtf.rtflib"/>
        <package name="org.apache.fop.render.rtf.rtflib.*"/>
      </group>
    </javadoc>
  </target>

  <target name="jar-javadocs" depends="javadocs" description="Generates a jar file containing the Javadocs">
    <jar jarfile="${build.dir}/${name}-${version}-javadoc.jar">
      <manifest>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <fileset dir="${build.javadocs.dir}"/>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
  </target>
  
  <!-- =================================================================== -->
  <!-- Checkstyle                                                          -->
  <!-- =================================================================== -->
  <property name="checkstyle.home.dir" value="${optional.lib.dir}"/>
  <property name="checkstyle.noframes.xslt" value="${checkstyle.home.dir}/contrib/checkstyle-noframes.xsl"/>

  <path id="checkstyle-path">
    <fileset dir="${basedir}/lib">
      <include name="checkstyle-all-*.jar"/>
      <include name="checkstyle-*.jar"/>
      <include name="antlr*.jar"/>
      <include name="commons-beanutils*.jar"/>
      <include name="commons-collections*.jar"/>
      <include name="commons-logging*.jar"/>
      <include name="jakarta-regexp*.jar"/>      
    </fileset>
    <fileset dir="${checkstyle.home.dir}">
      <include name="checkstyle-all-*.jar"/>
      <include name="checkstyle-*.jar"/>
      <include name="antlr*.jar"/>
      <include name="commons-beanutils*.jar"/>
      <include name="commons-collections*.jar"/>
      <include name="commons-logging*.jar"/>
      <include name="jakarta-regexp*.jar"/>      
    </fileset>
    <!--fileset dir="${optional.lib.dir}">
      <include name="checkstyle-all-*.jar"/>
      <include name="checkstyle-*.jar"/>
      <include name="antlr*.jar"/>
      <include name="commons-beanutils*.jar"/>
      <include name="commons-collections*.jar"/>
      <include name="commons-logging*.jar"/>
      <include name="jakarta-regexp*.jar"/>      
    </fileset-->
  </path>

  <path id="checkstyle-runpath">
    <path refid="checkstyle-path"/>
    <fileset dir="${basedir}/build">
      <include name="fop.jar"/>
      <include name="fop-hyph.jar" />
    </fileset>
  </path>

  <target name="checkstyle-avail" depends="init">
    <available property="checkstyle.available" classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" classpathref="checkstyle-path"/>
    <available property="checkstyle.4.x" classname="com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck" classpathref="checkstyle-path"/>
    <available property="checkstyle.noframes.xslt.available" file="${checkstyle.noframes.xslt}"/>
    <condition property="checkstyle.message" value="Checkstyle 4.x Support PRESENT">
      <and>
        <equals arg1="${checkstyle.available}" arg2="true"/>
        <equals arg1="${checkstyle.4.x}" arg2="true"/>
      </and>
    </condition>
    <condition property="checkstyle.message" value="Checkstyle 3.x Support PRESENT">
      <equals arg1="${checkstyle.available}" arg2="true"/>
    </condition>
    <condition property="checkstyle.message" value="Checkstyle Support NOT Present">
      <not>
        <equals arg1="${checkstyle.available}" arg2="true"/>
      </not>
    </condition>
    <echo message="${checkstyle.message}"/>
    <condition property="checkstyle.config" value="checkstyle-4.0.xml">
      <equals arg1="${checkstyle.4.x}" arg2="true"/>
    </condition>
    <condition property="checkstyle.config" value="checkstyle-3.5-fop-head.xml">
      <not>
        <equals arg1="${checkstyle.4.x}" arg2="true"/>
      </not>
    </condition>
    <condition property="checkstyle.noframes.xslt.message" value="Checkstyle HTML style sheet support PRESENT">
      <equals arg1="${checkstyle.noframes.xslt.available}" arg2="true"/>
    </condition>
    <condition property="checkstyle.noframes.xslt.message" value="Checkstyle HTML style sheet support NOT Present">
      <not>
        <equals arg1="${checkstyle.noframes.xslt.available}" arg2="true"/>
      </not>
    </condition>
    <echo message="${checkstyle.noframes.xslt.message}"/>
  </target>

  <target name="checkstyle-check" depends="checkstyle-avail, codegen" if="checkstyle.available">
    
    <taskdef name="checkstyle" classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" classpathref="checkstyle-runpath"/>
    <checkstyle config="${checkstyle.config}" failonviolation="false"
                classpathref="checkstyle-runpath">
      <fileset dir="${src.java.dir}" includes="**/*.java"/>
      <formatter type="plain" toFile="${build.dir}/checkstyle_report.txt"/>
      <formatter type="xml" toFile="${build.dir}/checkstyle_report.xml"/>
    </checkstyle>
  </target>

  <target name="checkstyle-html" depends="checkstyle-avail, checkstyle-check" if="checkstyle.noframes.xslt.available">
    <xslt in="${build.dir}/checkstyle_report.xml" out="${build.dir}/checkstyle_report.html" style="${checkstyle.noframes.xslt}"/>
  </target>

  <target name="checkstyle" depends="checkstyle-avail, checkstyle-check, checkstyle-html" description="Runs Checkstyle for a code quality report"/>

  <!-- =================================================================== -->
  <!-- Creates the documentation                                           -->
  <!-- =================================================================== -->
  <target name="docs" description="Generates documentation">
    <echo message="Building documentation with Forrest..."/>
    <!--
    <echo message="Make sure that you have installed Apache Forrest and"/>
    <echo message="the FORREST_HOME environment variable is set (see http://forrest.apache.org/)"/>
    <echo message="FORREST_HOME = ${forrest.home}"/>
    -->
    <echo message="Make sure you have a proper Forrest installation (see http://forrest.apache.org/)"/>

    <condition property="forrest.call" value="forrest.bat" else="forrest">
      <os family="windows"/>
    </condition>
    <exec executable="${forrest.call}"/>
  </target>
  
  <!-- =================================================================== -->
  <!-- Creates the distribution                                            -->
  <!-- =================================================================== -->
  <target name="dist" depends="dist-prereq,dist-src,dist-bin" description="Generates the distribution package"/>

  <target name="dist-prereq" depends="init">
    <fail message="A complete binary build requires JAI" unless="jai.present"/>
    <fail message="A complete binary build requires JCE" unless="jce.present"/>
  </target>

  <target name="dist-bin" depends="all,javadocs,docs">
    <echo message="Building the binary distribution files (zip,tar)"/>
    <mkdir dir="${dist.bin.result.dir}"/>
    <copy todir="${dist.bin.result.dir}">
      <fileset refid="dist.bin"/>
      <fileset refid="dist.bin.lib"/>
    </copy>
    <copy todir="${dist.bin.result.dir}/docs">
      <fileset dir="${build.dir}/site"/>
    </copy>
    <copy todir="${dist.bin.result.dir}/javadocs">
      <fileset dir="${build.javadocs.dir}"/>
    </copy>
    <mkdir dir="${dist.bin.result.dir}/build"/>
    <copy todir="${dist.bin.result.dir}/build" file="build/fop.jar"/>
    <chmod file="${dist.bin.result.dir}/fop" perm="ugo+rx"/>

    <zip zipfile="${name}-${version}-bin.zip" basedir="${dist.bin.dir}" includes="**"/>
    <tar longfile="gnu"
         destfile="${name}-${version}-bin.tar">
      <tarfileset dir="${dist.bin.dir}" mode="755">
        <include name="${name}-${version}/fop"/>
      </tarfileset>
      <tarfileset dir="${dist.bin.dir}">
        <include name="**"/>
        <exclude name="${name}-${version}/fop"/>
      </tarfileset>
    </tar>
    <gzip zipfile="${name}-${version}-bin.tar.gz" src="${name}-${version}-bin.tar"/>
    <delete file="${name}-${version}-bin.tar"/>
  </target>

  <target name="dist-src" depends="all">
    <echo message="Building the source distribution files (zip,tar)"/>
    <mkdir dir="${dist.src.result.dir}"/>
    <copy todir="${dist.src.result.dir}">
      <fileset refid="dist.src"/>
    </copy>
    <chmod file="${dist.src.result.dir}/fop" perm="ugo+rx"/>

    <zip zipfile="${name}-${version}-src.zip" basedir="${dist.src.dir}" includes="**"/>
    <tar longfile="gnu"
         destfile="${name}-${version}-src.tar" >
      <tarfileset dir="${dist.src.dir}" mode="755">
        <include name="${name}-${version}/fop"/>
      </tarfileset>
      <tarfileset dir="${dist.src.dir}">
        <include name="**"/>
        <exclude name="${name}-${version}/fop"/>
      </tarfileset>
    </tar>
    <gzip zipfile="${name}-${version}-src.tar.gz" src="${name}-${version}-src.tar"/>
    <delete file="${name}-${version}-src.tar"/>
  </target>

  <!-- =================================================================== -->
  <!-- Maven artifacts                                                     -->
  <!-- =================================================================== -->
  <target name="maven-artifacts" depends="jar-main, jar-sources, jar-javadocs" description="Builds a Maven artifact that can be uploaded to a Maven repository">
    <filter  token="version" value="${version}"/>
    <mkdir dir="${build.dir}/maven"/>
    <copy file="${basedir}/xmlgraphics-fop-pom-template.pom" tofile="${build.dir}/maven/pom.xml" filtering="true"/>
    <copy file="${build.dir}/${name}.jar" tofile="${build.dir}/maven/${name}-${version}.jar"/>
    <jar jarfile="${build.dir}/${name}-${version}-bundle.jar">
      <manifest>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}, Java ${java.runtime.version}])"/>
      </manifest>
      <fileset dir="${build.dir}">
        <include name="${name}-${version}-sources.jar"/>
        <include name="${name}-${version}-javadoc.jar"/>
      </fileset>
      <fileset dir="${build.dir}/maven"/>
      <metainf dir="${basedir}" includes="LICENSE,NOTICE"/>
    </jar>
  </target>
  
  <!-- =================================================================== -->
  <!-- Generate example PDFs                                               -->
  <!-- =================================================================== -->
  <target name="examples" depends="package" description="Generates example PDF files">
    <taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"
             classpathref="libs-run-classpath"/>
    <mkdir dir="${build.examples.dir}"/>
    <fop format="${build.property.examples.mime.type}" outdir="${build.examples.dir}"
         messagelevel="debug" basedir="${fo.examples.dir}" userconfig="${fo.examples.userconfig}"
         force="${fo.examples.force}">
      <fileset dir="${fo.examples.dir}">
        <include name="${fo.examples.include}"/>
      </fileset>
    </fop>
  </target>

  <!-- =================================================================== -->
  <!-- Helper task to generate source files that have already been         -->
  <!-- checked into CVS.  For these files, CVS version is the official one -->
  <!-- and may have updates that will *not* be generated by below.  This   -->
  <!-- target should never be part of the normal build process.            -->
  <!-- =================================================================== -->
  <target name="codegen-fo" >
    <style in="${src.codegen.dir}/fo/constants.xml" style="${src.codegen.dir}/fo/constants.xsl"
        out="Constants.java"/>
    <style in="${src.codegen.dir}/fo/foelements.xml" style="${src.codegen.dir}/fo/property-sets.xsl"
        out="PropertySets.java"/>
  </target>

  <!-- =================================================================== -->
  <!-- Helper task to generate source files that have already been         -->
  <!-- checked into CVS.  For these files, CVS version is the official one -->
  <!-- and may have updates that will *not* be generated by below.  This   -->
  <!-- target should never be part of the normal build process.            -->
  <!-- =================================================================== -->
  <target name="codegen-unicode" >
    <mkdir dir="${build.codegen-classes.dir}"/>
    <javac destdir="${build.codegen-classes.dir}" fork="${javac.fork}" debug="${javac.debug}"
           deprecation="${javac.deprecation}" optimize="${javac.optimize}"
           source="${javac.source}" target="${javac.target}">
      <src path="${src.codegen.dir}/unicode/java"/>
    </javac>
    <java classname="org.apache.fop.text.linebreak.GenerateLineBreakUtils" classpath="${build.codegen-classes.dir}" />
  </target>

  <!-- =================================================================== -->
  <!-- Special target for Gump                                             -->
  <!-- =================================================================== -->
  <target name="gump" depends="all, javadocs"/>
  <!-- =================================================================== -->
  <!-- Clean targets                                                       -->
  <!-- =================================================================== -->
  <target name="clean" description="Cleans the build directory">
    <delete dir="${build.dir}"/>
  </target>

  <target name="distclean" depends="clean" description="Cleans the distribution target directories">
    <delete dir="${dist.src.dir}"/>
    <delete dir="${dist.bin.dir}"/>
    <delete>
      <fileset dir="${basedir}" includes="${name}-*.tar.gz"/>
      <fileset dir="${basedir}" includes="${name}-*.zip"/>
    </delete>
  </target>

  <target name="validate-xdocs" description="Validate the
xdocs. Point schemas.dir to Forrest's 'schemas' directory.">
    <property name="schemas.dir" value="../xml-forrest/src/resources/schema"/>
    <xmlvalidate failonerror="no">
      <fileset dir="${xdocs.dir}" includes="**.xml"/>
      <xmlcatalog>
        <entity publicId="-//APACHE//DTD Compliance V1.0//EN"
          location="src/documentation/resources/schema/dtd/compliance-v10.dtd"/>
        <entity publicId="-//APACHE//DTD Documentation V1.1//EN"
          location="${schemas.dir}/dtd/document-v11.dtd"/>
        <entity publicId="-//APACHE//DTD Specification V1.1//EN"
          location="${schemas.dir}/dtd/specification-v11.dtd"/>
        <entity publicId="-//APACHE//DTD FAQ V1.1//EN"
          location="${schemas.dir}/dtd/faq-v11.dtd"/>
        <entity publicId="-//APACHE//DTD Changes V1.1//EN"
          location="${schemas.dir}/dtd/changes-v11.dtd"/>
        <entity publicId="-//APACHE//DTD Todo V1.1//EN"
          location="${schemas.dir}/dtd/todo-v11.dtd"/>
        <entity publicId="-//APACHE//DTD Cocoon Documentation Book V1.0//EN"
          location="${schemas.dir}/dtd/book-cocoon-v10.dtd"/>
        <entity publicId="-//APACHE//DTD Cocoon Documentation Tab V1.0//EN"
          location="${schemas.dir}/dtd/tab-cocoon-v10.dtd"/>
        <entity publicId="-//APACHE//DTD How-to V1.0//EN"
          location="${schemas.dir}/dtd/howto-v10.dtd"/>
        <entity publicId="-//APACHE//DTD Gump Descriptor V1.0//EN"
          location="${schemas.dir}/dtd/xgump-draft.dtd"/>
        <entity publicId="-//APACHE//DTD JavaDoc V1.0//EN"
          location="${schemas.dir}/dtd/javadoc-v04draft.dtd"/>
        <entity publicId="-//APACHE//DTD Contributors V1.0//EN"
          location="${schemas.dir}/dtd/contributors-v10.dtd"/>
        <entity publicId="-//Outerthought//DTD Libre Configuration V0.1//EN"
          location="${schemas.dir}/dtd/libre-v01.dtd"/>
        <entity publicId="-//APACHE//ENTITIES Documentation V1.1//EN"
          location="${schemas.dir}/dtd/document-v11.mod"/>
        <entity publicId="-//APACHE//ENTITIES FAQ V1.1//EN"
          location="${schemas.dir}/dtd/faq-v11.mod"/>
        <entity publicId="-//APACHE//ENTITIES Todo V1.1//EN"
          location="${schemas.dir}/dtd/todo-v11.mod"/>
        <entity publicId="-//APACHE//ENTITIES Common Elements V1.0//EN"
          location="${schemas.dir}/dtd/common-elems-v10.mod"/>
        <entity publicId="-//APACHE//ENTITIES Common Character Entity Sets V1.0//EN"
          location="${schemas.dir}/dtd/common-charents-v10.mod"/>

        <entity publicId="ISO 8879-1986//ENTITIES Added Latin 1//EN//XML"
          location="${schemas.dir}/entity/ISOlat1.pen"/>
        <entity publicId="ISO 9573-15:1993//ENTITIES Greek Letters//EN//XML"
          location="${schemas.dir}/entity/ISOgrk1.pen"/>
        <entity publicId="ISO 8879:1986//ENTITIES Publishing//EN//XML"
          location="${schemas.dir}/entity/ISOpub.pen"/>
        <entity publicId="ISO 8879:1986//ENTITIES General Technical//EN//XML"
          location="${schemas.dir}/entity/ISOtech.pen"/>
        <entity publicId="ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN//XML"
          location="${schemas.dir}/entity/ISOnum.pen"/>
        <entity publicId="ISO 8879:1986//ENTITIES Diacritical Marks//EN//XML"
          location="${schemas.dir}/entity/ISOdia.pen"/>
        <entity publicId="ISO 8879:1986//ENTITIES Added Latin 1//EN//XML"
          location="${schemas.dir}/entity/ISOlat1.pen"/>
      </xmlcatalog>
    </xmlvalidate>
  </target>
  
</project>