use of org.eclipse.core.runtime.SubMonitor in project xtext-xtend by eclipse.
the class XtendLibClasspathAdder method addLibsToClasspath.
public void addLibsToClasspath(IJavaProject javaProject, IProgressMonitor monitor) {
try {
SubMonitor progress = SubMonitor.convert(monitor, 2);
IProject project = javaProject.getProject();
if (!project.hasNature(PLUGIN_NATURE) || !addToPluginManifest(project, progress.newChild(1)))
addToClasspath(javaProject, progress.newChild(1));
} catch (Exception exc) {
LOG.error("Error adding Xtend libs to classpath", exc);
}
}
use of org.eclipse.core.runtime.SubMonitor in project AutoRefactor by JnRouvignac.
the class ApplyRefactoringsJob method run0.
private IStatus run0(IProgressMonitor monitor) throws Exception {
if (refactoringUnits.isEmpty()) {
// No java project exists.
return Status.OK_STATUS;
}
final SubMonitor loopMonitor = SubMonitor.convert(monitor, refactoringUnits.size());
try {
RefactoringUnit toRefactor;
while ((toRefactor = refactoringUnits.poll()) != null) {
final ICompilationUnit compilationUnit = toRefactor.getCompilationUnit();
final JavaProjectOptions options = toRefactor.getOptions();
try {
loopMonitor.subTask("Applying refactorings to " + getClassName(compilationUnit));
final AggregateASTVisitor refactoring = new AggregateASTVisitor(refactoringRulesToApply);
applyRefactoring(compilationUnit, refactoring, options, loopMonitor.newChild(1));
} catch (OperationCanceledException e) {
throw e;
} catch (Exception e) {
final String msg = "Exception when applying refactorings to file \"" + compilationUnit.getPath() + "\": " + e.getMessage();
throw new UnhandledException(null, msg, e);
}
}
} finally {
loopMonitor.done();
}
return Status.OK_STATUS;
}
use of org.eclipse.core.runtime.SubMonitor in project eclipse.platform.text by eclipse.
the class FileBufferOperationHandler method doRun.
/**
* Runs the given operation.
*
* @param files the file on which to run this operation
* @param location the file buffer location
* @param fileBufferOperation the operation to run
*/
protected final void doRun(final IFile[] files, final IPath location, final IFileBufferOperation fileBufferOperation) {
Job job = new Job(fileBufferOperation.getOperationName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus status;
try {
int ticks = 100;
SubMonitor subMonitor = SubMonitor.convert(monitor, fFileBufferOperation.getOperationName(), ticks);
IPath[] locations;
if (files != null) {
ticks -= 30;
locations = generateLocations(files, subMonitor.split(30));
} else
locations = new IPath[] { location };
if (locations != null && locations.length > 0) {
FileBufferOperationRunner runner = new FileBufferOperationRunner(FileBuffers.getTextFileBufferManager(), getShell());
runner.execute(locations, fileBufferOperation, subMonitor.split(ticks));
}
status = Status.OK_STATUS;
} catch (OperationCanceledException e) {
// $NON-NLS-1$
status = new Status(IStatus.CANCEL, EditorsUI.PLUGIN_ID, IStatus.OK, "", null);
} catch (CoreException e) {
// $NON-NLS-1$
status = new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IStatus.OK, "", e);
}
return status;
}
};
job.setUser(true);
job.schedule();
}
use of org.eclipse.core.runtime.SubMonitor in project eclipse.platform.text by eclipse.
the class ResourceTextFileBuffer method commitFileBufferContent.
@Override
protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException {
if (!isSynchronized() && !overwrite) {
String message = NLSUtility.format(FileBuffersMessages.FileBuffer_error_outOfSync, getFileStore().toURI());
throw new CoreException(new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IResourceStatus.OUT_OF_SYNC_LOCAL, message, null));
}
String encoding = computeEncoding();
if (fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16.equals(encoding))
encoding = CHARSET_UTF_16LE;
Charset charset;
try {
charset = Charset.forName(encoding);
} catch (UnsupportedCharsetException ex) {
String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_unsupported_encoding_message_arg, encoding);
IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, ex);
throw new CoreException(s);
} catch (IllegalCharsetNameException ex) {
String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_illegal_encoding_message_arg, encoding);
IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, ex);
throw new CoreException(s);
}
CharsetEncoder encoder = charset.newEncoder();
encoder.onMalformedInput(CodingErrorAction.REPLACE);
encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
InputStream stream;
try {
byte[] bytes;
ByteBuffer byteBuffer = encoder.encode(CharBuffer.wrap(fDocument.get()));
if (byteBuffer.hasArray())
bytes = byteBuffer.array();
else {
bytes = new byte[byteBuffer.limit()];
byteBuffer.get(bytes);
}
stream = new ByteArrayInputStream(bytes, 0, byteBuffer.limit());
} catch (CharacterCodingException ex) {
Assert.isTrue(ex instanceof UnmappableCharacterException);
String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_charset_mapping_failed_message_arg, encoding);
IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.CHARSET_MAPPING_FAILED, message, ex);
throw new CoreException(s);
}
/*
* XXX:
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
if (fBOM == IContentDescription.BOM_UTF_8 && CHARSET_UTF_8.equals(encoding))
stream = new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), stream);
if (fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16LE.equals(encoding))
stream = new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_16LE), stream);
if (fFile.exists()) {
// here the file synchronizer should actually be removed and afterwards added again. However,
// we are already inside an operation, so the delta is sent AFTER we have added the listener
fFile.setContents(stream, overwrite, true, monitor);
if (fDocument instanceof IDocumentExtension4) {
fSynchronizationStamp = ((IDocumentExtension4) fDocument).getModificationStamp();
fFile.revertModificationStamp(fSynchronizationStamp);
} else
fSynchronizationStamp = fFile.getModificationStamp();
if (fAnnotationModel instanceof IPersistableAnnotationModel) {
IPersistableAnnotationModel persistableModel = (IPersistableAnnotationModel) fAnnotationModel;
persistableModel.commit(fDocument);
}
} else {
SubMonitor subMonitor = SubMonitor.convert(monitor, FileBuffersMessages.ResourceTextFileBuffer_task_saving, 2);
ContainerCreator creator = new ContainerCreator(fFile.getWorkspace(), fFile.getParent().getFullPath());
creator.createContainer(subMonitor.split(1));
fFile.create(stream, false, subMonitor.split(1));
// set synchronization stamp to know whether the file synchronizer must become active
fSynchronizationStamp = fFile.getModificationStamp();
subMonitor.split(1);
// TODO commit persistable annotation model
}
}
use of org.eclipse.core.runtime.SubMonitor in project eclipse.platform.text by eclipse.
the class ContainerCreator method createProject.
private IProject createProject(IProject projectHandle, IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
projectHandle.create(subMonitor.split(1));
projectHandle.open(subMonitor.split(1));
return projectHandle;
}
Aggregations