Search in sources :

Example 11 with LogFileMetaData

use of org.eclipse.titan.log.viewer.models.LogFileMetaData in project titan.EclipsePlug-ins by eclipse.

the class OpenTextTableStatisticalViewMenuAction method run.

@Override
public void run() {
    Object element = this.selection.getFirstElement();
    if (!(element instanceof TestCase)) {
        return;
    }
    TestCase tc = (TestCase) element;
    LogFileMetaData logFileMetaData = this.statisticalView.getLogFileMetaData();
    TextTableViewHelper.open(logFileMetaData.getProjectName(), logFileMetaData.getProjectRelativePath(), tc.getStartRecordNumber());
}
Also used : TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData)

Example 12 with LogFileMetaData

use of org.eclipse.titan.log.viewer.models.LogFileMetaData 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 13 with LogFileMetaData

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

Example 14 with LogFileMetaData

use of org.eclipse.titan.log.viewer.models.LogFileMetaData 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 15 with LogFileMetaData

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

Aggregations

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