From a0320c713cb50a573af596c124fd368637286766 Mon Sep 17 00:00:00 2001 From: Hallvard Traetteberg Date: Tue, 13 Apr 2021 20:55:32 +0200 Subject: [PATCH] Some more refactoring and updated the readme --- README.md | 1 + .../plantuml/eclipse/Activator.java | 3 +- .../plantuml/eclipse/utils/PlantumlUtil.java | 32 +++++++++++-------- .../eclipse/views/AbstractPlantUmlView.java | 1 + .../views/actions/CopyAsciiAction.java | 2 +- .../eclipse/views/actions/ExportAction.java | 8 ++--- .../plantuml/util/DiagramImageData.java | 15 +++++---- 7 files changed, 35 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index e24e9fc41..38eed4798 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Note that the version numbers of the plantuml.lib plugin are a bit special, sinc ## [1.1.25](https://github.com/hallvard/plantuml/releases/tag/1.1.25) - Updated to use PlantUML library version 1.2021.3 (see [changes](https://plantuml.com/changes)). - Added new extension point that supports generating several alternative diagrams for the same content ([issue #109](https://github.com/hallvard/plantuml/issues/109)) and delays the computation of the diagram so it can run on a non-UI thread ([issue #82](https://github.com/hallvard/plantuml/issues/82)). Uses of old extension point should still work, but should be updated to use new one. +- I needed to remove (for now) the feature that recomputes saved diagram images during builds, when their source have changed. - Experimental PlantUML SVG view that handles zooming better ([issue #116](https://github.com/hallvard/plantuml/issues/116)) - Association is generated when type is Optional and for methods with a specific signature. (thanks to [dpolivaev](https://github.com/dpolivaev)) - Changes generated diagrams to use `name : type` UML format for attributes instead of java style `type name` ([issue #115](https://github.com/hallvard/plantuml/issues/115)) diff --git a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/Activator.java b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/Activator.java index 6a5b3ad60..f27243b11 100644 --- a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/Activator.java +++ b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/Activator.java @@ -24,7 +24,6 @@ import net.sourceforge.plantuml.eclipse.utils.DiagramTextProvider; import net.sourceforge.plantuml.eclipse.utils.ILinkOpener; -import net.sourceforge.plantuml.eclipse.utils.PlantumlUtil; import net.sourceforge.plantuml.preferences.DiagramIntentProvidersPreferencePage; import net.sourceforge.plantuml.util.DiagramIntentProvider; import net.sourceforge.plantuml.util.DiagramTextIntentProvider; @@ -60,7 +59,7 @@ public Activator() { public void start(final BundleContext context) throws Exception { super.start(context); plugin = this; - resourceListener = PlantumlUtil.createResourceListener(); + resourceListener = null; // TODO: re-enable PlantumlUtil.createResourceListener(); if (resourceListener != null) { ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener, IResourceChangeEvent.POST_BUILD); } diff --git a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/utils/PlantumlUtil.java b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/utils/PlantumlUtil.java index 22c585178..c46d58be8 100644 --- a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/utils/PlantumlUtil.java +++ b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/utils/PlantumlUtil.java @@ -36,6 +36,7 @@ public class PlantumlUtil { public static final String PLANTUML_MARKER = "plantumlmarker"; public static final String ORIGINAL_PATH_ATTRIBUTE = "original"; + public static final String DIAGRAM_INTENT_PROVIDER_ID_ATTRIBUTE = "diagramIntentProviderId"; public static final String DIAGRAM_SOURCE_ATTRIBUTE = "diagramSource"; public static final String TARGET_PATH_ATTRIBUTE = "target"; @@ -103,22 +104,27 @@ public boolean visit(final IResourceDelta delta) throws CoreException { final IMarker marker = getPlantUmlMarker((IFile) resource, false); if (marker != null) { final Object target = marker.getAttribute(TARGET_PATH_ATTRIBUTE); + final Object diagramIntentProviderId = marker.getAttribute(DIAGRAM_INTENT_PROVIDER_ID_ATTRIBUTE); if (target != null) { final IPath path = resource.getFullPath(); final WorkspaceDiagramIntentProviderContext intentProviderContext = new WorkspaceDiagramIntentProviderContext(path); for (final DiagramIntentProvider diagramIntentProvider : Activator.getDefault().getDiagramIntentProviders(null)) { - final Collection diagramInfos = diagramIntentProvider.getDiagramInfos(intentProviderContext); - for (final DiagramIntent diagramIntent : diagramInfos) { - final String textDiagram = diagramIntent.getDiagramText(); - if (textDiagram != null) { - final DiagramData diagram = new DiagramData(textDiagram); - diagram.setOriginal(path); - try { - saveDiagramImage(path, textDiagram, diagram.getImage(), new Path(target.toString()), false); - } catch (final Exception e) { - System.err.println(e); + if (diagramIntentProviderId == null || diagramIntentProviderId.toString().equals(Activator.getDefault().getDiagramIntentProviderId(diagramIntentProvider))) { + final Collection diagramInfos = diagramIntentProvider.getDiagramInfos(intentProviderContext); + if (diagramInfos != null) { + for (final DiagramIntent diagramIntent : diagramInfos) { + final String textDiagram = diagramIntent.getDiagramText(); + if (textDiagram != null) { + final DiagramData diagram = new DiagramData(textDiagram); + diagram.setOriginal(path); + try { + saveDiagramImage(path, textDiagram, diagram.getImage(), new Path(target.toString()), false); + } catch (final Exception e) { + System.err.println(e); + } + return false; + } } - break; } } } @@ -131,7 +137,7 @@ public boolean visit(final IResourceDelta delta) throws CoreException { public static void saveDiagramImage(final DiagramImageData diagramImageData, final IPath path, final boolean b) throws Exception { final Function fileNameProvider = PlantumlUtil.getImageFileNameProvider(path.lastSegment()); - final DiagramData diagram = diagramImageData.getDiagram(); + final DiagramData diagram = diagramImageData.getDiagramData(); if (fileNameProvider != null) { final IPath folderPath = path.removeLastSegments(1); final int imageCount = diagram.getImageCount(); @@ -148,7 +154,7 @@ public static void saveDiagramImage(final IPath sourcePath, final String textDia saveDiagramImage(sourcePath, textDiagram, 0, image, targetPath, create); } - public static void saveDiagramImage(final IPath sourcePath, final String textDiagram, final int imageNum, final ImageData image, final IPath targetPath, final boolean create) throws Exception { + private static void saveDiagramImage(final IPath sourcePath, final String textDiagram, final int imageNum, final ImageData image, final IPath targetPath, final boolean create) throws Exception { final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(targetPath); if (file != null && (create || file.exists())) { final String ext = targetPath.getFileExtension(); diff --git a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/AbstractPlantUmlView.java b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/AbstractPlantUmlView.java index 38c523787..e4961948f 100644 --- a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/AbstractPlantUmlView.java +++ b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/AbstractPlantUmlView.java @@ -100,6 +100,7 @@ protected void updateDiagramMarkers() { } } } + private Collection linkOpeners = null; private Collection getLinkOpeners() { diff --git a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/actions/CopyAsciiAction.java b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/actions/CopyAsciiAction.java index 23a34c23f..aaa5af688 100644 --- a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/actions/CopyAsciiAction.java +++ b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/actions/CopyAsciiAction.java @@ -37,7 +37,7 @@ public void run() { String s = "empty"; try { final DiagramImageData diagramImageData = getDiagramImageData(); - final String source = diagramImageData.getDiagram().getTextDiagram(); + final String source = diagramImageData.getDiagramData().getTextDiagram(); final SourceStringReader sourceStringReader = new SourceStringReader(source); final ByteArrayOutputStream os = new ByteArrayOutputStream(); sourceStringReader.outputImage(os, diagramImageData.getImageNum(), new FileFormatOption(FileFormat.ATXT)); diff --git a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/actions/ExportAction.java b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/actions/ExportAction.java index 89c6d806d..2a8548f32 100644 --- a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/actions/ExportAction.java +++ b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/eclipse/views/actions/ExportAction.java @@ -44,7 +44,7 @@ public void run() { final String filePathName = fDialog.getFilterPath() + System.getProperty("file.separator") + fileName; final String ext = fileName.substring(fileName.lastIndexOf(".") + 1); if ("svg".equals(ext)) { - createImageFileSvg(filePathName, getDiagramImageData().getDiagram().getTextDiagram()); + createImageFileSvg(filePathName, getDiagramImageData().getDiagramData().getTextDiagram()); } else { createImageFile(filePathName, ext); } @@ -54,9 +54,9 @@ public void run() { private void createImageFile(final String filePathName, final String format) { final Function fileNameProvider = PlantumlUtil.getImageFileNameProvider(filePathName); if (fileNameProvider != null) { - final int imageCount = getDiagramImageData().getDiagram().getImageCount(); + final int imageCount = getDiagramImageData().getDiagramData().getImageCount(); for (int i = 0; i < imageCount; i++) { - createImageFile(fileNameProvider.apply(i), format, getDiagramImageData().getDiagram().getImage(i, null)); + createImageFile(fileNameProvider.apply(i), format, getDiagramImageData().getDiagramData().getImage(i, null)); } } else { createImageFile(filePathName, format, getImage()); @@ -77,7 +77,7 @@ private void createImageFile(final String filePathName, final String format, fin private void createImageFileSvg(final String filePathName, final String textDiagram) { final Function fileNameProvider = PlantumlUtil.getImageFileNameProvider(filePathName); if (fileNameProvider != null) { - final int imageCount = getDiagramImageData().getDiagram().getImageCount(); + final int imageCount = getDiagramImageData().getDiagramData().getImageCount(); for (int i = 0; i < imageCount; i++) { createImageFileSvg(fileNameProvider.apply(i), textDiagram, i); } diff --git a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/util/DiagramImageData.java b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/util/DiagramImageData.java index 295ce6d79..0bc9aaef8 100644 --- a/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/util/DiagramImageData.java +++ b/bundles/net.sourceforge.plantuml.eclipse/src/net/sourceforge/plantuml/util/DiagramImageData.java @@ -10,15 +10,16 @@ public class DiagramImageData { - private final DiagramData diagram; + private final DiagramData diagramData; private final int imageNum; + private ImageData imageData; private final Collection links = new ArrayList(); public DiagramImageData(final DiagramData diagram, final int imageNum, final ImageData imageData) { super(); - this.diagram = diagram; + this.diagramData = diagram; this.imageNum = imageNum; this.imageData = imageData; } @@ -36,15 +37,15 @@ public DiagramImageData(final DiagramData diagram) { } public DiagramImageData withImageNum(final int imageNum) { - return new DiagramImageData(diagram, imageNum); + return new DiagramImageData(diagramData, imageNum); } - public DiagramData getDiagram() { - return diagram; + public DiagramData getDiagramData() { + return diagramData; } public IPath getSourcePath() { - return diagram.getOriginal(); + return diagramData.getOriginal(); } public int getImageNum() { @@ -53,7 +54,7 @@ public int getImageNum() { public ImageData getImage() { if (imageData == null) { - imageData = diagram.getImage(imageNum, links); + imageData = diagramData.getImage(imageNum, links); } return imageData; }