use of org.eclipse.titan.log.viewer.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class TestCaseExtractor method extractTestCasesFromLogFile.
/**
* Extracts Test Cases from a Log File
* @param logFileMetaData meta data about the log file
* @throws IOException if log file not found or error while extracting
*/
public void extractTestCasesFromLogFile(final LogFileMetaData logFileMetaData, final IProgressMonitor pMonitor) throws IOException {
IProgressMonitor monitor = pMonitor == null ? new NullProgressMonitor() : pMonitor;
this.logFile = logFileMetaData.getLogfile();
if (logFile == null) {
throw new IOException("Log file not found.");
}
extractFromLogFile(logFileMetaData, monitor);
if (monitor.isCanceled()) {
testCaseVector = null;
logRecordIndexVector = null;
crashed = true;
return;
}
if (this.crashed) {
if (!testCaseVector.isEmpty()) {
testCaseVector.get(testCaseVector.size() - 1).setEndRecordNumber(this.endRecordNumber);
}
} else if (this.withinTestCase) {
// Last test case finished missing!
this.crashed = true;
this.testCaseVector.add(new TestCase(logFile, -1, Messages.getString("TestCaseExtractor.3"), this.filePointer, Constants.VERDICT_CRASHED, this.currentTestCase.getStartRecordNumber(), this.endRecordNumber));
}
if (Constants.DEBUG) {
// $NON-NLS-1$
TITANDebugConsole.getConsole().newMessageStream().println("Total line " + this.lineCounter);
// $NON-NLS-1$
TITANDebugConsole.getConsole().newMessageStream().println("Total record " + this.logRecordIndexVector.size());
}
}
use of org.eclipse.titan.log.viewer.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class TestCaseExtractor method createTestcase.
private void createTestcase(final IFile logFile, final String name, final int recordNumber) {
this.currentTestCaseNumber++;
this.currentTestCase = new TestCase(logFile);
this.currentTestCase.setTestCaseNumber(this.currentTestCaseNumber);
this.currentProgress = (int) (this.filePointer * (100.0 / this.fileSize));
this.currentTestCase.setTestCaseName(name);
this.currentTestCase.setFilePointer(this.filePointer);
this.currentTestCase.setStartRecordNumber(recordNumber);
}
use of org.eclipse.titan.log.viewer.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class OpenMSCViewMenuAction method run.
public void run(final IStructuredSelection selection) {
if (!isEnabled()) {
return;
}
Object element = selection.getFirstElement();
if (!(element instanceof TestCase)) {
return;
}
final TestCase tc = (TestCase) element;
final IFile logFile = tc.getLogFile();
try {
logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(LogFileCacheHandler.getPropertyFileForLogFile(logFile));
} catch (IOException e1) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
} catch (ClassNotFoundException e1) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
}
try {
if (!PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName()).getVisualOrderComponents().isEmpty()) {
// Get start time
final long start = new Date().getTime();
if (!logFile.exists()) {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference[] viewReferences = activePage.getViewReferences();
ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenMSCViewMenuAction.4")));
return;
}
// Check if the file has been modified
if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
}
// Get log record index file for selected log file - No need to check is exists due to
// LogFileCacheHandler.hasLogFileChanged(logFile) returning false above
File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, tc.getStartRecordNumber(), tc.getNumberOfRecords());
final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
WorkspaceJob job = new WorkspaceJob("Loading log information") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
if (OpenMSCViewMenuAction.this.logFileMetaData == null || OpenMSCViewMenuAction.this.logFileMetaData.getExecutionMode() == null) {
return Status.CANCEL_STATUS;
}
final Parser parser;
final ExecutionModel model;
try {
parser = new Parser(OpenMSCViewMenuAction.this.logFileMetaData);
parser.setStart(start);
model = parser.preParse(tc, logRecordIndexes, preferences, null, monitor);
} catch (TechnicalException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
Messages.getString("OpenMSCViewMenuAction.3") + e.getMessage()));
return Status.CANCEL_STATUS;
} catch (ParseException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
Messages.getString("OpenMSCViewMenuAction.2") + e.getMessage()));
return Status.CANCEL_STATUS;
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
return Status.CANCEL_STATUS;
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
showView(model, parser, tc);
// Write data to the console
final long end = new Date().getTime();
parser.setEnd(end);
ConsoleWriter.getInstance().writeModelData(OpenMSCViewMenuAction.this.logFileMetaData.getProjectName(), parser, model, OpenMSCViewMenuAction.this.logFileMetaData.getFilePath().toString());
}
});
return Status.OK_STATUS;
}
};
job.schedule();
} else {
// $NON-NLS-1$
String userE = Messages.getString("OpenMSCViewMenuAction.1");
TitanLogExceptionHandler.handleException(new UserException(userE));
}
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
}
}
use of org.eclipse.titan.log.viewer.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class OpenStatisticalViewMenuAction method createStatisticalData.
private List<StatisticalData> createStatisticalData(Set<IFile> logFiles) {
List<StatisticalData> statisticalDataVector = new ArrayList<StatisticalData>();
for (IFile file : logFiles) {
this.logFile = file;
if (!this.logFile.exists()) {
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenStatisticalViewMenuAction.5")));
return null;
}
File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(this.logFile);
File propertyFile = LogFileCacheHandler.getPropertyFileForLogFile(this.logFile);
if (!logRecordIndexFile.exists() || !propertyFile.exists() || LogFileCacheHandler.hasLogFileChanged(this.logFile)) {
processLogFile();
} else {
// Get log file meta data
try {
this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
// Extract test cases from the index file
this.testCaseExtractor = new TestCaseExtractor();
this.testCaseExtractor.extractTestCasesFromIndexedLogFile(this.logFile);
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
} catch (ClassNotFoundException e) {
ErrorReporter.logExceptionStackTrace(e);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
}
}
if (this.logFileIsSupported) {
try {
if (this.logFileMetaData == null) {
this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
}
List<TestCase> testCases = this.testCaseExtractor.getTestCases();
// //Create data for the statistical view
final CachedLogReader reader = new CachedLogReader(LogFileReader.getReaderForLogFile(this.logFile));
StatisticalData statisticalData = new StatisticalData(this.logFileMetaData, testCases, reader);
statisticalDataVector.add(statisticalData);
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
} catch (ClassNotFoundException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
}
}
}
return statisticalDataVector;
}
use of org.eclipse.titan.log.viewer.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class OpenStatisticalViewMenuAction method run.
public void run(final IStructuredSelection selection) {
this.logFileMetaData = null;
this.logFileIsSupported = true;
if (this.selection == null) {
return;
}
Set<IFile> logFiles = new HashSet<IFile>(selection.size());
for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
Object object = iterator.next();
if (object instanceof IFile) {
logFiles.add((IFile) object);
} else if (object instanceof TestCase) {
logFiles.add(((TestCase) object).getLogFile());
}
}
if (logFiles.isEmpty()) {
return;
}
List<StatisticalData> statisticalDataVector = createStatisticalData(logFiles);
if (statisticalDataVector == null || statisticalDataVector.isEmpty()) {
return;
}
String secondId = Constants.STATISTICAL_VIEW;
if (statisticalDataVector.size() < 2) {
secondId = File.separator + this.logFile.getProject().getName() + File.separator + this.logFile.getProjectRelativePath().toOSString();
}
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference reference = activePage.findViewReference(Constants.STATISTICAL_VIEW_ID, secondId);
// get the view
if (reference != null) {
StatisticalView part = (StatisticalView) reference.getView(false);
}
// create a new view
try {
StatisticalView part = (StatisticalView) activePage.showView(Constants.STATISTICAL_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
part.setData(statisticalDataVector);
part.setFocus();
} catch (PartInitException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
}
}
Aggregations