W3C home > Mailing lists > Public > www-jigsaw@w3.org > January to February 2000

install.java: Test for packages...

From: Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>
Date: Tue, 25 Jan 2000 11:24:37 +0100
Message-Id: <388D79E5.F89295CD@informatik.med.uni-giessen.de>
To: W3 Jigsaw Mailinglist <www-jigsaw@w3.org>

Hi !

----

I've attached PackageTest.java, a small demo which checks for missing
packages.
The final goal is to embed this in both Install.java (to warn the user
that packages are missing instead of the cryptic exeption dump) and the
servlet loader (to warn: servlet packages missing - can't load servlet).

ToDo:
- embed the work into Install.java
- embed the work into the servlet loader
- Install.java: check if Unix native library can be loaded or not
- Add an option to Install.java to check the CLASSPATH without
installing (e.g. "-check")
Best would be to add an option "-install", too. If both "-install" or
"-check" are missing, the usage is printed.
- Install.java: Stop installation if "check" fails to locate the jigsaw
core packages.

Yves, Benoit... any comments ?

----

Bye,
Roland

--
  __ .  . __
 (o.\ \/ /.o) Roland.Mainz@informatik.med.uni-giessen.de
  \__\/\/__/  gisburn@informatik.med.uni-giessen.de
  /O /==\ O\  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
 (;O/ \/ \O;) TEL +49 (0) 641/99-13193 FAX +49 (0) 641/99-41359




// package test (demo) for jigsaw
// written by Roland.Mainz@informatik.med.uni-giessen.de
// ToDo:
// - integration into Install.java
// - integration in servlet support:
//   only load a servlet if servlet classes are available, 
//   otherwise print a SIMPLE error message instead of the huge cryptic exception
public class PackageTest
{   
    final static int EXIT_SUCCESS = 0;
    final static int EXIT_FAILURE = 1;
    
    // this should be package names, but because Package.getPackage() 
    // doesn't into our needs we're using explicit class names here 
    // to force that the packages gets loaded...
    static PackageTest JAVAX_SERVLETS        = new PackageTest( "javax.servlet",        "Servlet"     );
    static PackageTest JAVAX_SERVLETS_HTTP   = new PackageTest( "javax.servlet.http",   "HttpSession" );
    static PackageTest JAVAX_SERVLETS_JSP    = new PackageTest( "javax.servlet.jsp",    "JspPage"     );
    static PackageTest JAVAX_SWING           = new PackageTest( "javax.swing",          "JButton"     );
    static PackageTest ORG_W3C_UTIL          = new PackageTest( "org.w3c.util",         "IO"          );
    static PackageTest ORG_W3C_JIGSAW        = new PackageTest( "org.w3c.jigsaw",       "Main"        );
    static PackageTest ORG_W3C_JIGSAW_ADMIN  = new PackageTest( "org.w3c.jigsaw.admin", "JigKill"     );
    static PackageTest ORG_W3C_JIGADM        = new PackageTest( "org_w3c.jigadm",       "Main"        );
    static PackageTest ORG_W3C_JIGADMIN      = new PackageTest( "org_w3c.jigadmin",     "Main"        );
    
    
    protected String packagename;
    protected String testclass;
    
    PackageTest( String packagename, String testclass )
    {
        this.packagename = packagename;
        this.testclass   = testclass;
    }
    
   
    boolean hasPackage()
    {
        boolean found = false;
        
        // Intro: we're looking for...
        System.err.print( "--> checking for " + packagename + "...\t" );
        
        Throwable thrx = null;
        
        try
        {
          // Package.getPackage() doesn't work here because it only looks for already loaded packages ;-(
          found = (Class.forName( packagename + "." + testclass ) != null);
        }
        catch( Throwable thr )
        {
          // not a simple ClassNotFoundException ? Then we're interested in details - save it...
          if( !(thr instanceof ClassNotFoundException) )
            thrx = thr;
        }
        
        System.err.println( ((found)?("found"):("not found")) + ((thrx != null)?(" because " + thrx):("")) + "." );
        
        return( found  );
    }

    
    public static void main( String args[] )
    {
        d( "Checking packages in CLASSPATH..." );
        boolean hasSwing       = JAVAX_SWING.hasPackage();
        boolean hasJigsawZip   = ORG_W3C_JIGSAW.hasPackage() && ORG_W3C_JIGSAW_ADMIN.hasPackage();
        boolean hasServletCore = JAVAX_SERVLETS.hasPackage();
        boolean hasServletHttp = JAVAX_SERVLETS_HTTP.hasPackage();
        boolean hasServletJsp  = JAVAX_SERVLETS_JSP.hasPackage();
        boolean hasJigAdmin2   = ORG_W3C_JIGADMIN.hasPackage();
        
        d( "results:" );
        
        if( hasJigsawZip )
          d( "jigsaw core packages found." );
        else
          d( "jigsaw core packages not found - jigsaw.zip must be in CLASSPATH." );
        
        if( hasServletCore && hasServletHttp )
          d( "standard servlets packages found." );
        else
          d( "no servlet packages found - you need servlet.jar in CLASSPATH to use servlets." );
        
        if( hasServletCore && hasServletJsp )
          d( "javasoft jsp packages found." );
          
        if( hasJigsawZip && hasSwing && hasJigAdmin2 )
          d( "swing and JigAdmin2 packages found - you can use the new Swing-based JigAdmin2" );
              
        System.exit( EXIT_SUCCESS );
    }

  
    static void d( String s )
    {
        System.err.println( "PackageTest: " + s );
    }
}
Received on Tuesday, 25 January 2000 05:25:13 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:34 GMT