提交 772c664d 编写于 作者: S Skylot

Store version number in manifest

上级 29840e03
......@@ -7,9 +7,10 @@ apply plugin: 'idea'
sourceCompatibility = 1.6
targetCompatibility = 1.6
version = 'dev'
version = file('version').readLines().get(0)
mainClassName = "jadx.Main"
manifest.mainAttributes("jadx-version" : version)
project.ext {
mainSamplesClass = "jadx.samples.RunTests"
......
package jadx;
import jadx.utils.Utils;
public class Consts {
public static final String JADX_VERSION = "dev";
public static final String JADX_VERSION = Utils.getJadxVersion();
public static final boolean DEBUG = false;
......
......@@ -110,7 +110,7 @@ public class JadxArgs {
JCommander jc = new JCommander(this);
// print usage in not sorted fields order (by default its sorted by description)
PrintStream out = System.out;
out.println("jadx - dex to java decompiler, version: '" + Consts.JADX_VERSION + "'");
out.println("jadx - dex to java decompiler, version: " + Consts.JADX_VERSION);
out.println();
out.println("usage: jadx [options] " + jc.getMainParameterDescription());
out.println("options:");
......
package jadx.utils;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.jar.Manifest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Utils {
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
public static String cleanObjectName(String obj) {
int last = obj.length() - 1;
......@@ -52,4 +60,20 @@ public class Utils {
}
return sb.toString();
}
public static String getJadxVersion() {
try {
Enumeration<URL> resources =
new Utils().getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
String ver = manifest.getMainAttributes().getValue("jadx-version");
if (ver != null)
return ver;
}
} catch (IOException e) {
LOG.error("Can't get manifest file", e);
}
return "dev";
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册