1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 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 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
|
/*
* A Mac OS X Jar Bundler Ant Task.
*
*
* Copyright (c) 2003, Seth J. Morabito <sethm@loomcom.com> All rights reserved.
*
* 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.
*/
package net.sourceforge.jarbundler;
// This package's imports
import net.sourceforge.jarbundler.AppBundleProperties;
import net.sourceforge.jarbundler.DocumentType;
import net.sourceforge.jarbundler.JavaProperty;
import net.sourceforge.jarbundler.PropertyListWriter;
// Java I/O
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
// Java Utility
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
// Apache Jakarta
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.FileScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileList;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.PatternSet;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.taskdefs.Chmod;
import org.apache.tools.ant.taskdefs.Delete;
import org.apache.tools.ant.util.FileUtils;
// Java language imports
import java.lang.Boolean;
import java.lang.Process;
import java.lang.Runtime;
import java.lang.String;
import java.lang.System;
/**
* <p>
* An ant task which creates a Mac OS X Application Bundle for a Java
* application.
* </p>
*
* <dl>
* <dt>dir</dt>
* <dd>The directory into which to put the new application bundle.</dd>
* <dt>name</dt>
* <dd>The name of the application bundle. Note that the maximum length of this
* name is 16 characters, and it will be silently cropped if it is longer than
* this.</dd>
* <dt>mainclass</dt>
* <dd>The main Java class to call when running the application.</dd>
* </dl>
*
* <p>
* One of the following three MUST be used:
*
* <ol>
* <li>jars Space or comma-separated list of JAR files to include.; OR</li>
* <li>One or more nested <jarfileset>s. These are normal ANT FileSets;
* OR </li>
* <li>One or more nested <jarfilelist>s. These are standard ANT
* FileLists. </li>
* </ol>
*
* <p>
* Optional attributes:
*
* <p>
* The following attributes are not required, but you can use them to override
* default behavior.
*
* <dl>
* <dt>verbose
* <dd>If true, show more verbose output while running the task
*
* <dt>version
* <dd>Version information about your application (e.g., "1.0")
*
* <dt>infostring
* <dd>String to show in the "Get Info" dialog
* </dl>
*
* These attributes control the fine-tuning of the "Mac OS X" look and feel.
*
* <dl>
* <dt>arguments
* <dd>Command line arguments. (no default)
*
* <dt>smalltabs
* <dd>Use small tabs. (default "false") Deprecated under JVM 1.4.1
*
* <dt>antialiasedgraphics
* <dd>Use anti-aliased graphics (default "false")
*
* <dt>antialiasedtext
* <dd>Use anti-aliased text (default "false")
*
* <dt>bundleid
* <dd>Unique identifier for this bundle, in the form of a Java package. No
* default.
*
* <dt>buildnumber
* <dd>Unique identifier for this build
*
* <dt>developmentregion
* <dd>Development Region. Default "English".
*
* <dt>execs
* <dd>Files to be copied into "Resources/MacOS" and made executable
*
* <dt>liveresize
* <dd>Use "Live resizing" (default "false") Deprecated under JVM 1.4.1
*
*
* <dt>growbox
* <dd>Show growbox (default "true")
*
* <dt>growboxintrudes
* <dd>Intruding growbox (default "false") Deprecated under JVM 1.4.1
*
* <dt>screenmenu
* <dd>Put swing menu into Mac OS X menu bar.
*
* <dt>type
* <dd>Bundle type (default "APPL")
*
* <dt>signature
* <dd>Bundle Signature (default "????")
*
* <dt>stubfile
* <dd>The Java Application Stub file to copy for your application (default
* MacOS system stub file)
* </dl>
*
* <p>
* Rarely used optional attributes.
* <dl>
* <dt>chmod
* <dd>Full path to the chmod command. This almost certainly does NOT need to
* be set.
* </dl>
*
* <p>
* The task also supports nested <execfileset> and/or <execfilelist>
* elements, and <resourcefileset> and/or <resourcefilelist>
* elements, which are standard Ant FileSet and FileList elements. In the first
* case, the referenced files are copied to the <code>Contents/MacOS</code>
* directory and made executable, and in the second they are copied to the
* <code>Contents/Resources</code> directory and not made executable. If you
* winrces, note that in fact the files are installed in locations which have
* the same relation to the <code>Contents/Resources</code> directory as the
* files in the FileSet or FileList have to the 'dir' attribute. Thus in the
* case:
*
* <pre>
* <resourcefileset dir="builddir/architectures"
* includes="ppc/*.jnilib"/>
* </pre>
*
* <p>
* the <code>*.jnilib</code> files will be installed in
* <code>Contents/Resources/ppc</code>.
*
* <p>
* The task supports a nested <javaproperty> element, which allows you to
* specify further properties which are set for the JVM when the application is
* launched. This takes a required <code>key</code> attribute, giving the
* property key, plus an attribute giving the property value, which may be one
* of <code>value</code>, giving the string value of the property,
* <code>file</code>, setting the value of the property to be the absolute
* path of the given file, or <code>path</code>, which sets the value to the
* given path. If you are setting paths here, recall that, within the bundle,
* <code>$APP_PACKAGE</code> is set to the root directory of the bundle (ie,
* the path to the <code>foo.app</code> directory), and <code>$JAVAROOT</code>
* to the directory <code>Contents/Resources/Java</code>.
*
* <p>
* Minimum example:
*
* <pre>
*
* <jarbundler dir="release" name="Bar Project" mainclass="org.bar.Main"
* jars="bin/Bar.jar" />
* </pre>
*
* <p>
* Using Filesets
*
* <pre>
* <jarbundler dir="release" name="Bar Project" mainclass="org.bar.Main">
* <jarfileset dir="bin">
* <include name="*.jar" />
* <exclude name="test.jar" />
* </jarfileset>
* <execfileset dir="execs">
* <include name="**" />
* </execfileset>
* </jarbundler>
* </pre>
*
* <p>
* Much Longer example:
* </p>
*
* <pre>
* <jarbundler dir="release"
* name="Foo Project"
* mainclass="org.bar.Main"
* version="1.0 b 1"
* infostring="Foo Project (c) 2002"
* type="APPL"
* jars="bin/foo.jar bin/bar.jar"
* execs="exec/foobar"
* signature="????"
* workingdirectory="temp"
* icon="resources/foo.icns"
* jvmversion="1.4.1+"
* vmoptions="-Xmx256m"/>
* </pre>
*
* http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/
*/
public class JarBundler extends MatchingTask {
private static final String DEFAULT_STUB = "/System/Library/Frameworks/JavaVM.framework/Versions/Current/Resources/MacOS/JavaApplicationStub";
private static final String ABOUTMENU_KEY = "com.apple.mrj.application.apple.menu.about.name";
private static final Set menuItems = new HashSet();
private File mAppIcon;
private File mRootDir;
private final List mJavaFileLists = new ArrayList();
private final List mJarFileSets = new ArrayList();
private final List mExecFileLists = new ArrayList();
private final List mExecFileSets = new ArrayList();
private final List mResourceFileLists = new ArrayList();
private final List mResourceFileSets = new ArrayList();
private final List mJarFileLists = new ArrayList();
private final List mJavaFileSets = new ArrayList();
private final List mExtraClassPathFileLists = new ArrayList();
private final List mExtraClassPathFileSets = new ArrayList();
private final List mJarAttrs = new ArrayList();
private final List mExecAttrs = new ArrayList();
private final List mExtraClassPathAttrs = new ArrayList();
private final List mHelpBooks = new ArrayList();
private boolean mVerbose = false;
private boolean mShowPlist = false;
// Java properties used by Mac OS X Java applications
private File mStubFile = new File(DEFAULT_STUB);
private Boolean mAntiAliasedGraphics = null;
private Boolean mAntiAliasedText = null;
private Boolean mLiveResize = null;
private Boolean mScreenMenuBar = null;
private Boolean mGrowbox = null;
private Boolean mGrowboxIntrudes = null;
// The root of the application bundle
private File bundleDir;
// "Contents" directory
private File mContentsDir;
// "Contents/MacOS" directory
private File mMacOsDir;
// "Contents/Resources" directory
private File mResourcesDir;
// "Contents/Resources/Java" directory
private File mJavaDir;
// Full path to the 'chmod' command. Can be overridden
// with the 'chmod' attribute. Won't cause any harm if
// not set, or if this executable doesn't exist.
private AppBundleProperties bundleProperties = new AppBundleProperties();
// Ant file utilities
private FileUtils mFileUtils = FileUtils.getFileUtils();
/***************************************************************************
* Retreive task attributes
**************************************************************************/
/**
* Arguments to the
*
* @param s
* The arguments to pass to the application being launched.
*/
public void setArguments(String s) {
bundleProperties.setArguments(s);
}
/**
* Override the stub file path to build on non-MacOS platforms
*
* @param file
* the path to the stub file
*/
public void setStubFile(File file) {
mStubFile = (file.exists()) ? file : new File(DEFAULT_STUB);
bundleProperties.setCFBundleExecutable(file.getName());
}
/**
* Setter for the "dir" attribute (required)
*/
public void setDir(File f) {
mRootDir = f;
}
/**
* Setter for the "name" attribute (required) This attribute names the
* output application bundle and asks as the CFBundleName if 'bundlename' is
* not specified
*/
public void setName(String s) {
bundleProperties.setApplicationName(s);
}
/**
* Setter for the "shortname" attribute (optional) This key identifies the
* short name of the bundle. This name should be less than 16 characters
* long and be suitable for displaying in the menu and the About box. The
* name is (silently) cropped to this if necessary.
*/
public void setShortName(String s) {
bundleProperties.setCFBundleName(s);
}
/**
* Setter for the "mainclass" attribute (required)
*/
public void setMainClass(String s) {
bundleProperties.setMainClass(s);
}
/**
* Setter for the "WorkingDirectory" attribute (optional)
*/
public void setWorkingDirectory(String s) {
bundleProperties.setWorkingDirectory(s);
}
/**
* Setter for the "icon" attribute (optional)
*/
public void setIcon(File f) {
mAppIcon = f;
bundleProperties.setCFBundleIconFile(f.getName());
}
/**
* Setter for the "splashfile" attribute (optional). If it is somewhere
* in a jar file, which contains a Splash-Screen manifest entry,
* use "$JAVAROOT/myjar.jar"
*/
public void setSplashFile(String s) {
bundleProperties.setSplashFile(s);
}
/**
* Setter for the "bundleid" attribute (optional) This key specifies a
* unique identifier string for the bundle. This identifier should be in the
* form of a Java-style package name, for example com.mycompany.myapp. The
* bundle identifier can be used to locate the bundle at runtime. The
* preferences system uses this string to identify applications uniquely.
*
* No default.
*/
public void setBundleid(String s) {
bundleProperties.setCFBundleIdentifier(s);
}
/**
* Setter for the "developmentregion" attribute (optional) Default "English".
*/
public void setDevelopmentregion(String s) {
bundleProperties.setCFBundleDevelopmentRegion(s);
}
/** Tobias Fischer, v2.3.0
* Setter for the "allowmixedlocalizations" attribute (optional) Default "false".
*/
public void setAllowMixedLocalizations(boolean b) {
bundleProperties.setCFBundleAllowMixedLocalizations(b);
}
/** Tobias Fisher, v2.3.1
* Setter for the "NSHumanReadableCopyright" attribute (optional)
*/
public void setCopyright(String s) {
bundleProperties.setNSHumanReadableCopyright(s);
}
/**
* Setter for the deprecated "aboutmenuname" attribute (optional)
*/
public void setAboutmenuname(String s) {
System.err.println("WARNING: 'aboutmenuname' is deprecated! Use JarBundler attribute 'shortname' instead!");
bundleProperties.setCFBundleName(s);
}
/**
* Setter for the "smalltabs" attribute (optional)
*/
public void setSmallTabs(boolean b) {
bundleProperties.addJavaProperty("com.apple.smallTabs", new Boolean(b)
.toString());
}
/**
* Setter for the "vmoptions" attribute (optional)
*/
public void setVmoptions(String s) {
bundleProperties.setVMOptions(s);
}
/**
* Setter for the "antialiasedgraphics" attribute (optional)
*/
public void setAntialiasedgraphics(boolean b) {
mAntiAliasedGraphics = new Boolean(b);
}
/**
* Setter for the "antialiasedtext" attribute (optional)
*/
public void setAntialiasedtext(boolean b) {
mAntiAliasedText = new Boolean(b);
}
/**
* Setter for the "screenmenu" attribute (optional)
*/
public void setScreenmenu(boolean b) {
mScreenMenuBar = new Boolean(b);
}
/**
* Setter for the "growbox" attribute (optional)
*/
public void setGrowbox(boolean b) {
mGrowbox = new Boolean(b);
}
/**
* Setter for the "growboxintrudes" attribute (optional)
*/
public void setGrowboxintrudes(boolean b) {
mGrowboxIntrudes = new Boolean(b);
}
/**
* Setter for the "liveresize" attribute (optional)
*/
public void setLiveresize(boolean b) {
mLiveResize = new Boolean(b);
}
/**
* Setter for the "type" attribute (optional)
*/
public void setType(String s) {
bundleProperties.setCFBundlePackageType(s);
}
/**
* Setter for the "signature" attribute (optional)
*/
public void setSignature(String s) {
bundleProperties.setCFBundleSignature(s);
}
/**
* Setter for the "jvmversion" attribute (optional)
*/
public void setJvmversion(String s) {
bundleProperties.setJVMVersion(s);
}
// New in JarBundler 2.2.0; Tobias Bley ----------------
/**
* Setter for the "JVMArchs" attribute (optional)
*/
public void setJvmArchs(String s) {
bundleProperties.setJVMArchs(s);
}
/** Michael Bader <nufan_k@me.com> --------------------
* Setter for the "LSArchitecturePriority" attribute (optional)
*/
public void setLSArchitecturePriority(String s) {
bundleProperties.setLSArchitecturePriority(s);
}
//-------------------------------------------------------
/**
* Setter for the "startonmainthread" attribute (optional)
*/
public void setStartonmainthread(boolean b) {
bundleProperties.setStartOnMainThread(new Boolean(b));
}
/**
* Setter for the "startasagent" attribute (optional)
*/
public void setIsAgent( boolean b ) {
bundleProperties.setLSUIElement( new Boolean( b ) );
}
/**
* Setter for the "infostring" attribute (optional) This key identifies a
* human-readable plain text string displaying the copyright information for
* the bundle. The Finder displays this information in the Info window of
* the bundle. (This string was also known as the long version string in Mac
* OS 9). The format of the key should be of the following format: "©
* Great Software, Inc, 1999". You can localize this string by including it
* in the InfoPlist.strings file of the appropriate .lproj directory.
*/
public void setInfoString(String s) {
bundleProperties.setCFBundleGetInfoString(s);
}
/**
* Setter for the "shortinfostring" attribute (optional) This key identifies
* the marketing version of the bundle. The marketing version is a string
* that usually displays the major and minor version of the bundle. This
* string is usually of the form n.n.n where n is a number. The first number
* is the major version number of the bundle. The second and third numbers
* are minor revision numbers. You may omit minor revision numbers as
* appropriate. The value of this key is displayed in the default About box
* for Cocoa applications.
*
* The value for this key differs from the value for "CFBundleVersion",
* which identifies a specific build number. The CFBundleShortVersionString
* value represents a more formal version that does not change with every
* build.
*/
public void setShortInfoString(String s) {
System.err.println("WARNING: 'shortinfostring' is deprecated! Use JarBundler attribute 'infostring' instead!");
setVersion(s);
}
/**
* Setter for the "verbose" attribute (optional)
*/
public void setVerbose(boolean verbose) {
this.mVerbose = verbose;
}
public void setShowPlist(boolean showPlist) {
this.mShowPlist = showPlist;
}
/**
* Setter for the "buildnumber" attribute (optional) This key specifies the
* exact build version of the bundle. This string is usually of the form
* nn.n.nxnnn where n is a digit and x is a character from the set [abdf].
* The first number is the major version number of the bundle and can
* contain one or two digits to represent a number in the range 0-99. The
* second and third numbers are minor revision numbers and must be a single
* numeric digit. The fourth set of digits is the specific build number for
* the release.
*
* You may omit minor revision and build number information as appropriate.
* You may also omit major and minor revision information and specify only a
* build number. For example, valid version numbers include: 1.0.1,
* 1.2.1b10, 1.2d200, d125, 101, and 1.0.
*
* The value of this key typically changes between builds and is displayed
* in the Cocoa About panel in parenthesis. To specify the version
* information of a released bundle, use the CFBundleShortVersionString key.
*/
public void setBuild(String s) {
bundleProperties.setCFBundleVersion(s);
}
/**
* Setter for the version attribute (optional). It is this property, not
* CFBundleVersion, which should receive the `short' version string. See for
* example
* <http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/>
*/
public void setVersion(String s) {
bundleProperties.setCFBundleShortVersionString(s);
}
public void setHelpBookFolder(String s) {
bundleProperties.setCFBundleHelpBookFolder(s);
}
public void setHelpBookName(String s) {
bundleProperties.setCFBundleHelpBookName(s);
}
/**
* Setter for the "jars" attribute (required if no "jarfileset" is present)
*/
public void setJars(String s) {
PatternSet patset = new PatternSet();
patset.setIncludes(s);
String[] jarNames = patset.getIncludePatterns(getProject());
for (int i = 0; i < jarNames.length; i++)
mJarAttrs.add(getProject().resolveFile(jarNames[i]));
}
/**
* Setter for the "jar" attribute (required if no "jarfileset" is present)
*/
public void setJar(File s) {
mJarAttrs.add(s);
}
/**
* Setter for the "execs" attribute (optional)
*/
public void setExecs(String s) {
PatternSet patset = new PatternSet();
patset.setIncludes(s);
String[] execNames = patset.getIncludePatterns(getProject());
for (int i = 0; i < execNames.length; i++) {
File f = new File(execNames[i]);
mExecAttrs.add(f);
}
}
/**
* Setter for the "extraclasspath" attribute (optional)
*/
public void setExtraclasspath(String s) {
if (s == null || s.trim().equals("")) return;
PatternSet patset = new PatternSet();
patset.setIncludes(s);
String[] cpNames = patset.getIncludePatterns(getProject());
for (int i = 0; i < cpNames.length; i++) {
File f = new File(cpNames[i]);
mExtraClassPathAttrs.add(f);
}
}
/**
* Set the 'chmod' executable.
*/
public void setChmod(String s) {
log("The \"chmod\" attribute has deprecaited, using the ANT Chmod task internally");
}
/***************************************************************************
* Nested tasks - derived from FileList and FileSet
**************************************************************************/
public void addJarfileset(FileSet fs) {
mJarFileSets.add(fs);
}
public void addJarfilelist(FileList fl) {
mJarFileLists.add(fl);
}
public void addExecfileset(FileSet fs) {
mExecFileSets.add(fs);
}
public void addExecfilelist(FileList fl) {
mExecFileLists.add(fl);
}
public void addResourcefileset(FileSet fs) {
mResourceFileSets.add(fs);
}
public void addResourcefilelist(FileList fl) {
mResourceFileLists.add(fl);
}
public void addJavafileset(FileSet fs) {
mJavaFileSets.add(fs);
}
public void addJavafilelist(FileList fl) {
mJavaFileLists.add(fl);
}
public void addExtraclasspathfileset(FileSet fs) {
mExtraClassPathFileSets.add(fs);
}
public void addExtraclasspathfilelist(FileList fl) {
mExtraClassPathFileLists.add(fl);
}
/***************************************************************************
* Nested tasks - new tasks with custom attributes
**************************************************************************/
public void addConfiguredJavaProperty(JavaProperty javaProperty)
throws BuildException {
String name = javaProperty.getName();
String value = javaProperty.getValue();
if ((name == null) || (value == null))
throw new BuildException(
"'<javaproperty>' must have both 'name' and 'value' attibutes");
bundleProperties.addJavaProperty(name, value);
}
public void addConfiguredDocumentType(DocumentType documentType) throws BuildException {
String name = documentType.getName();
String role = documentType.getRole();
List osTypes = documentType.getOSTypes();
List extensions = documentType.getExtensions();
List mimeTypes = documentType.getMimeTypes();
if ((name == null) || (role == null))
throw new BuildException(
"'<documenttype>' must have both a 'name' and a 'role' attibute");
if ((osTypes.isEmpty()) && (extensions.isEmpty()) && (mimeTypes.isEmpty()))
throw new BuildException(
"'<documenttype>' of \""
+ name
+ "\" must have 'osTypes' or 'extensions' or 'mimeTypes'");
bundleProperties.addDocumentType(documentType);
}
public void addConfiguredService(Service service) {
//if (service.getPortName() == null)
// throw new BuildException("\"<service>\" must have a \"portName\" attribute");
if (service.getMessage() == null)
throw new BuildException("\"<service>\" must have a \"message\" attribute");
String menuItem = service.getMenuItem();
if (menuItem == null)
throw new BuildException("\"<service>\" must have a \"menuItem\" attribute");
if (!menuItems.add(menuItem))
throw new BuildException("\"<service>\" \"menuItem\" value must be unique");
if (service.getSendTypes().isEmpty() && service.getReturnTypes().isEmpty())
throw new BuildException("\"<service>\" must have either a \"sendTypes\" attribute, a \"returnTypes\" attribute or both");
String keyEquivalent = service.getKeyEquivalent();
if ((keyEquivalent != null) && (1 != keyEquivalent.length()))
throw new BuildException("\"<service>\" \"keyEquivalent\" must be one character if present");
String timeoutString = service.getTimeout();
if (timeoutString != null) {
long timeout = -1;
try {
timeout = Long.parseLong(timeoutString);
} catch (NumberFormatException nfe) {
throw new BuildException("\"<service>\" \"timeout\" must be a positive integral number");
}
if (timeout < 0)
throw new BuildException("\"<service>\" \"timeout\" must not be negative");
}
bundleProperties.addService(service);
}
public void addConfiguredHelpBook(HelpBook helpBook) {
// Validity check on 'foldername'
if (helpBook.getFolderName() == null) {
if (bundleProperties.getCFBundleHelpBookFolder() == null)
throw new BuildException("Either the '<helpbook>' attribute 'foldername' or the '<jarbundler>' attribute 'helpbookfolder' must be defined");
helpBook.setFolderName(bundleProperties.getCFBundleHelpBookFolder());
}
// Validity check on 'title'
if (helpBook.getName() == null) {
if (bundleProperties.getCFBundleHelpBookName() == null)
throw new BuildException("Either the '<helpbook>' attribute 'name' or the '<jarbundler>' attribute 'helpbookname' must be defined");
helpBook.setName(bundleProperties.getCFBundleHelpBookName());
}
// Make sure some file were selected...
List fileLists = helpBook.getFileLists();
List fileSets = helpBook.getFileSets();
if ( fileLists.isEmpty() && fileSets.isEmpty() )
throw new BuildException("The '<helpbook>' task must have either " +
"'<fileset>' or '<filelist>' nested tags");
mHelpBooks.add(helpBook);
}
/***************************************************************************
* Execute the task
**************************************************************************/
/**
* The method executing the task
*/
public void execute() throws BuildException {
// Delete any existing Application bundle directory structure
bundleDir = new File(mRootDir, bundleProperties.getApplicationName() + ".app");
if (bundleDir.exists()) {
Delete deleteTask = new Delete();
deleteTask.setProject(getProject());
deleteTask.setDir(bundleDir);
deleteTask.execute();
}
// Validate - look for required attributes
// ///////////////////////////////////////////
if (mRootDir == null)
throw new BuildException("Required attribute \"dir\" is not set.");
if (mJarAttrs.isEmpty() && mJarFileSets.isEmpty()
&& mJarFileLists.isEmpty())
throw new BuildException("Either the attribute \"jar\" must "
+ "be set, or one or more jarfilelists or "
+ "jarfilesets must be added.");
if (!mJarAttrs.isEmpty()
&& (!mJarFileSets.isEmpty() || !mJarFileLists.isEmpty()))
throw new BuildException(
"Cannot set both the attribute "
+ "\"jars\" and use jar filesets/filelists. Use only one or the other.");
if (bundleProperties.getApplicationName() == null)
throw new BuildException("Required attribute \"name\" is not set.");
if (bundleProperties.getMainClass() == null)
throw new BuildException(
"Required attribute \"mainclass\" is not set.");
// /////////////////////////////////////////////////////////////////////////////////////
// Set up some Java properties
// About Menu, deprecated under 1.4+
if (useOldPropertyNames())
bundleProperties.addJavaProperty(ABOUTMENU_KEY, bundleProperties
.getCFBundleName());
// Anti Aliased Graphics, renamed in 1.4+
String antiAliasedProperty = useOldPropertyNames()
? "com.apple.macosx.AntiAliasedGraphicsOn"
: "apple.awt.antialiasing";
if (mAntiAliasedGraphics != null)
bundleProperties.addJavaProperty(antiAliasedProperty,
mAntiAliasedGraphics.toString());
// Anti Aliased Text, renamed in 1.4+
String antiAliasedTextProperty = useOldPropertyNames()
? "com.apple.macosx.AntiAliasedTextOn"
: "apple.awt.textantialiasing";
if (mAntiAliasedText != null)
bundleProperties.addJavaProperty(antiAliasedTextProperty,
mAntiAliasedText.toString());
// Live Resize, deprecated under 1.4+
if (useOldPropertyNames() && (mLiveResize != null))
bundleProperties.addJavaProperty(
"com.apple.mrj.application.live-resize", mLiveResize
.toString());
// Screen Menu Bar, renamed in 1.4+
String screenMenuBarProperty = useOldPropertyNames()
? "com.apple.macos.useScreenMenuBar"
: "apple.laf.useScreenMenuBar";
if (mScreenMenuBar != null)
bundleProperties.addJavaProperty(screenMenuBarProperty,
mScreenMenuBar.toString());
// Growbox, added with 1.4+
if ((useOldPropertyNames() == false) && (mGrowbox != null))
bundleProperties.addJavaProperty("apple.awt.showGrowBox", mGrowbox
.toString());
// Growbox Intrudes, deprecated under 1.4+
if (useOldPropertyNames() && (mGrowboxIntrudes != null))
bundleProperties.addJavaProperty(
"com.apple.mrj.application.growbox.intrudes",
mGrowboxIntrudes.toString());
if (!mRootDir.exists()
|| (mRootDir.exists() && !mRootDir.isDirectory()))
throw new BuildException(
"Destination directory specified by \"dir\" "
+ "attribute must already exist.");
if (bundleDir.exists())
throw new BuildException("The directory/bundle \""
+ bundleDir.getName()
+ "\" already exists, cannot continue.");
// Status message
log("Creating application bundle: " + bundleDir);
if (!bundleDir.mkdir())
throw new BuildException("Unable to create bundle: " + bundleDir);
// Make the Contents directory
mContentsDir = new File(bundleDir, "Contents");
if (!mContentsDir.mkdir())
throw new BuildException("Unable to create directory "
+ mContentsDir);
// Make the "MacOS" directory
mMacOsDir = new File(mContentsDir, "MacOS");
if (!mMacOsDir.mkdir())
throw new BuildException("Unable to create directory " + mMacOsDir);
// Make the Resources directory
mResourcesDir = new File(mContentsDir, "Resources");
if (!mResourcesDir.mkdir())
throw new BuildException("Unable to create directory "
+ mResourcesDir);
// Make the Resources/Java directory
mJavaDir = new File(bundleProperties.getJavaVersion() < 1.7 ? mResourcesDir : mContentsDir, "Java");
if (!mJavaDir.mkdir())
throw new BuildException("Unable to create directory " + mJavaDir);
// Copy icon file to resource dir. If no icon parameter
// is supplied, the default icon will be used.
if (mAppIcon != null) {
try {
File dest = new File(mResourcesDir, mAppIcon.getName());
if(mVerbose)
log("Copying application icon file to \"" + bundlePath(dest) + "\"");
mFileUtils.copyFile(mAppIcon, dest);
} catch (IOException ex) {
throw new BuildException("Cannot copy icon file: " + ex);
}
}
// Copy document type icons, if any, to the resource dir
try {
Iterator itor = bundleProperties.getDocumentTypes().iterator();
while (itor.hasNext()) {
DocumentType documentType = (DocumentType) itor.next();
File iconFile = documentType.getIconFile();
if (iconFile != null) {
File dest = new File(mResourcesDir, iconFile.getName());
if(mVerbose)
log("Copying document icon file to \"" + bundlePath(dest) + "\"");
mFileUtils.copyFile(iconFile, dest);
}
}
} catch (IOException ex) {
throw new BuildException("Cannot copy document icon file: " + ex);
}
// Copy application jar(s) from the "jars" attribute (if any)
processJarAttrs();
// Copy application jar(s) from the nested jarfileset element(s)
processJarFileSets();
// Copy application jar(s) from the nested jarfilelist element(s)
processJarFileLists();
// Copy executable(s) from the "execs" attribute (if any)
processExecAttrs();
// Copy executable(s) from the nested execfileset element(s)
processExecFileSets();
// Copy executable(s) from the nested execfilelist element(s)
processExecFileLists();
// Copy resource(s) from the nested resourcefileset element(s)
processResourceFileSets();
// Copy resource(s) from the nested javafileset element(s)
processJavaFileSets();
// Copy resource(s) from the nested resourcefilelist element(s)
processResourceFileLists();
// Copy resource(s) from the nested javafilelist element(s)
processJavaFileLists();
// Add external classpath references from the extraclasspath attributes
processExtraClassPathAttrs();
// Add external classpath references from the nested
// extraclasspathfileset element(s)
processExtraClassPathFileSets();
// Add external classpath references from the nested
// extraclasspathfilelist attributes
processExtraClassPathFileLists();
// Copy HelpBooks into place
copyHelpBooks();
// Copy the JavaApplicationStub file from the Java system directory to
// the MacOS directory
copyApplicationStub();
// Create the Info.plist file
writeInfoPlist();
// Create the PkgInfo file
writePkgInfo();
// Done!
}
/***************************************************************************
* Private utility methods.
**************************************************************************/
private void setExecutable(File f) {
Chmod chmodTask = new Chmod();
chmodTask.setProject(getProject());
chmodTask.setFile(f);
chmodTask.setPerm("ugo+rx");
if (mVerbose)
log("Setting \"" + bundlePath(f) + "\" to executable");
chmodTask.execute();
}
/**
* Utility method to determine whether this app bundle is targeting a 1.3 or
* 1.4 VM. The Mac OS X 1.3 VM uses different Java property names from the
* 1.4 VM to hint at native Mac OS X look and feel options. For example, on
* 1.3 the Java property to tell the VM to display Swing menu bars as screen
* menus is "com.apple.macos.useScreenMenuBar". Under 1.4, it becomes
* "apple.laf.useScreenMenuBar". Such is the price of progress, I suppose.
*
* Obviously, this logic may need refactoring in the future.
*/
private boolean useOldPropertyNames() {
return (bundleProperties.getJavaVersion() <= 1.3);
}
private void processJarAttrs() throws BuildException {
try {
for (Iterator jarIter = mJarAttrs.iterator(); jarIter.hasNext();) {
File src = (File) jarIter.next();
File dest = new File(mJavaDir, src.getName());
if (mVerbose)
log("Copying JAR file to \"" + bundlePath(dest) + "\"");
mFileUtils.copyFile(src, dest);
bundleProperties.addToClassPath(dest.getName());
}
} catch (IOException ex) {
throw new BuildException("Cannot copy jar file: " + ex);
}
}
private void processJarFileSets() throws BuildException {
for (Iterator jarIter = mJarFileSets.iterator(); jarIter.hasNext();) {
FileSet fs = (FileSet) jarIter.next();
Project p = fs.getProject();
File srcDir = fs.getDir(p);
FileScanner ds = fs.getDirectoryScanner(p);
fs.setupDirectoryScanner(ds, p);
ds.scan();
String[] files = ds.getIncludedFiles();
try {
for (int i = 0; i < files.length; i++) {
String fileName = files[i];
File src = new File(srcDir, fileName);
File dest = new File(mJavaDir, fileName);
if (mVerbose)
log("Copying JAR file to \"" + bundlePath(dest) + "\"");
mFileUtils.copyFile(src, dest);
bundleProperties.addToClassPath(fileName);
}
} catch (IOException ex) {
throw new BuildException("Cannot copy jar file: " + ex);
}
}
}
private void processJarFileLists() throws BuildException {
for (Iterator jarIter = mJarFileLists.iterator(); jarIter.hasNext();) {
FileList fl = (FileList) jarIter.next();
Project p = fl.getProject();
File srcDir = fl.getDir(p);
String[] files = fl.getFiles(p);
try {
for (int i = 0; i < files.length; i++) {
String fileName = files[i];
File src = new File(srcDir, fileName);
File dest = new File(mJavaDir, fileName);
if (mVerbose)
log("Copying JAR file to \"" + bundlePath(dest) + "\"");
mFileUtils.copyFile(src, dest);
bundleProperties.addToClassPath(fileName);
}
} catch (IOException ex) {
throw new BuildException("Cannot copy jar file: " + ex);
}
}
}
private void processExtraClassPathAttrs() throws BuildException {
for (Iterator jarIter = mExtraClassPathAttrs.iterator(); jarIter
.hasNext();) {
File src = (File) jarIter.next();
String path = src.getPath().replace(File.separatorChar, '/');
bundleProperties.addToExtraClassPath(path);
}
}
private void processExtraClassPathFileSets() throws BuildException {
for (Iterator jarIter = mExtraClassPathFileSets.iterator(); jarIter
.hasNext();) {
FileSet fs = (FileSet) jarIter.next();
Project p = fs.getProject();
File srcDir = fs.getDir(p);
FileScanner ds = fs.getDirectoryScanner(p);
fs.setupDirectoryScanner(ds, p);
ds.scan();
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
File f = new File(srcDir, files[i]);
String path = f.getPath().replace(File.separatorChar, '/');
bundleProperties.addToExtraClassPath(path);
}
}
}
private void processExtraClassPathFileLists() throws BuildException {
for (Iterator jarIter = mExtraClassPathFileLists.iterator(); jarIter
.hasNext();) {
FileList fl = (FileList) jarIter.next();
Project p = fl.getProject();
File srcDir = fl.getDir(p);
String[] files = fl.getFiles(p);
for (int i = 0; i < files.length; i++) {
File f = new File(srcDir, files[i]);
String path = f.getPath().replace(File.separatorChar, '/');
bundleProperties.addToExtraClassPath(path);
}
}
}
private void processExecAttrs() throws BuildException {
try {
for (Iterator execIter = mExecAttrs.iterator(); execIter.hasNext();) {
File src = (File) execIter.next();
File dest = new File(mMacOsDir, src.getName());
if (mVerbose)
log("Copying exec file to \"" + bundlePath(dest) + "\"");
mFileUtils.copyFile(src, dest);
setExecutable(dest);
}
} catch (IOException ex) {
throw new BuildException("Cannot copy exec file: " + ex);
}
}
// Methods for copying FileSets into the application bundle ///////////////////////////////
// Files for the Contents/MacOS directory
private void processExecFileSets() {
processCopyingFileSets(mExecFileSets, mMacOsDir, true);
}
// Files for the Contents/Resources directory
private void processResourceFileSets() {
processCopyingFileSets(mResourceFileSets, mResourcesDir, false);
}
// Files for the Contents/Resources/Java directory
private void processJavaFileSets() {
processCopyingFileSets(mJavaFileSets, mJavaDir, false);
}
private void processCopyingFileSets(List fileSets, File targetdir, boolean setExec) {
for (Iterator execIter = fileSets.iterator(); execIter.hasNext();) {
FileSet fs = (FileSet) execIter.next();
Project p = fs.getProject();
File srcDir = fs.getDir(p);
FileScanner ds = fs.getDirectoryScanner(p);
fs.setupDirectoryScanner(ds, p);
ds.scan();
String[] files = ds.getIncludedFiles();
if (files.length == 0) {
// this is probably an error -- warn about it
System.err
.println("WARNING: fileset for copying from directory "
+ srcDir + ": no files found");
} else {
try {
for (int i = 0; i < files.length; i++) {
String fileName = files[i];
File src = new File(srcDir, fileName);
File dest = new File(targetdir, fileName);
if (mVerbose)
log("Copying "
+ (setExec ? "exec" : "resource")
+ " file to \"" + bundlePath(dest) +"\"");
mFileUtils.copyFile(src, dest);
if (setExec)
setExecutable(dest);
}
} catch (IOException ex) {
throw new BuildException("Cannot copy file: " + ex);
}
}
}
}
// Methods for copying FileLists into the application bundle /////////////////////////////
// Files for the Contents/MacOS directory
private void processExecFileLists() throws BuildException {
processCopyingFileLists(mExecFileLists, mMacOsDir, true);
}
// Files for the Contents/Resources directory
private void processResourceFileLists() throws BuildException {
processCopyingFileLists(mResourceFileLists, mResourcesDir, false);
}
// Files for the Contents/Resources/Java directory
private void processJavaFileLists() throws BuildException {
processCopyingFileLists(mJavaFileLists, mJavaDir, false);
}
private void processCopyingFileLists(List fileLists, File targetDir, boolean setExec) throws BuildException {
for (Iterator execIter = fileLists.iterator(); execIter.hasNext();) {
FileList fl = (FileList) execIter.next();
Project p = fl.getProject();
File srcDir = fl.getDir(p);
String[] files = fl.getFiles(p);
if (files.length == 0) {
// this is probably an error -- warn about it
System.err.println("WARNING: filelist for copying from directory "
+ srcDir + ": no files found");
} else {
try {
for (int i = 0; i < files.length; i++) {
String fileName = files[i];
File src = new File(srcDir, fileName);
File dest = new File(targetDir, fileName);
if (mVerbose)
log("Copying "
+ (setExec ? "exec" : "resource")
+ " file to \"" + bundlePath(dest) +"\"");
mFileUtils.copyFile(src, dest);
if (setExec)
setExecutable(dest);
}
} catch (IOException ex) {
throw new BuildException("Cannot copy jar file: " + ex);
}
}
}
}
private void copyHelpBooks() {
for (Iterator itor = mHelpBooks.iterator(); itor.hasNext();) {
HelpBook helpBook = (HelpBook)itor.next();
String folderName = helpBook.getFolderName();
String name = helpBook.getName();
String locale = helpBook.getLocale();
List fileLists = helpBook.getFileLists();
List fileSets = helpBook.getFileSets();
File helpBookDir = null;
if (locale == null) {
// Set the Bundle entries for a nonlocalized Help Book
if (folderName != null)
bundleProperties.setCFBundleHelpBookFolder(folderName);
if (name != null)
bundleProperties.setCFBundleHelpBookName(name);
// The non-localized Help Book is top level "/Resources"
helpBookDir = new File(mResourcesDir, folderName);
helpBookDir.mkdir();
if(mVerbose)
log("Creating Help Book at \"" +
bundlePath(helpBookDir) + "\"");
} else {
// The localized Help Book is "/Resources/locale.lproj"
File lproj = new File(mResourcesDir, locale + ".lproj");
lproj.mkdir();
helpBookDir = new File(lproj, folderName);
helpBookDir.mkdir();
if(mVerbose)
log("Creating Help Book for \"" + locale +
"\" at \"" + bundlePath(helpBookDir) + "\"");
// Create a local file to override the Bundle settings
File infoPList = new File(lproj, "InfoPlist.strings");
PrintWriter writer = null;
try {
writer = new PrintWriter(new FileWriter(infoPList));
writer.println("CFBundleHelpBookFolder = \"" + folderName + "\";");
writer.println("CFBundleHelpBookName = \"" + name + "\";");
writer.println("CFBundleName = \"" + bundleProperties.getCFBundleName() + "\";");
} catch (IOException ioe) {
throw new BuildException("IOException in writing Help Book locale: " + locale);
} finally {
mFileUtils.close(writer);
}
}
// Write the Help Book source files into the bundle
processCopyingFileSets(fileSets, helpBookDir, false);
processCopyingFileLists(fileLists, helpBookDir, false);
}
}
// Copy the application stub into the bundle
// /////////////////////////////////////////////
private void copyApplicationStub() throws BuildException {
File newStubFile = new File(mMacOsDir, bundleProperties.getCFBundleExecutable());
if (mVerbose)
log("Copying Java application stub to \"" + bundlePath(newStubFile) + "\"");
try {
mFileUtils.copyFile(mStubFile, newStubFile);
} catch (IOException ex) {
throw new BuildException("Cannot copy Java Application Stub: " + ex);
}
// Set the permissions on the stub file to executable
setExecutable(newStubFile);
}
private void writeInfoPlist() throws BuildException {
PropertyListWriter listWriter = new PropertyListWriter(bundleProperties);
File infoPlist = new File(mContentsDir, "Info.plist");
listWriter.writeFile(infoPlist);
if (mVerbose)
log("Creating \"" + bundlePath(infoPlist) + "\" file");
if (mShowPlist) {
try {
BufferedReader in = new BufferedReader(new FileReader(infoPlist));
String str;
while ((str = in.readLine()) != null)
log(str);
in.close();
} catch (IOException e) {
throw new BuildException(e);
}
}
}
//
// Write the PkgInfo file into the application bundle
//
private void writePkgInfo() throws BuildException {
File pkgInfo = new File(mContentsDir, "PkgInfo");
PrintWriter writer = null;
try {
writer = new PrintWriter(new BufferedWriter(new FileWriter(pkgInfo)));
writer.print(bundleProperties.getCFBundlePackageType());
writer.println(bundleProperties.getCFBundleSignature());
writer.flush();
} catch (IOException ex) {
throw new BuildException("Cannot create PkgInfo file: " + ex);
} finally {
mFileUtils.close(writer);
}
}
private String bundlePath(File bundleFile) {
String rootPath = bundleDir.getAbsolutePath();
String thisPath = bundleFile.getAbsolutePath();
return thisPath.substring(rootPath.length());
}
}
|