1 17 18 19 21 39 40 import java.io.*; import java.net.*; import java.util.*; import java.util.zip.*; import java.lang.reflect.*; 46 47 110 public class Extractor extends ClassLoader 111 implements URLStreamHandlerFactory 112 { 113 114 public static boolean debug=false; 115 116 117 protected Vector extractedFiles; 118 119 protected String archiveType=""; 120 121 protected String appClassName=""; 122 123 protected String extraClassPath=""; 124 125 private static Extractor extractor= null; 128 129 130 private static Hashtable filePathCache = new Hashtable(); 131 132 133 private static Hashtable reverseFilePathCache = new Hashtable(); 134 135 136 private static Hashtable classesCache = new Hashtable(); 137 138 private static boolean initialized = false; 139 140 141 public Extractor() 142 { 143 extractedFiles = new Vector(128); 144 if (!initialized) { 145 URL.setURLStreamHandlerFactory(this); 146 initialized = true; 147 } 148 } 149 150 157 public String addToFilePathCache( File filePath ) 158 { 159 int idx = filePathCache.size(); 160 String absolutePath = filePath.getAbsolutePath(); 161 String key; 162 String identifier; 163 164 if ( absolutePath.endsWith(".zip") || absolutePath.endsWith(".jar") ) 165 identifier="ZIP"; 166 else 167 identifier="FILE"; 168 169 key = (String )reverseFilePathCache.get( absolutePath ); 170 if (key != null) { 171 if (debug) System.out.println(">>>> *OLD* KEY: "+key+"\tVALUE:"+absolutePath); 172 return (key); 173 } 174 175 key = identifier+idx; 176 if (debug) System.out.println(">>>> *NEW* KEY: "+key+"\tVALUE:"+absolutePath); 177 filePathCache.put( key, absolutePath ); 178 reverseFilePathCache.put( absolutePath, key ); 179 180 return (key); 181 } 182 183 189 public Class loadClass( String typeName ) 190 throws ClassNotFoundException 191 { 192 return loadClass( typeName, true ); 193 } 194 195 208 public synchronized Class loadClass(String typeName, boolean resolveIt) 209 throws ClassNotFoundException 210 { 211 if (debug) System.out.println( "DEBUG: Extractor.loadClass("+typeName+","+resolveIt+")" ); 214 Class result = (Class )classesCache.get( typeName ); 215 if ( result != null ) { 216 return result; 218 } 219 220 result = findLoadedClass(typeName); 221 if (result != null) { 222 return result; 224 } 225 226 try { 231 result = super.findSystemClass(typeName); 232 return result; 234 } 235 catch (ClassNotFoundException e) { 236 } 237 238 if (typeName.startsWith("java.")) { 243 throw new ClassNotFoundException (); 244 } 245 246 byte typeData[] = getTypeFromExtendedClassPath(typeName); 248 if (typeData == null) { 249 throw new ClassNotFoundException (); 250 } 251 else { 252 } 253 254 result = defineClass(typeName, typeData, 0, typeData.length); 257 if (result == null) { 258 throw new ClassFormatError (); 259 } 260 261 if (resolveIt) { 264 resolveClass(result); 265 } 266 267 classesCache.put( typeName, result ); 269 270 return result; 272 } 273 274 279 private byte[] getTypeFromExtendedClassPath( String typeName ) 280 { 281 if (debug) System.out.println( "DEBUG: Extractor.getTypeFromExtendedClassPath("+typeName+")" ); 282 283 byte[] typeData = null; 284 String fileName = typeName.replace( '.', File.separatorChar ) + ".class"; 285 286 if (debug) System.out.println("fileName="+fileName ); 287 288 String ecp = extraClassPath + File.pathSeparatorChar + 289 System.getProperty("java.class.path"); 290 292 293 StringTokenizer st = 294 new StringTokenizer( ecp, File.pathSeparatorChar+"" ); 295 296 while ( st.hasMoreTokens() && typeData == null) { 297 String filePath = st.nextToken(); 298 299 File file = new File( filePath, fileName ); 300 302 if ( filePath.endsWith(".zip") || filePath.endsWith(".jar") ) { 303 File zf = new File(filePath); 304 if ( zf.exists() ) { 305 typeData = getTypeFromZipFile( new File(filePath), fileName ); 307 } 308 } 309 else if ( file.exists() ) { 310 typeData = getTypeFromLocalFile( file ); 312 } 313 } 314 315 return (typeData); 316 } 317 318 319 325 private byte[] getTypeFromLocalFile( File file ) 326 { 327 byte[] typeData = null; 328 BufferedInputStream bis=null; 329 ByteArrayOutputStream out = new ByteArrayOutputStream(); 330 331 try { 332 byte [] buffer = new byte[8192]; 333 bis = new BufferedInputStream( new FileInputStream( file )); 334 int total_bytes=0; 335 int num_bytes; 336 while ( (num_bytes = bis.read( buffer )) > 0 ) { 337 out.write( buffer, 0, num_bytes ); 338 total_bytes += num_bytes; 339 } 340 typeData = out.toByteArray(); 341 } 342 catch (IOException e) { 343 typeData = null; 344 } 345 finally { 346 if (bis != null) try { bis.close(); } catch (IOException e) { }; 347 } 348 349 return (typeData); 350 } 351 352 358 private byte[] getTypeFromZipFile( File file, String typeFileName ) 359 { 360 byte[] typeData = null; 361 ZipFile zipFile = null; 362 363 try { 364 zipFile = new ZipFile( file ); 365 Enumeration entries = zipFile.entries(); 366 while ( entries.hasMoreElements() ) { 367 ZipEntry zipEntry = (ZipEntry)entries.nextElement(); 368 370 if (zipEntry.getName().equals( typeFileName ) ) { 371 if (debug) System.out.println( "*FOUND* zip/jar file entry:`"+typeFileName+"' ("+file.getPath()+")" ); 372 373 byte [] buffer = new byte[8192]; 374 BufferedInputStream bis = 375 new BufferedInputStream( zipFile.getInputStream( zipEntry ) ); 376 ByteArrayOutputStream out = new ByteArrayOutputStream(); 377 378 long dataSize = zipEntry.getSize(); 379 int c = bis.read(); 380 while (c != -1 && dataSize > 0 ) { 381 --dataSize; 382 out.write(c); 383 if (dataSize > 0) c = bis.read(); 384 } 385 typeData = out.toByteArray(); 386 } 387 } 388 } 389 catch (IOException e) { 390 } 392 finally { 393 if (zipFile != null) try { zipFile.close(); } catch (IOException e) { }; 394 } 395 396 return (typeData); 397 } 398 399 402 public InputStream getResourceAsStream( String name ) 403 { 404 if (debug) System.out.println("Extractor.getResourceAsStream("+name+")" ); 405 406 URL url = getResource( name ); 407 InputStream is=null; 408 if ( url != null ) { 409 try { 410 is = url.openStream(); 411 } 412 catch (IOException ioe) { 413 is = null; 414 } 415 } 416 417 return (is); 418 } 419 420 423 public URL getResource( String name ) 424 { 425 if (debug) System.out.println("Extractor.getResource("+name+")" ); 426 427 return getCachedURLForResource( name ); 428 } 429 430 436 private URL getCachedURLForResource( String fileName ) 437 { 438 if (debug) System.out.println( "Extractor.getCachedURLForResource("+fileName+")" ); 439 440 URL url = null; 441 442 String ecp = extraClassPath + File.pathSeparatorChar + 443 System.getProperty("java.class.path"); 444 446 StringTokenizer st = 447 new StringTokenizer( ecp, File.pathSeparatorChar+"" ); 448 449 while ( st.hasMoreTokens() && url == null) { 450 String filePath = st.nextToken(); 451 452 File file = new File( filePath, fileName ); 453 455 if ( filePath.endsWith(".zip") || filePath.endsWith(".jar") ) { 456 File zf = new File(filePath); 457 if ( zf.exists() ) { 458 boolean found = 460 searchZipArchiveForFile( zf, fileName ); 461 if (found) { 462 String host = addToFilePathCache( zf ); 463 try { 464 url = new URL( "extractor", host, 0, fileName ); 465 } 466 catch (MalformedURLException mue) { } 467 } 468 } 469 } 470 else if ( file.exists() ) { 471 if (debug) System.out.println("DEBUG: resource file:`"+fileName+"' exists!"); 472 String host = addToFilePathCache( new File(filePath) ); 473 try { 474 url = new URL( "extractor", host, 0, fileName ); 475 } 476 catch (MalformedURLException mue) { } 477 } 478 } 479 480 if (debug) System.out.println("*FINAL* url = "+url+"\n"); 481 482 return (url); 483 } 484 485 506 public static InputStream getCachedResourceAsInputStream( URL url ) 507 throws IOException 508 { 509 if (debug) System.out.println( "Extractor.getCachedResourceAsInputStream("+url+")" ); 510 511 InputStream is; 512 URLConnection con = url.openConnection(); 513 String protocol = url.getProtocol(); 514 if ( protocol == null) 515 throw new IOException( "null protocol supplied."); 516 if ( !protocol.equalsIgnoreCase("extractor") ) 517 throw new IOException( "protocol unrecognized by self extractor."); 518 519 String host = url.getHost(); 520 if (host.startsWith("FILE")) { 521 String filePath = (String )filePathCache.get(host); 522 if (filePath == null) 523 throw new IOException("no such extractor file resource:"+url.toExternalForm() ); 524 String properFile = filePath + File.separatorChar + url.getFile(); 525 is = new FileInputStream( properFile ); 526 } 527 else if (host.startsWith("ZIP")) { 528 String filePath = (String )filePathCache.get(host); 529 String fileName = url.getFile(); 530 if (filePath == null) 531 throw new IOException("no such extractor zip file resource:"+url.toExternalForm() ); 532 is = getInputStreamFromZipFile( new File(filePath), fileName ); 533 if (debug) { 534 System.out.println("\tThread="+Thread.currentThread()); 535 System.out.println("\tThreadName="+Thread.currentThread().getName()); 536 System.out.println("\tActiveCount="+Thread.currentThread().activeCount()); 537 System.out.println("\tPriority="+Thread.currentThread().getPriority()); 538 System.out.println("\tThreadGroup="+Thread.currentThread().getThreadGroup()); 539 System.out.println("\tis="+is); 540 System.out.println("\tis.available()="+is.available() ); 541 } 542 } 543 else 544 throw new IOException("unknown extractor resource -- cannot retrieve:"+url.toExternalForm() ); 545 546 return (is); 547 } 548 549 554 private static boolean searchZipArchiveForFile( File file, String appresFileName ) 555 { 556 ZipFile zipFile = null; 557 boolean found = false; 558 559 if ( !file.exists() ) return (false); 561 try { 562 zipFile = new ZipFile( file ); 564 Enumeration entries = zipFile.entries(); 565 while ( entries.hasMoreElements() ) { 566 ZipEntry zipEntry = (ZipEntry)entries.nextElement(); 567 if (zipEntry.getName().equals( appresFileName ) ) { 569 if (debug) System.out.println( "*SFOUND* zip/jar resource:`"+appresFileName+"' ("+file.getPath()+")" ); 570 found = true; 571 break; 572 } 573 } 574 } 575 catch (IOException e) { 576 e.printStackTrace(); 577 System.err.println("file:"+file.getPath()+" "+appresFileName ); 578 System.err.println("DEATH 69"); System.exit(69); 579 } 580 finally { 581 if (zipFile != null) try { zipFile.close(); } catch (IOException e) { }; 582 } 583 584 return (found); 585 } 586 587 593 private static InputStream getInputStreamFromZipFile( File file, String appresFileName ) 594 { 595 ZipFile zipFile = null; 596 boolean found=false; 597 InputStream is = null; 598 599 if ( !file.exists() ) return (null); 601 ZipInputStream zis = null; 602 try { 603 zis = new ZipInputStream( new FileInputStream( file.getPath() )); 604 ZipEntry zipEntry; 605 do { 606 zipEntry = zis.getNextEntry(); 607 if (zipEntry != null ) { 608 if (zipEntry.getName().equals( appresFileName ) ) { 609 if (debug) System.out.println( "*RFOUND* zip/jar resource:`"+appresFileName+"' ("+file.getPath()+")" ); 610 is = zis; 611 found = true; 612 break; 613 } 614 else 615 zis.closeEntry(); } 617 } 618 while (zipEntry != null); 619 } 620 catch (IOException e) { 621 e.printStackTrace(); 622 System.err.println("file:"+file.getPath()+" "+appresFileName ); 623 System.err.println("**** DEATH 69 ****"); System.exit(69); 624 } 625 finally { 626 if (!found) 628 try { is.close(); } catch (IOException e) { }; 629 } 630 631 return (is); 632 } 633 634 635 636 private static void printChar( int ch ) 637 { 638 if ( ch >= 32 && ch < 128 ) 639 System.out.print((char)ch); 640 else 641 System.out.print("<"+ch+">"); 642 } 643 644 651 private boolean findArchiveKey( PushbackInputStream pis, String key ) 652 throws IOException 653 { 654 boolean archiveKeyFound=false; 655 int ch=0; 656 657 while ( ch != -1 ) { 658 int count=0; 659 for (int k=0; k<key.length(); ++k) { 660 ch = pis.read(); 661 if ( ch == key.charAt(k)) 663 ++count; 664 else 665 break; 666 } 667 if (count == key.length() ) { 668 archiveKeyFound = true; 669 break; 670 } 671 672 } 673 674 return (archiveKeyFound ); 675 } 676 677 680 private void readDelimiter( PushbackInputStream pis ) 681 throws IOException 682 { 683 if (debug) System.out.println("readDelimiter"); 684 685 int ch = pis.read(); 686 if ( ch != '|' ) 688 throw new IOException( "delimiter expected." ); 689 } 690 691 692 697 private String readArchiveType( PushbackInputStream pis ) 698 throws IOException 699 { 700 if (debug) System.out.println("readArchiveType"); 701 702 StringBuffer type = new StringBuffer (8); 703 int ch=0; 704 705 int counter=0; 706 do { 707 ch = pis.read(); ++counter; 708 if ( ch != '|' ) 710 type.append((char)ch); 711 else 712 pis.unread(ch); 713 } 714 while ( ch != '|' && counter < 32 ); 715 716 return type.toString(); 717 } 718 719 724 private String readApplicationClass( PushbackInputStream pis ) 725 throws IOException 726 { 727 if (debug) System.out.println("readApplicationClass"); 728 729 StringBuffer appClass = new StringBuffer (8); 730 int ch=0; 731 732 int counter=0; 733 do { 734 ch = pis.read(); ++counter; 735 if ( ch != '|' ) 737 appClass.append((char)ch); 738 else 739 pis.unread(ch); 740 } 741 while ( ch != '|' && counter < 512 ); 742 743 return appClass.toString(); 744 } 745 746 751 private String readExtraClassPath( PushbackInputStream pis ) 752 throws IOException 753 { 754 if (debug) System.out.println("readExtraClassPath"); 755 756 StringBuffer ecp = new StringBuffer (64); 757 int ch=0; 758 759 int counter=0; 760 do { 761 ch = pis.read(); ++counter; 762 if ( ch != '|' ) 764 ecp.append((char)ch); 765 else 766 pis.unread(ch); 767 } 768 while ( ch != '|' && counter < 512 ); 769 770 return ecp.toString(); 771 } 772 773 777 private void extractZipFiles( InputStream is ) 778 throws IOException 779 { 780 if (debug) System.out.println( "extractZipFiles()" ); 782 ZipInputStream zis = null; 783 try { 784 zis = new ZipInputStream( is ); 785 ZipEntry zipEntry; 786 int num_entries=0; 787 788 byte [] buffer = new byte[4096]; 789 int total_bytes=0; 790 do { 791 zipEntry = zis.getNextEntry(); 792 if (zipEntry != null ) { 793 ++num_entries; 794 int method = zipEntry.getMethod(); 795 if (debug) { 796 System.out.println( "*** ENTRY ["+num_entries+"] ***" ); 797 System.out.println( " name: " + zipEntry.getName() ); 798 System.out.println( " size: " + zipEntry.getSize() ); 799 System.out.println( " extra: " + zipEntry.getExtra() ); 800 System.out.println( " compressed size: " + zipEntry.getCompressedSize() ); 801 System.out.println( " method: " + 802 (method == ZipEntry.DEFLATED ? "(Compressed)" : 803 method == ZipEntry.STORED ? "(Stored)" : "UNKNOWN!" )); 804 } 805 System.out.print('.'); 806 807 String entryFilePath = zipEntry.getName(); 808 entryFilePath = entryFilePath.replace('/', File.separatorChar ); 809 entryFilePath = entryFilePath.replace('\\', File.separatorChar ); 810 if (debug) System.out.println( "extracting: `"+entryFilePath +"'"); 811 812 813 File entryFile = new File( entryFilePath ); 814 if (zipEntry.isDirectory() ) { 815 entryFile.mkdirs(); 817 } 818 else { 819 if ( entryFile.getParent() != null ) 821 new File(entryFile.getParent()).mkdirs(); 822 823 extractedFiles.addElement( entryFilePath ); 824 FileOutputStream fos = new FileOutputStream( entryFile ); 825 int num_bytes; 826 while ( (num_bytes = zis.read( buffer, 0, buffer.length )) >= 0 ) { 827 fos.write( buffer, 0, num_bytes ); 828 fos.flush(); total_bytes += num_bytes; 830 } 831 fos.close(); } 833 zis.closeEntry(); 834 } 835 } 836 while (zipEntry != null); 837 838 System.out.println("\n\nExtracted a total "+total_bytes+" byte"+ 839 (total_bytes == 1 ? "" : "s" ) + 840 " from "+ num_entries+" ent"+ 841 (num_entries == 1 ? "ry" : "ries" )+"." ); 842 } 843 finally { 844 if (zis != null) try { zis.close(); } catch (IOException e ) { ; } 846 } 847 } 848 849 853 public void extractFiles() 854 { 855 String resname = getClass().getName(); 856 857 String left ="-=+"; 858 String right="+=-"; 859 String key=left+"ARCHIVE"+right; 860 861 PushbackInputStream pis=null; 862 try { 863 pis = new PushbackInputStream( 864 new FileInputStream( resname+".class" )); 865 int ch=0; 866 boolean foundKey=false; 867 foundKey = findArchiveKey( pis, key ); 871 if ( foundKey ) { 872 if (debug) System.out.println("\n*** KEY FOUND !!! ***"); 873 readDelimiter(pis); 874 archiveType = readArchiveType(pis); 875 readDelimiter(pis); 876 appClassName = readApplicationClass(pis); 877 readDelimiter(pis); 878 extraClassPath = readExtraClassPath(pis); 879 readDelimiter(pis); 880 881 ch = pis.read(); 884 if ( ch != '\n' ) { 885 pis.unread(ch); 886 } 887 888 if (debug) { 889 System.out.println( "\n***DEBUG***" ); 890 System.out.println( "archiveType=`"+archiveType+"'"); 891 System.out.println( "appClassName=`"+appClassName+"'" ); 892 System.out.println( "extraClassPath=`"+extraClassPath+"'"); 893 } 894 895 if ( archiveType.equalsIgnoreCase("ZIP" ) ) 896 extractZipFiles( pis ); 897 else 898 throw new RuntimeException ("Cannot extract archive type:`"+archiveType+"'"); 899 } 900 else 901 throw new RuntimeException ("Cannot find archive key."); 902 903 } 904 catch (IOException ioe) { 905 System.err.println(ioe); 906 if (debug) ioe.printStackTrace(); 907 cleanupFiles(); 908 System.exit(1); 909 } 910 finally { 911 if (pis != null) try { pis.close(); } catch (IOException e) { ; } 912 } 913 914 } 915 916 928 public void runApplicationInstaller( String [] args ) 929 { 930 readDefaultPropertyFile( new File("Extractor.properties"), false ); 934 935 String tmp = System.getProperty("ext.debug"); 936 if (tmp.equalsIgnoreCase("yes") || tmp.equalsIgnoreCase("on")) 937 debug=true; 938 else if (tmp.equalsIgnoreCase("no") || tmp.equalsIgnoreCase("off")) 939 debug=false; 940 941 if (debug) { 942 System.out.println("**** DEBUG ****"); 943 System.out.println(getClass().getName()+".runApplicationInstaller()" ); 944 } 945 946 boolean launchProg=true; 947 tmp = System.getProperty("ext.launchprog"); 948 if (tmp.equalsIgnoreCase("no") || tmp.equalsIgnoreCase("off")) 949 launchProg=false; 950 951 if (!launchProg) { 952 System.out.println("directed not to launch main application"); 953 return; 954 } 955 956 extractFiles(); 957 958 961 invokeJVM( args ); 963 } 964 965 971 public boolean readDefaultPropertyFile( File propFile, boolean override ) 972 { 973 if ( !propFile.exists() ) 974 return (false); 975 976 Properties propJVM = System.getProperties (); 977 978 if (debug) 982 System.out.println("Loading default properties file: `"+propFile.getPath()+"'" ); 983 if ( !propFile.canRead() ) { 984 System.err.println("Cannot read default properties file:`"+propFile.getPath()+"'" ); 985 return (false); 986 } 987 988 boolean retval=false; 992 Properties propTemp = new Properties(); 993 try { 994 FileInputStream fis = new FileInputStream( propFile ); 995 propTemp.load(fis); 996 Enumeration keys = propTemp.propertyNames(); 997 while( keys.hasMoreElements() ) { 998 String name = (String )keys.nextElement(); 999 String value1 = propTemp.getProperty( name ); 1000 String value2 = propJVM.getProperty( name ); 1001 if (value2 == null || override) { 1002 propJVM.put( name, value1 ); 1004 } 1005 } 1006 } 1007 catch (IOException ioe) { 1008 retval = false; 1009 System.err.println( 1010 "I/O Exception occurred reading file:" + 1011 propFile.getPath() + " message:`" + ioe.getMessage()+"'" ); 1012 } 1013 1014 return (retval); 1015 } 1016 1017 private void invokeJVM( String [] args ) 1018 { 1019 String osname = System.getProperty("os.name"); 1020 String pathSep = System.getProperty("path.separator"); 1021 String fileSep = System.getProperty("file.separator"); 1022 1023 1024 if ( extraClassPath.length() > 0 ) { 1025 1030 if ( pathSep.equals(";") ) 1031 extraClassPath = extraClassPath.replace( ':' , ';' ); 1033 else 1034 extraClassPath = extraClassPath.replace( ';' , ':' ); 1036 1037 if ( fileSep.equals("\\") ) 1038 extraClassPath = extraClassPath.replace( '/' , '\\' ); 1040 else 1041 extraClassPath = extraClassPath.replace( '\\' , '/' ); 1043 1044 1049 } 1052 1053 String javaExe, jreExe, jrewExe; 1057 if ( osname.startsWith("Windows 95") || 1058 osname.startsWith("Windows 98") || 1059 osname.startsWith("Windows NT") || 1060 osname.startsWith("Windows 2000") || 1061 osname.startsWith("OS/2") ) { 1062 javaExe="java.exe"; 1063 jreExe="jre.exe"; 1064 jrewExe="jrew.exe"; 1065 } 1066 else { 1067 javaExe="java"; 1068 jreExe="jre"; 1069 jrewExe="jrew"; 1070 } 1071 1072 if (debug) { 1073 System.out.println("\n\tjavaExe="+javaExe+"\t *DEBUG*"); 1074 System.out.println("\tjreExe="+jreExe); 1075 System.out.println("\tjrewExe="+jrewExe); 1076 } 1077 1078 String jvmLauncher = System.getProperty("ext.jvm.launcher",""); 1079 String tmp; 1080 if ( jvmLauncher.length() < 1 ) { 1081 tmp = System.getProperty("java.home")+fileSep+"bin"+ fileSep+javaExe; 1082 if ( new File(tmp).exists() ) 1083 jvmLauncher = tmp; 1084 else { 1085 tmp = System.getProperty("java.home")+fileSep+"bin"+ fileSep+jreExe; 1086 if ( new File(tmp).exists() ) 1087 jvmLauncher = tmp; 1088 else { 1089 tmp = System.getProperty("java.home")+fileSep+"bin"+ fileSep+jrewExe; 1090 if ( new File(tmp).exists() ) 1091 jvmLauncher = tmp; 1092 } 1093 } 1094 } 1095 1096 if ( jvmLauncher.length() < 1 ) { 1097 System.err.println("BUMMER: What Java Virtual Machine interpreter should I use?"); 1098 System.err.println("Set the system property `ext.jvm.launcher' to path of your JVM."); 1099 System.exit(69); 1100 } 1101 1102 String options=""; 1106 1107 tmp = System.getProperty("ext.jvm.option.jit",""); 1109 if (tmp.equalsIgnoreCase("yes") || tmp.equalsIgnoreCase("on")) 1110 options +="-jit "; 1111 else if (tmp.equalsIgnoreCase("no") || tmp.equalsIgnoreCase("off") ) 1112 options +="-nojit "; 1113 1114 tmp = System.getProperty("ext.jvm.option.java.compiler"); 1116 if (tmp != null && tmp.length() > 1 ) 1117 options +="-Djava.compiler="+tmp.trim()+" "; 1118 1119 tmp = System.getProperty("ext.jvm.option.verbose",""); 1121 if (tmp.equalsIgnoreCase("yes") || tmp.equalsIgnoreCase("on")) 1122 options +="-verbose "; 1123 1124 tmp = System.getProperty("ext.jvm.option.verbosegc",""); 1126 if (tmp.equalsIgnoreCase("yes") || tmp.equalsIgnoreCase("on")) 1127 options +="-verbosegc "; 1128 1129 tmp = System.getProperty("ext.jvm.option.verify",""); 1131 if (tmp.equalsIgnoreCase("remote") ) 1132 options +="-verifyremote "; 1133 else if (tmp.equalsIgnoreCase("local") ) 1134 options +="-verify "; 1135 else if (tmp.equalsIgnoreCase("none") ) 1136 options +="-noverify "; 1137 1138 tmp = System.getProperty("ext.jvm.option.debug",""); 1140 if (tmp.equalsIgnoreCase("yes") || tmp.equalsIgnoreCase("on")) 1141 options +="-debug"; 1142 1143 tmp = System.getProperty("ext.jvm.option.native.stack.maxsize"); 1145 if (tmp != null && tmp.length() > 1 ) 1146 options += "-ss"+tmp.trim()+" "; 1147 1148 tmp = System.getProperty("ext.jvm.option.java.stack.maxsize"); 1150 if (tmp != null && tmp.length() > 1 ) 1151 options += "-oss"+tmp.trim()+" "; 1152 1153 tmp = System.getProperty("ext.jvm.option.java.heap.maxsize"); 1155 if (tmp != null && tmp.length() > 1 ) 1156 options += "-mx"+tmp.trim()+" "; 1157 1158 tmp = System.getProperty("ext.jvm.option.java.heap.initsize"); 1160 if (tmp != null && tmp.length() > 1 ) 1161 options += "-ms"+tmp.trim()+" "; 1162 1163 tmp = System.getProperty("ext.jvm.option.thread.model",""); 1165 if (tmp.equalsIgnoreCase("green") ) 1166 options +="-green "; 1167 else if (tmp.equalsIgnoreCase("native") ) 1168 options +="-native "; 1169 1170 tmp = System.getProperty("ext.jvm.option.extraflags"); 1172 if (tmp != null) 1173 options += tmp + " "; 1174 1175 String extraSystemClassPath = System.getProperty("ext.jvm.extra.class.path"); 1177 1178 boolean traceStdout=false; 1180 tmp = System.getProperty("ext.jvm.trace.stdout"); 1181 if (tmp.equalsIgnoreCase("yes") || tmp.equalsIgnoreCase("on")) 1182 traceStdout=true; 1183 1184 boolean traceStderr=false; 1186 tmp = System.getProperty("ext.jvm.trace.stderr"); 1187 if (tmp.equalsIgnoreCase("yes") || tmp.equalsIgnoreCase("on")) 1188 traceStderr=true; 1189 1190 try { 1191 Runtime runtime = Runtime.getRuntime(); 1192 String newClassPath = extraClassPath+pathSep+System.getProperty("java.class.path"); 1193 if ( extraSystemClassPath != null) 1194 newClassPath = extraSystemClassPath+pathSep+newClassPath; 1195 String finalCmd = 1196 jvmLauncher + " " +options+ " -classpath "+newClassPath+" "+ 1197 appClassName; 1198 1199 if (debug) System.out.println( "*DEBUG* finalCmd = `"+finalCmd+"'" ); 1200 System.out.println(); 1201 Process process = runtime.exec( finalCmd ); 1202 Thread tid1=null, tid2=null; 1203 1204 if (traceStdout) { 1205 InputStream is = process.getInputStream(); 1206 tid1 = new Thread ( new ExtractorProcessOutputReader( is, System.out )); 1209 tid1.start(); 1210 } 1211 1212 if (traceStderr) { 1213 InputStream isError = process.getInputStream(); 1214 tid2 = new Thread ( new ExtractorProcessOutputReader( isError, System.err )); 1217 tid2.start(); 1218 } 1219 1220 process.waitFor(); 1221 if (debug) System.out.println("DEBUG: exitValue:"+process.exitValue()); 1222 1223 if (tid1 != null) tid1.join(); 1225 if (tid2 != null) tid2.join(); 1226 } 1227 catch (IOException ioe ) { 1228 System.err.println( ioe ); 1229 } 1230 catch (InterruptedException ie ) { 1231 System.err.println( ie ); 1232 } 1233 } 1234 1235 1236 1298 private void invokeClassLoader( String [] args ) 1299 { 1300 1301 String osname = System.getProperty("os.name"); 1302 String pathSep = System.getProperty("path.separator"); 1303 String fileSep = System.getProperty("file.separator"); 1304 1305 try { 1313 String [] dummyArgs = new String [0]; 1314 final Extractor extractorCL = this; 1315 final Class faiClass = extractorCL.loadClass( "ixenon.free.install.FreeInstallerApplication"); 1316 if (debug) System.out.println( "loaded class:`"+faiClass.getName()+"'" ); 1317 1318 final Class mainClass = extractorCL.loadClass( appClassName ); 1319 if (debug) System.out.println( "loaded class:`"+appClassName+"'" ); 1320 1321 final Object mainObj = mainClass.newInstance(); 1322 if (debug) System.out.println( "created a new instance of `"+mainClass.getName()+"'"); 1323 1324 final Method mainMethod = mainClass.getMethod( 1325 "main", new Class [] { dummyArgs.getClass() } ); 1326 if (debug) System.out.println( "about to invoke `public static void main( String [] )'"); 1327 System.out.println(); 1328 Object retVal = mainMethod.invoke( mainObj, new Object [] { args } ); 1329 } 1331 catch ( ClassNotFoundException e1 ) { 1332 System.err.println(e1); 1333 e1.printStackTrace(); 1334 } 1335 catch ( InstantiationException e2 ) { 1336 System.err.println(e2); 1337 e2.printStackTrace(); 1338 } 1339 catch ( NoSuchMethodException e3 ) { 1340 System.err.println(e3); 1341 e3.printStackTrace(); 1342 } 1343 catch ( IllegalAccessException e4 ) { 1344 System.err.println(e4); 1345 e4.printStackTrace(); 1346 } 1347 catch ( InvocationTargetException e5 ) { 1348 System.err.println("Method threw an "+e5.getTargetException() ); 1349 e5.printStackTrace(); 1350 System.err.println ("Nested exception"); 1351 e5.getTargetException().printStackTrace(); 1352 } 1353 } 1354 1355 1356 public void cleanupFiles() 1357 { 1358 boolean doClean=true; 1359 String tmp = System.getProperty("ext.cleanup"); 1360 if (tmp.equalsIgnoreCase("no") || tmp.equalsIgnoreCase("off")) 1361 doClean=false; 1362 1363 if (!doClean) return; 1364 1365 System.out.println("========================================"); 1366 System.out.println("Cleaning up extracted files"); 1367 1368 Enumeration etor = extractedFiles.elements(); 1369 int k=0; 1370 while ( etor.hasMoreElements() ) { 1371 String filename = (String )etor.nextElement(); 1372 File file = new File( filename ); 1373 if ( file.exists() ) { 1374 if (debug) System.out.println(" ["+k+"] deleting file:`"+filename+"'" ); 1375 file.delete(); 1376 ++k; 1377 } 1378 } 1379 extractedFiles.removeAllElements(); 1380 } 1381 1382 1387 public void finalize() 1388 throws Throwable 1389 { 1390 try { 1391 if (debug) System.out.println("Extractor.finalize()"); 1392 cleanupFiles(); 1393 } 1394 finally { 1395 super.finalize(); } 1397 } 1398 1399 public static void main( String [] args ) 1400 { 1401 System.runFinalizersOnExit(true); 1419 1420 System.out.println("Java Self Extracting Class - XeNoNSoFT [c] 1999 "); 1421 System.out.println("This extractor program is a part of the `FreeInstaller' "); 1422 System.out.println("distribution, which is \"available as free software\"."); 1423 System.out.println("For more details, please read the `LICENSE-XPeL.txt'\n"); 1424 extractor = new Extractor(); 1425 extractor.runApplicationInstaller( args ); 1426 } 1427 1428 1429 1442 public URLStreamHandler createURLStreamHandler( String protocol ) 1443 { 1444 if (debug) System.out.println( "Extractor.createURLStreamHander("+protocol+")" ); 1445 if (protocol.equalsIgnoreCase("extractor")) { 1446 return new ExtractorURLStreamHandler(); 1447 } 1448 else { 1449 return (null); 1450 } 1451 } 1452 1453 1454} 1455 1456 | Popular Tags |