/**
 * Copyright (c) 2015, Lucee Assosication Switzerland. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package lucee;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import lucee.loader.TP;
import lucee.loader.engine.CFMLEngineFactory;

/**
 * returns th current built in version
 */
public class VersionInfo {

	private static org.osgi.framework.Version version = null;
	private static long created = -1;

	/**
	 * @return returns the current version
	 */
	public static org.osgi.framework.Version getIntVersion() {
		init();
		return version;
	}

	/**
	 * return creattion time of this version
	 * 
	 * @return creattion time
	 */
	public static long getCreateTime() {
		init();
		return created;
	}

	private static void init() {
		if (version != null) return;
		String content = "9000000:" + System.currentTimeMillis();
		try {
			content = getContentAsString(new TP().getClass().getClassLoader()
					.getResourceAsStream("lucee/version"), "UTF-8");

		} catch (IOException e) {
		}

		int index = content.indexOf(':');
		version = CFMLEngineFactory.toVersion(content.substring(0, index),CFMLEngineFactory.VERSION_ZERO);
		created = Long.parseLong(content.substring(index + 1));

	}

	private static String getContentAsString(InputStream is, String charset)
			throws IOException {

		BufferedReader br = (charset == null) ? new BufferedReader(
				new InputStreamReader(is)) : new BufferedReader(
				new InputStreamReader(is, charset));
		StringBuffer content = new StringBuffer();

		String line = br.readLine();
		if (line != null) {
			content.append(line);
			while ((line = br.readLine()) != null) {
				content.append("\n" + line);
			}
		}
		br.close();
		return content.toString();
	}
}
@@ -893,16 +893,84 @@
 mReader;
+%0Aimport java.text.ParseException;%0Aimport java.text.SimpleDateFormat;
 %0A%0Aimport
@@ -1929,63 +1929,299 @@
 ;%0A%09%09
-created = Long.parseLong(content.substring(index + 1));
+%0A%09%09String d=content.substring(index + 1);%0A%09%09try%7B%0A%09%09%09created = Long.parseLong(d);%0A%09%09%7D%0A%09%09catch(NumberFormatException nfe)%7B%0A%09%09%09try %7B%0A%09%09%09%09created=new SimpleDateFormat(%22yyyy/MM/dd HH:mm:ss z%22).parse(d).getTime();%0A%09%09%09%7D catch (ParseException pe) %7B%0A%09%09%09%09pe.printStackTrace();%0A%09%09%09%09created=0;%0A%09%09%09%7D%0A%09%09%7D%0A
 %0A%0A%09%7D

make the parsing of the version file more flexible