Skip to content

Commit

Permalink
Fixes #243 NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
krasa committed Oct 29, 2019
1 parent 61e067d commit 2b644d0
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 29 deletions.
9 changes: 7 additions & 2 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<idea-plugin version="2">
<name>PlantUML integration</name>
<version>2.21.0</version>
<version>2.22.0</version>
<vendor url="https://github.com/esteinberg/plantuml4idea/">Eugene Steinberg</vendor>
<!-- IJ 12+ -->
<idea-version since-build="182"/>
<idea-version since-build="182.2371.4"/>

<description>PlantUML diagramming tool integration</description>

<change-notes>
<![CDATA[
<p>2.22</p>
<ul>
<li>NPE fix</li>
<li>PlantUml library upgrade to v1.2019.11</li>
</ul>
<p>2.21</p>
<ul>
<li>Fixed '*' stripping</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ private SyntaxResult checkSyntax(PsiFile file, String source) {
Utils.setPlantUmlDir(baseDir);

PlantUmlIncludes.commitIncludes(source, baseDir);
} else {
Utils.resetPlantUmlDir();
}
return SyntaxChecker.checkSyntaxFair(source);
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/plantuml/idea/rendering/ImageItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ImageItem {
private final String documentSource;
private byte[] imageBytes;

public ImageItem(@NotNull File baseDir,
public ImageItem(@Nullable File baseDir,
@NotNull String documentSource,
@Nullable String pageSource,
int page,
Expand All @@ -59,7 +59,7 @@ public ImageItem(@NotNull File baseDir,
@Nullable byte[] svgBytes,
@NotNull RenderingType renderingType,
@Nullable String title,
String filename) {
@Nullable String filename) {
this.pageSource = pageSource;
this.documentSource = documentSource;
this.page = page;
Expand Down
4 changes: 4 additions & 0 deletions src/org/plantuml/idea/rendering/PlantUmlNormalRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public void renderAndSave(String source, @Nullable File baseDir, PlantUml.ImageF
try {
if (baseDir != null) {
Utils.setPlantUmlDir(baseDir);
} else {
Utils.resetPlantUmlDir();
}


PlantUmlIncludes.commitIncludes(source, baseDir);
SourceStringReader reader = Utils.newSourceStringReader(source, true);

Expand Down
42 changes: 22 additions & 20 deletions src/org/plantuml/idea/rendering/PlantUmlRendererUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class PlantUmlRendererUtil {
* @param source source code to be rendered
* @param baseDir base dir to set for "include" functionality
* @param format image format
* @param path path to use with first file
* @param path path to use with first file
* @param fileNameFormat file naming scheme for further files
* @param pageNumber -1 for all pages
* @param pageNumber -1 for all pages
* @throws IOException in case of rendering or saving fails
*/
public static void renderAndSave(String source, @Nullable File baseDir, PlantUml.ImageFormat format, String path, String fileNameFormat, int zoom, int pageNumber)
Expand All @@ -53,26 +53,28 @@ public static void renderAndSave(String source, @Nullable File baseDir, PlantUml
* to provided values
*/
public static RenderResult render(RenderRequest renderRequest, RenderCacheItem cachedItem) {
File baseDir = renderRequest.getBaseDir();
if (baseDir != null) {
Utils.setPlantUmlDir(baseDir);
}
long start = System.currentTimeMillis();
File baseDir = renderRequest.getBaseDir();
if (baseDir != null) {
Utils.setPlantUmlDir(baseDir);
} else {
Utils.resetPlantUmlDir();
}
long start = System.currentTimeMillis();

String source = renderRequest.getSource();
String[] sourceSplit = NEW_PAGE_PATTERN.split(source);
logger.debug("split done ", System.currentTimeMillis() - start, "ms");
String source = renderRequest.getSource();
String[] sourceSplit = NEW_PAGE_PATTERN.split(source);
logger.debug("split done ", System.currentTimeMillis() - start, "ms");

boolean partialRender = sourceSplit[0].contains(IDEA_PARTIAL_RENDER);
logger.debug("partialRender ", partialRender);
boolean partialRender = sourceSplit[0].contains(IDEA_PARTIAL_RENDER);
logger.debug("partialRender ", partialRender);

RenderResult renderResult;
if (partialRender) {
renderResult = PARTIAL_RENDERER.partialRender(renderRequest, cachedItem, start, sourceSplit);
} else {
renderResult = NORMAL_RENDERER.doRender(renderRequest, cachedItem, sourceSplit);
}
return renderResult;
RenderResult renderResult;
if (partialRender) {
renderResult = PARTIAL_RENDERER.partialRender(renderRequest, cachedItem, start, sourceSplit);
} else {
renderResult = NORMAL_RENDERER.doRender(renderRequest, cachedItem, sourceSplit);
}
return renderResult;
}

public static DiagramInfo zoomDiagram(SourceStringReader reader, int zoom) {
Expand All @@ -85,7 +87,7 @@ public static DiagramInfo zoomDiagram(SourceStringReader reader, int zoom) {
// logger.error("more than 1 block"); //TODO
//happens when the source is incorrectly extracted and contains multiple diagrams
}

for (int i = 0; i < blocks.size(); i++) {
BlockUml block = blocks.get(i);

Expand Down
6 changes: 4 additions & 2 deletions src/org/plantuml/idea/rendering/RenderCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.jetbrains.annotations.Nullable;
import org.plantuml.idea.plantuml.PlantUml;
import org.plantuml.idea.plantuml.PlantUmlIncludes;
import org.plantuml.idea.toolwindow.ExecutionStatusPanel;
Expand All @@ -17,6 +18,7 @@ public abstract class RenderCommand implements Runnable {
protected Reason reason;
protected String sourceFilePath;
protected final String source;
@Nullable
protected final File baseDir;
protected final int page;
protected int zoom;
Expand All @@ -35,7 +37,7 @@ public enum Reason {
SOURCE_PAGE_ZOOM
}

public RenderCommand(Reason reason, String sourceFilePath, String source, File baseDir, int page, int zoom, RenderCacheItem cachedItem, int version, boolean renderUrlLinks, LazyApplicationPoolExecutor.Delay delay, ExecutionStatusPanel label) {
public RenderCommand(Reason reason, String sourceFilePath, String source, @Nullable File baseDir, int page, int zoom, RenderCacheItem cachedItem, int version, boolean renderUrlLinks, LazyApplicationPoolExecutor.Delay delay, ExecutionStatusPanel label) {
this.reason = reason;
this.sourceFilePath = sourceFilePath;
this.source = source;
Expand Down Expand Up @@ -108,7 +110,7 @@ public String toString() {
return new ToStringBuilder(this)
.append("reason", reason)
.append("sourceFilePath", sourceFilePath)
.append("selectedDir", baseDir.getName())
.append("selectedDir", baseDir)
.append("page", page)
.append("zoom", zoom)
.append("cachedItem", cachedItem)
Expand Down
7 changes: 4 additions & 3 deletions src/org/plantuml/idea/rendering/RenderRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import org.apache.commons.lang.builder.ToStringBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.plantuml.idea.plantuml.PlantUml;

import java.io.File;

public class RenderRequest {
@NotNull
@Nullable
private final File baseDir;
@NotNull
private final String source;
Expand All @@ -20,7 +21,7 @@ public class RenderRequest {
private RenderCommand.Reason reason;
protected boolean useSettings = true;

public RenderRequest(@NotNull File baseDir,
public RenderRequest(@Nullable File baseDir,
@NotNull String source,
@NotNull PlantUml.ImageFormat format,
int page,
Expand Down Expand Up @@ -49,7 +50,7 @@ public RenderRequest(@NotNull RenderRequest renderRequest,
this.version = null;
}

@NotNull
@Nullable
public File getBaseDir() {
return baseDir;
}
Expand Down
6 changes: 6 additions & 0 deletions src/org/plantuml/idea/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public static void setPlantUmlDir(@NotNull File baseDir) {
System.setProperty("plantuml.include.path", baseDir.getAbsolutePath());
}

public static void resetPlantUmlDir() {
FileSystem.getInstance().reset();
System.clearProperty("plantuml.include.path");
}

@NotNull
public static SourceStringReader newSourceStringReader(String source, boolean useSettings) {
List<String> configAsList;
Expand All @@ -50,4 +55,5 @@ public static boolean isPlantUmlFileType(@NotNull PsiFile file) {
FileType fileType = file.getFileType();
return fileType.equals(PlantUmlFileType.PLANTUML_FILE_TYPE) || fileType.equals(PlantIUmlFileType.PLANTUML_FILE_TYPE);
}

}

0 comments on commit 2b644d0

Please sign in to comment.