From c178735c9f4c787db1ce3ab250d074bf5c07d0f7 Mon Sep 17 00:00:00 2001 From: selewis Date: Fri, 9 Dec 2016 11:25:06 -0800 Subject: [PATCH] Allow alpha-numeric for version fixes #47 --- .classpath | 2 +- resources/org/paint/resources/VERSION | 2 +- src/org/paint/config/VersionResource.java | 13 +-- src/org/paint/dialog/AboutDialog.java | 2 +- src/org/paint/main/PaintStartupTask.java | 2 +- src/org/paint/util/VersionNumber.java | 133 ---------------------- 6 files changed, 8 insertions(+), 146 deletions(-) delete mode 100755 src/org/paint/util/VersionNumber.java diff --git a/.classpath b/.classpath index 7532369..11ba752 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + diff --git a/resources/org/paint/resources/VERSION b/resources/org/paint/resources/VERSION index 5a5e4a2..0750657 100755 --- a/resources/org/paint/resources/VERSION +++ b/resources/org/paint/resources/VERSION @@ -1 +1 @@ -v2.28.c \ No newline at end of file +v2.29 \ No newline at end of file diff --git a/src/org/paint/config/VersionResource.java b/src/org/paint/config/VersionResource.java index fce23f8..dd2334f 100644 --- a/src/org/paint/config/VersionResource.java +++ b/src/org/paint/config/VersionResource.java @@ -26,7 +26,6 @@ import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; -import org.paint.util.VersionNumber; /** * Used for reading previous or default user settings from property file and storing current user settings @@ -39,7 +38,7 @@ public class VersionResource { // extends DirectoryUtil { protected static Logger log = Logger.getLogger("org.panther.paint.config.Preferences"); - private VersionNumber version; + private String version; private static VersionResource resource; @@ -60,7 +59,7 @@ public static VersionResource inst() { return resource; } - public VersionNumber getVersion() { + public String getVersion() { if (version == null) { try { InputStream inputStream = getExtensionLoader().getResourceAsStream( @@ -68,18 +67,14 @@ public VersionNumber getVersion() { if (inputStream != null) { List lines = IOUtils.readLines(inputStream); if (!lines.isEmpty()) { - version = new VersionNumber(lines.get(0)); + version = lines.get(0); } } } catch (Exception e) { log.warn("Clould not load version from resource", e); } if (version == null) { - try { - version = new VersionNumber("2.0"); - } catch (ParseException e) { - // ignore - } + version = "2.0"; } } return version; diff --git a/src/org/paint/dialog/AboutDialog.java b/src/org/paint/dialog/AboutDialog.java index 56f5f5f..acec897 100644 --- a/src/org/paint/dialog/AboutDialog.java +++ b/src/org/paint/dialog/AboutDialog.java @@ -88,7 +88,7 @@ protected void configure() { JPanel icon_panel = new JPanel(); icon_panel.setLayout(new BorderLayout()); JLabel program = new JLabel(paint_fullname, image, SwingConstants.CENTER); - JLabel version = new JLabel(VersionResource.inst().getVersion().toString(), image, SwingConstants.CENTER); + JLabel version = new JLabel(VersionResource.inst().getVersion(), image, SwingConstants.CENTER); program.setFont(new Font("Arial", Font.BOLD, 14)); version.setFont(new Font("Arial", Font.BOLD, 12)); icon_panel.add(program, BorderLayout.CENTER); diff --git a/src/org/paint/main/PaintStartupTask.java b/src/org/paint/main/PaintStartupTask.java index 319b002..0b6c974 100644 --- a/src/org/paint/main/PaintStartupTask.java +++ b/src/org/paint/main/PaintStartupTask.java @@ -200,7 +200,7 @@ protected void configureLogging() { // log4j straight up, and have log4j appender for an error window // error manager used to go to term info but no longer // ErrorManager.inst().addErrorListener(new LogErrorListener()); - LOG.info("Loading Paint version " + VersionResource.inst().getVersion().toString()); + LOG.info("Loading Paint version " + VersionResource.inst().getVersion()); } @Override diff --git a/src/org/paint/util/VersionNumber.java b/src/org/paint/util/VersionNumber.java deleted file mode 100755 index da6b8d1..0000000 --- a/src/org/paint/util/VersionNumber.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.paint.util; - -import java.text.ParseException; -import java.util.Scanner; -import java.util.regex.MatchResult; - -import org.bbop.util.StringUtil; - -import org.apache.log4j.*; - -public class VersionNumber implements Comparable { - - //initialize logger - protected final static Logger logger = Logger.getLogger(VersionNumber.class); - - protected int majorVersion; - - protected int minorVersion; - - // In case the version number has another place, e.g. 2.1.3 - protected int subminorVersion = -999; - - protected int betaVersion; - - //release candidate version - protected int rcVersion; - - public VersionNumber(String str) throws ParseException { - Scanner s = new Scanner(str); - try { - s.findInLine("(\\d+)"); - MatchResult result = s.match(); - majorVersion = Integer.parseInt(result.group(1)); - } catch (IllegalStateException ex) { - throw new ParseException(str, -1); - } - try { - s.findInLine(".(\\d+)"); - MatchResult result = s.match(); - minorVersion = Integer.parseInt(result.group(1)); - } catch (IllegalStateException ex) { - throw new ParseException(str, -1); - } - try { - // Need to leave s alone in case there's a beta or rc suffix - Scanner s2 = s; - s2.findInLine("\\.(\\d+)"); - MatchResult result = s2.match(); - subminorVersion = Integer.parseInt(result.group(1)); - } catch (Exception ex) { - // It's ok if there's not a subminor version; just be quiet - } - try { - s.findInLine("-beta(\\d+)"); - MatchResult result = s.match(); - betaVersion = Integer.parseInt(result.group(1)); - } catch (IllegalStateException ex) { - } - try { - s.findInLine("-rc(\\d+)"); - MatchResult result = s.match(); - rcVersion = Integer.parseInt(result.group(1)); - } catch (IllegalStateException ex) { - } - - s.close(); - } - - public String toString() { - return majorVersion + "." - + StringUtil.pad(minorVersion + "", '0', 1, true) - + ((subminorVersion == -999) ? "" : "." + subminorVersion) - + (isRC() ? "-rc" +rcVersion : "") - + (isBeta() ? "-beta" + betaVersion : ""); - } - - public static void main(String[] args) throws Exception { - logger.info(new VersionNumber("2.1-beta")); -// logger.info(new VersionNumber("3.008")); - } - - public boolean isBeta() { - return betaVersion > 0; - } - - public int getBetaVersion() { - return betaVersion; - } - - public boolean isRC() { - return rcVersion > 0; - } - - public int getRCVersion() { - return rcVersion; - } - - public int getMajorVersion() { - return majorVersion; - } - - public int getMinorVersion() { - return minorVersion; - } - - public int hashCode() { - return getMajorVersion() * 100000 + getMinorVersion() * 100 - + getRCVersion(); -// return getMajorVersion() * 100000 + getMinorVersion() * 100 -// + getBetaVersion(); - } - - public boolean equals(Object o) { - if (o instanceof VersionNumber) { - VersionNumber vn = (VersionNumber) o; - return vn.getRCVersion() == getRCVersion() - && vn.getMajorVersion() == getMajorVersion() - && vn.getMinorVersion() == getMinorVersion(); -// return vn.getBetaVersion() == getBetaVersion() -// && vn.getMajorVersion() == getMajorVersion() -// && vn.getMinorVersion() == getMinorVersion(); - } else - return false; - } - - public int compareTo(VersionNumber o) { - int majorDiff = o.getMajorVersion() - getMajorVersion(); - int minorDiff = o.getMinorVersion() - getMinorVersion(); - int rcDiff = o.getRCVersion() - getRCVersion(); -// int betaDiff = o.getBetaVersion() - getBetaVersion(); - return majorDiff * 100000 + minorDiff * 100 + rcDiff; - } -}