From 4ca1e26f0f96dc005a964df54b484d4c0e3fafaf Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 6 Aug 2016 12:25:23 +0200 Subject: [PATCH] Set version on build in sponge plugin --- api/pom.xml | 1 - bukkit/pom.xml | 16 ++++-- .../me/lucko/luckperms/LPBukkitPlugin.java | 8 +-- bungee/pom.xml | 16 ++++-- .../me/lucko/luckperms/LPBungeePlugin.java | 8 +-- common/pom.xml | 3 +- sponge/pom.xml | 57 +++++++++++++++++-- .../me/lucko/luckperms/LPSpongePlugin.java | 5 +- .../me/lucko/luckperms/utils/VersionUtil.java | 45 +++++++++++++++ 9 files changed, 131 insertions(+), 28 deletions(-) create mode 100644 sponge/src/main/java/me/lucko/luckperms/utils/VersionUtil.java diff --git a/api/pom.xml b/api/pom.xml index 65cd8f3e..56064edd 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -9,7 +9,6 @@ 4.0.0 - 1.5 luckperms-api diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 104355f1..0a44db72 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -10,9 +10,7 @@ 4.0.0 luckperms-bukkit - 1.5 jar - LuckPerms clean package @@ -46,6 +44,16 @@ true + + + org.slf4j + me.lucko.luckperms.lib.slf4j + + + com.zaxxer.hikari + me.lucko.luckperms.lib.hikari + + @@ -72,14 +80,14 @@ me.lucko.luckperms luckperms-common - 1.5 + ${project.version} compile me.lucko.luckperms luckperms-api - 1.5 + ${project.version} compile diff --git a/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java index 3642c0d3..df98b469 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java @@ -39,9 +39,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private TrackManager trackManager; private Datastore datastore; private UuidCache uuidCache; + private Logger log; @Override public void onEnable() { + log = LogUtil.wrap(getLogger()); + getLog().info("Loading configuration..."); configuration = new BukkitConfig(this); @@ -138,11 +141,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { Bukkit.getScheduler().runTask(this, r); } - @Override - public Logger getLog() { - return LogUtil.wrap(getLogger()); - } - @Override public String getVersion() { return getDescription().getVersion(); diff --git a/bungee/pom.xml b/bungee/pom.xml index 0d9d6bdf..6aadc021 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -10,9 +10,7 @@ 4.0.0 luckperms-bungee - 1.5 jar - LuckPerms clean package @@ -46,6 +44,16 @@ true + + + org.slf4j + me.lucko.luckperms.lib.slf4j + + + com.zaxxer.hikari + me.lucko.luckperms.lib.hikari + + @@ -65,14 +73,14 @@ me.lucko.luckperms luckperms-common - 1.5 + ${project.version} compile me.lucko.luckperms luckperms-api - 1.5 + ${project.version} compile diff --git a/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java index d26a88a8..97d2a3ec 100644 --- a/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java @@ -32,9 +32,12 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { private TrackManager trackManager; private Datastore datastore; private UuidCache uuidCache; + private Logger log; @Override public void onEnable() { + log = LogUtil.wrap(getLogger()); + getLog().info("Loading configuration..."); configuration = new BungeeConfig(this); @@ -98,11 +101,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { LuckPerms.unregisterProvider(); } - @Override - public Logger getLog() { - return LogUtil.wrap(getLogger()); - } - @Override public String getVersion() { return getDescription().getVersion(); diff --git a/common/pom.xml b/common/pom.xml index 047d0af6..f24e3a9b 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -9,7 +9,6 @@ 4.0.0 - 1.5 luckperms-common @@ -30,7 +29,7 @@ me.lucko.luckperms luckperms-api - 1.5 + ${project.version} compile diff --git a/sponge/pom.xml b/sponge/pom.xml index a37157c4..78888e84 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -10,9 +10,7 @@ 4.0.0 luckperms-sponge - 1.5 jar - LuckPerms clean package @@ -46,10 +44,54 @@ true + + + org.slf4j + me.lucko.luckperms.lib.slf4j + + + com.zaxxer.hikari + me.lucko.luckperms.lib.hikari + + + + de.icongmbh.oss.maven.plugins + javassist-maven-plugin + 1.1.0 + + false + + + me.lucko.luckperms.utils.VersionUtil + + + version + ${project.version} + + + + + + + + process-classes + + javassist + + + + + + me.lucko.luckperms + luckperms-sponge + ${project.version} + + + @@ -65,14 +107,14 @@ me.lucko.luckperms luckperms-common - 1.5 + ${project.version} compile me.lucko.luckperms luckperms-api - 1.5 + ${project.version} compile @@ -89,5 +131,12 @@ 1.7.9 compile + + + de.icongmbh.oss.maven.plugins + javassist-maven-plugin + 1.1.0 + provided + diff --git a/sponge/src/main/java/me/lucko/luckperms/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/LPSpongePlugin.java index f8e7fe83..fdda39b4 100644 --- a/sponge/src/main/java/me/lucko/luckperms/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/LPSpongePlugin.java @@ -37,9 +37,8 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Getter -@Plugin(id = "luckperms", name = "LuckPerms", version = LPSpongePlugin.VERSION, authors = {"Luck"}, description = "A permissions plugin") +@Plugin(id = "luckperms", name = "LuckPerms", version = "MAGIC", authors = {"Luck"}, description = "A permissions plugin") public class LPSpongePlugin implements LuckPermsPlugin { - static final String VERSION = "1.5"; // TODO load this from pom @Inject private Logger logger; @@ -142,7 +141,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { @Override public String getVersion() { - return VERSION; + return "MAGIC"; } @Override diff --git a/sponge/src/main/java/me/lucko/luckperms/utils/VersionUtil.java b/sponge/src/main/java/me/lucko/luckperms/utils/VersionUtil.java new file mode 100644 index 00000000..63c12725 --- /dev/null +++ b/sponge/src/main/java/me/lucko/luckperms/utils/VersionUtil.java @@ -0,0 +1,45 @@ +package me.lucko.luckperms.utils; + +import de.icongmbh.oss.maven.plugin.javassist.ClassTransformer; +import javassist.*; +import javassist.bytecode.AnnotationsAttribute; +import javassist.bytecode.annotation.Annotation; +import javassist.bytecode.annotation.StringMemberValue; +import me.lucko.luckperms.LPSpongePlugin; + +import java.util.Properties; + +/** + * Sets the version value of the plugin. + * Most of the code in this class was taken from: + * https://github.com/icon-Systemhaus-GmbH/javassist-maven-plugin/blob/master/README.textile + */ +public class VersionUtil extends ClassTransformer { + private String version = null; + + @Override + protected boolean shouldTransform(CtClass clazz) throws NotFoundException { + CtClass pluginClass = ClassPool.getDefault().get(LPSpongePlugin.class.getName()); + return !clazz.equals(pluginClass) && clazz.subtypeOf(pluginClass); + } + + @Override + protected void applyTransformations(CtClass clazz) throws Exception { + AnnotationsAttribute attribute = (AnnotationsAttribute) clazz.getClassFile().getAttribute(AnnotationsAttribute.visibleTag); + Annotation annotation = attribute.getAnnotation("org.spongepowered.api.plugin.Plugin"); + StringMemberValue versionValue = (StringMemberValue) annotation.getMemberValue("version"); + versionValue.setValue(version); + attribute.setAnnotation(annotation); + + CtMethod getVersionMethod = clazz.getDeclaredMethod("getVersion"); + CtMethod hackedVersionMethod = CtNewMethod.make("public String getVersion() { return \"" + this.version + "\"; }", clazz); + clazz.removeMethod(getVersionMethod); + clazz.addMethod(hackedVersionMethod); + } + + @Override + public void configure(final Properties properties) { + assert properties != null; + version = properties.getProperty("version"); + } +} \ No newline at end of file