1 21 22 package org.apache.derby.impl.tools.sysinfo; 23 24 import java.security.AccessController ; 25 import java.security.PrivilegedAction ; 26 import java.util.Locale ; 27 import java.io.IOException ; 28 import java.io.UnsupportedEncodingException ; 29 import java.io.InputStream ; 30 import java.util.Properties ; 31 import java.io.BufferedReader ; 32 import java.io.InputStreamReader ; 33 import java.util.Locale ; 34 import java.util.MissingResourceException ; 35 import java.util.ResourceBundle ; 36 import java.util.StringTokenizer ; 37 import java.io.File ; 38 import java.util.zip.ZipFile ; 39 import java.io.IOException ; 40 import java.util.zip.ZipEntry ; 41 import java.io.FileInputStream ; 42 import java.util.Vector ; 43 import java.io.InputStream ; 44 import java.lang.reflect.Method ; 45 import java.net.URL ; 46 import java.net.URLDecoder ; 47 import java.security.ProtectionDomain ; 48 import java.security.CodeSource ; 49 import java.security.AccessController ; 50 51 import org.apache.derby.iapi.services.info.PropertyNames; 52 import org.apache.derby.iapi.services.info.ProductVersionHolder; 53 import org.apache.derby.iapi.services.info.ProductGenusNames; 54 import org.apache.derby.iapi.error.StandardException; 55 56 import org.apache.derby.iapi.tools.i18n.*; 57 58 59 86 87 88 public final class Main { 89 90 95 public static void main(String args[]) { 96 LocalizedResource.getInstance(); 98 99 LocalizedOutput out; 100 101 103 out = LocalizedResource.OutputWriter(); 104 105 parseArgs (args); 108 109 if (cptester == true) 110 getClasspathInfo (args, out); 111 else 112 getMainInfo (out, setPause); 113 114 } 116 public static void getMainInfo (java.io.PrintWriter aw, boolean pause) { 117 118 aw.println (javaSep); 119 reportJavaInfo (aw); 120 aw.println (jbmsSep); 121 reportDerby (aw); 122 123 aw.println (sep); 124 125 try { 127 reportLocales (aw); 128 } 129 catch (Exception e) { 130 131 aw.println (Main.getTextMessage ("SIF01.Q")); 132 aw.println (Main.getTextMessage ("SIF01.B")); 133 } 134 135 136 if (pause) { 137 pause(); 138 } 139 140 } 142 143 private static boolean setPause = false; 144 145 private static boolean setLicense = false; 146 147 private static boolean cptester = false; 148 149 private static void parseArgs (String args[]) { 150 151 if (args == null) { 152 153 return; 154 } 155 156 157 for (int i = 0; i < args.length; i++) { 158 159 if (args[i].equals ("-pause")) { 160 161 setPause = true; 162 } 163 164 if (args[i].equals ("-cp")) { 165 166 cptester=true; 167 } 168 169 } 171 } 173 174 178 private static void pause () { 179 180 try { 181 182 System.out.print (Main.getTextMessage ("SIF01.C")); 183 BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); 184 br.readLine (); 185 } 186 catch (IOException ioe) { 187 188 } 190 191 } 193 198 199 private static void reportDerby (java.io.PrintWriter localAW) { 200 201 localAW.println("JRE - JDBC: " + org.apache.derby.iapi.services.info.JVMInfo.derbyVMLevel()); 202 203 String classpath; 204 205 try { 206 classpath = System.getProperty("java.class.path"); 207 } 208 catch (SecurityException se) { 209 localAW.println( 210 Main.getTextMessage ("SIF01.U", se.getMessage())); 211 classpath = null; 212 } 213 214 ZipInfoProperties zip[]= Main.getAllInfo (classpath); 215 216 if (zip != null) { 217 218 for (int i = 0; i < zip.length; i++) { 219 220 String thisInfo = "[" + zip[i].getLocation () + "] " + 221 zip[i].getVersionBuildInfo (); 222 223 localAW.println (thisInfo); 224 } 225 } 226 227 else { 228 229 localAW.println (Main.getTextMessage ("SIF01.D")); 230 } 231 232 233 } 235 242 243 private static void reportJavaInfo (java.io.PrintWriter localAW) { 244 245 246 247 localAW.println (Main.getTextMessage ("SIF02.A", 248 getJavaProperty ("java.version"))); 249 250 localAW.println (Main.getTextMessage ("SIF02.B", 251 getJavaProperty ("java.vendor"))); 252 253 localAW.println (Main.getTextMessage ("SIF02.C", 254 getJavaProperty ("java.home"))); 255 256 localAW.println (Main.getTextMessage ("SIF02.D", 257 getJavaProperty ("java.class.path"))); 258 259 localAW.println (Main.getTextMessage ("SIF02.E", 260 getJavaProperty ("os.name"))); 261 262 localAW.println (Main.getTextMessage ("SIF02.F", 263 getJavaProperty ("os.arch"))); 264 265 localAW.println (Main.getTextMessage ("SIF02.G", 266 getJavaProperty ("os.version"))); 267 268 localAW.println (Main.getTextMessage ("SIF02.H", 269 getJavaProperty ("user.name"))); 270 271 localAW.println (Main.getTextMessage ("SIF02.I", 272 getJavaProperty ("user.home"))); 273 274 localAW.println (Main.getTextMessage ("SIF02.J", 275 getJavaProperty ("user.dir"))); 276 277 localAW.println("java.specification.name: " + getJavaProperty("java.specification.name")); 278 localAW.println("java.specification.version: " + getJavaProperty("java.specification.version")); 279 280 281 } 283 284 285 292 293 private static String getJavaProperty (String whichProperty) { 294 295 String property; 296 String unavailable = Main.getTextMessage ("SIF01.H"); 297 298 try { 299 300 property = System.getProperty (whichProperty, unavailable); 301 return property; 302 } 303 catch (SecurityException se) { 304 305 return Main.getTextMessage ("SIF01.I", se); 306 } 307 308 } 310 311 312 315 316 private final static String sep = "------------------------------------------------------"; 317 private final static String javaSep = Main.getTextMessage ("SIF01.L"); 318 319 private final static String jbmsSep = Main.getTextMessage ("SIF01.M"); 320 321 private final static String licSep = Main.getTextMessage ("SIF01.N"); 322 323 private final static String locSep = Main.getTextMessage ("SIF01.P"); 324 325 private final static String curLoc = Main.getTextMessage ("SIF01.T"); 326 327 332 private final static String failureTag = Main.getTextMessage ("SIF01.J"); 333 334 private static void getClasspathInfo (String args[], java.io.PrintWriter aw) { 335 336 Main.useMe (args, aw); 337 } 338 339 340 341 342 350 private static void reportLocales (java.io.PrintWriter localAW) { 352 boolean cur_loc = true; 353 354 localAW.println (locSep); 355 356 359 Locale [] supportedLocales = Locale.getAvailableLocales(); 360 String [] stringLocales = new String [supportedLocales.length]; 361 for (int i = 0; i < supportedLocales.length; i++) 362 { 363 stringLocales[i] = supportedLocales[i].toString(); 364 } 365 java.util.Arrays.sort(stringLocales); 366 367 Properties p = new Properties (); 368 for (int i = 0; i < stringLocales.length; i++) { 369 370 String localeResource = 371 "/org/apache/derby/info/locale_" + stringLocales[i] + ".properties"; 372 373 final Properties finalp = p; 374 final String finalLocaleResource = localeResource; 375 376 try { 377 InputStream is = (InputStream ) AccessController.doPrivileged 378 (new PrivilegedAction () { 379 public Object run() { 380 InputStream locis = 381 finalp.getClass().getResourceAsStream (finalLocaleResource); 382 return locis; 383 } 384 } 385 ); 386 387 if (is == null) { 388 } 390 else { 391 392 try { 393 p.clear(); 394 p.load (is); 395 if (cur_loc) 397 { 398 Locale loc = null; 399 loc = Locale.getDefault(); 400 localAW.println(Main.getTextMessage ("SIF01.T") + " [" + loc.getDisplayLanguage() + "/" + loc.getDisplayCountry() + " [" + loc + "]]"); 401 cur_loc = false; 402 } 403 404 String localeName = p.getProperty("derby.locale.external.name"); 406 localeName = localeName.substring(localeName.indexOf("[")+1); 407 localeName = localeName.substring(0,localeName.indexOf("]")); 408 409 localAW.println (Main.getTextMessage ("SIF01.R", 410 localeName)); 411 412 413 int major = Integer.valueOf(p.getProperty ("derby.locale.version.major")).intValue(); 414 int minor = Integer.valueOf(p.getProperty ("derby.locale.version.minor")).intValue(); 415 int maint = Integer.valueOf(p.getProperty ("derby.locale.version.maint")).intValue(); 416 String build = p.getProperty ("derby.locale.build.number"); 417 418 String lv = ProductVersionHolder.fullVersionString(major, minor, maint, false, build); 419 420 421 localAW.println (Main.getTextMessage ("SIF01.S", lv)); 422 423 424 } 425 catch (IOException ioe) { 426 427 432 localAW.println("Could not get locale properties from : " + is); 433 } 434 } 435 436 } 437 catch (Throwable t) { 438 localAW.println ("Could not load resource: " + localeResource); 439 localAW.println ("Exception: " + t); 440 } 441 442 } 443 444 445 localAW.println (sep); 446 447 } 449 450 private static final String EMBEDDED = "embedded"; 451 452 453 private static final String TOOLS = "tools"; 454 455 private static final String NET = "server"; 456 private static final String CLIENT = "client"; 457 private static final String DB2DRIVER = "db2driver"; 458 459 460 461 private static final String MAINUSAGESTRING = "java org.apache.derby.tools.sysinfo -cp"; 462 463 private static final String USAGESTRINGPARTA = MAINUSAGESTRING + " [ [ " + EMBEDDED + " ][ " + NET + " ][ " + CLIENT + "] [ " + DB2DRIVER + " ] [ " + TOOLS + " ] [ "; 464 private static final String USAGESTRINGPARTB = ".class ] ]"; 465 466 static void useMe(String [] args, java.io.PrintWriter pw) { 467 java.io.PrintWriter localPW = pw; 468 469 if (localPW == null) 470 { 471 localPW = new java.io.PrintWriter (System.out); 472 } 473 474 475 int length = args.length; 476 if (length==1) { 477 478 try { 479 tryAllClasspaths(localPW); 480 481 } 482 483 catch (Throwable t) { 484 485 } 486 } 487 else { 488 try { 489 trySomeClasspaths(args, localPW); 490 } 491 492 catch (Throwable t) { 493 494 } 495 } 496 497 } 498 499 500 501 502 503 private static void tryAllClasspaths(java.io.PrintWriter localPW) throws Throwable { 504 localPW.println(Main.getTextMessage("SIF08.B")); 505 localPW.println(Main.getTextMessage("SIF08.C", MAINUSAGESTRING + " args")); 506 StringBuffer successes = new StringBuffer (Main.getTextMessage("SIF08.D")+ crLf()); 507 StringBuffer failures = new StringBuffer (crLf() + Main.getTextMessage("SIF08.E") + crLf()); 508 tryCoreClasspath(successes, failures); 509 tryNetClasspath(successes, failures); 510 tryClientClasspath(successes, failures); 511 tryDB2DriverClasspath(successes, failures); 512 tryUtilsClasspath(successes, failures); 513 localPW.println(successes.toString()); 514 if (!failures.toString().equals(crLf() + Main.getTextMessage("SIF08.E") + crLf())) { 515 localPW.println(failures.toString()); 516 } 517 else { 518 519 localPW.println(Main.getTextMessage("SIF08.F")); 520 } 521 localPW.flush(); 522 } 523 524 private static void trySomeClasspaths(String [] args, java.io.PrintWriter localPW) throws Throwable { 525 526 boolean seenArg = false; 527 StringBuffer successes = new StringBuffer (Main.getTextMessage("SIF08.D")+ crLf()); 528 StringBuffer failures = new StringBuffer (crLf() + Main.getTextMessage("SIF08.E") + crLf()); 529 530 if (argumentsContain(args, EMBEDDED)) 531 { 532 533 tryCoreClasspath(successes, failures); 534 seenArg =true; 535 536 } 537 if (argumentsContain(args,NET)) { 538 tryNetClasspath(successes, failures); 539 seenArg =true; 540 541 } 542 if (argumentsContain(args,CLIENT)) { 543 tryClientClasspath(successes, failures); 544 seenArg =true; 545 546 } 547 if (argumentsContain(args,DB2DRIVER)) { 548 tryDB2DriverClasspath(successes, failures); 549 seenArg =true; 550 } 551 552 if (argumentsContain(args,TOOLS) || argumentsContain(args,"utils")) { 553 tryUtilsClasspath(successes, failures); 554 seenArg =true; 555 556 } 557 558 559 String userclass = argumentMatches(args, ".class"); 560 if (!userclass.equals("")) { 561 tryMyClasspath(argumentMatches(args, ".class"), Main.getTextMessage("SIF08.H", userclass), successes, failures); 562 seenArg =true; 563 } 564 565 if (seenArg) 566 { 567 568 localPW.println(successes.toString()); 569 if (!failures.toString().equals(crLf() + Main.getTextMessage("SIF08.E") + crLf())) { 570 localPW.println(failures.toString()); 571 } 572 else { 573 574 localPW.println(Main.getTextMessage("SIF08.F")); 575 } 576 } 577 else 578 { 579 localPW.println(Main.getTextMessage("SIF08.A", USAGESTRINGPARTA, USAGESTRINGPARTB)); 580 } 581 localPW.flush(); 582 583 } 584 585 private static void tryCoreClasspath(StringBuffer successes, StringBuffer failures) { 586 tryMyClasspath("org.apache.derby.database.Database", Main.getTextMessage("SIF08.J","derby.jar" ), successes, failures); 587 } 588 private static void tryNetClasspath(StringBuffer successes, StringBuffer failures) { 589 tryMyClasspath("org.apache.derby.database.Database", Main.getTextMessage("SIF08.J","derby.jar" ), successes, failures); 590 tryMyClasspath("org.apache.derby.drda.NetworkServerControl", Main.getTextMessage("SIF08.I", "derbynet.jar"), successes, failures); 591 } 592 private static void tryClientClasspath(StringBuffer successes, StringBuffer failures) { 593 tryMyClasspath("org.apache.derby.jdbc.ClientDriver", Main.getTextMessage("SIF08.L", "derbyclient.jar"), successes, failures); 594 } 595 private static void tryDB2DriverClasspath(StringBuffer successes, 596 StringBuffer failures) 597 { 598 tryMyClasspath("com.ibm.db2.jcc.DB2Driver", 599 Main.getTextMessage("SIF08.L", "db2jcc.jar"), 600 successes, failures); 601 } 602 603 private static void tryUtilsClasspath(StringBuffer successes, StringBuffer failures) { 604 tryMyClasspath("org.apache.derby.tools.ij", Main.getTextMessage("SIF08.Q", "derbytools.jar"), successes, failures); 605 } 606 607 private static void tryMyClasspath(String cn, String library, StringBuffer successes, StringBuffer failures) { 608 609 try { 610 Class c = Class.forName(cn); 611 String loc = getFileWhichLoadedClass(c); 612 successes.append(found(cn, library, loc)); 613 } 614 615 catch (Throwable t) { 616 617 failures.append(notFound(cn, library)); 618 619 } 620 621 622 } 623 624 private static void tryAsResource(String cn, String library, StringBuffer successes, StringBuffer failures) { 625 626 try { 627 java.io.InputStream in = cn.getClass().getResourceAsStream(cn); 628 in.close(); 629 String loc = getFileWhichLoadedClass(cn.getClass()); 630 successes.append(found(cn, library, loc)); 631 } 632 633 catch (Throwable t) { 634 failures.append(notFound(cn, library)); 635 636 } 637 638 } 639 640 private static String found(String cn, String library, String loc) { 641 StringBuffer temp = new StringBuffer (crLf()); 642 temp.append(" " + library); 643 temp.append(crLf()); 644 if (loc != null) 645 temp.append(" ").append(loc).append(crLf()); 646 temp.append(crLf()); 647 return temp.toString(); 648 } 649 private static String notFound(String cn, String library) { 650 651 StringBuffer temp = new StringBuffer (crLf()); 652 temp.append(" " + library); 653 temp.append(crLf()); 654 temp.append(" " + Main.getTextMessage("SIF08.U", cn)); 655 temp.append(crLf()); 656 temp.append(crLf()); 657 return temp.toString(); 658 } 659 660 private static String crLf() { 661 return System.getProperty("line.separator"); 662 } 663 664 private static String lookForMainArg(String [] args, java.io.PrintWriter localPW) 665 { 666 int length=args.length; 667 String [] legalargs = new String [1]; 668 legalargs[0] = EMBEDDED; 669 670 int argsfound = 0; 671 String whichargument=""; 672 673 for (int i = 0; i < length; i++) { 674 675 for (int j=0; j < legalargs.length; j++) { 676 if (args[i].toUpperCase(java.util.Locale.ENGLISH).equals(legalargs[j].toUpperCase(java.util.Locale.ENGLISH))) { 677 argsfound++; 678 whichargument=legalargs[j]; 679 } 680 } 681 } 682 if (argsfound > 1 || argsfound < 1) { 683 localPW.println(Main.getTextMessage("SIF08.A", USAGESTRINGPARTA, USAGESTRINGPARTB)); 684 return ""; 685 } 686 return whichargument; 687 } 688 689 private static boolean argumentsContain(String [] args, String s) { 690 for (int i = 0; i < args.length; i++) { 691 if (args[i].equalsIgnoreCase(s)) 692 return true; 693 } 694 return false; 695 696 } 697 698 private static String argumentMatches(String [] args, String ss) { 699 String userclass = ""; 700 int length = args.length; 701 for (int i = 0; i < length; i++) { 702 if (args[i].endsWith(ss)) { 703 userclass = args[i].substring(0,args[i].length()-6) ; 704 705 } 706 707 } 708 return userclass; 709 } 710 711 714 715 private static final String infoNames[] = { 716 717 "org/apache/derby/info/" + 718 org.apache.derby.iapi.services.info.ProductGenusNames.DBMS + 719 ".properties", 720 721 722 "org/apache/derby/info/" + 723 org.apache.derby.iapi.services.info.ProductGenusNames.TOOLS + 724 ".properties", 725 726 "org/apache/derby/info/" + 727 org.apache.derby.iapi.services.info.ProductGenusNames.NET + 728 ".properties", 729 730 "org/apache/derby/info/" + 731 org.apache.derby.iapi.services.info.ProductGenusNames.DNC + 732 ".properties" 733 }; 734 735 747 public static ZipInfoProperties[] getAllInfo(String classpath) 748 { 749 ZipInfoProperties zips[] = loadZipFromResource(); 750 751 if (zips == null) 755 { 756 zips = new ZipInfoProperties[1]; 757 ZipInfoProperties zip = new ZipInfoProperties(ProductVersionHolder.getProductVersionHolderFromMyEnv(org.apache.derby.tools.sysinfo.TOOLS)); 758 zip.setLocation(getFileWhichLoadedClass(new Main().getClass())); 759 zips[0] = zip; 760 } 761 762 try 763 { 764 if (classpath != null) { 765 String cp [] = parseClasspath(classpath); 766 Vector v = new Vector (); 767 for (int i = 0; i < cp.length; i++) 768 { 769 ZipInfoProperties zip = null; 770 try { 771 zip = checkForInfo(cp[i]); 772 } 773 catch (SecurityException se) 774 { 775 zip = new ZipInfoProperties(null); 776 zip.setLocation( 777 Main.getTextMessage ("SIF03.C", se.getMessage())); 778 } 779 if (zip != null) 780 { 781 v.addElement(zip); 782 } 783 } 784 if (v.size() > 0) 785 { 786 ZipInfoProperties cpzips[] = new ZipInfoProperties[v.size()]; 787 v.copyInto(cpzips); 788 return mergeZips(zips, cpzips); 789 } 790 } 791 return mergeZips(zips, null); 792 793 } 794 catch (SecurityException se) 795 { 796 ZipInfoProperties zip[] = new ZipInfoProperties[1]; 797 zip[0] = new ZipInfoProperties(null); 798 zip[0].setLocation( 799 Main.getTextMessage ("SIF03.C", se.getMessage())); 800 return zip; 801 } 802 } 803 804 813 private static ZipInfoProperties [] loadZipFromResource() 814 { 815 java.util.ArrayList al = new java.util.ArrayList (); 816 817 for (int i = 0; i < infoNames.length; i++) 818 { 819 final String resource = "/".concat(infoNames[i]); 820 821 InputStream is = (InputStream ) AccessController.doPrivileged 822 (new PrivilegedAction () { 823 public Object run() { 824 InputStream locis = 825 new Main().getClass().getResourceAsStream(resource); 826 return locis; 827 } 828 } 829 ); 830 831 if (is == null) 832 continue; 833 834 ZipInfoProperties ze = new ZipInfoProperties(ProductVersionHolder.getProductVersionHolderFromMyEnv(is)); 835 836 URL locUrl = (URL ) AccessController.doPrivileged 838 (new PrivilegedAction () { 839 public Object run() { 840 URL realUrl = new Main().getClass().getResource(resource); 841 return realUrl; 842 } 843 }); 844 845 ze.setLocation(formatURL(locUrl)); 846 847 al.add(ze); 848 } 849 850 if (al.size() == 0) 851 { 852 return null; 853 } 854 855 ZipInfoProperties[] zip = new ZipInfoProperties[al.size()]; 856 857 al.toArray(zip); 858 859 return zip; 860 } 861 862 868 private static String [] parseClasspath(String cp) 869 { 870 StringTokenizer st = new StringTokenizer (cp, File.pathSeparator); 871 int count = st.countTokens(); 872 if (count == 0) 873 { 874 return null; 875 } 876 877 String vals[] = new String [count]; 878 for (int i =0; i < count; i++) 879 { 880 vals[i] = st.nextToken(); 881 } 882 return vals; 883 } 884 885 893 private static ZipInfoProperties checkForInfo(String cpEntry) 894 { 895 File f = new File (cpEntry); 896 if ( ! f.exists()) 897 { 898 return null; 899 } 900 901 if (f.isDirectory()) 902 { 903 ZipInfoProperties zip = checkDirectory(cpEntry); 904 return zip; 905 } 906 907 if (f.isFile()) 908 { 909 ZipInfoProperties zip = checkFile(cpEntry); 910 return zip; 911 } 912 return null; 913 } 914 915 922 private static ZipInfoProperties checkDirectory(String dirname) 923 { 924 boolean foundOne = false; 925 File f = null; 926 for (int i = 0; i < infoNames.length; i++) 927 { 928 String localSysinfo = infoNames[i].replace('/', File.separatorChar); 929 f = new File (dirname, localSysinfo); 930 if (f.exists()) 931 { 932 foundOne = true; 933 break; 934 } 935 } 936 937 if (!foundOne || (f == null)) 938 { 939 return null; 940 } 941 942 try 943 { 944 InputStream bis = new FileInputStream (f); 945 946 ZipInfoProperties zip = new ZipInfoProperties(ProductVersionHolder.getProductVersionHolderFromMyEnv(bis)); 947 zip.setLocation(new File (dirname).getCanonicalPath().replace('/', File.separatorChar)); 948 return zip; 949 } 950 catch (IOException ioe) 951 { 952 return null; 953 } 954 955 } 956 957 967 private static ZipInfoProperties checkFile(String filename) 968 { 969 971 if (filename.indexOf("db2jcc") >= 0) 973 { 974 Class c = null; 975 Method m = null; 976 Object o = null; 977 Integer build = null; 978 Integer major = null; 979 Integer minor = null; 980 try 981 { 982 try 983 { 984 c = Class.forName("com.ibm.db2.jcc.DB2Driver"); 985 m = c.getMethod("getJCCBuildNumber", null); 986 o = c.newInstance(); 987 build = (Integer )m.invoke(o,null); 988 } catch (ClassNotFoundException cnfe) { 989 c = Class.forName("com.ibm.db2.jcc.DB2Version"); 990 m = c.getMethod("getBuildNumber", null); 991 o = c.newInstance(); 992 build = (Integer )m.invoke(o,null); 993 } 994 m = c.getMethod("getMajorVersion", null); 995 major = (Integer )m.invoke(o,null); 996 m = c.getMethod("getMinorVersion", null); 997 minor = (Integer )m.invoke(o,null); 998 999 ProductVersionHolder jccVersion = ProductVersionHolder.getProductVersionHolder( 1000 "IBM Corp.", 1001 "DB2 Java Common Client", 1002 "DRDA:jcc", 1003 major.intValue(), 1004 minor.intValue(), 1005 0, 1006 0, 1007 build.toString(), 1008 Boolean.FALSE); 1009 1010 ZipInfoProperties zip = new ZipInfoProperties(jccVersion); 1011 1012 String loc = getFileWhichLoadedClass(c); 1013 if (loc != null && filename.indexOf("license_c") < 0) 1020 zip.setLocation(loc); 1021 else 1022 zip.setLocation(new File (filename).getCanonicalPath().replace('/', File.separatorChar)); 1023 return zip; 1024 } catch (Exception e) { return null; } 1025 } 1026 1027 try 1028 { 1029 ZipFile zf = new ZipFile (filename); 1030 1032 ZipEntry thisEntry = null; 1033 1034 for (int i =0; i < infoNames.length; i++) 1035 { 1036 thisEntry = zf.getEntry(infoNames[i]); 1037 if (thisEntry != null) 1038 { 1039 break; 1040 } 1041 } 1042 1043 if (thisEntry == null) 1044 { 1045 return null; 1046 } 1047 1048 InputStream bis = zf.getInputStream(thisEntry); 1049 if (bis == null) 1050 { 1051 return null; 1052 } 1053 1054 ZipInfoProperties zip = new ZipInfoProperties(ProductVersionHolder.getProductVersionHolderFromMyEnv(bis)); 1055 zip.setLocation(new File (filename).getCanonicalPath().replace('/', File.separatorChar)); 1056 return zip; 1057 1058 } 1059 catch (IOException ioe) 1060 { 1061 return null; 1063 } 1064 1065 } 1066 1067 1070 private static ResourceBundle getBundle() { 1071 try { 1072 return ResourceBundle.getBundle("org.apache.derby.loc.sysinfoMessages"); 1073 } catch (MissingResourceException mre) { 1074 } 1075 return null; 1076 } 1077 1078 public static String getTextMessage(String msgId) { 1079 return getCompleteMessage(msgId, (Object []) null); 1080 } 1081 public static String getTextMessage(String msgId, Object a1) { 1082 1083 return getCompleteMessage(msgId, new Object [] {a1}); 1084 } 1085 public static String getTextMessage(String msgId, Object a1, Object a2) { 1086 return getCompleteMessage(msgId, new Object [] {a1, a2}); 1087 } 1088 public static String getTextMessage(String msgId, Object a1, Object a2, Object a3) { 1089 return getCompleteMessage(msgId, new Object [] {a1, a2, a3}); 1090 } 1091 public static String getTextMessage(String msgId, Object a1, Object a2, Object a3, Object a4) { 1092 return getCompleteMessage(msgId, new Object [] {a1, a2, a3, a4}); 1093 } 1094 1095 1097 public static String getCompleteMessage(String msgId, Object [] arguments) { 1098 1099 return org.apache.derby.iapi.services.i18n.MessageService.formatMessage(getBundle(), msgId, arguments, false); 1101 } 1102 1103 1110 private static String getFileWhichLoadedClass(final Class cls) 1111 { 1112 return (String )AccessController.doPrivileged( new PrivilegedAction () 1113 { 1114 public Object run() 1115 { 1116 CodeSource cs = null; 1117 try { 1118 cs = cls.getProtectionDomain().getCodeSource (); 1119 } 1120 catch (SecurityException se) { 1121 return Main.getTextMessage("SIF01.V", cls, se.getMessage()); 1122 } 1123 1124 if ( cs == null ) 1125 return null; 1126 1127 URL result = cs.getLocation (); 1128 1129 return formatURL(result); 1130 } 1131 }); 1132 } 1133 1134 1152 private static ZipInfoProperties[] mergeZips(ZipInfoProperties[] zip1, 1153 ZipInfoProperties[] zip2) 1154 { 1155 Vector v = new Vector (); 1156 boolean foundDup = false; 1157 1158 for (int i = 0; i < zip1.length; i++) 1160 { 1161 if (zip1[i] != null && zip1.length > 1) 1162 { 1163 for (int j = i + 1; j < zip1.length; j++) 1164 { 1165 if (zip1[i].getLocation().equals(zip1[j].getLocation())) 1166 zip1[j] = null; 1167 } 1168 } 1169 if (zip1[i] != null) 1170 v.addElement(zip1[i]); 1171 } 1172 1173 if (zip2 != null) 1176 { 1177 for (int j = 0; j < zip2.length; j++) 1178 { 1179 for (int k = 0; k < v.size(); k++) 1180 { 1181 ZipInfoProperties z = (ZipInfoProperties)v.get(k); 1182 if (zip2[j].getLocation().equals(z.getLocation())) 1183 foundDup = true; 1184 } 1185 if (!foundDup) 1186 { 1187 v.addElement(zip2[j]); 1188 } 1189 foundDup = false; 1190 } 1191 } 1192 1193 ZipInfoProperties[] merged = new ZipInfoProperties[v.size()]; 1194 v.copyInto(merged); 1195 return merged; 1196 } 1197 1198 1203 private static String formatURL(URL loc) 1204 { 1205 String filename = URLDecoder.decode(loc.toString()); 1206 1207 if (filename.startsWith("jar:")) { filename = filename.substring(4); } 1208 if (filename.startsWith("file:")) { filename = filename.substring(5); } 1209 if (filename.indexOf("!") > -1) { filename = filename.substring(0, filename.indexOf("!")); } 1210 if (filename.indexOf("/org/apache/derby") > -1) { 1211 filename = filename.substring(0, filename.indexOf("/org/apache/derby")); 1212 } 1213 if (filename.charAt(0) == '/' && 1214 Character.isLetter(filename.charAt(1)) && 1215 filename.charAt(2) == ':' && 1216 filename.charAt(2) == '/') { filename = filename.substring(1); } 1217 1218 String result = ""; 1219 try { 1220 result = new File (filename).getCanonicalPath().replace('/', File.separatorChar); 1221 } catch (IOException e) { 1222 result = "IOException"; 1223 } 1224 return result; 1225 } 1226 1227} 1229 | Popular Tags |