Statistics
| Revision:

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

History | View | Annotate | Download (3.98 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.io.File;
25
import java.util.StringTokenizer;
26

    
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

    
30
import org.gvsig.andami.Launcher;
31
import org.gvsig.app.ApplicationLocator;
32
import org.gvsig.installer.lib.api.InstallerLocator;
33
import org.gvsig.installer.lib.api.PackageInfo;
34
import org.gvsig.installer.lib.api.creation.MakePluginPackageService;
35

    
36
/**
37
 * gvSIG application version information.
38
 * 
39
 * @author gvSIG Team
40
 * @version $Id: Version.java 34441 2011-01-25 16:16:45Z cordinyana $
41
 */
42
public class Version {
43

    
44
    private static final Logger LOG = LoggerFactory.getLogger(Version.class);
45
    private static final String APP_PACKAGE_CODE = "org.gvsig.app";
46

    
47
    private int majorVersionNumber;
48
    private int minorVersionNumber;
49
    private int releaseNumber;
50

    
51
    private String buildNumber = "unknown";
52

    
53
    @Deprecated
54
    public static String format() {
55
        return ApplicationLocator.getManager().getVersion().getFormat();
56
    }
57

    
58
    @Deprecated
59
    public static String longFormat() {
60
        return ApplicationLocator.getManager().getVersion().getLongFormat();
61
    }
62

    
63
    @Deprecated
64
    public static String getBuild() {
65
        return ApplicationLocator.getManager().getVersion().getBuildId();
66
    }
67

    
68
    /**
69
     * Constructor.
70
     * Loads version information from the application installation information.
71
     */
72
    public Version() {
73
        String[] versions = new String[] { "2", "0", "0" };
74
        try {
75
            MakePluginPackageService packageService =
76
                InstallerLocator.getInstallerManager()
77
                    .getMakePluginPackageService(
78
                        new File(Launcher.getAndamiConfig()
79
                            .getPluginsDirectory()).getAbsoluteFile());
80

    
81
            PackageInfo info =
82
                packageService.getPluginPackageInfo(APP_PACKAGE_CODE);
83

    
84
            String version = info.getGvSIGVersion();
85

    
86
            StringTokenizer tokens = new StringTokenizer(version, ".");
87
            int i = 0;
88
            while (tokens.hasMoreTokens() && i < 3) {
89
                versions[i] = tokens.nextToken();
90
                i++;
91
            }
92
            this.buildNumber = Integer.toString(info.getBuild());
93

    
94
        } catch (Exception e) {
95
            LOG.error("Error getting version information through "
96
                + "the InstallManager", e);
97
        }
98

    
99
        this.majorVersionNumber = Integer.parseInt(versions[0]);
100
        this.minorVersionNumber = Integer.parseInt(versions[1]);
101
        this.releaseNumber = Integer.parseInt(versions[2]);
102
        
103
        LOG.debug("Loaded version information: {}", getLongFormat());
104
    }
105

    
106
    public int getMinor() {
107
        return minorVersionNumber;
108
    }
109

    
110
    public int getMajor() {
111
        return majorVersionNumber;
112
    }
113

    
114
    public int getRelease() {
115
        return releaseNumber;
116
    }
117

    
118
    public String getBuildId() {
119
        return buildNumber;
120
    }
121

    
122
    public String toString() {
123
        return getLongFormat();
124
    }
125

    
126
    public String getFormat() {
127
        return getMajor() + "." + getMinor() + "." + getRelease();
128
    }
129

    
130
    public String getLongFormat() {
131
        return getFormat() + " (Build " + getBuildId() + ")";
132
    }
133
}