Skip to content

Commit

Permalink
add support for running windows scraper from gui, add beginnings of u…
Browse files Browse the repository at this point in the history
…ser preferences which are saved from run to run, fixed bugs
  • Loading branch information
ESIC-DA committed Oct 16, 2019
1 parent 23cdd60 commit 1443110
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 25 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<property name="build.numThreads" value="1" />
<property name="src.dir" value="./src"/>
<property name="lib.dir" value="./deps/org.graphstream/lib"/>
<property name="build.version" value="AHA-GUI v0.6.8b151"/>
<property name="build.version" value="AHA-GUI v0.7.0b1"/>
<property name="CP" value="."/>
<tstamp>
<format property="TODAY" pattern="yyyy-MM-dd HH:mm" />
Expand Down Expand Up @@ -62,7 +62,7 @@
<parallel threadsPerProcessor="${build.numThreads}">
<jar jarfile="${build.dir}/AHA-GUI.jar" basedir="${build.classes}" index="false" level="9" >
<manifest>
<attribute name="Class-Path" value="${CP} lib/gs-algo-2.0-alpha.jar lib/gs-core-2.0-alpha.jar lib/gs-ui-swing-2.0-alpha.jar"/>
<attribute name="Class-Path" value=". lib/gs-algo-2.0-alpha.jar lib/gs-core-2.0-alpha.jar lib/gs-ui-swing-2.0-alpha.jar"/>
<attribute name="Application-Name" value="AHA-GUI"/>
<attribute name="Implementation-Version" value="${build.version} ${build.timestamp}" />
<attribute name="Main-Class" value="esic/AHAGUI"/>
Expand Down
68 changes: 64 additions & 4 deletions src/esic/AHAController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package esic;
//Copyright 2018 ESIC at WSU distributed under the MIT license. Please see LICENSE file for further info.

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;
import javax.swing.SwingUtilities;
import esic.AHAGraph.AHANode;

Expand All @@ -12,10 +15,10 @@ public class AHAController implements org.graphstream.ui.view.ViewerListener, ja
protected java.util.concurrent.atomic.AtomicReference<String> m_layoutMode=new java.util.concurrent.atomic.AtomicReference<>(); //set the default in AHAGUI:resetUI
private java.util.concurrent.ExecutorService m_backgroundExec= java.util.concurrent.Executors.newCachedThreadPool();

public AHAController(String inputFileName, String scoreFileName, int verbosity, boolean useMultiLineGraph)
public AHAController(String inputFileName, String scoreFileName, int verbosity, boolean useMultiLineGraph, Properties props)
{
m_model.set(new AHAModel(this, inputFileName, scoreFileName, verbosity));
m_gui=new AHAGUI(m_model.get(), this, useMultiLineGraph);
m_gui=new AHAGUI(m_model.get(), this, useMultiLineGraph, props);
}

