Search in sources :

Example 16 with TechnicalException

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

the class DecipheringPreferenceHandler method exportToFile.

/**
 * Exports the currently stored rulesets to the given file.
 *
 * @param file The output file
 */
public static void exportToFile(final File file) {
    try {
        Document document = createDocument();
        Element root = document.getDocumentElement();
        root.setAttribute(VERSION_ATTRIBUTE_KEY, DECIPHERING_XML_VERSION);
        final List<String> ruleSets = PreferenceUtils.deserializeFromString(getPreferenceStore().getString(RULESETS_PREFIX));
        for (String ruleSet : ruleSets) {
            final Element ruleSetElem = createXMLElementFromRuleSet(document, ruleSet);
            root.appendChild(ruleSetElem);
        }
        writeToFile(file, document);
    } catch (FileNotFoundException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(e));
    } catch (ParserConfigurationException e) {
        ErrorReporter.logExceptionStackTrace("While exporting into `" + file.getName() + "'", e);
    } catch (TransformerConfigurationException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("LogViewerPreferenceRootPage.2") + e));
    } catch (TransformerException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("LogViewerPreferenceRootPage.2") + e));
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("LogViewerPreferenceRootPage.2") + e));
    }
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) Element(org.w3c.dom.Element) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException)

Example 17 with TechnicalException

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

the class ResourceListener method handlePostChange.

/**
 * Callback method that handles all post changes
 * Implemented using the design pattern visitor that traverses
 * through the changed resources
 *
 * @param event The change event to handle
 */
private void handlePostChange(final IResourceChangeEvent event) {
    IResourceDelta rootDelta = event.getDelta();
    if (rootDelta == null) {
        return;
    }
    IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {

        @Override
        public boolean visit(final IResourceDelta delta) {
            if (delta.getKind() != IResourceDelta.REMOVED) {
                return true;
            }
            IResource resource = delta.getResource();
            if (!changeInLogViewerProject(resource)) {
                return true;
            }
            switch(resource.getType()) {
                case IResource.FILE:
                    IFile file = (IFile) resource;
                    if (Constants.DEBUG) {
                        // $NON-NLS-1$
                        TITANDebugConsole.getConsole().newMessageStream().println("File delete " + file.getName());
                    }
                    if (SelectionUtils.hasLogFileExtension(file)) {
                        closeMSCWindows(file);
                    }
                    return false;
                case IResource.FOLDER:
                    IFolder folder = (IFolder) resource;
                    if (Constants.DEBUG) {
                        // $NON-NLS-1$
                        TITANDebugConsole.getConsole().newMessageStream().println("Folder delete " + folder.getName());
                    }
                    closeMSCWindows(folder);
                    return false;
                default:
                    return true;
            }
        }
    };
    try {
        rootDelta.accept(visitor);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        // $NON-NLS-1$
        String messageText = Messages.getString("ResourceListener.0") + ' ' + e.getMessage();
        TitanLogExceptionHandler.handleException(new TechnicalException(messageText));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta) IFolder(org.eclipse.core.resources.IFolder)

Example 18 with TechnicalException

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

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

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

the class ExtractTestCasesMenuAction method run.

public void run(final ISelection selection) {
    if (selection == null) {
        return;
    }
    if (!SelectionUtils.isSelectionALogFile(selection)) {
        return;
    }
    final IFile logFile = SelectionUtils.selectionToIFile(selection);
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            return;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    WorkspaceJob op = new WorkspaceJob("Testcase extraction from logfile " + logFile.getProjectRelativePath().toString()) {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) {
            final ExtractTestCasesAction extractTestCasesAction = new ExtractTestCasesAction(logFile);
            try {
                final long start = System.currentTimeMillis();
                extractTestCasesAction.run(monitor);
                final long stop = System.currentTimeMillis();
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        int numTestCases = extractTestCasesAction.getTestCases().size();
                        String projectName = logFile.getProject().getName();
                        ConsoleWriter.getInstance().writeToConsole(Messages.getString("ExtractTestCasesAction.3") + numTestCases + Messages.getString("ExtractTestCasesAction.1") + logFile.getName() + Messages.getString("ExtractTestCasesAction.2") + (stop - start) / 1000.0 + Messages.getString("ExtractTestCasesAction.4"), projectName);
                        // $NON-NLS-1$
                        ConsoleWriter.getInstance().writeToConsole("", projectName);
                    }
                });
            } catch (InvocationTargetException e) {
                ErrorReporter.logExceptionStackTrace(e);
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenWithLogViewer.2") + e.getTargetException().getMessage()));
            } catch (InterruptedException e) {
                // cancel button is de-activated, this exception can occur when the extraction fails
                ErrorReporter.logExceptionStackTrace(e);
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenWithLogViewer.3") + e.getMessage()));
            }
            return Status.OK_STATUS;
        }
    };
    op.setPriority(Job.LONG);
    op.setUser(true);
    op.setRule(logFile.getProject());
    op.schedule();
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException)

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