lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Janssen <jans...@parc.com>
Subject Re: two versioning problems with Lucene
Date Tue, 07 Dec 2004 17:37:39 GMT
This incredibly fragile bit of code should work for existing jar
files, but good grief!

Bill
---------------------------------------------------

import java.util.jar.*;
import java.io.*;
import java.net.*;

class test {

    public static void main (String[] argv) {

        int major_version = 0;
        int minor_version = 0;
        int micro_version = 0;

        try {
            String url = ClassLoader.getSystemClassLoader().getResource("org/apache/lucene/util/Constants.class").toExternalForm();
            if (url.startsWith("jar:")) {
                URI u = new URI(url.substring(4, url.indexOf("!")));
                JarFile jf = new JarFile (new File(u));
                Manifest mf = jf.getManifest();
                Attributes attrs = mf.getAttributes("org/apache/lucene");
                String version_string = attrs.getValue("Specification-Version");
                System.err.println("version_string is " + version_string);
                if (version_string != null) {
                    String[] parts = version_string.split("\\.");
                    if (parts.length == 3) {
                        major_version = Integer.parseInt(parts[0]);
                        minor_version = Integer.parseInt(parts[1]);
                        micro_version = Integer.parseInt(parts[2]);
                    }
                }
            }
        } catch (Exception x) {
            x.printStackTrace(System.err);
        }
        
        System.out.println("major " + major_version + ", minor " + minor_version + ", micro
" + micro_version);
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message