Search in sources :

Example 6 with PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.

the class Parser method parseRegion.

/**
 * Parses a given region from the log file and returns the contents as a list of events.
 * The SUT, MTC and System components are always added.
 *
 * @param startIndex the index of the event to be displayed.
 * @param endIndex the index of the last event to be displayed.
 * @param monitor the monitor to be used to report progress on.
 *
 * @return the events parsed from the given region.
 */
public List<EventObject> parseRegion(final int startIndex, final int endIndex, final IProgressMonitor monitor) throws IOException, ParseException {
    IProgressMonitor internalMonitor = monitor == null ? new NullProgressMonitor() : monitor;
    TestFileReader reader = null;
    wasCanceled = false;
    List<EventObject> result = new ArrayList<EventObject>(endIndex - startIndex + 6 + 1);
    final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
    // needed for memento of MSC view
    final TestCase testCase = this.executionModel.getTestCase();
    // The SUT element object always exists at all times, to make sure
    // it becomes visible before any test starts.
    EventObject sut = createEventObject(null, EventType.SYSTEM_CREATE);
    sut.setName(preferences.getSutName());
    result.add(sut);
    EventObject hc = createEventObject(null, EventType.HC_CREATE);
    result.add(hc);
    EventObject mtc = createEventObject(null, EventType.MTC_CREATE);
    result.add(mtc);
    if (Constants.DEBUG) {
        // $NON-NLS-1$
        TITANDebugConsole.getConsole().newMessageStream().println("Message type = " + this.messageAnalyser.getType());
    }
    this.tcRecords = logRecordIndexes.length;
    try {
        reader = new TestFileReader(this.logFileMetaData.getFilePath(), logRecordIndexes);
        internalMonitor.beginTask("Loading...", reader.size());
        for (int i = startIndex; i <= endIndex && i < eventVector.size() && !internalMonitor.isCanceled(); i++) {
            try {
                int actualIndex = eventVector.get(i) - testCase.getStartRecordNumber();
                reader.setCurrentLogRecord(actualIndex);
                LogRecord logRecord = reader.getNextRecord();
                // Add test case record number offset to record
                logRecord.setRecordNumber(testCase.getStartRecordNumber() + logRecord.getRecordNumber());
                EventObject event = parseLogRecord(logRecord, i);
                if (event != null) {
                    result.add(event);
                }
                internalMonitor.worked(1);
            } catch (ParseException e) {
                ErrorReporter.logExceptionStackTrace(e);
                ParseException throwable = new ParseException(e.getMessage(), 0);
                throwable.initCause(e);
                throw throwable;
            }
        }
    } finally {
        IOUtils.closeQuietly(reader);
    }
    wasCanceled = internalMonitor.isCanceled();
    internalMonitor.done();
    for (String compRef : currentlyLivingComponents) {
        EventObject event = new EventObject(EventType.PTC_TERMINATE);
        event.setReference(compRef);
        event.setName(compRef);
        result.add(event);
    }
    // if no mtc termination is made, do it here
    if (!mtcTerminated) {
        mtc = eventObjectFactory.createEventObject(EventType.MTC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
        result.add(mtc);
    }
    hc = eventObjectFactory.createEventObject(EventType.HC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
    result.add(hc);
    // The last thing that "dies" in a log is the SUT, that still exists
    // after the test case is over. Still add a marker for this in the
    // log.
    sut = eventObjectFactory.createEventObject(EventType.SYSTEM_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
    result.add(sut);
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) ArrayList(java.util.ArrayList) TestFileReader(org.eclipse.titan.log.viewer.readers.TestFileReader) ParseException(java.text.ParseException) EventObject(org.eclipse.titan.log.viewer.views.msc.model.EventObject)

Example 7 with PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.

the class ExtractComponentsMenuAction method run.

public void run(final ISelection selection) {
    List<String> components = null;
    if (selection == null) {
        return;
    }
    if (!SelectionUtils.isSelectionALogFile(selection)) {
        return;
    }
    IFile logFile = SelectionUtils.selectionToIFile(selection);
    if (logFile == null) {
        return;
    }
    try {
        ExtractComponentsAction extractCompAction = new ExtractComponentsAction(logFile);
        new ProgressMonitorDialog(null).run(false, false, extractCompAction);
        components = extractCompAction.getComponents();
    } catch (InvocationTargetException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
        Messages.getString("ExtractComponentsMenuAction.0") + e.getTargetException().getMessage()));
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // Should not happen, cancel button is de-activated
        TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
        Messages.getString("ExtractComponentsMenuAction.1") + e.getMessage()));
    }
    String projectName = logFile.getProject().getName();
    PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(projectName);
    setNewProperties(components, logFile, preferences);
}
Also used : PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder 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 PreferencesHolder

use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.

the class ConsoleWriter method writeToConsole.

/**
 * Writes to the console
 * @param msg, message to be written to the console
 */
public void writeToConsole(final String msg, final String projectName) {
    // Check with preference store
    PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(projectName);
    if (preferences.getVerbosePrintoutsEnabled()) {
        try {
            this.out.println(msg);
            this.out.flush();
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
            TitanLogExceptionHandler.handleException(// $NON-NLS-1$
            new TechnicalException(Messages.getString("ConsoleWriter.0") + e.getMessage()));
        }
    }
}
Also used : PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IOException(java.io.IOException)

Aggregations

PreferencesHolder (org.eclipse.titan.log.viewer.preferences.PreferencesHolder)9 IFile (org.eclipse.core.resources.IFile)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)5 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)4 IViewReference (org.eclipse.ui.IViewReference)4 File (java.io.File)3 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 LogRecordIndex (org.eclipse.titan.log.viewer.models.LogRecordIndex)3 Parser (org.eclipse.titan.log.viewer.parsers.Parser)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 CoreException (org.eclipse.core.runtime.CoreException)2 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)2 PartInitException (org.eclipse.ui.PartInitException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1