Search in sources :

Example 6 with TestCaseExtractor

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

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