Subversion Repository Public Repository

litesoft

Diff Revisions 314 vs 315 for /trunk/Java/ScarPlus/src/com/esotericsoftware/scar/Scar.java

Diff revisions: vs.
  @@ -62,7 +62,6 @@
62 62 */
63 63 @Override
64 64 public Project project( File pCanonicalCurrentDirectory, String pPath )
65 - throws IOException
66 65 {
67 66 Util.assertNotNull( "CurrentDirectory", pCanonicalCurrentDirectory );
68 67 pPath = Util.assertNotEmpty( "Path", pPath );
  @@ -71,7 +70,14 @@
71 70 {
72 71 zFile = new File( pCanonicalCurrentDirectory, pPath );
73 72 }
74 - zFile = zFile.getCanonicalFile();
73 + try
74 + {
75 + zFile = zFile.getCanonicalFile();
76 + }
77 + catch ( IOException e )
78 + {
79 + throw new WrappedIOException( e );
80 + }
75 81
76 82 String zPath = zFile.getPath();
77 83 Project zProject = mProjectCache.getByPath( zPath );
  @@ -90,9 +96,9 @@
90 96 return mProjectCache.initialize( this, zPath, createProject( findBuildFile( zFile ), zFile, zFile.getName() ) );
91 97 }
92 98 }
93 - catch ( IOException e )
99 + catch ( WrappedIOException e )
94 100 {
95 - throw new IOException( pPath, e );
101 + throw new WrappedIOException( pPath, e );
96 102 }
97 103 throw new IllegalArgumentException( "Project is Neither a Project File, nor a Project Directory: " + zFile );
98 104 }
  @@ -130,7 +136,6 @@
130 136 }
131 137
132 138 protected Project createProject( File pPossibleBuildFile, File pCanonicalProjectDir )
133 - throws IOException
134 139 {
135 140 String zBuildFileName = pPossibleBuildFile.getName();
136 141 int zDotAt = zBuildFileName.lastIndexOf( '.' );
  @@ -147,7 +152,6 @@
147 152 }
148 153
149 154 protected Project createProject( File pBuildFile, File pCanonicalProjectDir, String pProjectName )
150 - throws IOException
151 155 {
152 156 if ( pBuildFile == null )
153 157 {
  @@ -166,7 +170,6 @@
166 170 }
167 171
168 172 protected Project createYamlProject( File zYamlBuildFile, File pCanonicalProjectDir, String pProjectName )
169 - throws IOException
170 173 {
171 174 List<String> zLines = readLines( zYamlBuildFile );
172 175 int at = findLine( zLines, "---" );
  @@ -190,7 +193,6 @@
190 193 }
191 194
192 195 protected Project createJavaProject( File zJavaBuildFile, File pCanonicalProjectDir, String pProjectName )
193 - throws IOException
194 196 {
195 197 String zFile = mergeLines( readLines( zJavaBuildFile ), 0 );
196 198 Class<? extends Project> zClass = createJavaProjectClass();
  @@ -249,7 +251,6 @@
249 251 }
250 252
251 253 protected Map<Object, Object> parseYAML( File pProjectDir, String pYAML )
252 - throws IOException
253 254 {
254 255 final String zProjectDir = pProjectDir.getPath().replace( '\\', '/' );
255 256
  @@ -272,9 +273,20 @@
272 273 //noinspection unchecked
273 274 return yamlReader.read( HashMap.class );
274 275 }
276 + catch ( IOException e )
277 + {
278 + throw new WrappedIOException( e );
279 + }
275 280 finally
276 281 {
277 - yamlReader.close();
282 + try
283 + {
284 + yamlReader.close();
285 + }
286 + catch ( IOException e )
287 + {
288 + throw new WrappedIOException( e );
289 + }
278 290 }
279 291 }
280 292
  @@ -306,9 +318,16 @@
