Home » Modeling » TMF (Xtext) » Build triggered when opening file in language implemented by Xtext
Build triggered when opening file in language implemented by Xtext [message #1773385] |
Wed, 27 September 2017 03:59  |
Eclipse User |
|
|
|
Hi everyone,
I am experiencing the following behavior in Xtext in our N4JS IDE (https://github.com/eclipse/n4js) developed by Xtext but also in JDT with Xtend language:
Given a workspace W with project P1, P2 to Pn. We build some Pi and cancel it in the middle. Now, when we open any file in any project Pj in a language developed by Xtext (e.g. Xtend, Xpect, N4JS), the build for Pi is triggered. This can be reproduced both in N4JS IDE and in JDT.
This seems to be Xtext behavior as this happens only to languages developed by Xtext such as Xtend, Xpect or N4JS. In JDT, opening .java files does NOT trigger a build but opening .xtend files DOES trigger a build.
Can anyone tell how to prevent this behavior from happening?
Thanks a lot!
Quang
|
|
| |
Re: Build triggered when opening file in language implemented by Xtext [message #1773423 is a reply to message #1773420] |
Wed, 27 September 2017 12:55   |
Eclipse User |
|
|
|
bautobuildjob is called from this stacktrace
Thread [main] (Suspended (breakpoint at line 523 in BuildManager))
owns: WorkspaceModifyDelegatingOperation (id=18482)
BuildManager.endTopLevel(boolean) line: 523
Workspace.endOperation(ISchedulingRule, boolean) line: 1484
Workspace.run(ICoreRunnable, ISchedulingRule, int, IProgressMonitor) line: 2253
Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor) line: 2267
WorkspaceModifyDelegatingOperation(WorkspaceModifyOperation).run(IProgressMonitor) line: 128
WorkspaceOperationRunner.run(IRunnableWithProgress, ISchedulingRule) line: 73
WorkspaceOperationRunner.run(boolean, boolean, IRunnableWithProgress) line: 63
XbaseDocumentProvider(AbstractDocumentProvider).executeOperation(AbstractDocumentProvider$DocumentProviderOperation, IProgressMonitor) line: 536
XbaseDocumentProvider(FileDocumentProvider).refreshFile(IFile, IProgressMonitor) line: 967
XbaseDocumentProvider(FileDocumentProvider).refreshFile(IFile) line: 939
XbaseDocumentProvider(FileDocumentProvider).createElementInfo(Object) line: 689
XbaseDocumentProvider(XtextDocumentProvider).createElementInfo(Object) line: 270
XbaseDocumentProvider.createElementInfo(Object) line: 111
XbaseDocumentProvider(AbstractDocumentProvider).connect(Object) line: 392
XtendEditor(AbstractTextEditor).doSetInput(IEditorInput) line: 4183
XtendEditor(StatusTextEditor).doSetInput(IEditorInput) line: 257
XtendEditor(AbstractDecoratedTextEditor).doSetInput(IEditorInput) line: 1465
XtendEditor(TextEditor).doSetInput(IEditorInput) line: 150
XtendEditor(XtextEditor).doSetInput(IEditorInput) line: 247
XtendEditor(XbaseEditor).doSetInput(IEditorInput) line: 120
AbstractTextEditor$5.run(IProgressMonitor) line: 3159
ModalContext.runInCurrentThread(IRunnableWithProgress, IProgressMonitor) line: 437
ModalContext.run(IRunnableWithProgress, boolean, IProgressMonitor, Display) line: 353
WorkbenchWindow$14.run() line: 2213
BusyIndicator.showWhile(Display, Runnable) line: 70
WorkbenchWindow.run(boolean, boolean, IRunnableWithProgress) line: 2209
XtendEditor(AbstractTextEditor).internalInit(IWorkbenchWindow, IEditorSite, IEditorInput) line: 3177
XtendEditor(AbstractTextEditor).init(IEditorSite, IEditorInput) line: 3202
XtendEditor(XtextEditor).init(IEditorSite, IEditorInput) line: 288
EditorReference.initialize(IWorkbenchPart) line: 362
CompatibilityEditor(CompatibilityPart).create() line: 333
GeneratedMethodAccessor138.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 498
MethodRequestor.execute() line: 55
InjectorImpl.processAnnotated(Class<Annotation>, Object, Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier, ArrayList<Class<?>>) line: 990
InjectorImpl.processAnnotated(Class<Annotation>, Object, Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier, ArrayList<Class<?>>) line: 955
InjectorImpl.inject(Object, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 124
InjectorImpl.internalMake(Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 399
InjectorImpl.make(Class<T>, PrimaryObjectSupplier) line: 318
ContextInjectionFactory.make(Class<T>, IEclipseContext) line: 162
ReflectionContributionFactory.createFromBundle(Bundle, IEclipseContext, IEclipseContext, URI) line: 105
ReflectionContributionFactory.doCreate(String, IEclipseContext, IEclipseContext) line: 74
ReflectionContributionFactory.create(String, IEclipseContext) line: 56
ContributedPartRenderer.createWidget(MUIElement, Object) line: 129
PartRenderingEngine.createWidget(MUIElement, Object) line: 992
PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 661
PartRenderingEngine.safeCreateGui(MUIElement) line: 767
PartRenderingEngine.access$0(PartRenderingEngine, MUIElement) line: 738
PartRenderingEngine$2.run() line: 732
SafeRunner.run(ISafeRunnable) line: 42
PartRenderingEngine.createGui(MUIElement) line: 716
PartServiceImpl$1.handleEvent(Event) line: 104
UIEventHandler$1.run() line: 40
UISynchronizer(Synchronizer).syncExec(Runnable) line: 233
UISynchronizer.syncExec(Runnable) line: 144
Display.syncExec(Runnable) line: 4885
E4Application$1.syncExec(Runnable) line: 212
UIEventHandler.handleEvent(Event) line: 36
EventHandlerWrapper.handleEvent(Event, Permission) line: 201
EventHandlerTracker.dispatchEvent(EventHandlerWrapper, Permission, int, Event) line: 196
EventHandlerTracker.dispatchEvent(Object, Object, int, Object) line: 1
EventManager.dispatchEvent(Set<Entry<K,V>>, EventDispatcher<K,V,E>, int, E) line: 230
ListenerQueue<K,V,E>.dispatchEventSynchronous(int, E) line: 148
EventAdminImpl.dispatchEvent(Event, boolean) line: 135
EventAdminImpl.sendEvent(Event) line: 78
EventComponent.sendEvent(Event) line: 39
EventBroker.send(String, Object) line: 52
UIEventPublisher.notifyChanged(Notification) line: 60
PartStackImpl(BasicNotifierImpl).eNotify(Notification) line: 374
PartStackImpl(ElementContainerImpl<T>).setSelectedElement(T) line: 173
ModelServiceImpl.showElementInWindow(MWindow, MUIElement) line: 620
ModelServiceImpl.bringToTop(MUIElement) line: 584
PartServiceImpl.delegateBringToTop(MPart) line: 769
PartServiceImpl.bringToTop(MPart) line: 401
PartServiceImpl.showPart(MPart, EPartService$PartState) line: 1214
WorkbenchPage.busyOpenEditor(IEditorInput, String, boolean, int, IMemento, boolean) line: 3261
WorkbenchPage.access$25(WorkbenchPage, IEditorInput, String, boolean, int, IMemento, boolean) line: 3176
WorkbenchPage$10.run() line: 3158
BusyIndicator.showWhile(Display, Runnable) line: 70
WorkbenchPage.openEditor(IEditorInput, String, boolean, int, IMemento, boolean) line: 3153
WorkbenchPage.openEditor(IEditorInput, String, boolean, int) line: 3117
WorkbenchPage.openEditor(IEditorInput, String, boolean) line: 3107
IDE.openEditor(IWorkbenchPage, IFile, boolean, boolean) line: 563
IDE.openEditor(IWorkbenchPage, IFile, boolean) line: 518
EditorUtility.openInEditor(IFile, boolean) line: 360
EditorUtility.openInEditor(Object, boolean) line: 167
OpenAction.run(Object[]) line: 256
OpenAction.run(IStructuredSelection) line: 221
OpenAction(SelectionDispatchAction).dispatchRun(ISelection) line: 271
OpenAction(SelectionDispatchAction).run() line: 249
PackageExplorerActionGroup.handleOpen(ISelection, boolean) line: 379
PackageExplorerPart$4.open(ISelection, boolean) line: 540
OpenAndLinkWithEditorHelper$InternalListener.open(OpenEvent) line: 46
StructuredViewer$2.run() line: 851
SafeRunner.run(ISafeRunnable) line: 42
JFaceUtil.lambda$0(ISafeRunnable) line: 44
508864177.run(ISafeRunnable) line: not available
SafeRunnable.run(ISafeRunnable) line: 173
PackageExplorerPart$PackageExplorerProblemTreeViewer(StructuredViewer).fireOpen(OpenEvent) line: 848
PackageExplorerPart$PackageExplorerProblemTreeViewer(StructuredViewer).handleOpen(SelectionEvent) line: 1163
755583709.handleOpen(SelectionEvent) line: not available
OpenStrategy.fireOpenEvent(SelectionEvent) line: 273
OpenStrategy.access$2(OpenStrategy, SelectionEvent) line: 268
OpenStrategy$1.handleEvent(Event) line: 308
EventTable.sendEvent(Event) line: 86
Display.sendEvent(EventTable, Event) line: 4272
Tree(Widget).sendEvent(Event) line: 1509
Tree(Widget).sendEvent(int, Event, boolean) line: 1532
Tree(Widget).sendEvent(int, Event) line: 1517
Tree(Widget).notifyListeners(int, Event) line: 1321
Display.runDeferredEvents() line: 4096
Display.readAndDispatch() line: 3713
PartRenderingEngine$5.run() line: 1150
Realm.runWithDefault(Realm, Runnable) line: 336
PartRenderingEngine.run(MApplicationElement, IEclipseContext) line: 1039
E4Workbench.createAndRunUI(MApplicationElement) line: 153
Workbench.lambda$3(Display, WorkbenchAdvisor, int[]) line: 680
321795476.run() line: not available
Realm.runWithDefault(Realm, Runnable) line: 336
Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 594
PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 148
IDEApplication.start(IApplicationContext) line: 151
EclipseAppHandle.run(Object) line: 196
EclipseAppLauncher.runApplication(Object) line: 134
EclipseAppLauncher.start(Object) line: 104
EclipseStarter.run(Object) line: 388
EclipseStarter.run(String[], Runnable) line: 243
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 498
Main.invokeFramework(String[], URL[]) line: 653
Main.basicRun(String[]) line: 590
Main.run(String[]) line: 1499
Main.main(String[]) line: 1472
|
|
| | | | | | | | | | |
Re: Build triggered when opening file in language implemented by Xtext [message #1773839 is a reply to message #1773574] |
Thu, 05 October 2017 08:16   |
Eclipse User |
|
|
|
Being desperate, I tried to override XtextDocumentProvider and remove the refresh part manually. It seems to work in our N4JS IDE. Admittedly, it is really ugly.
/**
* This class customizes XtextDocumentProvider to prevent builds from being triggered when opening files. See:
* https://www.eclipse.org/forums/index.php/t/1089089/
*/
public class N4JSDocumentProvider extends XtextDocumentProvider {
@Override
protected ElementInfo createElementInfo(Object element) throws CoreException {
ElementInfo info;
if (isWorkspaceExternalEditorInput(element)) {
IDocument document = null;
IStatus status = null;
try {
document = createDocument(element);
} catch (CoreException x) {
status = x.getStatus();
document = createEmptyDocument();
}
info = new URIInfo(document, createAnnotationModel(element));
info.fStatus = status;
} else {
info = _createElementInfo(element);
}
registerAnnotationInfoProcessor(info);
return info;
}
/** Copied from {@link FileDocumentProvider#createElementInfo} */
private ElementInfo _createElementInfo(Object element) throws CoreException {
if (element instanceof IFileEditorInput) {
IFileEditorInput input = (IFileEditorInput) element;
// Custom behavior: Do NOT refresh file
// try {
// refreshFile(input.getFile());
// } catch (CoreException x) {
// handleCoreException(x, TextEditorMessages.FileDocumentProvider_createElementInfo);
// }
IDocument d = null;
IStatus s = null;
try {
d = createDocument(element);
} catch (CoreException x) {
handleCoreException(x, "N4JSDocumentProvider.createElementInfo");
s = x.getStatus();
d = createEmptyDocument();
}
// Set the initial line delimiter
if (d instanceof IDocumentExtension4) {
String initalLineDelimiter = getLineDelimiterPreference(input.getFile());
if (initalLineDelimiter != null)
((IDocumentExtension4) d).setInitialLineDelimiter(initalLineDelimiter);
}
IAnnotationModel m = createAnnotationModel(element);
FileSynchronizer f = new FileSynchronizer(input);
f.install();
FileInfo info = new FileInfo(d, m, f);
info.fModificationStamp = computeModificationStamp(input.getFile());
info.fStatus = s;
info.fEncoding = getPersistedEncoding(element);
// info.fBOM = getBOM(element);
// Use reflection to set the private field info.fBOM
Field field;
try {
field = FileInfo.class.getDeclaredField("fBOM");
field.setAccessible(true);
field.set(info, getBOM(element));
} catch (NoSuchFieldException | SecurityException e) {
// Do nothing
} catch (IllegalArgumentException x) {
// Do nothing
} catch (IllegalAccessException x) {
// Do nothing
}
/*
* The code below is a no-op in the implementation in this class because the info is not yet stored in the
* element map. Calling to not break clients who have overridden the method. see
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=109255
*/
cacheEncodingState(element);
return info;
}
return super.createElementInfo(element);
}
/**
* Returns the default line delimiter preference for the given file.
*
* @param file
* the file
* @return the default line delimiter
* @since 3.1
*/
private String getLineDelimiterPreference(IFile file) {
IScopeContext[] scopeContext;
if (file != null && file.getProject() != null) {
// project preference
scopeContext = new IScopeContext[] { new ProjectScope(file.getProject()) };
String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME,
Platform.PREF_LINE_SEPARATOR, null, scopeContext);
if (lineDelimiter != null)
return lineDelimiter;
}
// workspace preference
scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null,
scopeContext);
}
/**
* Returns whether the underlying file has a BOM.
*
* @param element
* the element, or <code>null</code>
* @return <code>true</code> if the underlying file has BOM
*/
private byte[] getBOM(Object element) {
if (element instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) element).getFile();
if (file != null) {
try {
IContentDescription description = file.getContentDescription();
if (description != null)
return (byte[]) description.getProperty(IContentDescription.BYTE_ORDER_MARK);
} catch (CoreException ex) {
return null;
}
}
}
return null;
}
}
|
|
| | | | | | | | | | | |
Re: Build triggered when opening file in language implemented by Xtext [message #1773959 is a reply to message #1773927] |
Sat, 07 October 2017 11:26  |
Eclipse User |
|
|
|
Hi Quang,
the XtextDocumentProvider provides the XtextDocument. The document is the owner of a resource set. Pretty much all the UI services are implemented based on the assumption that one document is associated with one resource set. Therefore, the document itself is the synchronization point for all modifications of the resource set. This is more or less the base line for the following argumentation:
The FileDocumentProvider implements a very simple model when it comes to writing changes to disk. Everything works directly with the resource API of Eclipse. Thus the platform:/resource URIs work rather reliably when it comes to loading referenced resources into the resource set. The TextFileDocumentProvider on the contrary works on the granularity buffers. Buffers implement an indirection between the document and the resource API of Eclipse. And they are shared across editors. Thus the synchronization does not happen anymore on the resource API level, but on the file buffer managers level. This is prone to errors / deadlocks given the different locking mechanisms for the buffers and on the documents.
Digging through the code a little bit more, I assume that it is possible to implement a kind-of working solution, but it appears to be significant effort.
Maybe we can discuss this next week.
Best
Sebastian
|
|
|
Goto Forum:
Current Time: Wed Jul 23 18:38:19 EDT 2025
Powered by FUDForum. Page generated in 0.06819 seconds
|