Ticket #1841: josm-1841-manifest_and_versioncheck.patch
File josm-1841-manifest_and_versioncheck.patch, 5.9 KB (added by , 16 years ago) |
---|
-
src/org/openstreetmap/josm/actions/AboutAction.java
12 12 import java.io.IOException; 13 13 import java.io.InputStream; 14 14 import java.io.InputStreamReader; 15 import java.net.MalformedURLException; 15 16 import java.net.URL; 16 17 import java.util.Map.Entry; 17 18 import java.util.regex.Matcher; … … 43 44 * 44 45 * @author imi 45 46 */ 47 /** 48 * @author Stephan 49 * 50 */ 46 51 public class AboutAction extends JosmAction { 47 52 48 p ublicstatic final String version;53 private static final String version; 49 54 50 55 private final static JTextArea revision; 51 56 private static String time; … … 50 55 private final static JTextArea revision; 51 56 private static String time; 52 57 53 static { 54 URL u = Main.class.getResource("/REVISION"); 55 if(u == null) u = Main.class.getResource("/META-INF/MANIFEST.MF"); 58 static { 59 URL u = Main.class.getResource("/REVISION"); 60 if(u == null) { 61 try { 62 u = new URL("jar:" + Main.class.getProtectionDomain().getCodeSource().getLocation().toString() 63 + "!/META-INF/MANIFEST.MF"); 64 } catch (MalformedURLException e) { 65 e.printStackTrace(); 66 } 67 } 56 68 revision = loadFile(u); 57 69 58 Pattern versionPattern = Pattern.compile(".*?(?:Revision|Main-Version): ([0-9]* ).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);70 Pattern versionPattern = Pattern.compile(".*?(?:Revision|Main-Version): ([0-9]*(?: SVN)?).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL); 59 71 Matcher match = versionPattern.matcher(revision.getText()); 60 72 version = match.matches() ? match.group(1) : tr("UNKNOWN"); 61 73 … … 64 76 time = match.matches() ? match.group(1) : tr("UNKNOWN"); 65 77 } 66 78 67 static public String getVersion() { 79 /** 80 * Return string describing version. 81 * Note that the strinc contains the version number plus an optional suffix of " SVN" to indicate an unofficial development build. 82 * @return version string 83 */ 84 static public String getVersionString() { 68 85 return version; 69 86 } 70 87 88 /** 89 * Return the number part of the version string. 90 * @return integer part of version number or Integer.MAX_VALUE if not available 91 */ 92 public static int getVersionNumber() { 93 int myVersion=Integer.MAX_VALUE; 94 try { 95 myVersion = Integer.parseInt(version.split(" ")[0]); 96 } catch (NumberFormatException e) { 97 e.printStackTrace(); 98 } 99 return myVersion; 100 } 101 102 /** 103 * check whether the version is a development build out of SVN. 104 * @return true if it is a SVN unofficial build 105 */ 106 public static boolean isDevelopmentVersion() { 107 return version.endsWith(" SVN"); 108 } 109 71 110 public AboutAction() { 72 111 super(tr("About"), "about", tr("Display the about screen."), Shortcut.registerShortcut("system:about", tr("About"), KeyEvent.VK_F1, Shortcut.GROUP_DIRECT, Shortcut.SHIFT_DEFAULT), true); 73 112 } -
src/org/openstreetmap/josm/Main.java
248 248 if (info != null) { 249 249 if (info.early != early) 250 250 continue; 251 if (info.mainversion != null && info.mainversion.compareTo(AboutAction.version) > 0) { 252 JOptionPane.showMessageDialog(Main.parent, tr("Plugin requires JOSM update: {0}.", pluginName)); 253 continue; 251 if (info.mainversion != null) { 252 int requiredJOSMVersion = 0; 253 try { 254 requiredJOSMVersion = Integer.parseInt(info.mainversion); 255 } catch(NumberFormatException e) { 256 e.printStackTrace(); 257 } 258 if (requiredJOSMVersion > AboutAction.getVersionNumber()) { 259 JOptionPane.showMessageDialog(Main.parent, tr("Plugin requires JOSM update: {0}.", pluginName)); 260 continue; 261 } 254 262 } 255 263 if (!p.containsKey(info.stage)) 256 264 p.put(info.stage, new LinkedList<PluginInformation>()); -
src/org/openstreetmap/josm/gui/SplashScreen.java
72 72 innerContentPane.add(caption, gbc); 73 73 74 74 // Add the version number 75 JLabel version = new JLabel(tr("Version {0}", AboutAction. version));75 JLabel version = new JLabel(tr("Version {0}", AboutAction.getVersionString())); 76 76 gbc.gridy = 1; 77 77 gbc.insets = new Insets(0, 0, 0, 0); 78 78 innerContentPane.add(version, gbc); -
src/org/openstreetmap/josm/gui/GettingStarted.java
56 56 ")</h2>"; 57 57 } 58 58 59 int myVersion; 60 try { 61 myVersion = Integer.parseInt(AboutAction.getVersion()); 62 } catch (NumberFormatException e) { 63 myVersion = 0; 64 } 59 int myVersion = AboutAction.getVersionNumber(); 65 60 66 61 Pattern commentPattern = Pattern.compile("\\<p\\>\\s*\\/\\*[^\\*]*\\*\\/\\s*\\<\\/p\\>", Pattern.CASE_INSENSITIVE|Pattern.DOTALL|Pattern.MULTILINE); 67 62 Matcher matcherComment = commentPattern.matcher(motdcontent);