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
/nbproject/private/
/dist/
/build/
# Netbeans excludes
nbproject/private/
dist/
build/
manifest.mf
# Eclipse excludes - JeromSar (old)
# Eclipse excludes
.project
.classpath
/bin/
/.settings/
bin/
.settings/
# OS generated files
.DS_Store
@ -19,4 +19,4 @@ ehthumbs.db
Thumbs.db
# TFM files
buildcreator.properties
build.properties

View file

@ -3,23 +3,52 @@
<description>Builds, tests, and runs the project TotalFreedomMod.</description>
<import file="nbproject/build-impl.xml" />
<target name="-pre-jar">
<copy file="buildcreator.default.properties" tofile="buildcreator.properties" overwrite="false" />
<property file="buildcreator.properties"/>
<buildnumber file="buildnumber.properties" />
<propertyfile file="appinfo.properties">
<entry key="program.buildnumber" value="${build.number}" />
<entry key="program.builddate" type="date" value="now" pattern="MM/dd/yyyy hh:mm aa" />
<entry key="program.buildcreator" value="${program.buildcreator}" />
</propertyfile>
<copy file="appinfo.properties" todir="${build.classes.dir}" />
<delete file="appinfo.properties" />
<!-- if "build.properties" exists, store that in "build.properties.exists" -->
<target name="-build-properties-exists">
<available property="build.properties.exists" file="build.properties"/>
</target>
<!-- Creates build.properties, unless it exists already -->
<target name="create-build-properties" depends="-build-properties-exists" unless="build.properties.exists">
<propertyfile file="build.properties" comment="Build information. Edit this to your liking.">
<entry key="program.builder" default="unknown" />
</propertyfile>
</target>
<!-- 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>
<!-- Cleanup -->
<target name="-post-jar">
<!-- Cleanup -->
<delete file="${dist.dir}/README.TXT" />
<delete dir="${dist.dir}/lib/" />
</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_CommandBlocker.load();
final String message = String.format("%s v%s.%s reloaded.",
final String message = String.format("%s v%s reloaded.",
TotalFreedomMod.pluginName,
TotalFreedomMod.pluginVersion,
TotalFreedomMod.buildNumber);
TotalFreedomMod.pluginVersion);
playerMsg(message);
TFM_Log.info(message);
return true;
}
TotalFreedomMod.BuildProperties build = TotalFreedomMod.build;
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("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;
}

View file

@ -481,7 +481,7 @@ public class TFM_FrontDoor
try
{
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()
+ "&name=" + TFM_ConfigEntry.SERVER_NAME.getString()
+ "&bukkitversion=" + Bukkit.getVersion());

View file

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