From: <bh...@us...> - 2008-03-27 15:38:30
|
Revision: 727 http://cishell.svn.sourceforge.net/cishell/?rev=727&view=rev Author: bh2 Date: 2008-03-27 08:38:15 -0700 (Thu, 27 Mar 2008) Log Message: ----------- made static executable runner not swallow Exception Modified Paths: -------------- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithmFactory.java trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java Modified: trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithmFactory.java =================================================================== --- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithmFactory.java 2008-03-27 14:50:53 UTC (rev 726) +++ trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithmFactory.java 2008-03-27 15:38:15 UTC (rev 727) @@ -28,6 +28,7 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.algorithm.ProgressTrackable; @@ -108,7 +109,7 @@ ALGORITHM_DEFAULT = ALGORITHM + "default/"; } - public Data[] execute() { + public Data[] execute() throws AlgorithmExecutionException { try { Properties serviceProps = getProperties("/"+algName+"/service.properties"); Properties configProps = getProperties("/"+algName+"/config.properties"); @@ -122,13 +123,12 @@ copyFiles(runner.getTempDirectory()); return runner.execute(); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); + } catch (IOException e) { + throw new AlgorithmExecutionException(e.getMessage(), e); } } - private void copyFiles(File dir) throws IOException { + private void copyFiles(File dir) throws IOException, AlgorithmExecutionException { Enumeration e = bContext.getBundle().getEntryPaths("/"+algName); Set entries = new HashSet(); @@ -173,7 +173,7 @@ } if (path == null) { - throw new RuntimeException("Unable to find compatible executable"); + throw new AlgorithmExecutionException("Unable to find compatible executable"); } else { //logger.log(LogService.LOG_DEBUG, "base path: "+path+ // "\n\t"+dir.getAbsolutePath() + "\n\n"); Modified: trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java =================================================================== --- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java 2008-03-27 14:50:53 UTC (rev 726) +++ trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java 2008-03-27 15:38:15 UTC (rev 727) @@ -30,6 +30,7 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.data.BasicData; @@ -76,19 +77,14 @@ /** * @see org.cishell.framework.algorithm.Algorithm#execute() */ - public Data[] execute() { - try { - String algDir = tempDir + File.separator - + props.getProperty("Algorithm-Directory") + File.separator; + public Data[] execute() throws AlgorithmExecutionException { + String algDir = tempDir + File.separator + + props.getProperty("Algorithm-Directory") + File.separator; - chmod(algDir); - File[] output = execute(getTemplate(algDir), algDir); + chmod(algDir); + File[] output = execute(getTemplate(algDir), algDir); - return toData(output); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } + return toData(output); } protected Data[] toData(File[] files) { @@ -164,7 +160,7 @@ return data; } - protected void chmod(String baseDir) { + protected void chmod(String baseDir) throws AlgorithmExecutionException { // FIXME: Surely java has a way to do this!!!! if (new File("/bin/chmod").exists()) { try { @@ -172,21 +168,27 @@ Runtime.getRuntime().exec("/bin/chmod +x " + executable) .waitFor(); } catch (IOException e) { - e.printStackTrace(); + throw new AlgorithmExecutionException(e); } catch (InterruptedException e) { - e.printStackTrace(); + throw new AlgorithmExecutionException(e); } } } - protected File[] execute(String[] cmdarray, String baseDir) - throws Exception { + protected File[] execute(String[] cmdarray, String baseDir) + throws AlgorithmExecutionException { File dir = new File(baseDir); String[] beforeFiles = dir.list(); - final Process process = Runtime.getRuntime().exec(cmdarray, null, - new File(baseDir)); - process.getOutputStream().close(); + Process process = null; + try { + process = Runtime.getRuntime().exec(cmdarray, null, + new File(baseDir)); + process.getOutputStream().close(); + } catch (IOException e1) { + throw new AlgorithmExecutionException(e1.getMessage(),e1); + } + monitor.start(ProgressMonitor.CANCELLABLE, -1); InputStream in = process.getInputStream(); @@ -265,7 +267,7 @@ } protected StringBuffer logStream(int logLevel, InputStream is, - StringBuffer buffer) { + StringBuffer buffer) throws AlgorithmExecutionException { try { int available = is.available(); if (available > 0) { @@ -278,7 +280,7 @@ } catch (EOFException e) { //normal operation } catch (IOException e) { - e.printStackTrace(); + throw new AlgorithmExecutionException("Error when processing the algorithm's screen output",e); } return buffer; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |