FileDocCategorySizeDatePackage
SunJspc.javaAPI DocGlassfish v2 API15138Fri May 04 22:32:42 BST 2007org.apache.tools.ant.taskdefs.optional.sun.appserv

SunJspc

public class SunJspc extends org.apache.tools.ant.taskdefs.MatchingTask
Ant task to run the jsp compiler.for SunONE Application Server

This task takes the given jsp files and compiles them into java files. It is then up to the user to compile the java files into classes.

The task requires the srcdir and destdir attributes to be set. This Task is a MatchingTask, so the files to be compiled can be specified using includes/excludes attributes or nested include/exclude elements. Optional attributes are verbose (set the verbosity level passed to jasper), package (name of the destination package for generated java classes and classpath (the classpath to use when running the jsp compiler).

Notes

The includes directive is necessary in the ant targets

The taskdef can contain in its classpath the path to the SunJspc compiled file

Usage

<taskdef
name="sun-appserv-jspc"
classname="org.apache.tools.ant.taskdefs.optional.sunone.SunJspc"
classpath=<classpath to the compiled file>/>

<sun-appserv-jspc srcdir="${basedir}/src/war"
destdir="${basedir}/gensrc"
package="com.i3sp.jsp"
verbose="9">
<include name="**\/*.jsp" />
</s1jspc>

<sun-appserv-jspc
destdir="${basedir}/gensrc"
verbose="9">
webapp=${basedir}
</sun-apserv-jspc>
author
Irfan Ahmed

Large Amount of cutting and pasting from the Javac task...

since
SunONE Application Server 7 SE

Fields Summary
private File
destDir
private File
srcDir
private String
packageName
private String
verboseLevel
private File
uriRoot
private File
uriBase
private org.apache.tools.ant.types.Path
classPath
private int
compileListLength
private boolean
failOnError
private File
webAppBaseDir
private File
sunoneHome
private File
asinstalldir
private static final String[]
CLASSPATH_ELEMENTS
Appserver runtime Libraries, expressed relative to the installation directory
LocalStringsManager
lsm
Constructors Summary
Methods Summary
private voidCheckForMutuallyExclusiveAttribute()
This private class checks for any mutually exclusive attributes. If mutually exclusive attributes that are specified, then a BuildException is thrown.

        if(webAppBaseDir!=null && srcDir!=null) {
            final String msg = lsm.getString("MutuallyExclusivelyAttribute",
                                             new Object[] {"srcdir",
                                                           "webapp"});
            throw new BuildException(msg, getLocation());
        }
    
private org.apache.tools.ant.types.PathconstructPath()

        StringBuffer classPathBuffer = new StringBuffer();
        if(getAsinstalldir()!=null)
        {
            for(int i=0;i<CLASSPATH_ELEMENTS.length;i++)
            {
                classPathBuffer.append((new File(getAsinstalldir(),CLASSPATH_ELEMENTS[i])).getPath());
                classPathBuffer.append(":");
            }
        }
        if(classPath!=null)
        {
            classPathBuffer.append(classPath);
            classPathBuffer.append(":");
        }
        classPathBuffer.append(Path.systemClasspath);
        return new Path(getProject(),classPathBuffer.toString());
    
public org.apache.tools.ant.types.PathcreateClasspath()
Nested ClassPath Element

        if(classPath==null)
            classPath = new Path(project);
        return classPath.createPath();
    
protected booleandoCompilation(java.lang.String[] args)

        try
        {
            Java java = (Java)project.createTask("java");
            java.setClasspath(constructPath());
            java.setClassname("org.apache.jasper.JspC");
            for(int i=0;i<args.length;i++)
            {
                java.createArg().setValue(args[i]);
            }
            java.setFailonerror(failOnError);
            java.setFork(true);
            log("Executing Jasper Compiler");
            int returnCode = java.executeJava();
            if(returnCode == 1)
            {
                log(lsm.getString("SetVerbose"));
                return false;
            }
            return true;
        }
        catch(Exception ex)
        {
            log(lsm.getString("ExceptionMessage", new Object[] {ex.toString()})); 
            return false;
        }
    
public voidexecute()

        
        CheckForMutuallyExclusiveAttribute();
        
        if(webAppBaseDir==null)
        {
            if(srcDir==null)
                throw new BuildException(lsm.getString("SourceDirectoryProviced"), location);
            if(!srcDir.exists() || !srcDir.isDirectory())
                throw new BuildException(lsm.getString("SourceDirectoryDoesNotExist",
                                                       new Object[] {srcDir.getAbsolutePath()}),
                                         location);
        }
        else
        {
            if(!webAppBaseDir.exists() || !webAppBaseDir.isDirectory())
                throw new BuildException(lsm.getString("WebAppDirectoryDoesNotExist",
                                                       new Object [] {webAppBaseDir.getAbsolutePath()}),
                                         location);
        }
            
        if(destDir!=null)
        {
            if(!destDir.exists())
                throw new BuildException(lsm.getString("DestinationDirectoryDoesNotExist",
                                                       new Object[] {destDir}));
            if(!destDir.isDirectory())
                throw new BuildException(lsm.getString("InvalidDestinationDirectory",
                                                       new Object[] {destDir}));
        }
        else
        {
            throw new BuildException(lsm.getString("DestinationDirectoryNoProvided"));
        }
        
        
        String args[] = getCommandString();
        if(srcDir!=null)
            log(lsm.getString("PreCompilation", new Object[] {String.valueOf(compileListLength),
                                                              destDir.getAbsolutePath()})); 
        if(!doCompilation(args))
            throw new BuildException(lsm.getString("CompilationFailed"));
    
protected java.io.FilegetAsinstalldir()
Returns the asinstalldir attribute specify by in the build script. If asinstalldir hasn't been explicitly set (using the setAsinstalldir method), the value stored in the sunone.home property will be returned.

return
File representing the app server installation directory. Returns null if the installation directory hasn't been explictly set and the sunone.home property isn't set.
throws
ClassNotFoundException if asinstalldir is an invalid directory

		if (asinstalldir == null) {
			String home = getProject().getProperty("asinstall.dir");
			if (home != null) {
                asinstalldir = new File(home);
			}
            else {
                home = getProject().getProperty("sunone.home");
                if (home != null)
                {
                    final String msg = lsm.getString("DeprecatedProperty", new Object[] {"sunone.home", "asinstall.dir"});
                    log(msg, Project.MSG_WARN);
                    asinstalldir = new File(home);
                }
                
            }
		}
        if (asinstalldir!=null) verifyAsinstalldir(asinstalldir);
		return asinstalldir;
	
protected java.lang.String[]getCommandString()

        ArrayList commandList = new ArrayList();
        
        commandList.add("-d");
        commandList.add(destDir.getAbsolutePath());
        
        if(packageName!=null && packageName.length()>0)
        {
            commandList.add("-p");
            commandList.add(packageName);
        }
        
        if(verboseLevel!=null)
            commandList.add("-v".concat(verboseLevel));
        
        if(uriRoot!=null && uriRoot.exists())
        {
            commandList.add("-uriroot");
            commandList.add(uriRoot.getAbsolutePath());
        }
        
        if(uriBase!=null && uriBase.exists())
        {
            commandList.add("-uribase");
            commandList.add(uriBase.getAbsolutePath());
        }
        else if(uriRoot!=null && uriRoot.exists())
        {
            commandList.add("-uribase");
            commandList.add(uriRoot.getAbsolutePath());
        }

        // START PWC 6386258
        commandList.add("-dtds");
        commandList.add("/dtds/");

        commandList.add("-schemas");
        commandList.add("/schemas/");
        // END PWC 6386258
 
        commandList.add("-die1");
        if(webAppBaseDir!=null)
        {
            commandList.add("-webapp");
            commandList.add(webAppBaseDir.getAbsolutePath());
        }
        else
        {
            DirectoryScanner ds = super.getDirectoryScanner(srcDir);
            String files[] = ds.getIncludedFiles();
            compileListLength = files.length;
            for(int i=0;i<files.length;i++)
            {
                File tempFile = new File(srcDir,files[i]);
                commandList.add(tempFile.getAbsolutePath());
            }
        }

        String args[] = (String[])commandList.toArray(new String[commandList.size()]);
        return args;
    
public java.io.FilegetDestdir()

        return destDir;
    
public booleangetFailonerror()

        return failOnError;
    
public java.lang.StringgetPackage()

        return packageName;
    
public java.io.FilegetSrcdir()

        return srcDir;
    
public java.io.FilegetUribase()

        if(uriBase!=null)
            return uriBase;
        return uriRoot;
    
public java.io.FilegetUriroot()

        return uriRoot;
    
public java.lang.StringgetVerbose()

        return verboseLevel;
    
public java.io.FilegetWebapp()

        return webAppBaseDir;
    
public voidsetAsinstalldir(java.io.File asinstalldir)
Specifies the installation directory for the Sun ONE Application Server 8. This may be used if the application server is installed on the local machine.

param
asinstalldir The home directory for the user's app server installation.

		this.asinstalldir = asinstalldir;
	
public voidsetClasspath(org.apache.tools.ant.types.Path cp)

        if(classPath == null)
            classPath = cp;
        else
            classPath.append(cp);
    
public voidsetClasspathref(org.apache.tools.ant.types.Reference ref)
Class Path Reference

        createClasspath().setRefid(ref);
    
public voidsetDestdir(java.io.File dest)

        destDir = dest;
    
public voidsetFailonerror(boolean fail)

        failOnError = fail;
    
public voidsetPackage(java.lang.String name)

        packageName = name;
    
public voidsetSrcdir(java.io.File src)

        srcDir = src;
    
public voidsetSunonehome(java.io.File sunoneHome)


       
    
        final String msg = lsm.getString("DeprecatedAttribute", new Object[] {"sunonehome",
         "asinstalldir"});
        log(msg, Project.MSG_WARN);
        this.asinstalldir = sunoneHome;
    
public voidsetUribase(java.io.File base)

        uriBase = base;
    
public voidsetUriroot(java.io.File root)

        uriRoot = root;
    
public voidsetVerbose(java.lang.String level)

        verboseLevel = level;
    
public voidsetWebapp(java.io.File baseDir)

        webAppBaseDir = baseDir;
    
private booleanverifyAsinstalldir(java.io.File home)
verify if asinsatlldir attribute is valid. asinstalldir must be a valid directory and must contain the config directory.

return
true if asinstalldir is valid
throws
ClassNotFoundException if asinstalldir is an invalid directory

        if (home!= null && home.isDirectory()) {
            if ( new File(home, "config").isDirectory() ) {
                return true;
            } 
        }
        throw new ClassNotFoundException("ClassCouldNotBeFound");