Search in sources :

Example 1 with TestCaseExtractor

use of org.eclipse.titan.log.viewer.extractors.TestCaseExtractor in project titan.EclipsePlug-ins by eclipse.

the class LogFileContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parentElement) {
    Object[] emptyResult = new Object[] {};
    if (!(parentElement instanceof IFile)) {
        return emptyResult;
    }
    final IFile logFile = (IFile) parentElement;
    if (!logFile.exists()) {
        return emptyResult;
    }
    String fileExtension = logFile.getFileExtension();
    if (fileExtension == null || !fileExtension.equals(Constants.LOG_EXTENSION)) {
        return emptyResult;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            return emptyResult;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        handleLogFileChange(logFile);
        return emptyResult;
    }
    try {
        final TestCaseExtractor extractor = new TestCaseExtractor();
        extractor.extractTestCasesFromIndexedLogFile(logFile);
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                if (view instanceof CommonNavigator) {
                    CommonViewer viewer = ((CommonNavigator) view).getCommonViewer();
                    for (TestCase testCase : extractor.getTestCases()) {
                        viewer.expandToLevel(testCase, AbstractTreeViewer.ALL_LEVELS);
                        viewer.refresh(testCase, true);
                    }
                }
            }
        });
        return extractor.getTestCases().toArray();
    } catch (Exception e) {
        LogFileCacheHandler.clearCache(logFile);
        ErrorReporter.logExceptionStackTrace(e);
        return emptyResult;
    }
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) CommonViewer(org.eclipse.ui.navigator.CommonViewer) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) CoreException(org.eclipse.core.runtime.CoreException) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Example 2 with TestCaseExtractor

use of org.eclipse.titan.log.viewer.extractors.TestCaseExtractor 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 3 with TestCaseExtractor

use of org.eclipse.titan.log.viewer.extractors.TestCaseExtractor 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 4 with TestCaseExtractor

use of org.eclipse.titan.log.viewer.extractors.TestCaseExtractor in project titan.EclipsePlug-ins by eclipse.

the class SwitchToMscAction method run.

@Override
public void run() {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    LogFileMetaData logFileMetaData = textTableView.getLogFileMetaData();
    IProject project = root.getProject(logFileMetaData.getProjectName());
    IFile logFile = project.getFile(logFileMetaData.getProjectRelativePath().substring(logFileMetaData.getProjectName().length() + 1));
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        LogFileCacheHandler.handleLogFileChange(logFile);
        return;
    }
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    TestCaseExtractor extractor = new TestCaseExtractor();
    try {
        extractor.extractTestCasesFromIndexedLogFile(logFile);
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        MessageBox mb = new MessageBox(activePage.getActivePart().getSite().getShell(), SWT.ICON_ERROR | SWT.OK);
        mb.setText("Test case extraction failed.");
        mb.setMessage("Error while extracting the test cases.");
        return;
    } catch (ClassNotFoundException e) {
        ErrorReporter.logExceptionStackTrace(e);
        MessageBox mb = new MessageBox(activePage.getActivePart().getSite().getShell(), SWT.ICON_ERROR | SWT.OK);
        mb.setText("Test case extraction failed.");
        mb.setMessage("Error while extracting the test cases.");
        return;
    }
    List<TestCase> testCases = extractor.getTestCases();
    if (textTableView.getSelectedRecord() == null) {
        MessageBox mb = new MessageBox(activePage.getActivePart().getSite().getShell(), SWT.ICON_ERROR | SWT.OK);
        mb.setText("Invalid selection.");
        mb.setMessage("Please select a record to open the MSC view.");
        return;
    }
    int recordNumber = textTableView.getSelectedRecord().getRecordNumber();
    int testCaseNumber = findContainingTestCase(testCases, recordNumber);
    if (testCaseNumber == -1) {
        MessageBox mb = new MessageBox(activePage.getActivePart().getSite().getShell(), SWT.ICON_ERROR | SWT.OK);
        mb.setText("Testcase can not be found.");
        mb.setMessage("The testcase containing the selected log record can not be found.");
        return;
    }
    final OpenMSCViewAction openMSCAction = new OpenMSCViewAction();
    openMSCAction.selectionChanged(null, new StructuredSelection(testCases.get(testCaseNumber)));
    openMSCAction.setFirstRow(recordNumber);
    openMSCAction.run();
}
Also used : IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) OpenMSCViewAction(org.eclipse.titan.log.viewer.actions.OpenMSCViewAction) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) MessageBox(org.eclipse.swt.widgets.MessageBox) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IWorkspace(org.eclipse.core.resources.IWorkspace) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 5 with TestCaseExtractor

