001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.util;
013:
014: import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
015:
016: import java.io.IOException;
017: import java.io.InputStream;
018: import java.util.Properties;
019:
020: /**
021: * @version 1.1.1
022: * @author TMate Software Ltd.
023: */
024: public class Version {
025:
026: private static String PROPERTIES_PATH = "/svnkit.build.properties";
027:
028: private static final String VERSION_STRING_PROPERTY = "svnkit.version.string";
029: private static final String VERSION_MAJOR_PROPERTY = "svnkit.version.major";
030: private static final String VERSION_MINOR_PROPERTY = "svnkit.version.minor";
031: private static final String VERSION_MICRO_PROPERTY = "svnkit.version.micro";
032: private static final String VERSION_REVISION_PROPERTY = "svnkit.version.revision";
033:
034: private static final String VERSION_STRING_DEFAULT = "SVNKit (http://svnkit.com/) rSNAPSHOT";
035: private static final String VERSION_MAJOR_DEFAULT = "0";
036: private static final String VERSION_MINOR_DEFAULT = "0";
037: private static final String VERSION_MICRO_DEFAULT = "0";
038: private static final String VERSION_REVISION_DEFAULT = "SNAPSHOT";
039: private static String ourUserAgent;
040:
041: private static Properties ourProperties;
042:
043: static {
044: ourUserAgent = System.getProperty("svnkit.http.userAgent");
045: }
046:
047: public static String getVersionString() {
048: loadProperties();
049: return ourProperties.getProperty(VERSION_STRING_PROPERTY,
050: VERSION_STRING_DEFAULT);
051: }
052:
053: public static void setUserAgent(String userAgent) {
054: ourUserAgent = userAgent;
055: }
056:
057: public static String getUserAgent() {
058: if (ourUserAgent != null) {
059: return ourUserAgent;
060: }
061: return getVersionString();
062: }
063:
064: public static int getMajorVersion() {
065: loadProperties();
066: try {
067: return Integer.parseInt(ourProperties.getProperty(
068: VERSION_MAJOR_PROPERTY, VERSION_MAJOR_DEFAULT));
069: } catch (NumberFormatException nfe) {
070: //
071: }
072: return 0;
073: }
074:
075: public static int getMinorVersion() {
076: loadProperties();
077: try {
078: return Integer.parseInt(ourProperties.getProperty(
079: VERSION_MINOR_PROPERTY, VERSION_MINOR_DEFAULT));
080: } catch (NumberFormatException nfe) {
081: //
082: }
083: return 0;
084: }
085:
086: public static int getMicroVersion() {
087: loadProperties();
088: try {
089: return Integer.parseInt(ourProperties.getProperty(
090: VERSION_MICRO_PROPERTY, VERSION_MICRO_DEFAULT));
091: } catch (NumberFormatException nfe) {
092: //
093: }
094: return 0;
095: }
096:
097: public static long getRevisionNumber() {
098: loadProperties();
099: try {
100: return Long.parseLong(ourProperties
101: .getProperty(VERSION_REVISION_PROPERTY,
102: VERSION_REVISION_DEFAULT));
103: } catch (NumberFormatException nfe) {
104: //
105: }
106: return -1;
107: }
108:
109: private static void loadProperties() {
110: if (ourProperties != null) {
111: return;
112: }
113: InputStream is = Version.class
114: .getResourceAsStream(PROPERTIES_PATH);
115: ourProperties = new Properties();
116: if (is == null) {
117: return;
118: }
119: try {
120: ourProperties.load(is);
121: } catch (IOException e) {
122: //
123: } finally {
124: SVNFileUtil.closeFile(is);
125: }
126:
127: }
128: }
|