use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceParser method updateSyntax.
/**
* The entry point of incremental parsing.
* <p>
* Handles the data storages, calls the module level incremental parser
* on the file, and if everything fails does a full parsing to correct
* possibly invalid states.
*
* @param file
* the edited file
* @param reparser
* the parser doing the incremental parsing.
*
* @return the WorkspaceJob in which the operation is running
*/
public WorkspaceJob updateSyntax(final IFile file, final TTCN3ReparseUpdater reparser) {
WorkspaceJob op = new WorkspaceJob("Updating the syntax incremantally for: " + file.getName()) {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
syntacticAnalyzer.updateSyntax(file, reparser);
return Status.OK_STATUS;
}
};
op.setPriority(Job.SHORT);
IPreferencesService preferenceService = Platform.getPreferencesService();
if (GeneralConstants.DEBUG && preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
op.setSystem(false);
op.setUser(true);
} else {
op.setSystem(true);
op.setUser(false);
}
op.setRule(file);
op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
op.schedule();
return op;
}
use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceParser method reportSyntacticOutdatingOnly.
/**
* Reports that the provided file has changed and so it's stored
* information became out of date. This version does not mark the
* semantic data out-of-date.
* <p>
* Stores that this file is out of date for later usage
* <p>
*
* @param outdatedFile
* the file which seems to have changed
*
* @return the WorkspaceJob in which the operation is running
*/
public WorkspaceJob reportSyntacticOutdatingOnly(final IFile outdatedFile) {
WorkspaceJob op = new WorkspaceJob("Reporting outdate for: " + outdatedFile.getName()) {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
syntacticAnalyzer.reportSyntacticOutdatingOnly(outdatedFile);
return Status.OK_STATUS;
}
};
op.setPriority(Job.SHORT);
IPreferencesService preferenceService = Platform.getPreferencesService();
if (GeneralConstants.DEBUG && preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
op.setSystem(false);
op.setUser(true);
} else {
op.setSystem(true);
op.setUser(false);
}
op.setRule(outdatedFile);
op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
op.schedule();
return op;
}
use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceSyntacticAnalyzer method internalDoAnalyzeSyntactically.
/**
* Internal function.
*
* @param monitor
* the progress monitor to provide feedback to the user
* about the progress.
*
* @return the status of the operation when it finished.
*/
synchronized IStatus internalDoAnalyzeSyntactically(final IProgressMonitor monitor) {
if (!project.isAccessible() || !TITANNature.hasTITANNature(project)) {
return Status.CANCEL_STATUS;
}
MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
SubMonitor progress = SubMonitor.convert(monitor, 1);
progress.setTaskName("On-the-fly syntactic checking of project: " + project.getName());
IPreferencesService preferenceService = Platform.getPreferencesService();
boolean reportDebugInformation = preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
if (syntacticallyOutdated) {
syntacticallyOutdated = false;
long absoluteStart = System.nanoTime();
removedReferencestoRemovedFiles();
removeTTCNPPFilesIndirectlyModifiedByTTCNINFiles();
final IContainer[] workingDirectories = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryResources(false);
OutdatedFileCollector visitor = new OutdatedFileCollector(workingDirectories, uptodateFiles, highlySyntaxErroneousFiles);
try {
project.accept(visitor);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
final List<IFile> ttcn3FilesToCheck = visitor.getTTCN3FilesToCheck();
final List<IFile> asn1FilesToCheck = visitor.getASN1FilesToCheck();
final List<IFile> ttcninFilesModified = visitor.getTtcninFilesModified();
// nothing to do with these files
for (IFile f : ttcninFilesModified) {
uptodateFiles.put(f, f.getName());
includeFileMap.put(f.getName(), f);
}
List<IFile> allCheckedFiles = new ArrayList<IFile>();
allCheckedFiles.addAll(uptodateFiles.keySet());
// remove all markers from the files that need to be
// parsed
boolean useIncrementalParsing = preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEINCREMENTALPARSING, false, null);
for (IFile file : ttcn3FilesToCheck) {
// later these markings can be removed if they can be skipped
if (useIncrementalParsing) {
MarkerHandler.markAllMarkersForRemoval(file, GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
} else {
// TODO:is it not too much????
MarkerHandler.markAllOnTheFlyMarkersForRemoval(file);
}
if (!fileMap.containsKey(file)) {
ParserMarkerSupport.removeAllCompilerMarkers(file);
ParserMarkerSupport.removeAllOnTheFlyMarkers(file);
}
}
allCheckedFiles.addAll(ttcn3FilesToCheck);
for (IFile file : asn1FilesToCheck) {
if (useIncrementalParsing) {
MarkerHandler.markAllMarkersForRemoval(file, GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
} else {
// TODO:is it not too much????
MarkerHandler.markAllOnTheFlyMarkersForRemoval(file);
}
if (!fileMap.containsKey(file)) {
ParserMarkerSupport.removeAllCompilerMarkers(file);
ParserMarkerSupport.removeAllOnTheFlyMarkers(file);
}
}
allCheckedFiles.addAll(asn1FilesToCheck);
if (reportDebugInformation) {
TITANDebugConsole.println(" **Syntax check to be done on " + (ttcn3FilesToCheck.size() + asn1FilesToCheck.size()) + " files.", stream);
}
// parsing the files
final SubMonitor parseProgress = SubMonitor.convert(progress, ttcn3FilesToCheck.size() + asn1FilesToCheck.size());
parseProgress.setTaskName("Syntactically analyzing");
final ThreadPoolExecutor executor = new ThreadPoolExecutor(NUMBER_OF_PROCESSORS, NUMBER_OF_PROCESSORS, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
executor.setThreadFactory(new ThreadFactory() {
@Override
public Thread newThread(final Runnable r) {
Thread t = new Thread(r);
t.setPriority(LoadBalancingUtilities.getThreadPriority());
return t;
}
});
final TemporalParseData[] tempResults = new TemporalParseData[ttcn3FilesToCheck.size() + asn1FilesToCheck.size()];
int nofFilesProcessed = 0;
final CountDownLatch latch = new CountDownLatch(ttcn3FilesToCheck.size() + asn1FilesToCheck.size());
for (IFile file : ttcn3FilesToCheck) {
// canceled and the file is not yet up-to-date
if (parseProgress.isCanceled()) {
parseProgress.done();
return Status.CANCEL_STATUS;
} else if (!file.isAccessible()) {
if (reportDebugInformation) {
TITANDebugConsole.println("The file " + file.getLocationURI() + " does not seem to exist.", stream);
}
latch.countDown();
} else if (OutOfMemoryCheck.isOutOfMemory()) {
latch.countDown();
if (!OutOfMemoryCheck.isOutOfMemoryAlreadyReported()) {
OutOfMemoryCheck.outOfMemoryEvent();
return Status.CANCEL_STATUS;
}
} else if (!uptodateFiles.containsKey(file) && !highlySyntaxErroneousFiles.contains(file)) {
// exists at all, if no continue
if (file.isLinked()) {
File f = new File(file.getLocation().toOSString());
if (!f.exists()) {
if (reportDebugInformation) {
// MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
TITANDebugConsole.println("The file " + file.getLocationURI() + " does not seem to exist.", stream);
}
latch.countDown();
continue;
}
}
parseProgress.subTask(" file: " + file.getProjectRelativePath().toOSString());
// parse the contents of the file
final IFile tempFile = file;
final int index = nofFilesProcessed;
nofFilesProcessed++;
executor.execute(new Runnable() {
@Override
public void run() {
if (parseProgress.isCanceled()) {
latch.countDown();
parseProgress.worked(1);
return;
}
try {
TemporalParseData temp = fileBasedTTCN3Analysis(tempFile);
tempResults[index] = temp;
} finally {
latch.countDown();
parseProgress.worked(1);
LoadBalancingUtilities.syntaxAnalyzerProcessedAFile();
}
}
});
}
}
ttcn3FilesToCheck.clear();
for (IFile file : asn1FilesToCheck) {
// canceled and the file is not yet up-to-date
if (parseProgress.isCanceled()) {
parseProgress.done();
return Status.CANCEL_STATUS;
} else if (!file.isAccessible()) {
if (reportDebugInformation) {
TITANDebugConsole.println("The file " + file.getLocationURI() + " does not seem to exist.", stream);
}
latch.countDown();
} else if (OutOfMemoryCheck.isOutOfMemory()) {
latch.countDown();
if (!OutOfMemoryCheck.isOutOfMemoryAlreadyReported()) {
OutOfMemoryCheck.outOfMemoryEvent();
return Status.CANCEL_STATUS;
}
} else if (!uptodateFiles.containsKey(file) && !highlySyntaxErroneousFiles.contains(file)) {
parseProgress.subTask(" file: " + file.getProjectRelativePath().toOSString());
// parse the contents of the file
final IFile tempFile = file;
final int index = nofFilesProcessed;
nofFilesProcessed++;
executor.execute(new Runnable() {
@Override
public void run() {
if (parseProgress.isCanceled()) {
latch.countDown();
parseProgress.worked(1);
return;
}
try {
TemporalParseData temp = fileBasedASN1Analysis(tempFile);
tempResults[index] = temp;
} finally {
latch.countDown();
parseProgress.worked(1);
LoadBalancingUtilities.syntaxAnalyzerProcessedAFile();
}
}
});
}
}
asn1FilesToCheck.clear();
try {
latch.await();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
executor.shutdown();
try {
executor.awaitTermination(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
executor.shutdownNow();
for (TemporalParseData temp : tempResults) {
if (temp != null) {
postFileBasedGeneralAnalysis(temp);
}
}
parseProgress.done();
if (reportDebugInformation) {
// MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
TITANDebugConsole.println(" **It took " + (System.nanoTime() - absoluteStart) * (1e-9) + " seconds till the files (" + uptodateFiles.size() + " pieces) of project " + project.getName() + " got syntactically analyzed", stream);
}
} else {
if (reportDebugInformation) {
TITANDebugConsole.println(" **The project " + project.getName() + " does not seem to need syntax check.", stream);
}
progress.worked(1);
progress.done();
}
return Status.OK_STATUS;
}
use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceSyntacticAnalyzer method internalDoAnalyzeSyntactically2.
/**
* Internal function. Used by delayed semantic check. It differs from
* the base implementation in that it does not remove semantic markers,
* and does not try to refresh semantic structures.
*
* @param monitor
* the progress monitor to provide feedback to the user
* about the progress.
*
* @return the status of the operation when it finished.
*/
synchronized IStatus internalDoAnalyzeSyntactically2(final IProgressMonitor monitor) {
if (!project.isAccessible() || !TITANNature.hasTITANNature(project)) {
return Status.CANCEL_STATUS;
}
MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
SubMonitor progress = SubMonitor.convert(monitor, 1);
progress.setTaskName("On-the-fly syntactic checking of project: " + project.getName());
IPreferencesService preferenceService = Platform.getPreferencesService();
boolean reportDebugInformation = preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
if (syntacticallyOutdated) {
syntacticallyOutdated = false;
long absoluteStart = System.nanoTime();
removedReferencestoRemovedFiles();
final IContainer[] workingDirectories = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryResources(false);
OutdatedFileCollector visitor = new OutdatedFileCollector(workingDirectories, uptodateFiles, highlySyntaxErroneousFiles);
try {
project.accept(visitor);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
final List<IFile> ttcn3FilesToCheck = visitor.getTTCN3FilesToCheck();
final List<IFile> asn1FilesToCheck = visitor.getASN1FilesToCheck();
List<IFile> allCheckedFiles = new ArrayList<IFile>();
allCheckedFiles.addAll(uptodateFiles.keySet());
// parsed
for (IFile file : ttcn3FilesToCheck) {
MarkerHandler.markAllMarkersForRemoval(file, GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
MarkerHandler.markAllTaskMarkersForRemoval(file);
}
allCheckedFiles.addAll(ttcn3FilesToCheck);
for (IFile file : asn1FilesToCheck) {
MarkerHandler.markAllMarkersForRemoval(file, GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
MarkerHandler.markAllTaskMarkersForRemoval(file);
}
allCheckedFiles.addAll(asn1FilesToCheck);
if (reportDebugInformation) {
TITANDebugConsole.println(" **Syntax only check to be done on " + (ttcn3FilesToCheck.size() + asn1FilesToCheck.size()) + " files.", stream);
}
// parsing the files
final SubMonitor parseProgress = SubMonitor.convert(progress, ttcn3FilesToCheck.size() + asn1FilesToCheck.size());
parseProgress.setTaskName("Parse");
final ThreadPoolExecutor executor = new ThreadPoolExecutor(NUMBER_OF_PROCESSORS, NUMBER_OF_PROCESSORS, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
executor.setThreadFactory(new ThreadFactory() {
@Override
public Thread newThread(final Runnable r) {
Thread t = new Thread(r);
t.setPriority(LoadBalancingUtilities.getThreadPriority());
return t;
}
});
final TemporalParseData[] tempResults = new TemporalParseData[ttcn3FilesToCheck.size() + asn1FilesToCheck.size()];
int nofFilesProcessed = 0;
final CountDownLatch latch = new CountDownLatch(ttcn3FilesToCheck.size() + asn1FilesToCheck.size());
for (IFile file : ttcn3FilesToCheck) {
// canceled and the file is not yet up-to-date
if (parseProgress.isCanceled()) {
parseProgress.done();
return Status.CANCEL_STATUS;
} else if (!file.isAccessible()) {
if (reportDebugInformation) {
TITANDebugConsole.println("The file " + file.getLocationURI() + " does not seem to exist.", stream);
}
latch.countDown();
} else if (!uptodateFiles.containsKey(file) && !highlySyntaxErroneousFiles.contains(file)) {
parseProgress.subTask("Syntactically analyzing file: " + file.getProjectRelativePath().toOSString());
// parse the contents of the file
final IFile tempFile = file;
final int index = nofFilesProcessed;
nofFilesProcessed++;
executor.execute(new Runnable() {
@Override
public void run() {
if (parseProgress.isCanceled()) {
latch.countDown();
parseProgress.worked(1);
return;
}
TemporalParseData temp = fileBasedTTCN3Analysis(tempFile);
tempResults[index] = temp;
latch.countDown();
parseProgress.worked(1);
LoadBalancingUtilities.syntaxAnalyzerProcessedAFile();
}
});
}
}
ttcn3FilesToCheck.clear();
for (IFile file : asn1FilesToCheck) {
// canceled and the file is not yet up-to-date
if (parseProgress.isCanceled()) {
parseProgress.done();
return Status.CANCEL_STATUS;
} else if (!file.isAccessible()) {
if (reportDebugInformation) {
TITANDebugConsole.println("The file " + file.getLocationURI() + " does not seem to exist.", stream);
}
latch.countDown();
} else if (!uptodateFiles.containsKey(file) && !highlySyntaxErroneousFiles.contains(file)) {
parseProgress.subTask("Syntactically analyzing file: " + file.getProjectRelativePath().toOSString());
// parse the contents of the file
final IFile tempFile = file;
final int index = nofFilesProcessed;
nofFilesProcessed++;
executor.execute(new Runnable() {
@Override
public void run() {
if (parseProgress.isCanceled()) {
latch.countDown();
parseProgress.worked(1);
return;
}
TemporalParseData temp = fileBasedASN1Analysis(tempFile);
tempResults[index] = temp;
latch.countDown();
parseProgress.worked(1);
LoadBalancingUtilities.syntaxAnalyzerProcessedAFile();
}
});
}
}
asn1FilesToCheck.clear();
try {
latch.await();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
executor.shutdown();
try {
executor.awaitTermination(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace(e);
}
executor.shutdownNow();
MarkerHandler.removeAllOnTheFlyMarkedMarkers(project);
parseProgress.done();
if (reportDebugInformation) {
// MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
TITANDebugConsole.println(" **It took " + (System.nanoTime() - absoluteStart) * (1e-9) + " seconds till the files (" + uptodateFiles.size() + " pieces) of project " + project.getName() + " got syntactically analyzed", stream);
}
} else {
if (reportDebugInformation) {
TITANDebugConsole.println(" **The project " + project.getName() + " does not seem to need syntax only check.", stream);
}
progress.worked(1);
progress.done();
}
return Status.OK_STATUS;
}
use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class NativeWIN32TITANJob method setEnvironmentalVariables.
/**
* Sets the required environmental variables for the ProcessBuilder
* passed in as argument. This must be separated from the general
* behavior, because different operating systems might require different
* environmental variables.
* <p>
* This version is for native win32 and assumes that no transformation
* is needed.
*
* @param pb
* the ProcessBuilder whose environmental variables need
* to be set.
*
* @see TITANJob#runInWorkspace(IProgressMonitor)
* @see TITANJob#setEnvironmentalVariables(ProcessBuilder)
*/
@Override
protected void setEnvironmentalVariables(final ProcessBuilder pb) {
final IPreferencesService service = Platform.getPreferencesService();
final String pathOfTITAN = service.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.TITAN_INSTALLATION_PATH, "", null);
final Map<String, String> env = pb.environment();
if (License.isLicenseNeeded()) {
final String licenseFilePath = service.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.LICENSE_FILE_PATH, "", null);
env.put(TTCN3_LICENSE_FILE_KEY, licenseFilePath);
}
env.put(TTCN3_DIR_KEY, pathOfTITAN);
}
Aggregations