mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-09 04:30:51 +08:00
Read WE version from manifest ourselves
This commit is contained in:
parent
3e15c6dfdd
commit
947775b5e5
@ -115,7 +115,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
val CLASSPATH = listOf("truezip", "truevfs", "js")
|
||||
.map { "$it.jar" }
|
||||
.flatMap { listOf(it, "WorldEdit/$it") }
|
||||
.joinToString(separator = " ")
|
||||
private val CLASSPATH = listOf("truezip", "truevfs", "js")
|
||||
.map { "$it.jar" }
|
||||
.flatMap { listOf(it, "WorldEdit/$it") }
|
||||
.joinToString(separator = " ")
|
||||
|
||||
fun Project.addJarManifest(includeClasspath: Boolean = false) {
|
||||
tasks.named<Jar>("jar") {
|
||||
val attributes = mutableMapOf(
|
||||
"WorldEdit-Version" to project(":worldedit-core").version
|
||||
)
|
||||
if (includeClasspath) {
|
||||
attributes["Class-Path"] = CLASSPATH
|
||||
}
|
||||
manifest.attributes(attributes)
|
||||
}
|
||||
}
|
||||
|
@ -43,12 +43,7 @@
|
||||
exclude("**/worldedit-adapters.jar")
|
||||
}
|
||||
|
||||
tasks.named<Jar>("jar") {
|
||||
manifest {
|
||||
attributes("Class-Path" to CLASSPATH,
|
||||
"WorldEdit-Version" to project.version)
|
||||
}
|
||||
}
|
||||
addJarManifest(includeClasspath = true)
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
dependencies {
|
||||
|
@ -739,23 +739,9 @@ public static String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
Package p = WorldEdit.class.getPackage();
|
||||
WorldEditManifest manifest = WorldEditManifest.load();
|
||||
|
||||
if (p == null) {
|
||||
p = Package.getPackage("com.sk89q.worldedit");
|
||||
}
|
||||
|
||||
if (p == null) {
|
||||
version = "(unknown)";
|
||||
} else {
|
||||
version = p.getImplementationVersion();
|
||||
|
||||
if (version == null) {
|
||||
version = "(unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
return version;
|
||||
return version = manifest.getWorldEditVersion();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
/**
|
||||
* Represents WorldEdit info from the MANIFEST.MF file.
|
||||
*/
|
||||
public class WorldEditManifest {
|
||||
|
||||
public static final String WORLD_EDIT_VERSION = "WorldEdit-Version";
|
||||
|
||||
public static WorldEditManifest load() {
|
||||
Attributes attributes = readAttributes();
|
||||
return new WorldEditManifest(
|
||||
readAttribute(attributes, WORLD_EDIT_VERSION, () -> "(unknown)")
|
||||
);
|
||||
}
|
||||
|
||||
private static @Nullable Attributes readAttributes() {
|
||||
Class<WorldEditManifest> clazz = WorldEditManifest.class;
|
||||
String className = clazz.getSimpleName() + ".class";
|
||||
String classPath = clazz.getResource(className).toString();
|
||||
if (!classPath.startsWith("jar")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
URL url = new URL(classPath);
|
||||
JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
|
||||
Manifest manifest = jarConnection.getManifest();
|
||||
return manifest.getMainAttributes();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String readAttribute(@Nullable Attributes attributes, String name,
|
||||
Supplier<String> defaultAction) {
|
||||
if (attributes == null) {
|
||||
return defaultAction.get();
|
||||
}
|
||||
String value = attributes.getValue(name);
|
||||
return value != null ? value : defaultAction.get();
|
||||
}
|
||||
|
||||
private final String worldEditVersion;
|
||||
|
||||
private WorldEditManifest(String worldEditVersion) {
|
||||
this.worldEditVersion = worldEditVersion;
|
||||
}
|
||||
|
||||
public String getWorldEditVersion() {
|
||||
return worldEditVersion;
|
||||
}
|
||||
}
|
@ -61,12 +61,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<Jar>("jar") {
|
||||
manifest {
|
||||
attributes("Class-Path" to CLASSPATH,
|
||||
"WorldEdit-Version" to project.version)
|
||||
}
|
||||
}
|
||||
addJarManifest(includeClasspath = true)
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
archiveClassifier.set("dist-dev")
|
||||
|
@ -80,11 +80,7 @@
|
||||
from(project(":worldedit-core").tasks.named("processResources"))
|
||||
}
|
||||
|
||||
tasks.named<Jar>("jar") {
|
||||
manifest {
|
||||
attributes("WorldEdit-Version" to project.version)
|
||||
}
|
||||
}
|
||||
addJarManifest(includeClasspath = false)
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
dependencies {
|
||||
|
@ -25,12 +25,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<Jar>("jar") {
|
||||
manifest {
|
||||
attributes("Class-Path" to CLASSPATH,
|
||||
"WorldEdit-Version" to project.version)
|
||||
}
|
||||
}
|
||||
addJarManifest(includeClasspath = true)
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
dependencies {
|
||||
@ -50,4 +45,4 @@
|
||||
tasks.named("build").configure {
|
||||
dependsOn("signShadowJar")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user