View Javadoc

1   /**
2    *  MicroEmulator
3    *  Copyright (C) 2006-2007 Bartek Teodorczyk <barteo@barteo.net>
4    *  Copyright (C) 2006-2007 Vlad Skarzhevskyy
5    *
6    *  It is licensed under the following two licenses as alternatives:
7    *    1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version
8    *    2. Apache License (the "AL") Version 2.0
9    *
10   *  You may not use this file except in compliance with at least one of
11   *  the above two licenses.
12   *
13   *  You may obtain a copy of the LGPL at
14   *      http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
15   *
16   *  You may obtain a copy of the AL at
17   *      http://www.apache.org/licenses/LICENSE-2.0
18   *
19   *  Unless required by applicable law or agreed to in writing, software
20   *  distributed under the License is distributed on an "AS IS" BASIS,
21   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   *  See the LGPL or the AL for the specific language governing permissions and
23   *  limitations.
24   *
25   *  @version $Id: BuildVersion.java 1751 2008-06-09 16:55:33Z vlads $
26   */
27  package org.microemu.app.util;
28  
29  import java.io.IOException;
30  import java.io.InputStream;
31  import java.util.Properties;
32  
33  /**
34   * @author vlads
35   * 
36   */
37  public class BuildVersion {
38  
39  	public static String getVersion() {
40  		InputStream buildVersionInputStream = BuildVersion.class
41  				.getResourceAsStream("/META-INF/microemulator-build.version");
42  		if (buildVersionInputStream != null) {
43  			Properties projectProperties = new Properties();
44  			try {
45  				projectProperties.load(buildVersionInputStream);
46  				String version = projectProperties.getProperty("build.version");
47  				if (version != null) {
48  					String buildNumber = projectProperties.getProperty("build.buildNum");
49  					if (buildNumber != null) {
50  						version += "." + buildNumber;
51  					}
52  					return version;
53  				}
54  			} catch (IOException ignore) {
55  			} finally {
56  				IOUtils.closeQuietly(buildVersionInputStream);
57  			}
58  		}
59  
60  		InputStream mavenDataInputStream = BuildVersion.class
61  				.getResourceAsStream("/META-INF/maven/org.microemu/microemu-javase/pom.properties");
62  		if (mavenDataInputStream != null) {
63  			Properties projectProperties = new Properties();
64  			try {
65  				projectProperties.load(mavenDataInputStream);
66  				String version = projectProperties.getProperty("version");
67  				if (version != null) {
68  					return version;
69  				}
70  			} catch (IOException ignore) {
71  			} finally {
72  				IOUtils.closeQuietly(mavenDataInputStream);
73  			}
74  		}
75  		return "n/a";
76  	}
77  }