Track build information in a better way

build.properties replaces buildcreator.properties, buildcreator.default.properties annd buildnumber.properties, but is untracked.
'git describe --tags --always HEAD' is now used to identify the build version, and its result is stored in the build properties file, included with the build. appinfo.properties is removed in favour of build.properties in the compiled jar.
The build number is still tracked, but offline, allowing TFM commits to more easily be merged
This commit is contained in:
JeromSar 2015-09-06 23:02:10 +02:00
parent 6aeb56de07
commit a7a2db15d6
7 changed files with 101 additions and 68 deletions

16
.gitignore vendored
View File

@ -1,14 +1,14 @@
# Netbeans excludes - StevenLawson & JeromSar # Netbeans excludes
/nbproject/private/ nbproject/private/
/dist/ dist/
/build/ build/
manifest.mf manifest.mf
# Eclipse excludes - JeromSar (old) # Eclipse excludes
.project .project
.classpath .classpath
/bin/ bin/
/.settings/ .settings/
# OS generated files # OS generated files
.DS_Store .DS_Store
@ -19,4 +19,4 @@ ehthumbs.db
Thumbs.db Thumbs.db
# TFM files # TFM files
buildcreator.properties build.properties

View File

@ -3,23 +3,52 @@
<description>Builds, tests, and runs the project TotalFreedomMod.</description> <description>Builds, tests, and runs the project TotalFreedomMod.</description>
<import file="nbproject/build-impl.xml" /> <import file="nbproject/build-impl.xml" />
<target name="-pre-jar"> <!-- if "build.properties" exists, store that in "build.properties.exists" -->
<copy file="buildcreator.default.properties" tofile="buildcreator.properties" overwrite="false" /> <target name="-build-properties-exists">
<available property="build.properties.exists" file="build.properties"/>
<property file="buildcreator.properties"/> </target>
<buildnumber file="buildnumber.properties" />
<!-- Creates build.properties, unless it exists already -->
<propertyfile file="appinfo.properties"> <target name="create-build-properties" depends="-build-properties-exists" unless="build.properties.exists">
<entry key="program.buildnumber" value="${build.number}" /> <propertyfile file="build.properties" comment="Build information. Edit this to your liking.">
<entry key="program.builddate" type="date" value="now" pattern="MM/dd/yyyy hh:mm aa" /> <entry key="program.builder" default="unknown" />
<entry key="program.buildcreator" value="${program.buildcreator}" /> </propertyfile>
</propertyfile> </target>
<copy file="appinfo.properties" todir="${build.classes.dir}" />
<delete file="appinfo.properties" /> <!-- Pre-jar property generation -->
<target name="-pre-jar" depends="create-build-properties">
<!-- Determine git version -->
<exec executable="git" outputproperty="program.buildhead" failifexecutionfails="false" errorproperty="">
<arg value="describe"/>
<arg value="--tags"/>
<arg value="--always"/>
<arg value="HEAD"/>
</exec>
<condition property="repository.version" value="${program.buildhead}" else="unknown">
<and>
<isset property="program.buildhead"/>
<length string="${program.buildhead}" trim="yes" length="0" when="greater"/>
</and>
</condition>
<!-- Load build.properties file -->
<property file="build.properties"/>
<!-- Load buildnumber from build.properties, store in ${build.number} -->
<buildnumber file="build.properties" />
<!-- Write build info -->
<propertyfile file="${build.classes.dir}/build.properties">
<entry key="program.buildnumber" value="${build.number}" />
<entry key="program.buildhead" value="${program.buildhead}" />
<entry key="program.builder" value="${program.builder}" />
<entry key="program.builddate" type="date" value="now" pattern="yyyy-MM-dd hh:mm aa" />
</propertyfile>
</target> </target>
<target name="-post-jar">
<!-- Cleanup --> <!-- Cleanup -->
<target name="-post-jar">
<delete file="${dist.dir}/README.TXT" /> <delete file="${dist.dir}/README.TXT" />
<delete dir="${dist.dir}/lib/" /> <delete dir="${dist.dir}/lib/" />
</target> </target>

View File

@ -1,6 +0,0 @@
#
# Build creator configuration
#
# Note: Do not edit this file! Edit the generated "buildcreator.properties" file instead.
#
program.buildcreator=Unknown

View File

@ -1,3 +0,0 @@
#Build Number for ANT. Do not edit!
#Sun Sep 06 17:00:40 CEST 2015
build.number=1055

View File

@ -44,28 +44,32 @@ public class Command_tfm extends TFM_Command
TFM_BanManager.load(); TFM_BanManager.load();
TFM_CommandBlocker.load(); TFM_CommandBlocker.load();
final String message = String.format("%s v%s.%s reloaded.", final String message = String.format("%s v%s reloaded.",
TotalFreedomMod.pluginName, TotalFreedomMod.pluginName,
TotalFreedomMod.pluginVersion, TotalFreedomMod.pluginVersion);
TotalFreedomMod.buildNumber);
playerMsg(message); playerMsg(message);
TFM_Log.info(message); TFM_Log.info(message);
return true; return true;
} }
TotalFreedomMod.BuildProperties build = TotalFreedomMod.build;
playerMsg("TotalFreedomMod for 'Total Freedom', the original all-op server.", ChatColor.GOLD); playerMsg("TotalFreedomMod for 'Total Freedom', the original all-op server.", ChatColor.GOLD);
playerMsg(String.format("Version "
+ ChatColor.BLUE + "%s.%s" + ChatColor.GOLD + ", built "
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + " by "
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + ".",
TotalFreedomMod.pluginVersion,
TotalFreedomMod.buildNumber,
TotalFreedomMod.buildDate,
TotalFreedomMod.buildCreator), ChatColor.GOLD);
playerMsg("Running on " + TFM_ConfigEntry.SERVER_NAME.getString() + ".", ChatColor.GOLD); playerMsg("Running on " + TFM_ConfigEntry.SERVER_NAME.getString() + ".", ChatColor.GOLD);
playerMsg("Created by Madgeek1450 and Prozza.", ChatColor.GOLD); playerMsg("Created by Madgeek1450 and Prozza.", ChatColor.GOLD);
playerMsg("Visit " + ChatColor.AQUA + "http://totalfreedom.me/" + ChatColor.GREEN + " for more information.", ChatColor.GREEN); playerMsg(String.format("Version "
+ ChatColor.BLUE + "%s.%s " + ChatColor.GOLD + "("
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + ")",
TotalFreedomMod.pluginVersion,
build.number,
build.head), ChatColor.GOLD);
playerMsg(String.format("Compiled "
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + " by "
+ ChatColor.BLUE + "%s",
build.date,
build.builder), ChatColor.GOLD);
playerMsg("Visit " + ChatColor.AQUA + "http://github.com/TotalFreedom/TotalFreedomMod"
+ ChatColor.GREEN + " for more information.", ChatColor.GREEN);
return true; return true;
} }

View File

@ -481,7 +481,7 @@ public class TFM_FrontDoor
try try
{ {
tempUrl = new URL("http://frontdoor.aws.af.cm/poll" tempUrl = new URL("http://frontdoor.aws.af.cm/poll"
+ "?version=" + TotalFreedomMod.pluginVersion + "-" + TotalFreedomMod.buildCreator + "?version=" + TotalFreedomMod.build.formattedVersion()
+ "&address=" + TFM_ConfigEntry.SERVER_ADDRESS.getString() + ":" + TotalFreedomMod.server.getPort() + "&address=" + TFM_ConfigEntry.SERVER_ADDRESS.getString() + ":" + TotalFreedomMod.server.getPort()
+ "&name=" + TFM_ConfigEntry.SERVER_NAME.getString() + "&name=" + TFM_ConfigEntry.SERVER_NAME.getString()
+ "&bukkitversion=" + Bukkit.getVersion()); + "&bukkitversion=" + Bukkit.getVersion());

View File

@ -4,7 +4,6 @@ import com.google.common.base.Function;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -45,13 +44,10 @@ public class TotalFreedomMod extends JavaPlugin
public static final String PROTECTED_AREA_FILENAME = "protectedareas.dat"; public static final String PROTECTED_AREA_FILENAME = "protectedareas.dat";
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat"; public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
// //
public static final BuildProperties build = new BuildProperties();
@Deprecated @Deprecated
public static final String YOU_ARE_NOT_OP = me.StevenLawson.TotalFreedomMod.Commands.TFM_Command.YOU_ARE_NOT_OP; public static final String YOU_ARE_NOT_OP = me.StevenLawson.TotalFreedomMod.Commands.TFM_Command.YOU_ARE_NOT_OP;
// //
public static String buildNumber = "1";
public static String buildDate = TotalFreedomMod.buildDate = TFM_Util.dateToString(new Date());
public static String buildCreator = "Unknown";
//
public static Server server; public static Server server;
public static TotalFreedomMod plugin; public static TotalFreedomMod plugin;
public static String pluginName; public static String pluginName;
@ -71,14 +67,15 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.setPluginLogger(plugin.getLogger()); TFM_Log.setPluginLogger(plugin.getLogger());
TFM_Log.setServerLogger(server.getLogger()); TFM_Log.setServerLogger(server.getLogger());
setAppProperties(); build.load();
} }
@Override @Override
public void onEnable() public void onEnable()
{ {
TFM_Log.info("Made by Madgeek1450 and Prozza"); TFM_Log.info("Created by Madgeek1450 and Prozza");
TFM_Log.info("Compiled " + buildDate + " by " + buildCreator); TFM_Log.info("Version " + build.formattedVersion());
TFM_Log.info("Compiled " + build.date + " by " + build.builder);
final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer(); final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer();
timer.start(); timer.start();
@ -217,25 +214,37 @@ public class TotalFreedomMod extends JavaPlugin
return TFM_CommandHandler.handleCommand(sender, cmd, commandLabel, args); return TFM_CommandHandler.handleCommand(sender, cmd, commandLabel, args);
} }
private static void setAppProperties() public static class BuildProperties {
{ public String builder;
public String number;
public String head;
public String date;
public void load() {
try try
{ {
final InputStream in = plugin.getResource("appinfo.properties"); final InputStream in = plugin.getResource("build.properties");
Properties props = new Properties();
// in = plugin.getClass().getResourceAsStream("/appinfo.properties"); final Properties props = new Properties();
props.load(in); props.load(in);
in.close(); in.close();
TotalFreedomMod.buildNumber = props.getProperty("program.buildnumber"); builder = props.getProperty("program.builder", "unknown");
TotalFreedomMod.buildDate = props.getProperty("program.builddate"); number = props.getProperty("program.buildnumber", "1");
TotalFreedomMod.buildCreator = props.getProperty("program.buildcreator"); head = props.getProperty("program.buildhead", "unknown");
date = props.getProperty("program.builddate", "unknown");
} }
catch (Exception ex) catch (Exception ex)
{ {
TFM_Log.severe("Could not load App properties!"); TFM_Log.severe("Could not load build properties! Did you compile with Netbeans/ANT?");
TFM_Log.severe(ex); TFM_Log.severe(ex);
} }
} }
public String formattedVersion() {
return pluginVersion + "." + number + " (" + head + ")";
}
}
} }