Skip to content

Commit

Permalink
fix GraphViz Adapter for Linux and show install instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Zasch committed Oct 22, 2014
1 parent 70166ba commit dea69ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
6 changes: 5 additions & 1 deletion Adapter/GraphViz/Java/org/sdmlib/doc/GraphViz.java
Expand Up @@ -165,7 +165,11 @@ public boolean drawImg(String imgName, String context)
}
catch (Exception e)
{
e.printStackTrace();
System.err.println("Can't run GraphViz: "+ e.getMessage());
if("linux".equals(System.getProperty("os.name").toLowerCase())){
System.err.println("Please install GraphViz: "+ "apt-get install graphviz");
}
//e.printStackTrace();
}
return true;
}
Expand Down
51 changes: 29 additions & 22 deletions src/main/java/org/sdmlib/doc/GraphFactory.java
@@ -1,6 +1,7 @@
package org.sdmlib.doc;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void generate(String path) {
rootPath = rootPath.substring(0, rootPath.length() - 1);
}
if (rootPath.length()>0 && !(rootPath.endsWith("\\") || rootPath.endsWith("/"))) {
rootPath += "/";
rootPath += File.separator;
}
ArrayList<URL> plugins = new ArrayList<URL>();
for (File item : dir.listFiles()) {
Expand All @@ -94,8 +95,11 @@ public void generate(String path) {
if (libPath.startsWith("file:\\")) {
libPath = libPath.substring(6);
}
if (!(libPath.endsWith("\\") || libPath.endsWith("/"))) {
libPath += "/";
if (libPath.startsWith("file:/")) {
libPath = libPath.substring(5);
}
if (!(libPath.endsWith(File.separator))) {
libPath += File.separator;
}

if (libPath.startsWith(rootPath)) {
Expand All @@ -106,7 +110,6 @@ public void generate(String path) {


public void loadPlugins(List<URL> plugins) {
try {
URLClassLoader ucl = new URLClassLoader(plugins.toArray(new URL[plugins.size()]), this.getClass().getClassLoader());

for (URL plugin : plugins) {
Expand All @@ -128,25 +131,29 @@ public void loadPlugins(List<URL> plugins) {
if (name.indexOf("_")>0) {
name = name.substring(0, name.indexOf("_"));
}
Class<?> c = ucl.loadClass("org.sdmlib.doc." + name);
Object p =c.newInstance();
if( p instanceof GuiAdapter){
this.with((GuiAdapter)p);
}else if(p instanceof GuiFileDrawer){
GuiFileDrawer drawer = (GuiFileDrawer) p;
ArrayList<GuiAdapter> adapters = getAdapters();
for(GuiAdapter item : adapters){
if(item.getName().equalsIgnoreCase(name)){
item.withDrawer(drawer);
drawer.withPlugin(new File(path), plugin.getPath());
}
}
}
try {
Class<?> c = ucl.loadClass("org.sdmlib.doc." + name);
Object p =c.newInstance();
if( p instanceof GuiAdapter){
this.with((GuiAdapter)p);
}else if(p instanceof GuiFileDrawer){
GuiFileDrawer drawer = (GuiFileDrawer) p;
ArrayList<GuiAdapter> adapters = getAdapters();
for(GuiAdapter item : adapters){
if(item.getName().equalsIgnoreCase(name)){
item.withDrawer(drawer);
drawer.withPlugin(new File(path), plugin.getPath());
}
}
}
} catch (Exception e) {
//e.printStackTrace();
}
}
ucl.close();
} catch (Exception e) {
//e.printStackTrace();
}
try {
ucl.close();
} catch (IOException e) {
}
}

public ArrayList<GuiAdapter> getAdapters()
Expand Down

0 comments on commit dea69ba

Please sign in to comment.