Skip to content

Commit

Permalink
Cleaner way of determining the version of dot
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurrier committed Nov 24, 2006
1 parent 1e79f5a commit b6e4d25
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/net/sourceforge/schemaspy/util/Dot.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.sourceforge.schemaspy.util;

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Dot {
private static Dot instance = new Dot();
Expand All @@ -10,7 +10,7 @@ public class Dot {
private final Version badVersion = new Version("2.4");

private Dot() {
String found = null;
String versionText = null;
try {
// dot -V should return something similar to:
// dot version 2.8 (Fri Feb 3 22:38:53 UTC 2006)
Expand All @@ -20,16 +20,11 @@ private Dot() {
Process process = Runtime.getRuntime().exec(dotCommand);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String versionLine = reader.readLine();
StringTokenizer tokenizer = new StringTokenizer(versionLine);
if (tokenizer.nextToken().equals("dot")) { // skip 'dot'
// search for numeric portion of dot's output
while (found == null) {
// Jean-François Veillette provides this logic:
String token = tokenizer.nextToken(); // skip 'version'
if (token.matches("[0-9.]*")) {
found = token; // found numeric portion
}
}

// look for a number followed numbers or dots
Matcher matcher = Pattern.compile("[0-9][0-9.]+").matcher(versionLine);
if (matcher.find()) {
versionText = matcher.group();
} else {
System.err.println();
System.err.println("Invalid dot configuration detected. '" + dotCommand + "' returned:");
Expand All @@ -38,7 +33,7 @@ private Dot() {
} catch (Exception validDotDoesntExist) {
}

version = new Version(found);
version = new Version(versionText);
}

public static Dot getInstance() {
Expand Down

0 comments on commit b6e4d25

Please sign in to comment.