Search in sources :

Example 6 with LogRecordIndex

use of org.eclipse.titan.log.viewer.models.LogRecordIndex 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 7 with LogRecordIndex

use of org.eclipse.titan.log.viewer.models.LogRecordIndex in project titan.EclipsePlug-ins by eclipse.

the class TestCaseExtractor method addLogRecordIndex.

private void addLogRecordIndex(final long filePointer, final int offsetStart, final int offsetEnd, final int recordNumber) {
    int recordLength = offsetEnd - offsetStart + 1;
    this.endRecordNumber = recordNumber;
    // Check if current line contains a valid time-stamp, if not the record continues...
    if (hasValidTimeStamp(offsetStart, recordLength)) {
        if (Constants.DEBUG) {
            if (!Character.isDigit(this.buffer[offsetStart])) {
                // $NON-NLS-1$
                TITANDebugConsole.getConsole().newMessageStream().println("--Faulty " + this.buffer[offsetStart]);
            }
            if (this.buffer[offsetEnd] != '\n') {
                // $NON-NLS-1$
                TITANDebugConsole.getConsole().newMessageStream().println("><<Faulty " + this.buffer[offsetEnd]);
            }
        }
        // Time-stamp found, create new log record index
        LogRecordIndex currentLogRecordIndex = new LogRecordIndex(filePointer, recordLength, recordNumber);
        this.logRecordIndexVector.add(currentLogRecordIndex);
        // keep the last found record
        this.lastRecordIndex = currentLogRecordIndex;
    } else {
        if (this.lastRecordIndex != null) {
            this.lastRecordIndex.addRecordLen(recordLength);
            this.recordNumber--;
        }
    }
}
Also used : LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex)

Example 8 with LogRecordIndex

use of org.eclipse.titan.log.viewer.models.LogRecordIndex in project titan.EclipsePlug-ins by eclipse.

the class LogSearchQuery method run.

@Override
public IStatus run(final IProgressMonitor monitor) {
    result.removeAll();
    int numOfRecords = 0;
    for (IFile logFile : files) {
        File indexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
        numOfRecords += LogFileCacheHandler.getNumberOfLogRecordIndexes(indexFile);
    }
    monitor.beginTask("Searching", numOfRecords);
    for (IFile logFile : files) {
        if (monitor.isCanceled()) {
            break;
        }
        if (LogFileCacheHandler.hasLogFileChanged(logFile) && !LogFileCacheHandler.processLogFile(logFile, new NullProgressMonitor(), true)) {
            continue;
        }
        File indexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
        try {
            LogRecordIndex[] indexes = LogFileCacheHandler.readLogRecordIndexFile(indexFile, 0, LogFileCacheHandler.getNumberOfLogRecordIndexes(indexFile));
            SequentialLogFileReader reader = new SequentialLogFileReader(logFile.getLocationURI(), indexes);
            monitor.subTask("Filtering");
            filterRecords(monitor, logFile, reader);
            monitor.done();
        } catch (ParseException e) {
            ErrorReporter.logExceptionStackTrace(e);
            TitanLogExceptionHandler.handleException(new TechnicalException(logFile.getName() + ": Could not parse the log file. Reason: " + e.getMessage()));
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
            TitanLogExceptionHandler.handleException(new TechnicalException(logFile.getName() + ": Error while searching. Reason: " + e.getMessage()));
        }
    }
    monitor.done();
    return new Status(IStatus.OK, Constants.PLUGIN_ID, IStatus.OK, "Search done.", null);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) SequentialLogFileReader(org.eclipse.titan.log.viewer.readers.SequentialLogFileReader) LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex) ParseException(java.text.ParseException) IOException(java.io.IOException) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Example 9 with LogRecordIndex

use of org.eclipse.titan.log.viewer.models.LogRecordIndex in project titan.EclipsePlug-ins by eclipse.

the class SearchLabelProvider method getText.

@Override
public String getText(final Object element) {
    if (element instanceof IResource) {
        return WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider().getText(element);
    }
    if (element instanceof Match) {
        Match match = (Match) element;
        IFile logFile = (IFile) match.getElement();
        RandomAccessFile file = null;
        String result = "";
        try {
            // TODO: This should be cached in some way
            File indexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
            LogRecordIndex[] indexes = LogFileCacheHandler.readLogRecordIndexFile(indexFile, match.getOffset(), 1);
            file = new RandomAccessFile(new File(logFile.getLocationURI()), "r");
            int length = indexes[0].getRecordLength() > MAX_TEXT_LENGTH ? MAX_TEXT_LENGTH : indexes[0].getRecordLength();
            byte[] record = new byte[length];
            file.seek(indexes[0].getFileOffset());
            file.read(record);
            result = new String(record);
        } catch (FileNotFoundException e) {
            ErrorReporter.logExceptionStackTrace(e);
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new TechnicalException(logFile.getName() + ": File not found " + e.getMessage()));
            return logFile.getName() + ": File not found";
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new TechnicalException("Error while reading the log file." + e.getMessage()));
            return "Error while reading the log file.";
        } finally {
            IOUtils.closeQuietly(file);
        }
        return result;
    }
    return "Unexpected element";
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) LogRecordIndex(org.eclipse.titan.log.viewer.models.LogRecordIndex) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Match(org.eclipse.search.ui.text.Match) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource)

Aggregations

LogRecordIndex (org.eclipse.titan.log.viewer.models.LogRecordIndex)9 File (java.io.File)6 IFile (org.eclipse.core.resources.IFile)6 IOException (java.io.IOException)4 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)4 ParseException (java.text.ParseException)3 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)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 RandomAccessFile (java.io.RandomAccessFile)2 ByteBuffer (java.nio.ByteBuffer)2 FileChannel (java.nio.channels.FileChannel)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)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