Search in sources :

Example 1 with Parser

use of org.eclipse.titan.log.viewer.parsers.Parser in project titan.EclipsePlug-ins by eclipse.

the class RefreshMSCViewAction method run.

@Override
public void run() {
    // Set current log file meta data
    final LogFileMetaData logFileMetaData = this.mscView.getLogFileMetaData();
    ExecutionModel model = this.mscView.getModel();
    final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(logFileMetaData.getProjectName());
    if (preferences.getVisualOrderComponents().isEmpty()) {
        // $NON-NLS-1$
        String userE = Messages.getString("RefreshMSCViewAction.3");
        TitanLogExceptionHandler.handleException(new UserException(userE));
        return;
    }
    final IFile logFile = getSelectedLogFile(logFileMetaData);
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    // Check if the log file exists
    if (!logFile.exists()) {
        IViewReference[] viewReferences = activePage.getViewReferences();
        ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new UserException(Messages.getString("RefreshMSCViewAction.1")));
        return;
    }
    // Check if the log 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);
    try {
        // Read/parse log file
        final TestCase tc = model.getTestCase();
        final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, tc.getStartRecordNumber(), tc.getNumberOfRecords());
        WorkspaceJob job = new WorkspaceJob("Loading log information") {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                ExecutionModel model;
                try {
                    model = parseLogFile();
                } catch (Exception e) {
                    ErrorReporter.logExceptionStackTrace(e);
                    TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
                    Messages.getString("RefreshMSCViewAction.5") + e.getMessage()));
                    return Status.CANCEL_STATUS;
                }
                final int firstRow = getFirstRow(model, preferences);
                final ExecutionModel finalModel = model;
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        RefreshMSCViewAction.this.mscView.setModel(finalModel, firstRow);
                    }
                });
                return Status.OK_STATUS;
            }

            private ExecutionModel parseLogFile() throws TechnicalException {
                ExecutionModel model;
                if (logFileMetaData.getExecutionMode() == null) {
                    throw new TechnicalException("Error while parsing of the log file: ExecutionMode is null");
                }
                try {
                    // re-parse tc
                    Parser parser = new Parser(logFileMetaData);
                    model = parser.preParse(tc, logRecordIndexes, preferences, mscView.getFilterPattern(), null);
                } catch (IOException e) {
                    throw new TechnicalException("Error while parsing of the log file");
                } catch (ParseException e) {
                    throw new TechnicalException("Error while parsing of the log file");
                }
                return model;
            }
        };
        job.schedule();
    } 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) CoreException(org.eclipse.core.runtime.CoreException) ParseException(java.text.ParseException) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IOException(java.io.IOException) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) 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) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) 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 2 with Parser

use of org.eclipse.titan.log.viewer.parsers.Parser in project titan.EclipsePlug-ins by eclipse.

the class MSCView method restoreState.

/**
 * Called in the view life-cycle restore chain Reads back all view data if
 * memento has been set
 *
 * The restore is very restricted an checks that the
 * <li> Project still exists and is open
 * <li> The file is within the project
 * <li> The file size and file date has not changed
 */
private WorkspaceJob restoreState() {
    if (this.memento == null) {
        return null;
    }
    WorkspaceJob job = null;
    this.problemDuringRestore = true;
    // $NON-NLS-1$
    this.memento = this.memento.getChild("mscview");
    if (this.memento != null) {
        try {
            // $NON-NLS-1$
            IMemento viewAttributes = this.memento.getChild("attributes");
            // Restore logfilemetaData
            // $NON-NLS-1$
            String propertyFilePath = viewAttributes.getString("propertyFile");
            if (propertyFilePath != null) {
                File propertyFile = new File(propertyFilePath);
                if (propertyFile.exists()) {
                    this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
                }
            }
            // Get project
            // $NON-NLS-1$
            String projectName = viewAttributes.getString("projectName");
            IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
            if ((this.logFileMetaData != null) && (project != null) && project.exists() && project.isOpen()) {
                Path path = new Path(this.logFileMetaData.getProjectRelativePath());
                IFile logFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
                if ((logFile != null) && logFile.exists() && logFile.getProject().getName().equals(project.getName())) {
                    // $NON-NLS-1$
                    String fileSizeString = viewAttributes.getString("fileSize");
                    long fileSize = 0;
                    if (fileSizeString != null) {
                        fileSize = Long.parseLong(fileSizeString);
                    }
                    // $NON-NLS-1$
                    String fileModificationString = viewAttributes.getString("fileModification");
                    long fileModification = 0;
                    if (fileModificationString != null) {
                        fileModification = Long.parseLong(fileModificationString);
                    }
                    File file = logFile.getLocation().toFile();
                    if ((file.lastModified() == fileModification) && (file.length() == fileSize)) {
                        // Load the Test case from index file
                        // $NON-NLS-1$
                        Integer testCaseNumber = viewAttributes.getInteger("testCaseNumber");
                        File indexFileForLogFile = LogFileCacheHandler.getIndexFileForLogFile(logFile);
                        File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
                        if (!indexFileForLogFile.exists() || !logRecordIndexFile.exists()) {
                            return null;
                        }
                        final Parser parser = new Parser(this.logFileMetaData);
                        final TestCase testCase = TestCaseExtractor.getTestCaseFromIndexFile(indexFileForLogFile, testCaseNumber);
                        final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, testCase.getStartRecordNumber(), testCase.getNumberOfRecords());
                        final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(projectName);
                        // Restore model
                        job = new WorkspaceJob("Loading log information") {

                            @Override
                            public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                                try {
                                    MSCView.this.model = parser.preParse(testCase, logRecordIndexes, preferences, null, monitor);
                                } catch (Exception e) {
                                    ErrorReporter.logExceptionStackTrace(e);
                                }
                                return Status.OK_STATUS;
                            }
                        };
                        job.schedule();
                        // Restore selection
                        // $NON-NLS-1$
                        final Integer temp = viewAttributes.getInteger("rowSelection");
                        if (temp == null) {
                            this.restoredSelection = 0;
                        } else {
                            this.restoredSelection = temp.intValue();
                        }
                        this.problemDuringRestore = false;
                    } else {
                    // TODO: what should we do if something went wrong?
                    }
                }
            }
        } catch (Exception e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    this.memento = null;
    return job;
}
Also used : Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IMemento(org.eclipse.ui.IMemento) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Parser(org.eclipse.titan.log.viewer.parsers.Parser) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 3 with Parser

use of org.eclipse.titan.log.viewer.parsers.Parser 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)

Aggregations

File (java.io.File)3 IFile (org.eclipse.core.resources.IFile)3 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 LogRecordIndex (org.eclipse.titan.log.viewer.models.LogRecordIndex)3 Parser (org.eclipse.titan.log.viewer.parsers.Parser)3 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)3 PreferencesHolder (org.eclipse.titan.log.viewer.preferences.PreferencesHolder)3 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 CoreException (org.eclipse.core.runtime.CoreException)2 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)2 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)2 ExecutionModel (org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel)2 IViewReference (org.eclipse.ui.IViewReference)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 Date (java.util.Date)1 IProject (org.eclipse.core.resources.IProject)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1