Skip to content

Commit

Permalink
Added the build number in /uh about. (Useful for bug reports.)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryCarrade committed Nov 25, 2014
1 parent 807a367 commit 8486776
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
36 changes: 36 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<url>https://github.com/AmauryCarrade/UHPlugin/issues</url>
</issueManagement>

<scm>
<connection>scm:git:https://github.com/AmauryCarrade/UHPlugin.git</connection>
<url>https://github.com/AmauryCarrade/UHPlugin.git</url>
</scm>

<build>
<plugins>
<plugin>
Expand All @@ -22,6 +27,37 @@
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<shortRevisionLength>10</shortRevisionLength>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifestEntries>
<Git-Commit>${buildNumber}</Git-Commit>
<Git-Branch>${scmBranch}</Git-Branch>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/me/azenet/UHPlugin/UHPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

package me.azenet.UHPlugin;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -29,6 +32,8 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import me.azenet.UHPlugin.i18n.I18n;

Expand Down Expand Up @@ -354,6 +359,8 @@ private void doAbout(CommandSender sender, Command command, String label, String
if(sender instanceof Player) sender.sendMessage("");
sender.sendMessage(i.t("cmd.titleHelp", p.getDescription().getDescription(), p.getDescription().getVersion()));

// Authors

String authors = "";
List<String> listAuthors = p.getDescription().getAuthors();
for(String author : listAuthors) {
Expand All @@ -370,6 +377,34 @@ else if(author == listAuthors.get(listAuthors.size() - 1)) {
}
sender.sendMessage(i.t("about.authors", authors));

// Build number

String build = null;
try {
Class<? extends UHPlugin> clazz = p.getClass();
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
if (classPath.startsWith("jar")) { // Class from JAR
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
"/META-INF/MANIFEST.MF";
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();

build = attr.getValue("Git-Commit");
}
} catch (IOException e) {
// Build not available.
}

if(build != null) {
sender.sendMessage(i.t("about.build.number", build));
}
else {
sender.sendMessage(i.t("about.build.notAvailable"));
}

// Translation

sender.sendMessage(i.t("about.i18n.title"));
sender.sendMessage(i.t("about.i18n.selected", i.getSelectedLanguage(), i.getTranslator(i.getSelectedLanguage())));
sender.sendMessage(i.t("about.i18n.fallback", i.getDefaultLanguage(), i.getTranslator(i.getDefaultLanguage())));
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/i18n/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ keys:
timersHelpRemove: "{cc}/uh timers remove <title ...> {ci}: deletes a timer."
timersHelpList: "{cc}/uh timers list {ci}: lists the registered timers."
timersHelpDurations: "{gray}Durations' format : mm, mm:ss or hh:mm:ss."

about:
authors: "Plugin made with love by {0}."
and: "and"

build:
number: "Build number: {0}."
notAvailable: "Build number not available."

i18n:
title: "{aqua}------ Translations ------"
selected: "Current language: {0} (translated by {1})."
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/i18n/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ keys:
authors: "Plugin réalisé avec amour par {0}."
and: "et"

build:
number: "Numéro de construction : {0}."
notAvailable: "Numéro de construction indisponible."

i18n:
title: "{aqua}------ Traductions ------"
selected: "Langue courante : {0} (traduit par {1})."
Expand Down

0 comments on commit 8486776

Please sign in to comment.