use of org.eclipse.titan.log.viewer.extractors.TestCaseExtractor in project titan.EclipsePlug-ins by eclipse.

the class StatisticalView method restoreState.

/**
 * Called in the view life-cycle restore chain
 * Reads back all view data if memento has been set
 *
 * The restore is very restricted an checks that the
 * <li> Project still exists and is open
 * <li> The file is within the project
 * <li> The file size and file date has not changed
 */
private List<StatisticalData> restoreState() {
    if (this.memento == null) {
        return new ArrayList<StatisticalData>();
    }
    // $NON-NLS-1$
    this.memento = this.memento.getChild("selection");
    if (this.memento == null) {
        return new ArrayList<StatisticalData>();
    }
    List<StatisticalData> tmpStatisticalDataVector = new ArrayList<StatisticalData>();
    try {
        // get project
        // $NON-NLS-1$
        IMemento[] viewAttributes = this.memento.getChildren("viewAttributes");
        for (IMemento viewAttribute : viewAttributes) {
            // $NON-NLS-1$
            String projectName = viewAttribute.getString("projectName");
            IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
            if ((project == null) || !project.exists() || !project.isOpen()) {
                return new ArrayList<StatisticalData>();
            }
            // retrieve log file meta data
            // $NON-NLS-1$
            String propertyFilePath = viewAttribute.getString("propertyFile");
            if (propertyFilePath == null) {
                return new ArrayList<StatisticalData>();
            }
            File propertyFile = new File(propertyFilePath);
            if (!propertyFile.exists()) {
                return new ArrayList<StatisticalData>();
            }
            LogFileMetaData tmpLogFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
            // get log file
            Path path = new Path(tmpLogFileMetaData.getProjectRelativePath());
            IFile logFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            if ((logFile == null) || !logFile.exists() || !logFile.getProject().getName().equals(project.getName())) {
                return new ArrayList<StatisticalData>();
            }
            File file = logFile.getLocation().toFile();
            // get file attributes to see if file has changed
            // $NON-NLS-1$
            String fileSizeString = viewAttribute.getString("fileSize");
            long fileSize = 0;
            if (fileSizeString != null) {
                fileSize = Long.parseLong(fileSizeString);
            }
            // $NON-NLS-1$
            String fileModificationString = viewAttribute.getString("fileModification");
            long fileModification = 0;
            if (fileModificationString != null) {
                fileModification = Long.valueOf(fileModificationString);
            }
            if ((file.lastModified() != fileModification) || (file.length() != fileSize) || LogFileCacheHandler.hasLogFileChanged(logFile)) {
                return new ArrayList<StatisticalData>();
            }
            // create reader and set as input
            this.reader = new CachedLogReader(LogFileReader.getReaderForLogFile(logFile));
            TestCaseExtractor extractor = new TestCaseExtractor();
            extractor.extractTestCasesFromIndexedLogFile(logFile);
            StatisticalData statisticalData = new StatisticalData(tmpLogFileMetaData, extractor.getTestCases(), reader);
            tmpStatisticalDataVector.add(statisticalData);
        }
        return tmpStatisticalDataVector;
    } catch (Exception e) {
        ErrorReporter.logExceptionStackTrace(e);
    } finally {
        this.memento = null;
    }
    return new ArrayList<StatisticalData>();
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IMemento(org.eclipse.ui.IMemento) IProject(org.eclipse.core.resources.IProject) PartInitException(org.eclipse.ui.PartInitException) ParseException(java.text.ParseException) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IOException(java.io.IOException) CachedLogReader(org.eclipse.titan.log.viewer.readers.CachedLogReader) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

TestCaseExtractor (org.eclipse.titan.log.viewer.extractors.TestCaseExtractor)6 IOException (java.io.IOException)5 IFile (org.eclipse.core.resources.IFile)4 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)4 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)4 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)3 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 CachedLogReader (org.eclipse.titan.log.viewer.readers.CachedLogReader)2 StatisticalData (org.eclipse.titan.log.viewer.views.details.StatisticalData)2 IViewPart (org.eclipse.ui.IViewPart)2 CommonNavigator (org.eclipse.ui.navigator.CommonNavigator)2 ParseException (java.text.ParseException)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1