From: <mwl...@us...> - 2007-08-16 21:06:32
|
Revision: 478 http://cishell.svn.sourceforge.net/cishell/?rev=478&view=rev Author: mwlinnem Date: 2007-08-16 14:06:26 -0700 (Thu, 16 Aug 2007) Log Message: ----------- Cleaned up. Modified Paths: -------------- trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithm.java trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithmFactory.java Modified: trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithm.java =================================================================== --- trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithm.java 2007-08-16 20:36:06 UTC (rev 477) +++ trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithm.java 2007-08-16 21:06:26 UTC (rev 478) @@ -32,22 +32,17 @@ import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; -//TODO: Only just barely usable to run converter tester from GUI. -//TODO: Make it nice eventually +//TODO: Maybe let the user specify which converters he/she wants to test, or other things +//TODO: Make it progress-trackable public class ConverterTesterAlgorithm implements Algorithm, AlgorithmProperty { - private static File currentDir; - - private Data[] data; - private Dictionary parameters; + private CIShellContext cContext; private BundleContext bContext; private LogService log; public ConverterTesterAlgorithm(Data[] data, Dictionary parameters, CIShellContext cContext, BundleContext bContext ) { - this.data = data; - this.parameters = parameters; this.cContext = cContext; this.bContext = bContext; @@ -58,12 +53,13 @@ public Data[] execute() { - this.log.log(LogService.LOG_WARNING, "-------NOTICE-------" + "\n" + + this.log.log(LogService.LOG_WARNING, + "-------NOTICE-------" + "\n" + "The Converter Tester will take " + "approximately 30 seconds to run all the tests, and around " + "20 seconds to display all the results. Thank you for " + "waiting :)" + "\n" + - "-----END NOTICE-----"); + "-----END NOTICE-----"); Data[] returnDM; @@ -95,17 +91,7 @@ } - public static String getFileExtension(File theFile) { - String fileName = theFile.getName() ; - String extension ; - if (fileName.lastIndexOf(".") != -1) - extension = fileName.substring(fileName.lastIndexOf(".")+1) ; - else - extension = "" ; - return extension ; - } - - final class DataUpdater implements Runnable{ + final class DataUpdater implements Runnable { boolean loadFileSuccess = false; IWorkbenchWindow window; ArrayList returnList = new ArrayList(); @@ -116,46 +102,46 @@ this.window = window; } - public void run (){ -// if (currentDir == null) { -// currentDir = new File(System.getProperty("user.dir") + File.separator + "sampledata"); -// -// if (!currentDir.exists()) { -// currentDir = new File(System.getProperty("user.home") + File.separator + "anything"); -// } else { -// currentDir = new File(System.getProperty("user.dir") + File.separator + "sampledata" + File.separator + "anything"); -// } -// } -// dialog.setFilterPath(currentDir.getPath()); -// dialog.setText("Select a File: Too bad we aren't using it, haha!"); -// String fileName = dialog.open(); -// if (fileName == null) { -// return; -// } - - try { - ConverterTester2 ct = new ConverterTester2(log); - ServiceReference[] refs = getServiceReferences(); + public void run () { + + try { + //get all the converters + ServiceReference[] convRefs = getConverterReferences(); - ConverterGraph converterGraph = new ConverterGraph(refs, bContext, log); + //generate converter paths inside converter graph, for use in executing the test + ConverterGraph converterGraph = new ConverterGraph(convRefs, bContext, log); + //extract converter graph in nwb file format. File nwbGraph = converterGraph.asNWB(); + //initialize all the report generators + AllTestsReportGenerator allGen = new AllTestsReportGenerator(this.log); AllConvsReportGenerator allConvGen = new AllConvsReportGenerator(this.log); GraphReportGenerator graphGen = new GraphReportGenerator(nwbGraph, this.log); ReadMeReportGenerator readmeGen = new ReadMeReportGenerator(); - ct.execute(converterGraph, new ReportGenerator[] {allGen, allConvGen, graphGen, readmeGen}, cContext, bContext); + //execute the tests, and provide the results to the report generators + ConverterTester2 ct = new ConverterTester2(log); + ct.execute(converterGraph, + new ReportGenerator[] + {allGen, allConvGen, graphGen, readmeGen}, + cContext, bContext); + /* + * report generators have now been supplied with the test + * results, and their reports can now be extracted. + */ - // readme report + //return readme report + ReadMeReport readmeReport = readmeGen.getReadMe(); File readmeFile = readmeReport.getReportFile(); Data readMeData = createReportData(readmeFile, readmeReport.getName(), null); addReturn(readMeData); - //all tests report + //return all tests report + AllTestsReport allReport = allGen.getAllTestsReport(); File allReportFile = allReport.getAllTestsReport(); Data allReportData = createReportData(allReportFile, @@ -171,7 +157,7 @@ TestReport[] fTestReports = allReport.getFailedTestReports(); addFilePasses(fTestReports, allReportData); - //all conv report + //return all converters report AllConvsReport allConvReport = allConvGen.getAllConvsReport(); File allConvReportFile = allConvReport.getReport(); @@ -179,6 +165,7 @@ null); addReturn(allConvReportData); + //return each converter report ConvReport[] convReports = allConvReport.getConverterReports(); for (int ii = 0; ii < convReports.length; ii++) { ConvReport convReport = convReports[ii]; @@ -190,33 +177,39 @@ addFilePasses(trs, convReportData); } + //return annotated graph report + File graphReportFile = graphGen.getGraphReport(); Data graphReport = createReportData(graphReportFile, "Annotated Graph Report", null, "file:text/nwb", DataProperty.NETWORK_TYPE); addReturn(graphReport); - - - - } catch (Exception e) { - System.out.println("Why oh why am I catching type Exception?"); - System.out.println(e); - e.printStackTrace(); - } + } catch (Exception e) { + this.log.log(LogService.LOG_ERROR, "Converter Tester Failed.", e); + } } + /** + * Add a report to a list of reports that are later returned. + * @param report the report to be returned from this algorithm + */ private void addReturn(Data report) { this.returnList.add(report); } - private void addFilePasses(TestReport[] testReports, Data allReportData) { + /** + * Returns file pass reports associated with tests or converters. + * @param testReports reports to be returned as children or test or converter + * @param parent the parent of the file pass + */ + private void addFilePasses(TestReport[] testReports, Data parent) { for (int ii = 0; ii < testReports.length; ii++) { TestReport tr = testReports[ii]; File testReportFile = tr.getTestReport(); - System.out.println("In algorithm, file pass name is : " + tr.getName()); - System.out.println("In algorithm FILE name is : " + testReportFile.getName()); +// System.out.println("In algorithm, file pass name is : " + tr.getName()); +// System.out.println("In algorithm FILE name is : " + testReportFile.getName()); Data testReportData = createReportData(testReportFile, - tr.getName(), allReportData); + tr.getName(), parent); addReturn(testReportData); FilePassReport[] sFilePassReports = tr.getSuccessfulFilePassReports(); @@ -239,6 +232,18 @@ } } + /** + * Wraps the report with metadata in a form that is ready to be + * returned from the algorithm. + * + * @param report the report to be turned into data + * @param label how the report will be labeled in the data manager window + * @param parent which report this report will hang from + * (null if it is not a child of any report) + * @param format The file format or class name of the report + * @param type whether the report is a network or text file + * @return the report encapsulated in data, ready to be returned. + */ private Data createReportData(Object report, String label, Data parent, String format, String type) { Data reportData = new BasicData(report, format); Dictionary metadata = reportData.getMetaData(); @@ -250,6 +255,14 @@ return reportData; } + /** + * Alternate version of createReportData that assumes the report is a plain text file + * @param report the report to be turned into data + * @param label how the report will be labeled in the data manager window + * @param parent which report this report will hang from + * (null if it is not a child of any report) + * @return the report encapsulated in data, ready to be returned. + */ private Data createReportData(Object report, String label, Data parent) { return createReportData(report, label, parent, "file:text/plain", DataProperty.TEXT_TYPE); } @@ -257,7 +270,7 @@ - private ServiceReference[] getServiceReferences() { + private ServiceReference[] getConverterReferences() { String filter = "(&("+ALGORITHM_TYPE+"="+TYPE_CONVERTER+"))";// + try { Modified: trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithmFactory.java =================================================================== --- trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithmFactory.java 2007-08-16 20:36:06 UTC (rev 477) +++ trunk/testing/org.cishell.testing.convertertester.algorithm/src/org/cishell/testing/convertertester/algorithm/ConverterTesterAlgorithmFactory.java 2007-08-16 21:06:26 UTC (rev 478) @@ -13,19 +13,13 @@ public class ConverterTesterAlgorithmFactory implements AlgorithmFactory { - private MetaTypeProvider provider; private BundleContext bContext; protected void activate(ComponentContext ctxt) { - //You may delete all references to metatype service if - //your algorithm does not require parameters and return - //null in the createParameters() method - MetaTypeService mts = (MetaTypeService)ctxt.locateService("MTS"); - this.bContext = ctxt.getBundleContext(); - provider = mts.getMetaTypeInformation(this.bContext.getBundle()); + this.bContext = ctxt.getBundleContext();; } + protected void deactivate(ComponentContext ctxt) { - provider = null; } public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |