Search in sources :

Example 16 with LogRecord

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

the class OpenSourceAction method run.

@Override
public void run() {
    if (selectedLineInvalid()) {
        return;
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IWorkbenchPage activePage = window.getActivePage();
    if (activePage == null) {
        return;
    }
    LogFileMetaData logFileMetaData = this.mscView.getLogFileMetaData();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IProject project = root.getProject(logFileMetaData.getProjectName());
    IFile logFile = project.getFile(logFileMetaData.getProjectRelativePath().substring(logFileMetaData.getProjectName().length() + 1));
    if (!logFile.exists()) {
        IViewReference[] viewReferences = activePage.getViewReferences();
        ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenValueViewAction.1")));
        return;
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    }
    ExecutionModel model = this.mscView.getModel();
    String testCase = model.getTestCase().getTestCaseName();
    EventObject eventObject;
    int actualLine = selectedLine;
    SourceInformation sourceInformation = null;
    while (sourceInformation == null && actualLine > 2) {
        IEventObject ieventObject = model.getEvent(actualLine - 2);
        if (!(ieventObject instanceof EventObject)) {
            actualLine--;
            continue;
        }
        eventObject = (EventObject) ieventObject;
        if ((testCase == null) || eventObject.getRecordNumber() == 0) {
            return;
        }
        // get value
        LogRecord logrecord;
        try {
            logrecord = ValueReader.getInstance().readLogRecordFromLogFileCached(this.mscView.getLogFileMetaData().getFilePath(), eventObject);
        } catch (final IOException valueException) {
            ErrorReporter.logExceptionStackTrace(valueException);
            // $NON-NLS-1$
            ErrorReporter.INTERNAL_ERROR(Messages.getString("OpenValueViewAction.3"));
            return;
        } catch (final ParseException valueException) {
            ErrorReporter.logExceptionStackTrace(valueException);
            // $NON-NLS-1$
            ErrorReporter.INTERNAL_ERROR(Messages.getString("OpenValueViewAction.3"));
            return;
        }
        try {
            sourceInformation = SourceInformation.createInstance(logrecord.getSourceInformation());
        } catch (InvalidSourceInformationException e) {
        // Do nothing
        // try to find the closest source information
        }
        actualLine--;
    }
    if (sourceInformation == null) {
        if (!silent) {
            String setting = logFileMetaData.getOptionsSettings("SourceInfoFormat");
            if (setting == null) {
                ErrorReporter.parallelErrorDisplayInMessageDialog("Error opening source", "This log file is not generated with source location information inserted. And it really does not seem to contain source location information");
            } else {
                ErrorReporter.parallelErrorDisplayInMessageDialog("Error opening source", "This log record does not seem to contain source location information");
            }
        }
        return;
    }
    if (sourceInformation.getSourceFileName() == null) {
        mscView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The name of the target file could not be extracted");
        return;
    }
    final String fileName = sourceInformation.getSourceFileName();
    IFile targetFile;
    if (lastFilename != null && lastFilename.equals(fileName) && lastPath != null) {
        IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(lastPath);
        if (files.length == 0) {
            mscView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The file `" + lastFilename + "' could not be found");
            setLastFilename(null);
            return;
        }
        targetFile = files[0];
    } else {
        targetFile = findSourceFile(project, fileName);
        if (targetFile == null) {
            mscView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The file `" + fileName + "' could not be found");
            return;
        }
        setLastFilename(fileName);
        setLastPath(targetFile.getLocationURI());
    }
    openEditor(targetFile, sourceInformation.getLineNumber(), mscView, forceEditorOpening);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) InvalidSourceInformationException(org.eclipse.titan.log.viewer.models.SourceInformation.InvalidSourceInformationException) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) EventObject(org.eclipse.titan.log.viewer.views.msc.model.EventObject) IEventObject(org.eclipse.titan.log.viewer.views.msc.model.IEventObject) SourceInformation(org.eclipse.titan.log.viewer.models.SourceInformation) IEventObject(org.eclipse.titan.log.viewer.views.msc.model.IEventObject) ExecutionModel(org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) IWorkspace(org.eclipse.core.resources.IWorkspace) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) ParseException(java.text.ParseException)

Example 17 with LogRecord

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

the class LogFileReader method getRecord.

@Override
public LogRecord getRecord(final int position) throws IOException, ParseException {
    LogRecord aRecord;
    try {
        aRecord = recordParser.parse(readRecord(position));
        aRecord.setRecordOffset(logRecordIndexes[position].getFileOffset());
        aRecord.setRecordLength(logRecordIndexes[position].getRecordLength());
        aRecord.setRecordNumber(logRecordIndexes[position].getRecordNumber());
    } catch (ParseException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        ParseException throwable = new ParseException(Messages.getString("TestFileReader.1"), 0);
        throwable.initCause(e);
        throw throwable;
    }
    return aRecord;
}
Also used : LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) ParseException(java.text.ParseException)

Example 18 with LogRecord

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

the class TestFileReader method getNextRecord.

/**
 * Reads a record
 *
 * REQUIRES that hasNextRecord() is true
 *
 * @return a record or null
 * @throws IOException
 * @throws ParseException
 */
public LogRecord getNextRecord() throws IOException, ParseException {
    String logData = readNextRecord();
    LogRecord aRecord;
    try {
        RecordParser recordParser = new RecordParser();
        aRecord = recordParser.parse(logData);
        aRecord.setRecordOffset(this.logRecordIndexes[this.currentRecord].getFileOffset());
        aRecord.setRecordLength(this.logRecordIndexes[this.currentRecord].getRecordLength());
        aRecord.setRecordNumber(this.currentRecord);
        this.currentRecord++;
    } catch (ParseException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        ParseException throwable = new ParseException("Could not parse the " + currentRecord + "th record ", 0);
        throwable.initCause(e);
        throw throwable;
    }
    return aRecord;
}
Also used : LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) RecordParser(org.eclipse.titan.log.viewer.parsers.RecordParser) ParseException(java.text.ParseException)

Example 19 with LogRecord

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

the class ValueReader method readLogRecordFromLogFile.

public LogRecord readLogRecordFromLogFile(final URI logFilePath, final EventObject event) throws IOException, ParseException {
    long offset = event.getRecordOffset();
    int length = event.getRecordLength();
    LogRecord logrecord = getLogRecord(logFilePath, offset, length);
    String message = logrecord.getMessage();
    EventType type = event.getType();
    switch(type) {
        case SEND:
            message = readSendEvent(message);
            break;
        case RECEIVE:
            message = readReceiveEvent(message);
            break;
        case SILENT_EVENT:
            message = getValue(logFilePath, offset, length);
            break;
        case ENQUEUED:
            message = readEnqueuedEvent(message);
            break;
        case SETVERDICT:
            ConnectedRecord[] connectedRecords = event.getConnectedRecords();
            if (connectedRecords != null) {
                StringBuilder messageBuilder = new StringBuilder("{ message := " + message.trim());
                if (connectedRecords.length > 0) {
                    messageBuilder.append(", causedBy := { ");
                }
                for (int i = 0; i < connectedRecords.length; i++) {
                    int eventNumber = i + 1;
                    ConnectedRecord connectedEvent = connectedRecords[i];
                    logrecord = getLogRecord(logFilePath, connectedEvent.getRecordOffset(), connectedEvent.getRecordLength());
                    messageBuilder.append("event" + eventNumber + " := { timestamp := " + logrecord.getTimestamp() + ", componentRef := " + logrecord.getComponentReference() + ", eventType := " + logrecord.getEventType() + ", sourceInfo := " + logrecord.getSourceInformation() + ", message := {" + logrecord.getMessage().trim() + "} }");
                }
                if (connectedRecords.length > 0) {
                    messageBuilder.append(" }");
                }
                message = messageBuilder.toString();
            }
            // $NON-NLS-1$
            message = message + "}\n";
            break;
        case PTC_CREATE:
        default:
            break;
    }
    logrecord.setMessage(message);
    return logrecord;
}
Also used : LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) EventType(org.eclipse.titan.log.viewer.views.msc.model.EventType) ConnectedRecord(org.eclipse.titan.log.viewer.parsers.ConnectedRecord)

Example 20 with LogRecord

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

the class ValueReader method readLogRecordFromLogFileCached.

public LogRecord readLogRecordFromLogFileCached(final URI logFilePath, final EventObject event) throws IOException, ParseException {
    if (cache.containsKey(event.getRecordOffset())) {
        return cache.get(event.getRecordOffset());
    }
    LogRecord temp = readLogRecordFromLogFile(logFilePath, event);
    cache.put(event.getRecordOffset(), temp);
    return temp;
}
Also used : LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord)

Aggregations

LogRecord (org.eclipse.titan.log.viewer.parsers.data.LogRecord)21 ParseException (java.text.ParseException)9 EventObject (org.eclipse.titan.log.viewer.views.msc.model.EventObject)9 IFile (org.eclipse.core.resources.IFile)6 TableItem (org.eclipse.swt.widgets.TableItem)5 IOException (java.io.IOException)4 IProject (org.eclipse.core.resources.IProject)4 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)4 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)4 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)4 IViewReference (org.eclipse.ui.IViewReference)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 File (java.io.File)3 IWorkspace (org.eclipse.core.resources.IWorkspace)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 RecordParser (org.eclipse.titan.log.viewer.parsers.RecordParser)3 ExecutionModel (org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel)3 RandomAccessFile (java.io.RandomAccessFile)2 ArrayList (java.util.ArrayList)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2