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;
}
Aggregations