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