Search in sources :

Example 6 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class OpenStatisticalViewMenuAction method processLogFile.

private void processLogFile() {
    try {
        new ProgressMonitorDialog(null).run(false, false, new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                OpenStatisticalViewMenuAction.this.monitor = monitor;
                OpenStatisticalViewMenuAction.this.testCaseExtractor = null;
                try {
                    LogFileHandler logFileHandler = new LogFileHandler(logFile);
                    // First of all, verify that the file is a TITAN supported log file
                    try {
                        OpenStatisticalViewMenuAction.this.logFileMetaData = logFileHandler.autoDetect();
                    } catch (final TechnicalException e) {
                        ErrorReporter.logExceptionStackTrace(e);
                        OpenStatisticalViewMenuAction.this.logFileIsSupported = false;
                        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
                        return;
                    }
                    OpenStatisticalViewMenuAction.this.testCaseExtractor = new TestCaseExtractor();
                    OpenStatisticalViewMenuAction.this.testCaseExtractor.addObserver(OpenStatisticalViewMenuAction.this);
                    if (OpenStatisticalViewMenuAction.this.monitor != null) {
                        OpenStatisticalViewMenuAction.this.monitor.beginTask(Messages.getString("OpenStatisticalViewMenuAction.4") + OpenStatisticalViewMenuAction.this.logFile.getName() + Messages.getString("OpenStatisticalViewMenuAction.3"), 100);
                    }
                    // Extract test cases from log file
                    OpenStatisticalViewMenuAction.this.testCaseExtractor.extractTestCasesFromLogFile(OpenStatisticalViewMenuAction.this.logFileMetaData, monitor);
                    LogFileCacheHandler.fillCache(logFile, logFileMetaData, testCaseExtractor.getTestCases(), testCaseExtractor.getLogRecordIndexes());
                    if (OpenStatisticalViewMenuAction.this.testCaseExtractor.failedDuringExtraction()) {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                MessageDialog.openInformation(null, Messages.getString("OpenStatisticalViewMenuAction.2"), Messages.getString("OpenStatisticalViewMenuAction.1"));
                            }
                        });
                    }
                } catch (IOException e) {
                    ErrorReporter.logExceptionStackTrace(e);
                    TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
                } finally {
                    if (OpenStatisticalViewMenuAction.this.testCaseExtractor != null) {
                        OpenStatisticalViewMenuAction.this.testCaseExtractor.deleteObserver(OpenStatisticalViewMenuAction.this);
                    }
                    if (OpenStatisticalViewMenuAction.this.monitor != null) {
                        OpenStatisticalViewMenuAction.this.monitor.done();
                    }
                }
            }
        });
    } catch (InvocationTargetException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getTargetException()));
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) LogFileHandler(org.eclipse.titan.log.viewer.utils.LogFileHandler) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 7 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class OpenValueViewMenuAction method run.

@Override
public void run() {
    if (this.eventSelection == null) {
        return;
    }
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    LogFileMetaData logFileMetaData;
    if (this.view instanceof MSCView) {
        logFileMetaData = ((MSCView) this.view).getLogFileMetaData();
    } else if (this.view instanceof TextTableView) {
        logFileMetaData = ((TextTableView) this.view).getLogFileMetaData();
    } else {
        return;
    }
    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);
        if (this.view instanceof TextTableView) {
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new UserException("The log file could not be found.\n Please perform the Open Text Table action again."));
        } else {
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenValueViewMenuAction.1")));
        }
        return;
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    }
    DetailsView detailsview = (DetailsView) activePage.findView(Constants.DETAILS_VIEW_ID);
    if (detailsview == null && !forceEditorOpening) {
        return;
    }
    if (forceEditorOpening) {
        try {
            detailsview = (DetailsView) activePage.showView(Constants.DETAILS_VIEW_ID);
        } catch (PartInitException e) {
            ErrorReporter.logExceptionStackTrace(e);
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("MSCView.1") + e.getMessage()));
            return;
        }
    }
    // pass log file meta data
    detailsview.setLogFileMetaData(logFileMetaData);
    EventObject eventObject = this.eventSelection.getEventObject();
    String testCase = this.eventSelection.getTestCaseName();
    if ((eventObject == null) || (testCase == null)) {
        return;
    }
    // get value
    LogRecord logrecord;
    try {
        logrecord = ValueReader.getInstance().readLogRecordFromLogFile(logFileMetaData.getFilePath(), eventObject);
    } catch (final IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("MSCView.8")));
        return;
    } catch (final ParseException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("MSCView.8")));
        return;
    }
    String message = logrecord.getMessage();
    DetailData detailData = new DetailData(eventObject.getName(), eventObject.getPort(), message, testCase, eventObject.getEventType(), logrecord.getSourceInformation());
    detailsview.setData(detailData, false);
    detailsview.setFocus();
}
Also used : IFile(org.eclipse.core.resources.IFile) DetailsView(org.eclipse.titan.log.viewer.views.DetailsView) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) EventObject(org.eclipse.titan.log.viewer.views.msc.model.EventObject) 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) MSCView(org.eclipse.titan.log.viewer.views.MSCView) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) PartInitException(org.eclipse.ui.PartInitException) ParseException(java.text.ParseException) TextTableView(org.eclipse.titan.log.viewer.views.text.table.TextTableView) DetailData(org.eclipse.titan.log.viewer.views.details.DetailData)

