1+ package com .ibm .wala .util ;
2+
3+ import java .io .File ;
4+ import java .io .IOException ;
5+ import java .nio .file .Files ;
6+ import java .nio .file .Path ;
7+ import java .nio .file .Paths ;
8+ import java .util .ArrayList ;
9+ import java .util .stream .Collectors ;
10+
11+
12+ /*
13+ Author: Ali Shokri (as8308@rit.edu)
14+ This class is a replacement for com.ibm.wala.util.PlatformUtil to make an adhoc fix on getBootClassPathJars() method
15+ */
16+
17+ public class PlatformUtil {
18+ public PlatformUtil () {
19+ }
20+
21+ public static boolean onMacOSX () {
22+ String osname = System .getProperty ("os.name" );
23+ return osname .toLowerCase ().contains ("mac" );
24+ }
25+
26+ public static boolean onLinux () {
27+ String osname = System .getProperty ("os.name" );
28+ return osname .equalsIgnoreCase ("linux" );
29+ }
30+
31+ public static boolean onWindows () {
32+ String osname = System .getProperty ("os.name" );
33+ return osname .toLowerCase ().contains ("windows" );
34+ }
35+
36+ public static boolean onIKVM () {
37+ return "IKVM.NET" .equals (System .getProperty ("java.runtime.name" ));
38+ }
39+
40+ public static String [] getBootClassPathJars () {
41+ String classpath = null ;
42+ String javaVersion = System .getProperty ("java.specification.version" );
43+ if (!javaVersion .equals ("1.8" )) {
44+
45+ // Ali: Below try-catch is put in an if condition to cover the situation that this method is called in the run-time (e.g. creating class hierarchy at runtime.
46+ // jmods folder is not available in the runtime!
47+
48+ if ( Paths .get (System .getProperty ("java.home" ), "jmods" ).toFile ().exists () ) {
49+ try {
50+ classpath = String .join (File .pathSeparator , (Iterable ) Files .list (Paths .get (System .getProperty ("java.home" ), "jmods" )).map (Path ::toString ).collect (Collectors .toList ()));
51+ } catch (IOException var8 ) {
52+ throw new IllegalStateException (var8 );
53+ }
54+ }
55+ else
56+ classpath = System .getProperty ("java.class.path" );
57+
58+ } else {
59+ classpath = System .getProperty ("sun.boot.class.path" );
60+ }
61+
62+ if (classpath == null ) {
63+ throw new IllegalStateException ("could not find boot classpath" );
64+ } else {
65+ String [] jars = classpath .split (File .pathSeparator );
66+ ArrayList <String > result = new ArrayList ();
67+ String [] var4 = jars ;
68+ int var5 = jars .length ;
69+
70+ for (int var6 = 0 ; var6 < var5 ; ++var6 ) {
71+ String jar = var4 [var6 ];
72+ if ((jar .endsWith (".jar" ) || jar .endsWith (".jmod" )) && (new File (jar )).exists ()) {
73+ result .add (jar );
74+ }
75+ }
76+
77+ return (String [])result .toArray (new String [0 ]);
78+ }
79+ }
80+ }
0 commit comments