use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class BrokenPartsViaReferences method execute.
public void execute() {
if (writeDebugInfo) {
TITANDebugConsole.println(String.format(format, header, simpleDateFormat.format(new Date())));
}
start = System.nanoTime();
final List<Module> startModules = collectStartModules(allModules);
final Map<Module, List<Module>> invertedImports = buildInvertedImportStructure(allModules, startModules);
computeAnalyzeOnlyDefinitionsFlag(allModules, startModules);
if (analyzeOnlyAssignments) {
final IPreferencesService preferenceService = Platform.getPreferencesService();
final boolean useIncrementalParsing = preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEINCREMENTALPARSING, false, null);
final Map<Module, List<AssignmentHandler>> result = collectBrokenParts(startModules, invertedImports, useIncrementalParsing);
if (writeDebugInfo && !isTooSlow()) {
writeDebugInfo(result);
}
collectRealBrokenParts(result, useIncrementalParsing);
}
if (writeDebugInfo && isTooSlow()) {
TITANDebugConsole.println(" Switching back to old selection format");
}
// if we need to use the old selection or the new selection method took too long
if (!analyzeOnlyAssignments || isTooSlow()) {
analyzeOnlyAssignments = false;
modulesToCheck.clear();
moduleAndBrokenAssignments.clear();
final List<Module> modules = collectBrokenModulesViaInvertedImports(startModules, invertedImports);
modulesToCheck.addAll(modules);
}
afterExecute();
end = System.nanoTime() - start;
if (writeDebugInfo) {
TITANDebugConsole.println(String.format(format, footer, simpleDateFormat.format(new Date())));
infoAfterExecute();
}
}
use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class TITANJob method runInWorkspace.
/**
* Runs the list of commands that it has to process.
* <p>
* <ul>
* <li>switch to the working directory.
* <li>in cycle it executes the actual command, and parses the output
* for errors.
* </ul>
*
* @see OutputAnalyzer
*
* @param monitor
* the progress monitor to report progress on.
*
* @return the status of the operation when it finishes.
*/
@Override
public final IStatus runInWorkspace(final IProgressMonitor monitor) {
final IProgressMonitor internalMonitor = monitor == null ? new NullProgressMonitor() : monitor;
if (commands == null || descriptions == null || commands.size() != descriptions.size()) {
return Status.CANCEL_STATUS;
}
final IPreferencesService prefs = Platform.getPreferencesService();
if (Cygwin.isMissingInOSWin32()) {
if (!reportedNoCygwin) {
ErrorReporter.logError(CYGWIN);
final List<String> al = new ArrayList<String>();
al.add(CYGWIN);
reportExecutionProblem(project, prefs, getName(), al, null, true);
// do not report it next time!
reportedNoCygwin = true;
}
return Status.CANCEL_STATUS;
}
internalMonitor.beginTask(getName(), commands.size());
Activator.getDefault().pauseHandlingResourceChanges();
final ProcessBuilder pb = new ProcessBuilder();
setEnvironmentalVariables(pb);
pb.directory(workingDir);
pb.redirectErrorStream(true);
Process proc = null;
final MessageConsoleStream stream = TITANConsole.getConsole().newMessageStream();
String line;
BufferedReader stdout;
if (removeCompilerMarkers || removeOnTheFlyMarkers) {
if (removeCompilerMarkers) {
MarkerHandler.markMarkersForRemoval(GeneralConstants.COMPILER_ERRORMARKER, project);
MarkerHandler.markMarkersForRemoval(GeneralConstants.COMPILER_WARNINGMARKER, project);
MarkerHandler.markMarkersForRemoval(GeneralConstants.COMPILER_INFOMARKER, project);
}
if (removeOnTheFlyMarkers) {
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SEMANTIC_MARKER, project);
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, project);
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_MIXED_MARKER, project);
}
for (IFile file : files.values()) {
if (removeCompilerMarkers) {
MarkerHandler.markMarkersForRemoval(GeneralConstants.COMPILER_ERRORMARKER, file);
MarkerHandler.markMarkersForRemoval(GeneralConstants.COMPILER_WARNINGMARKER, file);
MarkerHandler.markMarkersForRemoval(GeneralConstants.COMPILER_INFOMARKER, file);
}
if (removeOnTheFlyMarkers) {
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SEMANTIC_MARKER, file);
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, file);
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_MIXED_MARKER, file);
}
}
}
OutputAnalyzer analyzer = new OutputAnalyzer(files, project);
for (int i = 0; i < commands.size(); i++) {
if (internalMonitor.isCanceled()) {
internalMonitor.done();
analyzer.dispose();
analyzer = null;
clearBeforeFinish();
return Status.CANCEL_STATUS;
}
setName(descriptions.get(i));
final List<String> finalCommand = getFinalCommand(commands.get(i));
final StringBuilder builder = new StringBuilder();
for (String c : finalCommand) {
builder.append(c + SPACE);
}
TITANConsole.println(builder.toString(), stream);
pb.command(finalCommand);
try {
proc = pb.start();
} catch (IOException e) {
TITANConsole.println(ExternalTitanAction.EXECUTION_FAILED, stream);
ErrorReporter.logExceptionStackTrace(e);
reportExecutionProblem(project, prefs, getName(), finalCommand, null, false);
foundErrors = true;
internalMonitor.done();
analyzer.dispose();
analyzer = null;
if (proc != null) {
proc.destroy();
}
clearBeforeFinish();
return Status.CANCEL_STATUS;
}
stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
final BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
try {
while ((line = stdout.readLine()) != null) {
if (internalMonitor.isCanceled()) {
internalMonitor.done();
analyzer.dispose();
analyzer = null;
proc.destroy();
clearBeforeFinish();
return Status.CANCEL_STATUS;
}
analyzer.parseTitanErrors(line);
TITANConsole.println(line, stream);
}
int exitval = proc.waitFor();
if ((exitval == 0) && (analyzer.hasProcessedErrorMessages())) {
// make returns error if there was a linker error, but does not propagate the error code
exitval = analyzer.getExternalErrorCode();
}
if (exitval != 0) {
TITANConsole.println(FAILURE + exitval, stream);
if (!analyzer.hasProcessedErrorMessages()) {
if (stderr.ready()) {
final StringBuilder builder2 = new StringBuilder();
while ((line = stderr.readLine()) != null) {
builder2.append(line);
}
reportExecutionProblem(project, prefs, getName(), finalCommand, builder2.toString(), false);
} else {
reportExecutionProblem(project, prefs, getName(), finalCommand, null, false);
}
}
foundErrors = true;
internalMonitor.done();
analyzer.dispose();
analyzer = null;
proc.destroy();
clearBeforeFinish();
return Status.CANCEL_STATUS;
}
TITANConsole.println(SUCCESS, stream);
} catch (IOException e) {
TITANConsole.println(ExternalTitanAction.EXECUTION_FAILED, stream);
ErrorReporter.logExceptionStackTrace(ExternalTitanAction.EXECUTION_FAILED, e);
} catch (InterruptedException e) {
TITANConsole.println(ExternalTitanAction.INTERRUPTION, stream);
ErrorReporter.logExceptionStackTrace(ExternalTitanAction.INTERRUPTION, e);
} finally {
try {
stdout.close();
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
}
try {
stderr.close();
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
internalMonitor.worked(1);
}
internalMonitor.done();
analyzer.dispose();
clearBeforeFinish();
return Status.OK_STATUS;
}
use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class ExternalMakefileGenerator method createMakefileGeneratorCommand.
/**
* Creates the commandline command to be used to generate the Makefile for the passed project.
*
* @param project the project to generate the Makefile for
*/
public static List<String> createMakefileGeneratorCommand(final IProject project) {
final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, false, null);
final TITANBuilderResourceVisitor visitor = ProjectBasedBuilder.getProjectBasedBuilder(project).getResourceVisitor();
final Map<String, IFile> files = visitor.getFiles();
final Map<String, IFile> centralStorageFiles = visitor.getCentralStorageFiles();
final Map<String, IFile> referencedFiles = ProjectBasedBuilder.getProjectBasedBuilder(project).getFilesofReferencedProjects();
final List<String> command = new ArrayList<String>();
final IPreferencesService prefs = Platform.getPreferencesService();
final String pathOfTITAN = prefs.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.TITAN_INSTALLATION_PATH, "", null);
final Path makefilegenPath = new Path(pathOfTITAN + File.separatorChar + BIN_DIRECTORY + File.separatorChar + MAKEFILEGENERATOR);
command.add(PathConverter.convert(makefilegenPath.toOSString(), reportDebugInformation, TITANDebugConsole.getConsole()));
final String decoratorParametersLong = TITANDecorator.propertiesAsParameters(project, true);
if (!EMPTY_STRING.equals(decoratorParametersLong)) {
final String[] parameters = decoratorParametersLong.split(" ");
for (int i = 0; i < parameters.length; i++) {
command.add(parameters[i]);
}
}
SymbolicLinkHandler.createSymlinks(project);
for (final String path : files.keySet()) {
command.add(APOSTROPHE + path + APOSTROPHE);
}
final IPath centralStorageDirectoryPath = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryPath(true);
final String centralStorageDirectory = centralStorageDirectoryPath.toOSString();
for (final String fileName : centralStorageFiles.keySet()) {
final IFile file = centralStorageFiles.get(fileName);
final IProject otherProject = file.getProject();
final IPath referencedCentralStorageDirectoryPath = ProjectBasedBuilder.getProjectBasedBuilder(otherProject).getWorkingDirectoryPath(true);
final String referencedCentralStorageDirectory = referencedCentralStorageDirectoryPath.toOSString();
final String relativePathToDirectory = PathUtil.getRelativePath(centralStorageDirectory, referencedCentralStorageDirectory);
final Path relativePath = new Path(relativePathToDirectory);
final String path = relativePath.append(fileName).toOSString();
command.add(APOSTROPHE + PathConverter.convert(path, reportDebugInformation, TITANDebugConsole.getConsole()) + APOSTROPHE);
}
final IPath workingDirectoryPath = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryPath(true);
final String workingDirectory = workingDirectoryPath.toOSString();
for (final String fileName : referencedFiles.keySet()) {
final IFile file = referencedFiles.get(fileName);
final IProject otherProject = file.getProject();
final IPath referencedWorkingDirectoryPath = ProjectBasedBuilder.getProjectBasedBuilder(otherProject).getWorkingDirectoryPath(true);
final String referencedWorkingDirectory = referencedWorkingDirectoryPath.toOSString();
final String relativePathToDirectory = PathUtil.getRelativePath(workingDirectory, referencedWorkingDirectory);
final Path relativePath = new Path(relativePathToDirectory);
final String path = relativePath.append(fileName).toOSString();
command.add(APOSTROPHE + PathConverter.convert(path, reportDebugInformation, TITANDebugConsole.getConsole()) + APOSTROPHE);
}
return command;
}
use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class ConvertXSD2TTCN method doConversion.
/**
* Do the actual work of converting the selected files to TTCN-3
*/
private void doConversion() {
if (!TITANInstallationValidator.check(true)) {
return;
}
if (!LicenseValidator.check()) {
return;
}
processSelection();
if (files == null || files.isEmpty()) {
ErrorReporter.parallelErrorDisplayInMessageDialog(JOB_TITLE + FAILURE_SUFFIX, NO_VALID_FILES);
return;
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
final DirectoryDialog dialog = new DirectoryDialog(new Shell(Display.getDefault()), SWT.SAVE | SWT.PRIMARY_MODAL | SWT.FOCUSED | SWT.ON_TOP);
dialog.setFilterPath(project.getLocation().toOSString());
String outFolder = dialog.open();
if (outFolder != null) {
outFolder = outFolder.trim();
if (outFolder.length() > 0) {
setOutputFolder(new File(outFolder));
}
}
}
});
if (outputFolder == null) {
return;
}
final TITANJob titanJob = new TITANJob(JOB_TITLE, files, outputFolder, project);
titanJob.setPriority(Job.DECORATE);
titanJob.setUser(true);
titanJob.setRule(project);
final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, false, null);
final List<String> command = new ArrayList<String>();
final IPreferencesService prefs = Platform.getPreferencesService();
final String pathOfTITAN = prefs.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.TITAN_INSTALLATION_PATH, "", null);
command.add(PathConverter.convert(new Path(pathOfTITAN + File.separatorChar + "bin" + File.separatorChar + "xsd2ttcn").toOSString(), reportDebugInformation, TITANDebugConsole.getConsole()));
for (String filePath : files.keySet()) {
command.add('\'' + filePath + '\'');
}
titanJob.addCommand(command, JOB_TITLE);
titanJob.removeCompilerMarkers();
final String markersAfterCompiler = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.ONTHEFLYMARKERSAFTERCOMPILER, PreferenceConstantValues.ONTHEFLYOPTIONREMOVE, null);
if (PreferenceConstantValues.ONTHEFLYOPTIONREMOVE.equals(markersAfterCompiler)) {
titanJob.removeOnTheFlyMarkers();
}
titanJob.schedule();
}
use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.
the class ExternalTitanAction method buildFileList.
/**
* Adds every file in the given resource to the list of checked files.
*
* @param resource
* The resource whose files are to be added to the list
* of files to be checked
*/
public final void buildFileList(final IResource resource) {
if (resource == null) {
return;
}
project = resource.getProject();
if (!project.isAccessible() || !resource.isAccessible()) {
return;
}
workingDir = new File(project.getLocation().toOSString());
final IPreferencesService prefs = Platform.getPreferencesService();
final boolean processExludedOnes = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.TITANACTIONS_PROCESSEXCLUDEDRESOURCES, true, null);
try {
// Is the source already in an excluded folder ?
if (!processExludedOnes) {
IContainer parent = resource.getParent();
while (parent != null && parent instanceof IFolder) {
if (ResourceExclusionHelper.isDirectlyExcluded((IFolder) parent)) {
return;
}
parent = parent.getParent();
}
}
resource.accept(new InternalResourceVisitor(processExludedOnes));
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
Aggregations