hallvard / plantuml

Embed UML diagrams in files and view them in Eclipse
http://plantuml.sourceforge.net/
212 stars 58 forks source link

After update to 1.1.25 certain diagrams with Windows' line endings don't render #128

Closed Lutz13 closed 3 years ago

Lutz13 commented 3 years ago

So far I was able to edit a digram-code in Eclipse text editor (file extension: *.puml), and the diagram was automatically generated and shown in the PlantUML view. After updating the plugin to version 1.1.25 today, the diagram is no longer generated, whatever I try. Eclipse: Version: 2021-03 (4.19.0) Build id: 20210312-0638

hallvard commented 3 years ago

Could you also check the PlantUML source view?

danieleb2000 commented 3 years ago

For me the same. The diagram generated only if the text is rewritten from scratch. No diagram is (re-)generated after opening or modifying an existing one. Only PlantUML source view is correctly updated with the text. Same on Eclipse 2019 and Eclipse 2021.

hallvard commented 3 years ago

If the source view is updated, we at least know that the views are correctly triggered by changes in the editor, but something must be happening when the text is converted to a diagram. No entries in the Error log view?

I'm a bit confused when you say "rewritten from scratch", do you mean removing and recreating the file, or clearing the editor before reentering the (same) code? Could you provide a sample file?

danieleb2000 commented 3 years ago

If I create a new txt file from scratch, and write @startuml and so on, the diagram is shown. But if a txt file is preexisting, the diagram is never shown, no matter what content it has and even after changing it or clearing and paste back the same code. With 1.24 this never happens.

hallvard commented 3 years ago

I must admit I haven't a clue, as I couldn't reproduce it. Perhaps we could have a screen sharing session with e.g. Teams where you can show it to me.

danieleb2000 commented 3 years ago

I also tried with the following combination, still same issue:

PlantUML Ecore Feature 1.24 PlantUML Feature 1.25 PlantUML Library 2021

It seems the issue depends on PlantUML Feature 1.25 or PlantUML Library 2021.

Other combinations are not possible since not compatible (according to the update attempt).

danieleb2000 commented 3 years ago

Probaby one of the following two features for 1.25 introduced the issue:

hallvard commented 3 years ago

Diagram generation is split in three. First the intention is provided, this happens on the UI thread. Then the source of the diagram is generated, as a background task. This part apparently works, as the source view updates correctly. Finally, if you need an actual diagram, the image is generated (in the same background task) and the UI is updated (naturally on the UI thread). There's logic to prevent the UI to update when a diagram arrives, if it thinks it is about to overwrite a more recently requested diagram. Perhaps this logic is faulty. But as I said, it works for me, and I would assume it works for most others, as there hasn't been reports other than those in this issue.

BTW, what platform are you on? I'm not sure that should matter, but it's worth noting.

danieleb2000 commented 3 years ago

Windows 10 64 bits. Tried with both Eclipse 2019 and an Eclipse 2021 freshly installed. 1.24 works perfectly on both. The only update-diagram trigger that always works with 1.1.25 is just creating a new file from scratch and then editing it. But in a later session also that file becomes a "preexisting" one and therefore stops to generate a new diagram after being updated or just opened.

danieleb2000 commented 3 years ago

Please see screenshot below. A diagram text is updated and the Tab PlantUML Source shows it correctly, but the PlantUML diagram TAB is stuck to a previous diagram.

image

hallvard commented 3 years ago

That's so strange, when an editor opens and triggers my listener, the listener doesn't know whether the file is new or not. It seems a bit strange that the source doesn't include the @enduml line, perhaps that's important. If it's not part of what's sent to the underlying plantuml library, generating the actual diagram won't work!

danieleb2000 commented 3 years ago

That's the point. I confirm: the diagram is updated only if @enduml is shown in the Source view, which is often not the case...

danieleb2000 commented 3 years ago

I think I understood where the problem is. @enduml is shown only if it is the last line, or at least if there is no empty line after. But even with empty lines after, the diagram should still be valid...

danieleb2000 commented 3 years ago

By the way, also math formulas are not shown anymore.

hallvard commented 3 years ago

If you can experiment and identify the precise conditions for when the ending @enduml is missing, it will be very helpful!

Please open another issue for the math formulas.

danieleb2000 commented 3 years ago

Simply:
@enduml is missing always if it is not on the last line of the file

hallvard commented 3 years ago

A cannot reproduce this in either my development eclipse (Eclipse 2020-6) or Luna (the target), sorry.

danieleb2000 commented 3 years ago

Crazy. Did you try with a file where @enduml is followed by some empty lines? Maybe this is due to the encoding of empty lines (Dos vs Unix)?

hallvard commented 3 years ago

