Search in sources :

Example 1 with CachedLogReader

use of org.eclipse.titan.log.viewer.readers.CachedLogReader in project titan.EclipsePlug-ins by eclipse.

the class TextTableView 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 void restoreState() {
    if (this.memento == null) {
        return;
    }
    // this.problemDuringRestore = true; // TODO check the save and restore methods
    // $NON-NLS-1$
    this.memento = this.memento.getChild("selection");
    if (this.memento == null) {
        return;
    }
    try {
        // get project
        // $NON-NLS-1$
        IMemento viewAttributes = this.memento.getChild("viewAttributes");
        // $NON-NLS-1$
        String projectName = viewAttributes.getString("projectName");
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        if ((project == null) || !project.exists() || !project.isOpen()) {
            return;
        }
        // retrieve log file meta data
        // $NON-NLS-1$
        String propertyFilePath = viewAttributes.getString("propertyFile");
        if (propertyFilePath == null) {
            return;
        }
        File propertyFile = new File(propertyFilePath);
        if (!propertyFile.exists()) {
            return;
        }
        this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
        // get log file
        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())) {
            return;
        }
        File file = logFile.getLocation().toFile();
        // get file attributes to see if file has changed
        // $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);
        }
        if ((file.lastModified() != fileModification) || (file.length() != fileSize)) {
            return;
        }
        if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
            return;
        }
        // create reader and set as input
        this.filteredLogReader = new FilteredLogReader(LogFileReader.getReaderForLogFile(logFile));
        this.cachedLogReader = new CachedLogReader(filteredLogReader);
        // $NON-NLS-1$
        this.selectedRow = viewAttributes.getInteger("selectedRow");
        // $NON-NLS-1$
        this.viewerWidth = viewAttributes.getInteger("viewWidth");
        this.problemDuringRestore = false;
    } catch (final IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
    } catch (final ClassNotFoundException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    this.memento = null;
}
Also used : Path(org.eclipse.core.runtime.Path) CachedLogReader(org.eclipse.titan.log.viewer.readers.CachedLogReader) IFile(org.eclipse.core.resources.IFile) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IMemento(org.eclipse.ui.IMemento) IProject(org.eclipse.core.resources.IProject) FilteredLogReader(org.eclipse.titan.log.viewer.readers.FilteredLogReader)

Example 2 with CachedLogReader

use of org.eclipse.titan.log.viewer.readers.CachedLogReader in project titan.EclipsePlug-ins by eclipse.

the class TextTableView method setInput.

/**
 * Sets the given file as the input of the view. The content of the log file will be displayed.
 * @param logFile The log file
 * @throws IOException in case of file I/O errors
 * @throws ClassNotFoundException if the log file meta data can not be found
 */
public void setInput(final IFile logFile, final int selection) throws IOException, ClassNotFoundException {
    LogFileMetaData newLogFileMetaData = LogFileCacheHandler.logFileMetaDataReader(LogFileCacheHandler.getPropertyFileForLogFile(logFile));
    final FilteredLogReader filteredReader = new FilteredLogReader(LogFileReader.getReaderForLogFile(logFile));
    final CachedLogReader cachedReader = new CachedLogReader(filteredReader);
    setInput(newLogFileMetaData, cachedReader, filteredReader, selection);
}
Also used : CachedLogReader(org.eclipse.titan.log.viewer.readers.CachedLogReader) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) FilteredLogReader(org.eclipse.titan.log.viewer.readers.FilteredLogReader)

Example 3 with CachedLogReader

use of org.eclipse.titan.log.viewer.readers.CachedLogReader in project titan.EclipsePlug-ins by eclipse.

the class OpenStatisticalViewMenuAction method createStatisticalData.

private List<StatisticalData> createStatisticalData(Set<IFile> logFiles) {
    List<StatisticalData> statisticalDataVector = new ArrayList<StatisticalData>();
    for (IFile file : logFiles) {
        this.logFile = file;
        if (!this.logFile.exists()) {
            // $NON-NLS-1$
            TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenStatisticalViewMenuAction.5")));
            return null;
        }
        File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(this.logFile);
        File propertyFile = LogFileCacheHandler.getPropertyFileForLogFile(this.logFile);
        if (!logRecordIndexFile.exists() || !propertyFile.exists() || LogFileCacheHandler.hasLogFileChanged(this.logFile)) {
            processLogFile();
        } else {
            // Get log file meta data
            try {
                this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
                // Extract test cases from the index file
                this.testCaseExtractor = new TestCaseExtractor();
                this.testCaseExtractor.extractTestCasesFromIndexedLogFile(this.logFile);
            } catch (IOException e) {
                ErrorReporter.logExceptionStackTrace(e);
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            } catch (ClassNotFoundException e) {
                ErrorReporter.logExceptionStackTrace(e);
                // $NON-NLS-1$
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            }
        }
        if (this.logFileIsSupported) {
            try {
                if (this.logFileMetaData == null) {
                    this.logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
                }
                List<TestCase> testCases = this.testCaseExtractor.getTestCases();
                // //Create data for the statistical view
                final CachedLogReader reader = new CachedLogReader(LogFileReader.getReaderForLogFile(this.logFile));
                StatisticalData statisticalData = new StatisticalData(this.logFileMetaData, testCases, reader);
                statisticalDataVector.add(statisticalData);
            } catch (IOException e) {
                ErrorReporter.logExceptionStackTrace(e);
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            } catch (ClassNotFoundException e) {
                ErrorReporter.logExceptionStackTrace(e);
                TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
            }
        }
    }
    return statisticalDataVector;
}
Also used : IFile(org.eclipse.core.resources.IFile) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) ArrayList(java.util.ArrayList) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IOException(java.io.IOException) CachedLogReader(org.eclipse.titan.log.viewer.readers.CachedLogReader) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 4 with CachedLogReader

