use of org.eclipse.titan.log.viewer.models.LogRecordIndex 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.models.LogRecordIndex in project titan.EclipsePlug-ins by eclipse.
the class TestCaseExtractor method addLogRecordIndex.
private void addLogRecordIndex(final long filePointer, final int offsetStart, final int offsetEnd, final int recordNumber) {
int recordLength = offsetEnd - offsetStart + 1;
this.endRecordNumber = recordNumber;
// Check if current line contains a valid time-stamp, if not the record continues...
if (hasValidTimeStamp(offsetStart, recordLength)) {
if (Constants.DEBUG) {
if (!Character.isDigit(this.buffer[offsetStart])) {
// $NON-NLS-1$
TITANDebugConsole.getConsole().newMessageStream().println("--Faulty " + this.buffer[offsetStart]);
}
if (this.buffer[offsetEnd] != '\n') {
// $NON-NLS-1$
TITANDebugConsole.getConsole().newMessageStream().println("><<Faulty " + this.buffer[offsetEnd]);
}
}
// Time-stamp found, create new log record index
LogRecordIndex currentLogRecordIndex = new LogRecordIndex(filePointer, recordLength, recordNumber);
this.logRecordIndexVector.add(currentLogRecordIndex);
// keep the last found record
this.lastRecordIndex = currentLogRecordIndex;
} else {
if (this.lastRecordIndex != null) {
this.lastRecordIndex.addRecordLen(recordLength);
this.recordNumber--;
}
}
}
use of org.eclipse.titan.log.viewer.models.LogRecordIndex in project titan.EclipsePlug-ins by eclipse.
the class LogSearchQuery method run.
@Override
public IStatus run(final IProgressMonitor monitor) {
result.removeAll();
int numOfRecords = 0;
for (IFile logFile : files) {
File indexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
numOfRecords += LogFileCacheHandler.getNumberOfLogRecordIndexes(indexFile);
}
monitor.beginTask("Searching", numOfRecords);
for (IFile logFile : files) {
if (monitor.isCanceled()) {
break;
}
if (LogFileCacheHandler.hasLogFileChanged(logFile) && !LogFileCacheHandler.processLogFile(logFile, new NullProgressMonitor(), true)) {
continue;
}
File indexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
try {
LogRecordIndex[] indexes = LogFileCacheHandler.readLogRecordIndexFile(indexFile, 0, LogFileCacheHandler.getNumberOfLogRecordIndexes(indexFile));
SequentialLogFileReader reader = new SequentialLogFileReader(logFile.getLocationURI(), indexes);
monitor.subTask("Filtering");
filterRecords(monitor, logFile, reader);
monitor.done();
} catch (ParseException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(logFile.getName() + ": Could not parse the log file. Reason: " + e.getMessage()));
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(logFile.getName() + ": Error while searching. Reason: " + e.getMessage()));
}
}
monitor.done();
return new Status(IStatus.OK, Constants.PLUGIN_ID, IStatus.OK, "Search done.", null);
}
use of org.eclipse.titan.log.viewer.models.LogRecordIndex in project titan.EclipsePlug-ins by eclipse.
the class SearchLabelProvider method getText.
@Override
public String getText(final Object element) {
if (element instanceof IResource) {
return WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider().getText(element);
}
if (element instanceof Match) {
Match match = (Match) element;
IFile logFile = (IFile) match.getElement();
RandomAccessFile file = null;
String result = "";
try {
// TODO: This should be cached in some way
File indexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
LogRecordIndex[] indexes = LogFileCacheHandler.readLogRecordIndexFile(indexFile, match.getOffset(), 1);
file = new RandomAccessFile(new File(logFile.getLocationURI()), "r");
int length = indexes[0].getRecordLength() > MAX_TEXT_LENGTH ? MAX_TEXT_LENGTH : indexes[0].getRecordLength();
byte[] record = new byte[length];
file.seek(indexes[0].getFileOffset());
file.read(record);
result = new String(record);
} catch (FileNotFoundException e) {
ErrorReporter.logExceptionStackTrace(e);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new TechnicalException(logFile.getName() + ": File not found " + e.getMessage()));
return logFile.getName() + ": File not found";
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new TechnicalException("Error while reading the log file." + e.getMessage()));
return "Error while reading the log file.";
} finally {
IOUtils.closeQuietly(file);
}
return result;
}
return "Unexpected element";
}
Aggregations