Yes, tried with lots of combinations of nothing, whitespace and stuff. Encoding of line endings may have something to do with it (I'm on MacOS).

danieleb2000 commented 3 years ago

Yes, it seems to be the reason! Lines ending with "\r\n" after @enduml generates this issue (Windows newline) With lines ending only with "\n" after @enduml the tool works

danieleb2000 commented 3 years ago

Probably lines after @enduml does not play any role; the real issue is if the newline on the same line of @enduml is "\n" instead of "\r\n". But "\r\n" is the End Of Line on a windows platform.

hallvard commented 3 years ago

In general I'm used to java converting line endings from platform specific ones to just \n, but that might not be happening when I use the editor (Document) API. I can see if there are places where I look for @enduml (or other tags) followed by just \n. Maybe I can replace that with the platform line ending. It's a bit difficult for me to test, though, since I don't use or have a windows computer. But I may be able to at least insert a \r before the \n to see why/where it fail.

hallvard commented 3 years ago

Note to self: IDocument has a getLineDelimiter(int line) method that maybe should be used in TextDiagramIntentHelper for normalising the end of line, so most code can expect to see only \n

hallvard commented 3 years ago

@danieleb2000 and @Lutz13 Could you try the following update site and see if the snapshot solves this problem: http://hallvard.github.io/plantuml/plantuml.eclipse/1.1.26-snapshot

Lutz13 commented 3 years ago

When I open or switch windows to a textfile (extension .puml) that contains PlantUML code, it works fine. When I open or switch to a java code files, I get the attached error message Error This is the last Exception from the logfile: !ENTRY org.eclipse.e4.ui.workbench 4 0 2021-05-16 13:48:42.148 !MESSAGE An exception occurred while notifying part listeners !STACK 0 java.lang.NullPointerException: inStream parameter is null at java.base/java.util.Objects.requireNonNull(Objects.java:233) at java.base/java.util.Properties.load(Properties.java:407) at net.sourceforge.plantuml.eclipse.Activator.getDefaults(Activator.java:325) at net.sourceforge.plantuml.eclipse.Activator.getDefaults(Activator.java:323) at net.sourceforge.plantuml.eclipse.Activator.getDefaults(Activator.java:323) at net.sourceforge.plantuml.eclipse.Activator.getDefaults(Activator.java:323) at net.sourceforge.plantuml.text.AbstractClassDiagramIntent.(AbstractClassDiagramIntent.java:23) at net.sourceforge.plantuml.jdt.JdtDiagramIntent.(JdtDiagramIntent.java:27) at net.sourceforge.plantuml.jdt.JavaEditorDiagramIntentProvider.getDiagramInfos(JavaEditorDiagramIntentProvider.java:51) at net.sourceforge.plantuml.jdt.JavaEditorDiagramIntentProvider.getDiagramInfos(JavaEditorDiagramIntentProvider.java:35) at net.sourceforge.plantuml.text.AbstractDiagramIntentProvider.getDiagramInfos(AbstractDiagramIntentProvider.java:120) at net.sourceforge.plantuml.eclipse.views.AbstractDiagramSourceView.updateDiagramText(AbstractDiagramSourceView.java:516) at net.sourceforge.plantuml.eclipse.views.AbstractDiagramSourceView.updateDiagramText(AbstractDiagramSourceView.java:445) at net.sourceforge.plantuml.eclipse.views.AbstractDiagramSourceView$DiagramTextChangedListener.diagramChanged(AbstractDiagramSourceView.java:352) at net.sourceforge.plantuml.eclipse.views.AbstractDiagramSourceView$DiagramTextChangedListener.selectionChanged(AbstractDiagramSourceView.java:347) at org.eclipse.ui.internal.e4.compatibility.SelectionService.notifyListeners(SelectionService.java:266) at org.eclipse.ui.internal.e4.compatibility.SelectionService.notifyListeners(SelectionService.java:180) at org.eclipse.ui.internal.WorkbenchPage$E4PartListener.partActivated(WorkbenchPage.java:220) at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$2.run(PartServiceImpl.java:249) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.firePartActivated(PartServiceImpl.java:246) at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:770) at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:679) at org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.activate(AbstractPartRenderer.java:97) at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.lambda$4(StackRenderer.java:979) at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:84) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:252) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4209) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1043) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1067) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:766) at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3243) at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1881) at org.eclipse.swt.custom.CTabFolder.lambda$0(CTabFolder.java:330) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4209) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1043) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4026) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3626) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155) at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590) at org.eclipse.equinox.launcher.Main.run(Main.java:1461)

hallvard commented 3 years ago

Ok, so the original problem seems to be solved. This particular error message is due to work on a new feature, that wasn't finished when publishing the snapshot. I'll release 1.1.26 soon with fixes for both.

Lutz13 commented 3 years ago

Great, thank you!