Example 8 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class ComponentsVisualOrderPrefPage method importPreferences.

@Override
protected void importPreferences() {
    Map<String, String> prop = ImportExportUtils.importSettings(PreferenceConstants.PAGE_ID_COMP_VIS_ORDER_PAGE);
    // if cancel
    if (prop == null) {
        return;
    }
    String propertyValues = prop.get(PreferenceConstants.PREF_COMPONENT_ORDER_ID);
    if (propertyValues == null) {
        return;
    }
    boolean sutFound = false;
    boolean mtcFound = false;
    String[] propertyValuesSeparated = propertyValues.split(File.pathSeparator);
    for (int i = 0; (i < propertyValuesSeparated.length) && !(sutFound && mtcFound); i++) {
        String currValue = propertyValuesSeparated[i];
        if (currValue.contentEquals(PreferenceConstants.SUT_DESCRIPTION)) {
            sutFound = true;
        } else if (currValue.contentEquals(PreferenceConstants.MTC_DESCRIPTION)) {
            mtcFound = true;
        }
    }
    // sut is missing (mandatory)
    if (!sutFound) {
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new UserException(Messages.getString("ComponentsVisualOrderPrefPage.0")));
    } else if (!mtcFound) {
        // mtc is missing (mandatory)
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new UserException(Messages.getString("ComponentsVisualOrderPrefPage.1")));
    } else {
        setOldPreferences(getCurrentPreferences());
        setProperties(prop);
        // Settings changed -> Enable apply button
        getApplyButton().setEnabled(true);
    }
}
Also used : UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Example 9 with UserException

use of org.eclipse.titan.log.viewer.exceptions.UserException in project titan.EclipsePlug-ins by eclipse.

the class ExtractTestCasesAction method run.

@Override
public void run(final IProgressMonitor pMonitor) throws InvocationTargetException, InterruptedException {
    this.monitor = pMonitor == null ? new NullProgressMonitor() : pMonitor;
    // First of all, verify that the file is a TITAN supported log file
    try {
        this.logFileMetaData = this.logFileHandler.autoDetect();
    } catch (TechnicalException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
        return;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            monitor.done();
            return;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
    }
    try {
        // $NON-NLS-1$
        this.monitor.beginTask(Messages.getString("ExtractTestCasesAction.0"), 100);
        // Check if a property file exists for the log file (if log file has changed or not)
        boolean logFileHasChanged = LogFileCacheHandler.hasLogFileChanged(this.logFile);
        // Get the property file
        File propertyFile = LogFileCacheHandler.getPropertyFileForLogFile(this.logFile);
        if (logFileHasChanged) {
            if (updateLogFileIndex()) {
                return;
            }
        } else {
            if (Constants.DEBUG) {
                // $NON-NLS-1$
                TITANDebugConsole.getConsole().newMessageStream().println("Log file has NOT changed -> extracting from index file!");
            }
            // Get log file meta data
            this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
            // Extract test cases from the index file
            this.testCaseExtractor.extractTestCasesFromIndexedLogFile(this.logFile);
        }
    } catch (final IOException e) {
        handleExtractingError(e);
    } catch (final ClassNotFoundException e) {
        handleExtractingError(e);
    } catch (final CoreException e) {
        handleExtractingError(e);
    }
    setExtractionRunningProperty(false);
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IViewPart view = activePage.findView(PROJECT_EXPLORER_VIEW_ID);
            if (view instanceof CommonNavigator) {
                CommonViewer viewer = ((CommonNavigator) view).getCommonViewer();
                viewer.refresh(logFile, true);
                viewer.expandToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
            }
        }
    });
    this.testCaseEventDispatcher.deleteObserver(this);
    this.testCaseExtractor.deleteObserver(this.testCaseEventDispatcher);
    this.monitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) CommonViewer(org.eclipse.ui.navigator.CommonViewer) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 10 with UserException

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

UserException (org.eclipse.titan.log.viewer.exceptions.UserException)14 IFile (org.eclipse.core.resources.IFile)10 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 IOException (java.io.IOException)9 IViewReference (org.eclipse.ui.IViewReference)7 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)6 IProject (org.eclipse.core.resources.IProject)5 CoreException (org.eclipse.core.runtime.CoreException)5 File (java.io.File)4 ParseException (java.text.ParseException)4 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 TestCaseExtractor (org.eclipse.titan.log.viewer.extractors.TestCaseExtractor)4 LogRecord (org.eclipse.titan.log.viewer.parsers.data.LogRecord)4 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)4 EventObject (org.eclipse.titan.log.viewer.views.msc.model.EventObject)4 ExecutionModel (org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel)4 IViewPart (org.eclipse.ui.IViewPart)3