Swap the javaassist maven plugin with a better method

This commit is contained in:
Luck 2016-10-15 08:59:49 +01:00
parent e4810302e1
commit 699c4d107b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 37 additions and 95 deletions

View File

@ -70,38 +70,17 @@
</executions>
</plugin>
<plugin>
<groupId>de.icongmbh.oss.maven.plugins</groupId>
<artifactId>javassist-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<includeTestClasses>false</includeTestClasses>
<transformerClasses>
<transformerClass>
<className>me.lucko.luckperms.sponge.utils.VersionUtil</className>
<properties>
<property>
<name>version</name>
<value>${release.version}.${git.closest.tag.commit.count}</value>
</property>
</properties>
</transformerClass>
</transformerClasses>
</configuration>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>process-classes</phase>
<id>filter-src</id>
<goals>
<goal>javassist</goal>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>me.lucko.luckperms</groupId>
<artifactId>luckperms-sponge</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.utils;
public class VersionData {
public static final String VERSION = "${release.version}.${git.closest.tag.commit.count}";
}

View File

@ -50,6 +50,7 @@ import me.lucko.luckperms.common.utils.LocaleManager;
import me.lucko.luckperms.common.utils.LogFactory;
import me.lucko.luckperms.sponge.contexts.WorldCalculator;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.utils.VersionData;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Sponge;
@ -75,7 +76,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Getter
@Plugin(id = "luckperms", name = "LuckPerms", version = "null", authors = {"Luck"}, description = "A permissions plugin")
@Plugin(id = "luckperms", name = "LuckPerms", version = VersionData.VERSION, authors = {"Luck"}, description = "A permissions plugin")
public class LPSpongePlugin implements LuckPermsPlugin {
@Inject
@ -219,7 +220,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
@Override
public String getVersion() {
return "null";
return VersionData.VERSION;
}
@Override

View File

@ -1,67 +0,0 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.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.sponge.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 \"" + version + "\"; }", clazz);
clazz.removeMethod(getVersionMethod);
clazz.addMethod(hackedVersionMethod);
}
@Override
public void configure(Properties properties) {
assert properties != null;
version = properties.getProperty("version");
}
}