use of org.eclipse.titan.log.viewer.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class RefreshMSCViewAction method run.
@Override
public void run() {
// Set current log file meta data
final LogFileMetaData logFileMetaData = this.mscView.getLogFileMetaData();
ExecutionModel model = this.mscView.getModel();
final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(logFileMetaData.getProjectName());
if (preferences.getVisualOrderComponents().isEmpty()) {
// $NON-NLS-1$
String userE = Messages.getString("RefreshMSCViewAction.3");
TitanLogExceptionHandler.handleException(new UserException(userE));
return;
}
final IFile logFile = getSelectedLogFile(logFileMetaData);
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
// Check if the log file exists
if (!logFile.exists()) {
IViewReference[] viewReferences = activePage.getViewReferences();
ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new UserException(Messages.getString("RefreshMSCViewAction.1")));
return;
}
// Check if the log 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);
try {
// Read/parse log file
final TestCase tc = model.getTestCase();
final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, tc.getStartRecordNumber(), tc.getNumberOfRecords());
WorkspaceJob job = new WorkspaceJob("Loading log information") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
ExecutionModel model;
try {
model = parseLogFile();
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
Messages.getString("RefreshMSCViewAction.5") + e.getMessage()));
return Status.CANCEL_STATUS;
}
final int firstRow = getFirstRow(model, preferences);
final ExecutionModel finalModel = model;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
RefreshMSCViewAction.this.mscView.setModel(finalModel, firstRow);
}
});
return Status.OK_STATUS;
}
private ExecutionModel parseLogFile() throws TechnicalException {
ExecutionModel model;
if (logFileMetaData.getExecutionMode() == null) {
throw new TechnicalException("Error while parsing of the log file: ExecutionMode is null");
}
try {
// re-parse tc
Parser parser = new Parser(logFileMetaData);
model = parser.preParse(tc, logRecordIndexes, preferences, mscView.getFilterPattern(), null);
} catch (IOException e) {
throw new TechnicalException("Error while parsing of the log file");
} catch (ParseException e) {
throw new TechnicalException("Error while parsing of the log file");
}
return model;
}
};
job.schedule();
} 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.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class LogFileContentProvider method getChildren.
@Override
public Object[] getChildren(final Object parentElement) {
Object[] emptyResult = new Object[] {};
if (!(parentElement instanceof IFile)) {
return emptyResult;
}
final IFile logFile = (IFile) parentElement;
if (!logFile.exists()) {
return emptyResult;
}
String fileExtension = logFile.getFileExtension();
if (fileExtension == null || !fileExtension.equals(Constants.LOG_EXTENSION)) {
return emptyResult;
}
try {
Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
if (temp != null && (Boolean) temp) {
return emptyResult;
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
}
if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
handleLogFileChange(logFile);
return emptyResult;
}
try {
final TestCaseExtractor extractor = new TestCaseExtractor();
extractor.extractTestCasesFromIndexedLogFile(logFile);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
if (view instanceof CommonNavigator) {
CommonViewer viewer = ((CommonNavigator) view).getCommonViewer();
for (TestCase testCase : extractor.getTestCases()) {
viewer.expandToLevel(testCase, AbstractTreeViewer.ALL_LEVELS);
viewer.refresh(testCase, true);
}
}
}
});
return extractor.getTestCases().toArray();
} catch (Exception e) {
LogFileCacheHandler.clearCache(logFile);
ErrorReporter.logExceptionStackTrace(e);
return emptyResult;
}
}
use of org.eclipse.titan.log.viewer.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class MSCView method restoreState.
/**
* Called in the view life-cycle restore chain Reads back all view data if
* memento has been set
*
* The restore is very restricted an checks that the
* <li> Project still exists and is open
* <li> The file is within the project
* <li> The file size and file date has not changed
*/
private WorkspaceJob restoreState() {
if (this.memento == null) {
return null;
}
WorkspaceJob job = null;
this.problemDuringRestore = true;
// $NON-NLS-1$
this.memento = this.memento.getChild("mscview");
if (this.memento != null) {
try {
// $NON-NLS-1$
IMemento viewAttributes = this.memento.getChild("attributes");
// Restore logfilemetaData
// $NON-NLS-1$
String propertyFilePath = viewAttributes.getString("propertyFile");
if (propertyFilePath != null) {
File propertyFile = new File(propertyFilePath);
if (propertyFile.exists()) {
this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
}
}
// Get project
// $NON-NLS-1$
String projectName = viewAttributes.getString("projectName");
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if ((this.logFileMetaData != null) && (project != null) && project.exists() && project.isOpen()) {
Path path = new Path(this.logFileMetaData.getProjectRelativePath());
IFile logFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if ((logFile != null) && logFile.exists() && logFile.getProject().getName().equals(project.getName())) {
// $NON-NLS-1$
String fileSizeString = viewAttributes.getString("fileSize");
long fileSize = 0;
if (fileSizeString != null) {
fileSize = Long.parseLong(fileSizeString);
}
// $NON-NLS-1$
String fileModificationString = viewAttributes.getString("fileModification");
long fileModification = 0;
if (fileModificationString != null) {
fileModification = Long.parseLong(fileModificationString);
}
File file = logFile.getLocation().toFile();
if ((file.lastModified() == fileModification) && (file.length() == fileSize)) {
// Load the Test case from index file
// $NON-NLS-1$
Integer testCaseNumber = viewAttributes.getInteger("testCaseNumber");
File indexFileForLogFile = LogFileCacheHandler.getIndexFileForLogFile(logFile);
File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
if (!indexFileForLogFile.exists() || !logRecordIndexFile.exists()) {
return null;
}
final Parser parser = new Parser(this.logFileMetaData);
final TestCase testCase = TestCaseExtractor.getTestCaseFromIndexFile(indexFileForLogFile, testCaseNumber);
final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, testCase.getStartRecordNumber(), testCase.getNumberOfRecords());
final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(projectName);
// Restore model
job = new WorkspaceJob("Loading log information") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
try {
MSCView.this.model = parser.preParse(testCase, logRecordIndexes, preferences, null, monitor);
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace(e);
}
return Status.OK_STATUS;
}
};
job.schedule();
// Restore selection
// $NON-NLS-1$
final Integer temp = viewAttributes.getInteger("rowSelection");
if (temp == null) {
this.restoredSelection = 0;
} else {
this.restoredSelection = temp.intValue();
}
this.problemDuringRestore = false;
} else {
// TODO: what should we do if something went wrong?
}
}
}
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
this.memento = null;
return job;
}
use of org.eclipse.titan.log.viewer.parsers.data.TestCase in project titan.EclipsePlug-ins by eclipse.
the class OpenTextTableProjectsViewMenuAction method run.
public void run(final IStructuredSelection selection) {
if (selection == null) {
return;
}
int logRecordToSelect = 0;
if (SelectionUtils.isSelectionALogFile(this.selection)) {
this.logFile = SelectionUtils.selectionToIFile(this.selection);
} else if (selection.getFirstElement() instanceof TestCase) {
TestCase testCase = (TestCase) selection.getFirstElement();
this.logFile = testCase.getLogFile();
logRecordToSelect = testCase.getStartRecordNumber();
} else {
return;
}
if (this.logFile == null) {
return;
}
final String projectName = logFile.getProject().getName();
final String projectRelativePath = File.separator + projectName + File.separator + this.logFile.getProjectRelativePath().toOSString();
if (LogFileCacheHandler.hasLogFileChanged(logFile) && !LogFileCacheHandler.processLogFile(logFile, new NullProgressMonitor(), false)) {
return;
}
TextTableViewHelper.open(projectName, projectRelativePath, logRecordToSelect);
}
use of org.eclipse.titan.log.viewer.parsers.data.TestCase 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;
}
Aggregations