Search in sources :

Example 11 with UserException

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

the class OpenStatisticalViewMenuAction method createStatisticalData.

private List<StatisticalData> createStatisticalData(Set<IFile> logFiles) {
    List<StatisticalData> statisticalDataVector = new ArrayList<StatisticalData>();
    for (IFile file : logFiles) {
        this.logFile = file;
        if (!this.logFile.exists()) {
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenStatisticalViewMenuAction.5")));
            return null;
        }
        File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(this.logFile);
        File propertyFile = LogFileCacheHandler.getPropertyFileForLogFile(this.logFile);
        if (!logRecordIndexFile.exists() || !propertyFile.exists() || LogFileCacheHandler.hasLogFileChanged(this.logFile)) {
            processLogFile();
        } else {
            // Get log file meta data
            try {
                this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
                // Extract test cases from the index file
                this.testCaseExtractor = new TestCaseExtractor();
                this.testCaseExtractor.extractTestCasesFromIndexedLogFile(this.logFile);
            } catch (IOException e) {
                ErrorReporter.logExceptionStackTrace(e);
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            } catch (ClassNotFoundException e) {
                ErrorReporter.logExceptionStackTrace(e);
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            }
        }
        if (this.logFileIsSupported) {
            try {
                if (this.logFileMetaData == null) {
                    this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
                }
                List<TestCase> testCases = this.testCaseExtractor.getTestCases();
                // //Create data for the statistical view
                final CachedLogReader reader = new CachedLogReader(LogFileReader.getReaderForLogFile(this.logFile));
                StatisticalData statisticalData = new StatisticalData(this.logFileMetaData, testCases, reader);
                statisticalDataVector.add(statisticalData);
            } catch (IOException e) {
                ErrorReporter.logExceptionStackTrace(e);
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            } catch (ClassNotFoundException e) {
                ErrorReporter.logExceptionStackTrace(e);
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            }
        }
    }
    return statisticalDataVector;
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) ArrayList(java.util.ArrayList) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) CachedLogReader(org.eclipse.titan.log.viewer.readers.CachedLogReader) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 12 with UserException

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

the class LogFileCacheHandler method processLogFile.

/**
 * Processes the given LogFile if it has changed. The property file, index file, and log record index file will be created.
 * Does nothing if the log file has not changed, or test case extraction is already running on the file.
 * @param logFile The log file
 * @param pMonitor Progress monitor.
 * @param quietMode If false, the error messages will be displayed to the user.
 * @return true if the processing was successful, false otherwise
 */
public static boolean processLogFile(final IFile logFile, final IProgressMonitor pMonitor, final boolean quietMode) {
    IProgressMonitor monitor = pMonitor == null ? new NullProgressMonitor() : pMonitor;
    if (!logFile.exists()) {
        if (!quietMode) {
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new UserException("The log file does not exist: " + logFile.getName()));
        }
        return false;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            if (!quietMode) {
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException("Test case extraction is running on the given logfile: " + logFile.getName()));
            }
            return false;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
        return false;
    }
    if (!LogFileCacheHandler.hasLogFileChanged(logFile)) {
        return true;
    }
    try {
        logFile.setSessionProperty(Constants.EXTRACTION_RUNNING, true);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return false;
    }
    final LogFileHandler logFileHandler = new LogFileHandler(logFile);
    try {
        LogFileMetaData logFileMetaData = logFileHandler.autoDetect();
        final TestCaseExtractor testCaseExtractor = new TestCaseExtractor();
        testCaseExtractor.extractTestCasesFromLogFile(logFileMetaData, monitor);
        if (monitor.isCanceled()) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                    if (view instanceof CommonNavigator) {
                        CommonNavigator navigator = (CommonNavigator) view;
                        navigator.getCommonViewer().update(logFile, null);
                        navigator.getCommonViewer().collapseToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
                    }
                }
            });
            return false;
        }
        fillCache(logFile, logFileMetaData, testCaseExtractor.getTestCases(), testCaseExtractor.getLogRecordIndexes());
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                if (view instanceof CommonNavigator) {
                    CommonNavigator navigator = (CommonNavigator) view;
                    navigator.getCommonViewer().refresh(logFile, true);
                    navigator.getCommonViewer().expandToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
                }
            }
        });
        if (testCaseExtractor.failedDuringExtraction()) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openInformation(null, Messages.getString("OpenTextTableProjectsViewMenuAction.8"), Messages.getString("OpenTextTableProjectsViewMenuAction.9"));
                }
            });
            return false;
        }
    } catch (IOException e) {
        if (!quietMode) {
            ErrorReporter.logExceptionStackTrace(e);
            TitanLogExceptionHandler.handleException(// $NON-NLS-1$
            new TechnicalException(Messages.getString("OpenTextTableProjectsViewMenuAction.2") + e.getMessage()));
        }
        return false;
    } catch (TechnicalException e) {
        // invalid file format
        if (!quietMode) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Invalid log file", e.getMessage());
        }
        return false;
    } finally {
        try {
            logFile.setSessionProperty(Constants.EXTRACTION_RUNNING, false);
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    return true;
}
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) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Example 13 with UserException

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

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

the class TitanListEditor method addPressed.

/**
 * Notifies that the Add button has been pressed.
 */
private void addPressed() {
    setPresentsDefaultValue(false);
    String input = getNewInputObject();
    if (input != null) {
        // make sure that leading and trailing white space is removed
        input = input.trim();
        // check if already added to the list
        if (this.list.indexOf(input) != -1) {
            TitanLogExceptionHandler.handleException(new UserException(input + "  " + Messages.getString("TitanListEditor.2")));
            return;
        }
        int index = this.list.getSelectionIndex();
        if (index >= 0) {
            this.list.add(input, index + 1);
        } else {
            this.list.add(input, 0);
        }
        selectionChanged();
    }
}
Also used : UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

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