Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / Version.java @ 37822

History | View | Annotate | Download (3.8 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.extension;
23

    
24
import java.util.StringTokenizer;
25

    
26
import org.gvsig.app.ApplicationLocator;
27
import org.gvsig.installer.lib.api.InstallerLocator;
28
import org.gvsig.installer.lib.api.PackageInfo;
29
import org.gvsig.installer.lib.api.creation.MakePluginPackageService;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

    
33
/**
34
 * gvSIG application version information.
35
 * 
36
 * @author gvSIG Team
37
 * @version $Id: Version.java 37822 2012-01-27 13:46:11Z nfrancisco $
38
 */
39
public class Version {
40

    
41
    private static final Logger LOG = LoggerFactory.getLogger(Version.class);
42
    private static final String APP_PACKAGE_CODE = "org.gvsig.app";
43

    
44
    private int majorVersionNumber;
45
    private int minorVersionNumber;
46
    private int releaseNumber;
47

    
48
    private String buildNumber = "unknown";
49

    
50
    @Deprecated
51
    public static String format() {
52
        return ApplicationLocator.getManager().getVersion().getFormat();
53
    }
54

    
55
    @Deprecated
56
    public static String longFormat() {
57
        return ApplicationLocator.getManager().getVersion().getLongFormat();
58
    }
59

    
60
    @Deprecated
61
    public static String getBuild() {
62
        return ApplicationLocator.getManager().getVersion().getBuildId();
63
    }
64

    
65
    /**
66
     * Constructor.
67
     * Loads version information from the application installation information.
68
     */
69
    public Version() {
70
        String[] versions = new String[] { "2", "0", "0" };
71
        try {
72
            MakePluginPackageService packageService =
73
                InstallerLocator.getInstallerManager()
74
                    .getMakePluginPackageService();
75

    
76
            PackageInfo info =
77
                packageService.getPluginPackageInfo(APP_PACKAGE_CODE);
78

    
79
            String version = info.getGvSIGVersion();
80

    
81
            StringTokenizer tokens = new StringTokenizer(version, ".");
82
            int i = 0;
83
            while (tokens.hasMoreTokens() && i < 3) {
84
                versions[i] = tokens.nextToken();
85
                i++;
86
            }
87
            this.buildNumber = Integer.toString(info.getBuild());
88

    
89
        } catch (Exception e) {
90
            LOG.error("Error getting version information through "
91
                + "the InstallManager", e);
92
        }
93

    
94
        this.majorVersionNumber = Integer.parseInt(versions[0]);
95
        this.minorVersionNumber = Integer.parseInt(versions[1]);
96
        this.releaseNumber = Integer.parseInt(versions[2]);
97
        
98
        LOG.debug("Loaded version information: {}", getLongFormat());
99
    }
100

    
101
    public int getMinor() {
102
        return minorVersionNumber;
103
    }
104

    
105
    public int getMajor() {
106
        return majorVersionNumber;
107
    }
108

    
109
    public int getRelease() {
110
        return releaseNumber;
111
    }
112

    
113
    public String getBuildId() {
114
        return buildNumber;
115
    }
116

    
117
    public String toString() {
118
        return getLongFormat();
119
    }
120

    
121
    public String getFormat() {
122
        return getMajor() + "." + getMinor() + "." + getRelease();
123
    }
124

    
125
    public String getLongFormat() {
126
        return getFormat() + " (Build " + getBuildId() + ")";
127
    }
128
}