Search in sources :

Example 6 with TestCase

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());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IOException(java.io.IOException)

Example 7 with TestCase

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);
}
Also used : TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase)

Example 8 with TestCase

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()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) Date(java.util.Date) Parser(org.eclipse.titan.log.viewer.parsers.Parser) ExecutionModel(org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) ParseException(java.text.ParseException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 9 with TestCase

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) ArrayList(java.util.ArrayList) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) CachedLogReader(org.eclipse.titan.log.viewer.readers.CachedLogReader) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 10 with TestCase

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()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StatisticalView(org.eclipse.titan.log.viewer.views.StatisticalView) PartInitException(org.eclipse.ui.PartInitException) HashSet(java.util.HashSet)

Aggregations

TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)20 IFile (org.eclipse.core.resources.IFile)10 File (java.io.File)7 IOException (java.io.IOException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)5 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)5 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)4 PreferencesHolder (org.eclipse.titan.log.viewer.preferences.PreferencesHolder)4 IViewReference (org.eclipse.ui.IViewReference)4 ParseException (java.text.ParseException)3 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 TestCaseExtractor (org.eclipse.titan.log.viewer.extractors.TestCaseExtractor)3 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)3 LogRecordIndex (org.eclipse.titan.log.viewer.models.LogRecordIndex)3 Parser (org.eclipse.titan.log.viewer.parsers.Parser)3 StatisticalData (org.eclipse.titan.log.viewer.views.details.StatisticalData)3