use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.
the class Parser method parseRegion.
/**
* Parses a given region from the log file and returns the contents as a list of events.
* The SUT, MTC and System components are always added.
*
* @param startIndex the index of the event to be displayed.
* @param endIndex the index of the last event to be displayed.
* @param monitor the monitor to be used to report progress on.
*
* @return the events parsed from the given region.
*/
public List<EventObject> parseRegion(final int startIndex, final int endIndex, final IProgressMonitor monitor) throws IOException, ParseException {
IProgressMonitor internalMonitor = monitor == null ? new NullProgressMonitor() : monitor;
TestFileReader reader = null;
wasCanceled = false;
List<EventObject> result = new ArrayList<EventObject>(endIndex - startIndex + 6 + 1);
final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
// needed for memento of MSC view
final TestCase testCase = this.executionModel.getTestCase();
// The SUT element object always exists at all times, to make sure
// it becomes visible before any test starts.
EventObject sut = createEventObject(null, EventType.SYSTEM_CREATE);
sut.setName(preferences.getSutName());
result.add(sut);
EventObject hc = createEventObject(null, EventType.HC_CREATE);
result.add(hc);
EventObject mtc = createEventObject(null, EventType.MTC_CREATE);
result.add(mtc);
if (Constants.DEBUG) {
// $NON-NLS-1$
TITANDebugConsole.getConsole().newMessageStream().println("Message type = " + this.messageAnalyser.getType());
}
this.tcRecords = logRecordIndexes.length;
try {
reader = new TestFileReader(this.logFileMetaData.getFilePath(), logRecordIndexes);
internalMonitor.beginTask("Loading...", reader.size());
for (int i = startIndex; i <= endIndex && i < eventVector.size() && !internalMonitor.isCanceled(); i++) {
try {
int actualIndex = eventVector.get(i) - testCase.getStartRecordNumber();
reader.setCurrentLogRecord(actualIndex);
LogRecord logRecord = reader.getNextRecord();
// Add test case record number offset to record
logRecord.setRecordNumber(testCase.getStartRecordNumber() + logRecord.getRecordNumber());
EventObject event = parseLogRecord(logRecord, i);
if (event != null) {
result.add(event);
}
internalMonitor.worked(1);
} catch (ParseException e) {
ErrorReporter.logExceptionStackTrace(e);
ParseException throwable = new ParseException(e.getMessage(), 0);
throwable.initCause(e);
throw throwable;
}
}
} finally {
IOUtils.closeQuietly(reader);
}
wasCanceled = internalMonitor.isCanceled();
internalMonitor.done();
for (String compRef : currentlyLivingComponents) {
EventObject event = new EventObject(EventType.PTC_TERMINATE);
event.setReference(compRef);
event.setName(compRef);
result.add(event);
}
// if no mtc termination is made, do it here
if (!mtcTerminated) {
mtc = eventObjectFactory.createEventObject(EventType.MTC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
result.add(mtc);
}
hc = eventObjectFactory.createEventObject(EventType.HC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
result.add(hc);
// The last thing that "dies" in a log is the SUT, that still exists
// after the test case is over. Still add a marker for this in the
// log.
sut = eventObjectFactory.createEventObject(EventType.SYSTEM_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
result.add(sut);
return result;
}
use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder 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.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.
the class OpenMSCViewMenuAction method run.
public void run(final IStructuredSelection selection) {
if (!isEnabled()) {
return;
}
Object element = selection.getFirstElement();
if (!(element instanceof TestCase)) {
return;
}
final TestCase tc = (TestCase) element;
final IFile logFile = tc.getLogFile();
try {
logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(LogFileCacheHandler.getPropertyFileForLogFile(logFile));
} catch (IOException e1) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
} catch (ClassNotFoundException e1) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
}
try {
if (!PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName()).getVisualOrderComponents().isEmpty()) {
// Get start time
final long start = new Date().getTime();
if (!logFile.exists()) {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference[] viewReferences = activePage.getViewReferences();
ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenMSCViewMenuAction.4")));
return;
}
// Check if the file has been modified
if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
}
// Get log record index file for selected log file - No need to check is exists due to
// LogFileCacheHandler.hasLogFileChanged(logFile) returning false above
File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, tc.getStartRecordNumber(), tc.getNumberOfRecords());
final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
WorkspaceJob job = new WorkspaceJob("Loading log information") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
if (OpenMSCViewMenuAction.this.logFileMetaData == null || OpenMSCViewMenuAction.this.logFileMetaData.getExecutionMode() == null) {
return Status.CANCEL_STATUS;
}
final Parser parser;
final ExecutionModel model;
try {
parser = new Parser(OpenMSCViewMenuAction.this.logFileMetaData);
parser.setStart(start);
model = parser.preParse(tc, logRecordIndexes, preferences, null, monitor);
} catch (TechnicalException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
Messages.getString("OpenMSCViewMenuAction.3") + e.getMessage()));
return Status.CANCEL_STATUS;
} catch (ParseException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
Messages.getString("OpenMSCViewMenuAction.2") + e.getMessage()));
return Status.CANCEL_STATUS;
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
return Status.CANCEL_STATUS;
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
showView(model, parser, tc);
// Write data to the console
final long end = new Date().getTime();
parser.setEnd(end);
ConsoleWriter.getInstance().writeModelData(OpenMSCViewMenuAction.this.logFileMetaData.getProjectName(), parser, model, OpenMSCViewMenuAction.this.logFileMetaData.getFilePath().toString());
}
});
return Status.OK_STATUS;
}
};
job.schedule();
} else {
// $NON-NLS-1$
String userE = Messages.getString("OpenMSCViewMenuAction.1");
TitanLogExceptionHandler.handleException(new UserException(userE));
}
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
}
}
use of org.eclipse.titan.log.viewer.preferences.PreferencesHolder in project titan.EclipsePlug-ins by eclipse.
the class ConsoleWriter method writeToConsole.
/**
* Writes to the console
* @param msg, message to be written to the console
*/
public void writeToConsole(final String msg, final String projectName) {
// Check with preference store
PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(projectName);
if (preferences.getVerbosePrintoutsEnabled()) {
try {
this.out.println(msg);
this.out.flush();
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(// $NON-NLS-1$
new TechnicalException(Messages.getString("ConsoleWriter.0") + e.getMessage()));
}
}
}
Aggregations