plantuml/src/net/sourceforge/plantuml/version/Version.java

127 lines
3.3 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2022-08-17 17:34:24 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
2022-08-17 17:34:24 +00:00
*
2017-03-15 19:13:31 +00:00
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
2022-08-17 17:34:24 +00:00
*
2010-11-15 20:35:36 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
2022-08-17 17:34:24 +00:00
*
2010-11-15 20:35:36 +00:00
*
*/
package net.sourceforge.plantuml.version;
2015-04-07 18:18:37 +00:00
import java.util.Date;
2022-08-17 17:34:24 +00:00
import net.sourceforge.plantuml.log.Logme;
2020-05-30 15:20:23 +00:00
import net.sourceforge.plantuml.security.SURL;
2010-11-15 20:35:36 +00:00
public class Version {
2017-04-26 17:48:37 +00:00
private static final int MAJOR_SEPARATOR = 1000000;
2010-11-15 20:35:36 +00:00
public static int version() {
2023-01-29 14:24:49 +00:00
return 1202301;
2017-06-05 11:27:21 +00:00
}
public static int versionPatched() {
if (beta() != 0) {
return version() + 1;
}
return version();
2013-12-10 19:36:50 +00:00
}
public static String versionString() {
2016-05-11 21:31:47 +00:00
if (beta() != 0) {
2017-03-21 21:37:59 +00:00
return dotted(version() + 1) + "beta" + beta();
2013-12-10 19:36:50 +00:00
}
2017-03-21 21:37:59 +00:00
return dotted(version());
}
2020-02-18 21:24:31 +00:00
2019-07-14 20:09:26 +00:00
public static String fullDescription() {
return "PlantUML version " + Version.versionString() + " (" + Version.compileTimeString() + ")";
}
2017-03-21 21:37:59 +00:00
private static String dotted(int nb) {
2017-04-26 17:48:37 +00:00
final String minor = "" + nb % MAJOR_SEPARATOR;
final String major = "" + nb / MAJOR_SEPARATOR;
return major + "." + minor.substring(0, 4) + "." + Integer.parseInt(minor.substring(4));
2013-12-10 19:36:50 +00:00
}
2015-05-03 15:36:36 +00:00
public static String versionString(int size) {
final StringBuilder sb = new StringBuilder(versionString());
while (sb.length() < size) {
sb.append(' ');
}
return sb.toString();
}
2017-03-12 17:22:02 +00:00
public static int beta() {
2023-01-29 14:24:49 +00:00
final int beta = 0;
2015-04-07 18:18:37 +00:00
return beta;
}
2017-03-15 19:13:31 +00:00
public static String etag() {
2017-04-26 17:48:37 +00:00
return Integer.toString(version() % MAJOR_SEPARATOR - 201670, 36) + Integer.toString(beta(), 36);
2016-06-19 14:16:41 +00:00
}
public static String turningId() {
2017-03-21 21:37:59 +00:00
return etag();
2016-06-19 14:16:41 +00:00
}
2016-05-11 21:31:47 +00:00
public static long compileTime() {
2023-01-29 14:24:49 +00:00
return 1674997136325L;
2010-11-15 20:35:36 +00:00
}
2015-04-07 18:18:37 +00:00
public static String compileTimeString() {
if (beta() != 0) {
2017-04-26 17:48:37 +00:00
return "Unknown compile time";
2015-04-07 18:18:37 +00:00
}
return new Date(Version.compileTime()).toString();
2010-11-15 20:35:36 +00:00
}
2015-05-31 18:56:03 +00:00
public static String getJarPath() {
try {
final ClassLoader loader = Version.class.getClassLoader();
if (loader == null) {
return "No ClassLoader?";
}
2020-05-30 15:20:23 +00:00
final SURL url = SURL.create(loader.getResource("net/sourceforge/plantuml/version/Version.class"));
2022-08-17 17:34:24 +00:00
if (url == null) {
return "No URL?";
}
2015-05-31 18:56:03 +00:00
String fullpath = url.toString();
fullpath = fullpath.replaceAll("net/sourceforge/plantuml/version/Version\\.class", "");
return fullpath;
} catch (Throwable t) {
2022-08-17 17:34:24 +00:00
Logme.error(t);
2015-05-31 18:56:03 +00:00
return t.toString();
}
}
2010-11-15 20:35:36 +00:00
}