lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Janssen <jans...@parc.com>
Subject Re: How do Lucene applications deal with API changes?
Date Tue, 02 Nov 2004 17:51:59 GMT
I know, I know, it's bad form to answer your own question.  But here's
a test program to distinguish between Lucene 1.4.1 and 1.4.2.

Bill

import java.io.*;

import java.lang.Class;
import java.lang.reflect.Method;

class testLucene {

    private static boolean compareArgs (Class[] args1, Class[] args2) throws Exception {
        if (args1.length != args2.length)
            return false;
        for (int i = 0;  i < args1.length;  i++) {
            if (args1[i] != args2[i])
                return false;
        }
        return true;
    }

    public static void main(String[] args) {

        try {
            Class queryparser = Class.forName("org.apache.lucene.queryParser.QueryParser");
            Method[] methods = queryparser.getDeclaredMethods();
            // check to see if the getFieldQuery() method in QueryParser has 
            // two args (1.4.2), or three (1.4.1)

            Class[] args1_4_1 = new Class[] { Class.forName("java.lang.String"),
                                              Class.forName("org.apache.lucene.analysis.Analyzer"),
                                              Class.forName("java.lang.String") };

            Class[] args1_4_2 = new Class[] { Class.forName("java.lang.String"),
                                              Class.forName("java.lang.String") };

            for (int i = 0;  i < methods.length;  i++) {
                if (methods[i].getName().equals("getFieldQuery")) {
                    Class[] parmTypes = methods[i].getParameterTypes();
                    if (compareArgs(args1_4_1, parmTypes)) {
                        System.out.println("1.4.1");
                        Runtime.getRuntime().exit(0);
                    }
                    if (compareArgs(args1_4_2, parmTypes)) {
                        System.out.println("1.4.2");
                        Runtime.getRuntime().exit(0);
                    }
                }
            }

            System.out.println("unknown");
            Runtime.getRuntime().exit(0);
        } catch (Exception x) {
            System.out.println("unknown");
            Runtime.getRuntime().exit(1);
        }
    };
}


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


Mime
View raw message