Search in sources :

Example 21 with TechnicalException

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

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

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

the class OpenStatisticalViewMenuAction method run.

public void run(final IStructuredSelection selection) {
    this.logFileMetaData = null;
    this.logFileIsSupported = true;
    if (this.selection == null) {
        return;
    }
    Set<IFile> logFiles = new HashSet<IFile>(selection.size());
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
        Object object = iterator.next();
        if (object instanceof IFile) {
            logFiles.add((IFile) object);
        } else if (object instanceof TestCase) {
            logFiles.add(((TestCase) object).getLogFile());
        }
    }
    if (logFiles.isEmpty()) {
        return;
    }
    List<StatisticalData> statisticalDataVector = createStatisticalData(logFiles);
    if (statisticalDataVector == null || statisticalDataVector.isEmpty()) {
        return;
    }
    String secondId = Constants.STATISTICAL_VIEW;
    if (statisticalDataVector.size() < 2) {
        secondId = File.separator + this.logFile.getProject().getName() + File.separator + this.logFile.getProjectRelativePath().toOSString();
    }
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewReference reference = activePage.findViewReference(Constants.STATISTICAL_VIEW_ID, secondId);
    // get the view
    if (reference != null) {
        StatisticalView part = (StatisticalView) reference.getView(false);
    }
    // create a new view
    try {
        StatisticalView part = (StatisticalView) activePage.showView(Constants.STATISTICAL_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
        part.setData(statisticalDataVector);
        part.setFocus();
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StatisticalView(org.eclipse.titan.log.viewer.views.StatisticalView) PartInitException(org.eclipse.ui.PartInitException) HashSet(java.util.HashSet)

Example 24 with TechnicalException

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

Example 25 with TechnicalException

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

the class TestCaseExtractor method getTestCaseFromIndexFile.

/**
 * Fetches a given test case with a passed id from a previously created index file
 *
 * @param indexFile the index file to extract test cases from, can NOT be null
 * @param testCaseNumber number of the test case to fetch
 * @throws IOException if file IO or parse errors occur
 * @throws ClassNotFoundException if test cases can not be read from the index file
 */
public static TestCase getTestCaseFromIndexFile(final File indexFile, final int testCaseNumber) throws IOException, TechnicalException, ClassNotFoundException {
    ObjectInputStream indexFileInputStream = null;
    try {
        indexFileInputStream = new ObjectInputStream(new FileInputStream(indexFile));
        Object o = indexFileInputStream.readObject();
        if (o instanceof List) {
            List<?> testCases = (List<?>) o;
            // the vector is zero based but the testCase number starts numbering on 1
            // so there must be an alignment
            int testCasePosition = testCaseNumber - 1;
            if (testCases.size() < testCasePosition) {
                // $NON-NLS-1$
                throw new TechnicalException(Messages.getString("TestCaseExtractor.4"));
            }
            return (TestCase) testCases.get(testCasePosition);
        }
    } finally {
        IOUtils.closeQuietly(indexFileInputStream);
    }
    return null;
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) ArrayList(java.util.ArrayList) List(java.util.List) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)33 IOException (java.io.IOException)18 IFile (org.eclipse.core.resources.IFile)16 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 File (java.io.File)9 IViewReference (org.eclipse.ui.IViewReference)8 CoreException (org.eclipse.core.runtime.CoreException)7 PartInitException (org.eclipse.ui.PartInitException)7 ParseException (java.text.ParseException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IProject (org.eclipse.core.resources.IProject)5 PreferencesHolder (org.eclipse.titan.log.viewer.preferences.PreferencesHolder)5 FileNotFoundException (java.io.FileNotFoundException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)4 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Map (java.util.Map)3