use of org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel in project titan.EclipsePlug-ins by eclipse.
the class Parser method preParse.
/**
* This function will parse eventObject from the log file
*
* @param testCase
* test case, PreferenceHolder preferences
* @return ExecutionModel throws IOException
*/
// FIXME signals, send, receive and silent events must be delayed.
// TODO Preferences could be calculated
public ExecutionModel preParse(final TestCase testCase, final LogRecordIndex[] logRecordIndexes, final PreferencesHolder preferences, final FilterPattern filterPattern, final IProgressMonitor monitor) throws IOException, ParseException, TechnicalException {
IProgressMonitor internalMonitor = monitor == null ? new NullProgressMonitor() : monitor;
wasCanceled = false;
this.logRecordIndexes = logRecordIndexes;
this.executionModel = new ExecutionModel(this);
this.executionModel.setFilterPattern(filterPattern);
// Add ignored components
this.executionModel.addIgnoredComponent(preferences.getIgnoredComponents());
this.executionModel.setSutName(preferences.getSutName());
// Add ignored signals
this.executionModel.addIgnoredSignals(preferences.getIgnoredSignals());
// Add ignored functions
this.executionModel.addIgnoredFunctions(preferences.getIgnoredFunctions());
// needed for memento of MSC view
this.executionModel.setContainedTestCase(testCase);
this.executionModel.getTestCase().setTestCaseName(testCase.getTestCaseName());
this.executionModel.getTestCase().setVerdict(testCase.getVerdict());
// 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());
sut.setEventNumber(0);
this.executionModel.addComponent(sut);
executionModel.addLifeLineInfo(sut);
EventObject hc = createEventObject(null, EventType.HC_CREATE);
hc.setEventNumber(1);
this.executionModel.addComponent(hc);
executionModel.addLifeLineInfo(hc);
EventObject mtc = createEventObject(null, EventType.MTC_CREATE);
mtc.setEventNumber(2);
this.executionModel.addComponent(mtc);
executionModel.addLifeLineInfo(mtc);
components = this.executionModel.getComponents();
this.messageAnalyser = MessageAnalyserFactory.createMessageAnalyser(this.logFileMetaData);
setUpFromPreferences(preferences, filterPattern);
if (Constants.DEBUG) {
// $NON-NLS-1$
TITANDebugConsole.getConsole().newMessageStream().println("Message type = " + this.messageAnalyser.getType());
}
this.tcRecords = logRecordIndexes.length;
TestFileReader reader = null;
try {
reader = new TestFileReader(this.logFileMetaData.getFilePath(), logRecordIndexes);
eventVector = new ArrayList<Integer>();
internalMonitor.beginTask("Loading...", reader.size());
/**
* Stores the components that was not terminated before the given log record.
* It can be used for partial log files.
*/
currentlyLivingComponents = new HashSet<String>();
while (reader.hasNextRecord() && !internalMonitor.isCanceled()) {
try {
LogRecord logRecord = reader.getNextRecord();
// Add test case record number offset to record
logRecord.setRecordNumber(testCase.getStartRecordNumber() + logRecord.getRecordNumber());
preParseLogRecord(logRecord, currentlyLivingComponents);
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);
}
// remove some of those components that are part of the surrounding system
currentlyLivingComponents.remove(Constants.MTC_REFERENCE);
currentlyLivingComponents.remove(Constants.HC_REFERENCE);
currentlyLivingComponents.remove(Constants.SUT_REFERENCE);
// The components which were not terminated
int additionalIndex = 3;
for (String compRef : currentlyLivingComponents) {
EventObject event = new EventObject(EventType.PTC_TERMINATE);
event.setEventNumber(eventVector.size() + additionalIndex);
additionalIndex++;
event.setReference(compRef);
event.setName(compRef);
executionModel.addLifeLineInfo(event);
}
wasCanceled = internalMonitor.isCanceled();
internalMonitor.done();
// if no mtc termination is made, do it here
if (!mtcTerminated) {
mtc = eventObjectFactory.createEventObject(EventType.MTC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
mtc.setEventNumber(eventVector.size() + additionalIndex);
additionalIndex++;
executionModel.addLifeLineInfo(mtc);
}
hc = eventObjectFactory.createEventObject(EventType.HC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
hc.setEventNumber(eventVector.size() + additionalIndex);
additionalIndex++;
executionModel.addLifeLineInfo(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());
sut.setEventNumber(eventVector.size() + additionalIndex);
executionModel.addLifeLineInfo(sut);
setVerdict();
return this.executionModel;
}
use of org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel 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.views.msc.model.ExecutionModel in project titan.EclipsePlug-ins by eclipse.
the class JumpToPreviousSetverdictAction method run.
@Override
public void run() {
if (this.widget == null) {
return;
}
ExecutionModel model = this.view.getModel();
if (model == null) {
return;
}
int[] setverdictPlaces = model.getSetverdict();
int selectedLine = (Integer) this.selection.getFirstElement();
selectSetVerdict(setverdictPlaces, selectedLine);
}
use of org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel 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);
}
Aggregations