lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: two versioning problems with Lucene
Date Wed, 08 Dec 2004 01:55:31 GMT
On Dec 7, 2004, at 8:37 PM, Bill Janssen wrote:
> This incredibly fragile bit of code should work for existing jar
> files, but good grief!

So we hide this behind a utility method and no one needs to see any  
ugliness at all :)

	Erik

> ---------------------------------------------------
>
> 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


---------------------------------------------------------------------
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