Skip to content

Commit d33e6e2

Browse files
committed
Resolving Code Generator issue with Java 9 and later versions.
1 parent d891a88 commit d33e6e2

2 files changed

Lines changed: 83 additions & 2 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
}

src/main/java/edu/rit/se/design/ArCodePlugin/recommendation/DotGraphViewerPanel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public synchronized void setDot(StringBuilder dot) {
6363
Graphviz graphviz = Graphviz.fromGraph( mutableGraph );
6464
bufferedImage = graphviz./*width(500).height(1000).*/render(Format.SVG).toImage();
6565

66-
File imgeOutput = new File( label + ".png" );
67-
ImageIO.write( bufferedImage, "png", imgeOutput );
66+
// File imgeOutput = new File( label + ".png" );
67+
// ImageIO.write( bufferedImage, "png", imgeOutput );
6868

6969

7070
int biWidth = bufferedImage.getWidth();
@@ -92,6 +92,7 @@ public synchronized void setDot(StringBuilder dot) {
9292
// noPreviewIsAvailable.setVisible(false);
9393
// add( new JLabel( new ImageIcon( bufferedImage ) ) );
9494
} catch (IOException | ParserException | GraphvizException e) {
95+
e.printStackTrace();
9596
noPreviewIsAvailable.setVisible(true);
9697
}
9798
}

0 commit comments

Comments
 (0)