public void start() { model().run(); }
Expand All @@ -24,7 +27,7 @@ public AHAController(String inputFileName, String scoreFileName, int verbosity,
protected void openfileOrReload(boolean reload)
{
String title="AHA-GUI";
try { title=AHAGUI.class.getPackage().getImplementationVersion().split(" B")[0]; } catch (Exception ex) {ex.printStackTrace();}
try { title=AHAGUI.class.getPackage().getImplementationVersion().split(" B")[0]; } catch (Exception ex) {ex.printStackTrace(); }
boolean ret=reload;
if (!reload) { ret=m_gui.openFile(model(), title); }
if (ret==true)
Expand All @@ -33,6 +36,7 @@ protected void openfileOrReload(boolean reload)
m_currentlyDisplayedNode.set(null);
System.err.println("\n");
AHAModel oldModel=model();
m_gui.setTitle(title+" "+oldModel.m_inputFileName);
AHAModel newModel=new AHAModel(this, oldModel.m_inputFileName, oldModel.m_scoreFileName, oldModel.m_verbosity);
m_model.set(newModel);
m_gui.initGraphView(newModel);
Expand All @@ -49,6 +53,7 @@ public void actionPerformed(java.awt.event.ActionEvent ae) //swing actions go to

//the first few actions do not require access to graph, and thus we don't bother putting them on the background thread
if (actionCommand.equals("dataView")) { m_gui.showDataView(model(), m_gui); }
else if (actionCommand.equals("showPrefsPane")) { m_gui.showPrefsPane(m_gui); }
else if (actionCommand.equals("exit")) { m_gui.dispatchEvent(new java.awt.event.WindowEvent(m_gui, java.awt.event.WindowEvent.WINDOW_CLOSING)); }
else if (actionCommand.equals("openNewFile")) { openfileOrReload(false); }
else if (actionCommand.equals("refreshInfoPanel")) { updateSidebar(m_currentlyDisplayedNode.get(), false); }
Expand All @@ -57,7 +62,7 @@ public void actionPerformed(java.awt.event.ActionEvent ae) //swing actions go to
final AHAController controller=this;
m_backgroundExec.execute(new Runnable()
{
public void run()
public void run()
{
if (actionCommand.equals("hideOSProcs")) { model().hideOSProcs(selected); }
else if (actionCommand.equals("resetZoom")) { m_gui.m_graphViewPanel.getCamera().resetView(); }
Expand Down Expand Up @@ -87,6 +92,61 @@ else if (actionCommand.equals("search")) //both uses the graph and requires an u
public void run() { m_gui.m_btmPnlSearchStatus.setText(status); }
});
}
else if (actionCommand.equals("runAHAScraper"))
{
try
{ //TODO: this will probably fail gloriously if they have not done the exec powershell bypass thing.
String dirName="AHA-Scraper-Win", taskString="powershell.exe -ExecutionPolicy Bypass -File ./AHA-Scraper.ps1";
java.io.File workingDir=new java.io.File(dirName), scriptFile=new java.io.File(dirName+"/AHA-Scraper.ps1");
if ( !workingDir.exists() || !scriptFile.exists() )
{
String message="AHA-Scraper could not be located.\nPlease place it within the AHA-GUI directory in a directory called 'AHA-Scraper-Win'";
if (!System.getProperty("java.vendor").toLowerCase().contains("window")) { message="Direct run of the scaper is currently only supported on Windows™"; }
javax.swing.JOptionPane.showMessageDialog(m_gui, message, "Scraper Error", javax.swing.JOptionPane.WARNING_MESSAGE);
return;
}
System.out.printf("Attempting to run AHA task '%s'\n", taskString);
final Process process=new ProcessBuilder(taskString.split(" ")).redirectErrorStream(true).directory(workingDir).start();

long startTime=System.currentTimeMillis();
int progress=0;
javax.swing.ProgressMonitor pm=null;
AHAGUIHelpers.tryCancelSplashScreen();
try
{
String message="Running AHA-Scraper: "; //the giant blank string helps us guarantee a reasonable minimum size
pm=new javax.swing.ProgressMonitor(m_gui,message,"Preparing to start updating file...",progress++,100);
pm.setMillisToDecideToPopup(1);
pm.setMillisToPopup(1);
} catch (Exception e) {} //in case we're running headlessly

java.io.BufferedReader reader=new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()));
while (process.isAlive() && (System.currentTimeMillis()-startTime < 100000) ) //limit max runtime to 100s
{
String output=reader.readLine();
if (output==null) { break; }
if (output.toLowerCase().contains("complete, elapsed time")) { break; }
if (progress > 90) { progress--; }
AHAGUIHelpers.tryUpdateProgress(pm,progress++,100,output);
if (output.length()>0) { System.out.println(output.trim()); }
}
try { process.destroyForcibly(); } //older OSes/powershells may not exit when the script is done.
catch (Exception e) { e.printStackTrace(); }
AHAGUIHelpers.tryUpdateProgress(pm,100,100,"Done.");
java.io.File f=new java.io.File(dirName+"/BinaryAnalysis.csv");
if (f.exists())
{
java.util.Date date = new java.util.Date();
String today= new java.text.SimpleDateFormat("yyyy-MM-dd-hhmm").format(date);
System.out.println("calculated date as '"+today+"'");
String newFileName="BinaryAnalysis"+today+".csv";
Files.copy(Paths.get(dirName+"/BinaryAnalysis.csv"), Paths.get(newFileName), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
model().m_inputFileName=newFileName;
openfileOrReload(true);
}
}
catch (Exception e) { e.printStackTrace(); }
}
else { System.err.println("AHAController: ActionPerformed: Unknown action command='"+actionCommand+"'"); }
}
});
Expand Down
Loading

0 comments on commit 1443110

Please sign in to comment.