use of org.eclipse.titan.log.viewer.readers.CachedLogReader in project titan.EclipsePlug-ins by eclipse.

the class StatisticalView 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 List<StatisticalData> restoreState() {
    if (this.memento == null) {
        return new ArrayList<StatisticalData>();
    }
    // $NON-NLS-1$
    this.memento = this.memento.getChild("selection");
    if (this.memento == null) {
        return new ArrayList<StatisticalData>();
    }
    List<StatisticalData> tmpStatisticalDataVector = new ArrayList<StatisticalData>();
    try {
        // get project
        // $NON-NLS-1$
        IMemento[] viewAttributes = this.memento.getChildren("viewAttributes");
        for (IMemento viewAttribute : viewAttributes) {
            // $NON-NLS-1$
            String projectName = viewAttribute.getString("projectName");
            IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
            if ((project == null) || !project.exists() || !project.isOpen()) {
                return new ArrayList<StatisticalData>();
            }
            // retrieve log file meta data
            // $NON-NLS-1$
            String propertyFilePath = viewAttribute.getString("propertyFile");
            if (propertyFilePath == null) {
                return new ArrayList<StatisticalData>();
            }
            File propertyFile = new File(propertyFilePath);
            if (!propertyFile.exists()) {
                return new ArrayList<StatisticalData>();
            }
            LogFileMetaData tmpLogFileMetaData = LogFileCacheHandler.logFileMetaDataReader(propertyFile);
            // get log file
            Path path = new Path(tmpLogFileMetaData.getProjectRelativePath());
            IFile logFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            if ((logFile == null) || !logFile.exists() || !logFile.getProject().getName().equals(project.getName())) {
                return new ArrayList<StatisticalData>();
            }
            File file = logFile.getLocation().toFile();
            // get file attributes to see if file has changed
            // $NON-NLS-1$
            String fileSizeString = viewAttribute.getString("fileSize");
            long fileSize = 0;
            if (fileSizeString != null) {
                fileSize = Long.parseLong(fileSizeString);
            }
            // $NON-NLS-1$
            String fileModificationString = viewAttribute.getString("fileModification");
            long fileModification = 0;
            if (fileModificationString != null) {
                fileModification = Long.valueOf(fileModificationString);
            }
            if ((file.lastModified() != fileModification) || (file.length() != fileSize) || LogFileCacheHandler.hasLogFileChanged(logFile)) {
                return new ArrayList<StatisticalData>();
            }
            // create reader and set as input
            this.reader = new CachedLogReader(LogFileReader.getReaderForLogFile(logFile));
            TestCaseExtractor extractor = new TestCaseExtractor();
            extractor.extractTestCasesFromIndexedLogFile(logFile);
            StatisticalData statisticalData = new StatisticalData(tmpLogFileMetaData, extractor.getTestCases(), reader);
            tmpStatisticalDataVector.add(statisticalData);
        }
        return tmpStatisticalDataVector;
    } catch (Exception e) {
        ErrorReporter.logExceptionStackTrace(e);
    } finally {
        this.memento = null;
    }
    return new ArrayList<StatisticalData>();
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) IMemento(org.eclipse.ui.IMemento) IProject(org.eclipse.core.resources.IProject) PartInitException(org.eclipse.ui.PartInitException) ParseException(java.text.ParseException) TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) IOException(java.io.IOException) CachedLogReader(org.eclipse.titan.log.viewer.readers.CachedLogReader) StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) LogFileMetaData(org.eclipse.titan.log.viewer.models.LogFileMetaData) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

CachedLogReader (org.eclipse.titan.log.viewer.readers.CachedLogReader)4 File (java.io.File)3 IOException (java.io.IOException)3 IFile (org.eclipse.core.resources.IFile)3 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 Path (org.eclipse.core.runtime.Path)2 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)2 TestCaseExtractor (org.eclipse.titan.log.viewer.extractors.TestCaseExtractor)2 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)2 FilteredLogReader (org.eclipse.titan.log.viewer.readers.FilteredLogReader)2 StatisticalData (org.eclipse.titan.log.viewer.views.details.StatisticalData)2 IMemento (org.eclipse.ui.IMemento)2 ParseException (java.text.ParseException)1 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)1 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)1 PartInitException (org.eclipse.ui.PartInitException)1