Skip to content

Commit

Permalink
refactor: remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Apr 14, 2024
1 parent 171a359 commit 91e87b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/net/sourceforge/plantuml/OptionFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void reset(boolean exit) {
systemExit = exit;
gui = false;
quiet = false;
checkDotError = false;
// checkDotError = false;
printFonts = false;
// failOnError = false;
encodesprite = false;
Expand All @@ -130,7 +130,7 @@ public boolean useJavaInsteadOfDot() {
private boolean systemExit;
private boolean gui;
private boolean quiet;
private boolean checkDotError;
// private boolean checkDotError;
private boolean printFonts;
private boolean encodesprite;
private boolean dumpHtmlStats;
Expand Down Expand Up @@ -195,12 +195,12 @@ public final void setQuiet(boolean quiet) {
this.quiet = quiet;
}

public final boolean isCheckDotError() {
return checkDotError;
}
// public final boolean isCheckDotError() {
// return checkDotError;
// }

public final void setCheckDotError(boolean checkDotError) {
this.checkDotError = checkDotError;
// this.checkDotError = checkDotError;
}

private final AtomicBoolean logDataInitized = new AtomicBoolean(false);
Expand Down
23 changes: 11 additions & 12 deletions src/net/sourceforge/plantuml/dot/AbstractGraphviz.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,17 @@ final public ProcessState createFile3(OutputStream os) {
} finally {
Log.info("Ending Graphviz process");
}
if (OptionFlags.getInstance().isCheckDotError() && p != null && p.getError().length() > 0) {
Log.error("GraphViz error stream : " + p.getError());
if (OptionFlags.getInstance().isCheckDotError())
throw new IllegalStateException("Dot error " + p.getError());

}
if (OptionFlags.getInstance().isCheckDotError() && p != null && p.getOut().length() > 0) {
Log.error("GraphViz out stream : " + p.getOut());
if (OptionFlags.getInstance().isCheckDotError())
throw new IllegalStateException("Dot out " + p.getOut());

}
// if (OptionFlags.getInstance().isCheckDotError() && p != null && p.getError().length() > 0) {
// Log.error("GraphViz error stream : " + p.getError());
// if (OptionFlags.getInstance().isCheckDotError())
// throw new IllegalStateException("Dot error " + p.getError());
//
// }
// if (OptionFlags.getInstance().isCheckDotError() && p != null && p.getOut().length() > 0) {
// Log.error("GraphViz out stream : " + p.getOut());
// if (OptionFlags.getInstance().isCheckDotError())
// throw new IllegalStateException("Dot out " + p.getOut());
// }
return state;
}

Expand Down
35 changes: 22 additions & 13 deletions src/net/sourceforge/plantuml/dot/ProcessRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
package net.sourceforge.plantuml.dot;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.TimeUnit;
Expand All @@ -49,8 +48,8 @@ public class ProcessRunner {
// ::remove file when __CORE__

private final String[] cmd;
private String error = "";
private String out = "";
private String error;
private String out;

public ProcessRunner(String[] cmd) {
this.cmd = cmd;
Expand All @@ -61,14 +60,14 @@ public ProcessState run(byte[] in, OutputStream redirection) {
}

public ProcessState run(byte[] in, OutputStream redirection, SFile dir) {
Process process = null;
try {
final ProcessBuilder builder = new ProcessBuilder(cmd);
if (dir != null)
builder.directory(dir.conv());

builder.redirectErrorStream(true);

final Process process = builder.start();
process = builder.start();

// Handling input to the process
if (in != null)
Expand Down Expand Up @@ -96,20 +95,30 @@ public ProcessState run(byte[] in, OutputStream redirection, SFile dir) {
return ProcessState.TERMINATED_OK();
}

// Process did not finish in time, kill it
process.destroy();
this.error = "Timeout - kill";
if (process.waitFor(500, TimeUnit.MILLISECONDS) == false) {
process.destroyForcibly();
this.error = "Timeout - kill force";
}

return ProcessState.TIMEOUT();

} catch (Throwable e) {
Logme.error(e);
this.error = e.toString();
return ProcessState.EXCEPTION(e);
} finally {
if (process != null && out == null && process.isAlive()) {
// Process did not finish in time, kill it
process.destroy();
// Not really sure that we should overwrite "this.error" here
this.error = "Timeout - kill";
try {
if (process.waitFor(500, TimeUnit.MILLISECONDS) == false) {
process.destroyForcibly();
this.error = "Timeout - kill force";
}
} catch (InterruptedException e) {
// Nothing we can really do
e.printStackTrace();
}

}

}
}

Expand Down

0 comments on commit 91e87b9

Please sign in to comment.