306 318 }
307 319
308 320 protected List<String> readLines( File zFile )
309 - throws IOException
310 321 {
311 - BufferedReader fileReader = new BufferedReader( new FileReader( zFile ) );
322 + BufferedReader fileReader;
323 + try
324 + {
325 + fileReader = new BufferedReader( new FileReader( zFile ) );
326 + }
327 + catch ( FileNotFoundException e )
328 + {
329 + throw new WrappedIOException( e );
330 + }
312 331 try
313 332 {
314 333 List<String> lines = new ArrayList<String>();
  @@ -334,7 +353,7 @@
334 353 // Whatever!
335 354 }
336 355 }
337 - throw e;
356 + throw new WrappedIOException( e );
338 357 }
339 358 }
340 359
  @@ -381,7 +400,6 @@
381 400 */
382 401 @SuppressWarnings({"UnusedDeclaration"})
383 402 public void cleanAll()
384 - throws IOException
385 403 {
386 404 progress( "CleanAll" );
387 405 Set<Project> zProjects = mProjectCache.getAllProjects();
  @@ -396,7 +414,6 @@
396 414 */
397 415 @SuppressWarnings({"UnusedDeclaration"})
398 416 public void build()
399 - throws IOException
400 417 {
401 418 mLaunchProject.build();
402 419 }
  @@ -420,7 +437,6 @@
420 437 * @param path Path to a YAML project file, or a directory containing a "project.yaml" file.
421 438 */
422 439 // public Project project( String path, Project defaults )
423 - // throws IOException
424 440 // {
425 441 // Util.assertNotNull( "path", path );
426 442 // Util.assertNotNull( "defaults", defaults );
  @@ -470,13 +486,20 @@
470 486 * @return The path to the JAR file.
471 487 */
472 488 public String unsign( String jarFile )
473 - throws IOException
474 489 {
475 490 Util.assertNotNull( "jarFile", jarFile );
476 491
477 492 progress( "Removing signature from JAR: " + jarFile );
478 493
479 - File tempFile = File.createTempFile( "scar", "removejarsig" );
494 + File tempFile;
495 + try
496 + {
497 + tempFile = File.createTempFile( "scar", "removejarsig" );
498 + }
499 + catch ( IOException e )
500 + {
501 + throw new WrappedIOException( e );
502 + }
480 503 JarOutputStream jarOutput = null;
481 504 JarInputStream jarInput = null;
482 505 try
  @@ -522,30 +545,12 @@
522 545 }
523 546 catch ( IOException ex )
524 547 {
525 - throw new IOException( "Error unsigning JAR file: " + jarFile, ex );
548 + throw new WrappedIOException( "Error unsigning JAR file: " + jarFile, ex );
526 549 }
527 550 finally
528 551 {
529 - try
530 - {
531 - if ( jarInput != null )
532 - {
533 - jarInput.close();
534 - }
535 - }
536 - catch ( Exception ignored )
537 - {
538 - }
539 - try
540 - {
541 - if ( jarOutput != null )
542 - {
543 - jarOutput.close();
544 - }
545 - }
546 - catch ( Exception ignored )
547 - {
548 - }
552 + dispose( jarInput );
553 + dispose( jarOutput );
549 554 tempFile.delete();
550 555 }
551 556 return jarFile;
  @@ -557,7 +562,6 @@
557 562 * @return The path to the JAR.
558 563 */
559 564 public String sign( String jarFile, String keystoreFile, String alias, String password )
560 - throws IOException
561 565 {
562 566 Util.assertNotNull( "jarFile", jarFile );
563 567 Util.assertNotNull( "keystoreFile", keystoreFile );
  @@ -580,7 +584,6 @@
580 584 * @return The path to the encoded file.
581 585 */
582 586 public String pack200( String jarFile )
583 - throws IOException
584 587 {
585 588 String packedFile = pack200( jarFile, jarFile + ".pack" );
586 589 delete( jarFile );
  @@ -593,7 +596,6 @@
593 596 * @return The path to the encoded file.
594 597 */
595 598 public String pack200( String jarFile, String packedFile )
596 - throws IOException
597 599 {
598 600 Util.assertNotNull( "jarFile", jarFile );
599 601 Util.assertNotNull( "packedFile", packedFile );
  @@ -611,7 +613,6 @@
611 613 * @return The path to the decoded file.
612 614 */
613 615 public String unpack200( String packedFile )
614 - throws IOException
615 616 {
616 617 Util.assertNotNull( "packedFile", packedFile );
617 618 if ( !packedFile.endsWith( ".pack" ) )
  @@ -630,7 +631,6 @@
630 631 * @return The path to the decoded file.
631 632 */
632 633 public String unpack200( String packedFile, String jarFile )
633 - throws IOException
634 634 {
635 635 Util.assertNotNull( "packedFile", packedFile );
636 636 Util.assertNotNull( "jarFile", jarFile );
  @@ -647,7 +647,6 @@
647 647 * @return The path to the encoded file.
648 648 */
649 649 public String gzip( String file )
650 - throws IOException
651 650 {
652 651 String gzipFile = gzip( file, file + ".gz" );
653 652 delete( file );
  @@ -660,27 +659,32 @@
660 659 * @return The path to the encoded file.
661 660 */
662 661 public String gzip( String file, String gzipFile )
663 - throws IOException
664 662 {
665 663 Util.assertNotNull( "file", file );
666 664 Util.assertNotNull( "gzipFile", gzipFile );
667 665
668 666 progress( "GZIP encoding: " + file + " -> " + gzipFile );
669 667
670 - InputStream input = new FileInputStream( file );
668 + InputStream input;
669 + try
670 + {
671 + input = new FileInputStream( file );
672 + }
673 + catch ( FileNotFoundException e )
674 + {
675 + throw new WrappedIOException( e );
676 + }
671 677 try
672 678 {
673 679 copyStream( input, new GZIPOutputStream( new FileOutputStream( gzipFile ) ) );
674 680 }
681 + catch ( IOException e )
682 + {
683 + throw new WrappedIOException( e );
684 + }
675 685 finally
676 686 {
677 - try
678 - {
679 - input.close();
680 - }
681 - catch ( Exception ignored )
682 - {
683 - }
687 + dispose( input );
684 688 }
685 689 return gzipFile;
686 690 }
  @@ -692,7 +696,6 @@
692 696 * @return The path to the decoded file.
693 697 */
694 698 public String ungzip( String gzipFile )
695 - throws IOException
696 699 {
697 700 Util.assertNotNull( "gzipFile", gzipFile );
698 701 if ( !gzipFile.endsWith( ".gz" ) )
  @@ -711,26 +714,31 @@
711 714 * @return The path to the decoded file.
712 715 */
713 716 public String ungzip( String gzipFile, String file )
714 - throws IOException
715 717 {
716 718 Util.assertNotNull( "gzipFile", gzipFile );
717 719 Util.assertNotNull( "file", file );
718 720 progress( "GZIP decoding: " + gzipFile + " -> " + file );
719 721
720 - InputStream input = new GZIPInputStream( new FileInputStream( gzipFile ) );
722 + InputStream input;
723 + try
724 + {
725 + input = new GZIPInputStream( new FileInputStream( gzipFile ) );
726 + }
727 + catch ( IOException e )
728 + {
729 + throw new WrappedIOException( e );
730 + }
721 731 try
722 732 {
723 733 copyStream( input, new FileOutputStream( file ) );
724 734 }
735 + catch ( FileNotFoundException e )
736 + {
737 + throw new WrappedIOException( e );
738 + }
725 739 finally
726 740 {
727 - try
728 - {
729 - input.close();
730 - }
731 - catch ( Exception ignored )
732 - {
733 - }
741 + dispose( input );
734 742 }
735 743 return file;
736 744 }
  @@ -741,7 +749,6 @@
741 749 * @return The path to the encoded file.
742 750 */
743 751 public String zip( Paths paths, String zipFile )
744 - throws IOException
745 752 {
746 753 Util.assertNotNull( "paths", paths );
747 754 Util.assertNotNull( "zipFile", zipFile );
  @@ -757,18 +764,33 @@
757 764 * @return The path to the output directory.
758 765 */
759 766 public String unzip( String zipFile, String outputDir )
760 - throws IOException
761 767 {
762 768 Util.assertNotNull( "zipFile", zipFile );
763 769 Util.assertNotNull( "outputDir", outputDir );
764 770 progress( "ZIP decoding: " + zipFile + " -> " + outputDir );
765 771
766 - ZipInputStream input = new ZipInputStream( new FileInputStream( zipFile ) );
772 + ZipInputStream input;
773 + try
774 + {
775 + input = new ZipInputStream( new FileInputStream( zipFile ) );
776 + }
777 + catch ( FileNotFoundException e )
778 + {
779 + throw new WrappedIOException( e );
780 + }
767 781 try
768 782 {
769 783 while ( true )
770 784 {
771 - ZipEntry entry = input.getNextEntry();
785 + ZipEntry entry;
786 + try
787 + {
788 + entry = input.getNextEntry();
789 + }
790 + catch ( IOException e )
791 + {
792 + throw new WrappedIOException( e );
793 + }
772 794 if ( entry == null )
773 795 {
774 796 break;
  @@ -780,7 +802,15 @@
780 802 continue;
781 803 }
782 804 mkdir( file.getParent() );
783 - FileOutputStream output = new FileOutputStream( file );
805 + FileOutputStream output;
806 + try
807 + {
808 + output = new FileOutputStream( file );
809 + }
810 + catch ( FileNotFoundException e )
811 + {
812 + throw new WrappedIOException( e );
813 + }
784 814 try
785 815 {
786 816 byte[] buffer = new byte[4096];
  @@ -794,27 +824,19 @@
794 824 output.write( buffer, 0, length );
795 825 }
796 826 }
827 + catch ( IOException e )
828 + {
829 + throw new WrappedIOException( e );
830 + }
797 831 finally
798 832 {
799 - try
800 - {
801 - output.close();
802 - }
803 - catch ( Exception ignored )
804 - {
805 - }
833 + dispose( output );
806 834 }
807 835 }
808 836 }
809 837 finally
810 838 {
811 - try
812 - {
813 - input.close();
814 - }
815 - catch ( Exception ignored )
816 - {
817 - }
839 + dispose( input );
818 840 }
819 841 return outputDir;
820 842 }
  @@ -826,7 +848,6 @@
826 848 * @return The path to the encoded file.
827 849 */
828 850 public String lzma( String file )
829 - throws IOException
830 851 {
831 852 String lzmaFile = lzma( file, file + ".lzma" );
832 853 delete( file );
  @@ -839,7 +860,6 @@
839 860 * @return The path to the encoded file.
840 861 */
841 862 public String lzma( String file, String lzmaFile )
842 - throws IOException
843 863 {
844 864 Util.assertNotNull( "file", file );
845 865 Util.assertNotNull( "lzmaFile", lzmaFile );
  @@ -851,7 +871,7 @@
851 871 }
852 872 catch ( Exception ex )
853 873 {
854 - throw new IOException( "Error lzma compressing file: " + file, ex );
874 + throw new WrappedIOException( "Error lzma compressing file: " + file, ex );
855 875 }
856 876 return lzmaFile;
857 877 }
  @@ -863,7 +883,6 @@
863 883 * @return The path to the decoded file.
864 884 */
865 885 public String unlzma( String lzmaFile )
866 - throws IOException
867 886 {
868 887 Util.assertNotNull( "lzmaFile", lzmaFile );
869 888 if ( !lzmaFile.endsWith( ".lzma" ) )
  @@ -882,7 +901,6 @@
882 901 * @return The path to the decoded file.
883 902 */
884 903 public String unlzma( String lzmaFile, String file )
885 - throws IOException
886 904 {
887 905 Util.assertNotNull( "lzmaFile", lzmaFile );
888 906 Util.assertNotNull( "file", file );
  @@ -894,7 +912,7 @@
894 912 }
895 913 catch ( Exception ex )
896 914 {
897 - throw new IOException( "Error lzma decompressing file: " + file, ex );
915 + throw new WrappedIOException( "Error lzma decompressing file: " + file, ex );
898 916 }
899 917 return file;
900 918 }
  @@ -905,7 +923,6 @@
905 923 * GZIP.
906 924 */
907 925 public void jws( Project project, boolean pack, String keystoreFile, String alias, String password )
908 - throws IOException
909 926 {
910 927 Util.assertNotNull( "Project", project );
911 928 Util.assertNotNull( "keystoreFile", keystoreFile );
  @@ -945,7 +962,6 @@
945 962 * JARs and regular JARs, based on capability of the client requesting the JAR.
946 963 */
947 964 public void jwsHtaccess( Project project )
948 - throws IOException
949 965 {
950 966 Util.assertNotNull( "Project", project );
951 967
  @@ -956,7 +972,15 @@
956 972 {
957 973 String packedFileName = fileName( packedFile );
958 974 String jarFileName = substring( packedFileName, 0, -8 );
959 - FileWriter writer = new FileWriter( jwsDir + jarFileName + ".var" );
975 + FileWriter writer;
976 + try
977 + {
978 + writer = new FileWriter( jwsDir + jarFileName + ".var" );
979 + }
980 + catch ( IOException e )
981 + {
982 + throw new WrappedIOException( e );
983 + }
960 984 try
961 985 {
962 986 writer.write( "URI: packed/" + packedFileName + "\n" );
  @@ -965,18 +989,24 @@
965 989 writer.write( "URI: unpacked/" + jarFileName + "\n" );
966 990 writer.write( "Content-Type: x-java-archive\n" );
967 991 }
992 + catch ( IOException e )
993 + {
994 + throw new WrappedIOException( e );
995 + }
968 996 finally
969 997 {
970 - try
971 - {
972 - writer.close();
973 - }
974 - catch ( Exception ignored )
975 - {
976 - }
998 + dispose( writer );
977 999 }
978 1000 }
979 - FileWriter writer = new FileWriter( jwsDir + ".htaccess" );
1001 + FileWriter writer;
1002 + try
1003 + {
1004 + writer = new FileWriter( jwsDir + ".htaccess" );
1005 + }
1006 + catch ( IOException e )
1007 + {
1008 + throw new WrappedIOException( e );
1009 + }
980 1010 try
981 1011 {
982 1012 writer.write( "AddType application/x-java-jnlp-file .jnlp" ); // JNLP mime type.
  @@ -989,15 +1019,13 @@
989 1019 writer.write( "RemoveEncoding .gz\n" ); // Prevent mod_gzip from messing with the Content-Encoding response.
990 1020 writer.write( "</Files>\n" );
991 1021 }
1022 + catch ( IOException e )
1023 + {
1024 + throw new WrappedIOException( e );
1025 + }
992 1026 finally
993 1027 {
994 - try
995 - {
996 - writer.close();
997 - }
998 - catch ( Exception ignored )
999 - {
1000 - }
1028 + dispose( writer );
1001 1029 }
1002 1030 }
1003 1031
  @@ -1009,7 +1037,6 @@
1009 1037 * @param splashImage Can be null.
1010 1038 */
1011 1039 public void jnlp( Project project, String url, String company, String title, String splashImage )
1012 - throws IOException
1013 1040 {
1014 1041 Util.assertNotNull( "Project", project );
1015 1042 Util.assertNotNull( "company", company );
  @@ -1045,7 +1072,15 @@
1045 1072 String jnlpFile = url.substring( lastSlash + 1 );
1046 1073
1047 1074 String jwsDir = mkdir( project.path( "$target$/jws/" ) );
1048 - FileWriter writer = new FileWriter( jwsDir + jnlpFile );
1075 + FileWriter writer;
1076 + try
1077 + {
1078 + writer = new FileWriter( jwsDir + jnlpFile );
1079 + }
1080 + catch ( IOException e )
1081 + {
1082 + throw new WrappedIOException( e );
1083 + }
1049 1084 try
1050 1085 {
1051 1086 writer.write( "<?xml version='1.0' encoding='utf-8'?>\n" );
  @@ -1121,20 +1156,17 @@
1121 1156 writer.write( "<application-desc main-class='" + project.getMain() + "'/>\n" );
1122 1157 writer.write( "</jnlp>" );
1123 1158 }
1159 + catch ( IOException e )
1160 + {
1161 + throw new WrappedIOException( e );
1162 + }
1124 1163 finally
1125 1164 {
1126 - try
1127 - {
1128 - writer.close();
1129 - }
1130 - catch ( Exception ignored )
1131 - {
1132 - }
1165 + dispose( writer );
1133 1166 }
1134 1167 }
1135 1168
1136 1169 public String lwjglApplet( Project project, String keystoreFile, String alias, String password )
1137 - throws IOException
1138 1170 {
1139 1171 Util.assertNotNull( "Project", project );
1140 1172 Util.assertNotNull( "keystoreFile", keystoreFile );
  @@ -1178,7 +1210,15 @@
1178 1210 return appletDir;
1179 1211 }
1180 1212 progress( "Generating: applet.html" );
1181 - FileWriter writer = new FileWriter( appletDir + "applet.html" );
1213 + FileWriter writer;
1214 + try
1215 + {
1216 + writer = new FileWriter( appletDir + "applet.html" );
1217 + }
1218 + catch ( IOException e )
1219 + {
1220 + throw new WrappedIOException( e );
1221 + }
1182 1222 try
1183 1223 {
1184 1224 writer.write( "<html>\n" );
  @@ -1229,15 +1269,13 @@
1229 1269 writer.write( "</applet>\n" );
1230 1270 writer.write( "</body></html>\n" );
1231 1271 }
1272 + catch ( IOException e )
1273 + {
1274 + throw new WrappedIOException( e );
1275 + }
1232 1276 finally
1233 1277 {
1234 - try
1235 - {
1236 - writer.close();
1237 - }
1238 - catch ( Exception ignored )
1239 - {
1240 - }
1278 + dispose( writer );
1241 1279 }
1242 1280 return appletDir;
1243 1281 }
  @@ -1253,7 +1291,6 @@
1253 1291 * @param excludeJARs The names of any JARs to exclude.
1254 1292 */
1255 1293 public void oneJAR( Project project, String... excludeJARs )
1256 - throws IOException
1257 1294 {
1258 1295 Util.assertNotNull( "Project", project );
1259 1296
  @@ -1422,7 +1459,6 @@
1422 1459 * @return true if code was executed.
1423 1460 */
1424 1461 public boolean executeDocument( Project project )
1425 - throws IOException
1426 1462 {
1427 1463 String code = null; // todo: was -- project.getDocument();
1428 1464 if ( code == null || code.trim().isEmpty() )
  @@ -1491,7 +1527,6 @@
1491 1527 }
1492 1528
1493 1529 private Project initialize( ProjectFactory pFactory, String pPath, Project pProject )
1494 - throws IOException
1495 1530 {
1496 1531 synchronized ( this )
1497 1532 {
  @@ -1516,7 +1551,6 @@
1516 1551 }
1517 1552
1518 1553 protected Runnable createRunnableFor( String pMethodName )
1519 - throws IOException
1520 1554 {
1521 1555 Runnable zRunnable = createRunnableFor( this, pMethodName );
1522 1556 return (zRunnable != null) ? zRunnable : createRunnableFor( mLaunchProject, pMethodName );
  @@ -1571,13 +1605,11 @@
1571 1605 }
1572 1606
1573 1607 protected void createLaunchProject()
1574 - throws IOException
1575 1608 {
1576 1609 mLaunchProject = project( CANONICAL_USER_DIR, mArgs.get( "file", "." ) );
1577 1610 }
1578 1611
1579 1612 protected int run()
1580 - throws IOException
1581 1613 {
1582 1614 if ( mArgs.count() == 0 )
1583 1615 {
  @@ -1593,7 +1625,6 @@
1593 1625 }
1594 1626
1595 1627 private ArrayList<Runnable> getArgsBasedRunnables()
1596 - throws IOException
1597 1628 {
1598 1629 ArrayList<Runnable> zRunnables = new ArrayList<Runnable>();
1599 1630 List<String> zUnrecognizedNames = new ArrayList<String>();