[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OPP task?



Yes, it's attached.



Eric Richardson wrote:

> Hi,
> 
> I was wondering if anyone has worked on the OPP task for ant that was
> mentioned before?
> 
> Eric
> 
> ----------------------------------------------------------------------
> Post a message:         mailto:ozone-dev@ozone-db.org
> Unsubscribe:            mailto:ozone-dev-request@ozone-db.org?body=unsubscribe
> Contact adminstrator:   mailto:ozone-dev-owner@ozone-db.org
> Read archived messages: http://www.ozone-db.org/
> ----------------------------------------------------------------------
> 
> 


// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by DigitalSesame are
// Copyright (C) 2000-2001, DigitalSesame, Inc All rights reserved.
//
// $Id: Opp.java,v 1.1.2.8 2001/05/08 05:01:40 david Exp $

package org.ozoneDB.tools.OPP.ant;

import java.io.File;

import org.apache.tools.ant.*;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.*;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Category;
import org.apache.log4j.FileAppender;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.Priority;

import org.ozoneDB.tools.OPP.OPP;

/**
 * Ant taskdef for OPP. The following is the ant syntax for this
 * taskdef.
 *
 * <pre>
 * &lt;opp srcdir="src/com/foo/bar"
 *         package="com.foo.bar"
 *         
 *         
 *
 * </pre>
 *
 * @author David Li <a href="/ozone-dev/07-2001/mailto:david@d11e.com">david@d11e.com</a> */
public class Opp extends MatchingTask
{
    /**
     * static flag to indicate whether the log is configured
     */
    private static boolean logConfigurd = false;
    static {
	if (!logConfigurd) {
	    BasicConfigurator.configure(new FileAppender(new PatternLayout("%m%n"),
							 System.out));
	    Category.getRoot().setPriority(Priority.INFO);
	    logConfigurd = true;
	}
    }

    /**
     * class path for the Opp execution (mainly for the BCEL library)
     */
    private Path fClasspath;
    
    /**
     * set whether to execute quietly
     */
    private boolean fQuiet;

    /**
     * OPP object
     */
    OPP fOPP;

    /**
     * Source directory
     */
    private String fPackage = "";

    /**
     * Constructor
     */
    public Opp () {
	super();
	fOPP = new OPP();
	fOPP.setCompileSource(false);
	fOPP.setKeepSource(true);
    }

    /**
     * Set the classpath to be used for this compilation.
     */
    public void setClasspath(Path s) {
        createClasspath().append(s);
    }
    
    /**
     * Creates a nested classpath element
     */
    public Path createClasspath() {
	if (fClasspath == null) {
	    fClasspath = new Path(project);
	}
        return fClasspath.createPath();
    }

    /**
     * Adds a reference to a CLASSPATH defined elsewhere.
     */
    public void setClasspathRef(Reference ref) {
        createClasspath().setRefid(ref);
    }

    /**
     * Set 'srcdir' (ant taskdef method)
     */
    public void setSrcdir (File srcdir) {
	fOPP.setSourceDir (srcdir);
    }

    /**
     * Set 'outdir' (ant taskdef method)
     */
    public void setOutdir (File outdir) {
	fOPP.setOutputDir (outdir);
    }

    /**
     * Set 'keepsource' attribute
     */
    public void setKeepsource(boolean keepsource) {
	fOPP.setKeepSource(keepsource);
    }

    /**
     * Set 'compile' attribute
     */
    public void setCompile(boolean compile) {
	fOPP.setCompileSource(compile);
    }

    /**
     * Set 'quiet' attribute
     */
    public void setQuiet(boolean quiet) {
	fQuiet = quiet;
    }

    /**
     * Set 'cache' attribute
     */
    public void setCache(boolean cache) {
	fOPP.setCache(cache);
    }

    /**
     * Set 'pattern' attribute
     */
    public void setPattern (String pattern) {
	fOPP.setUpdateMethodPattern(pattern);
    }

    /**
     * Set 'logging' attribute
     */
    public void setLogging (boolean logging) {
	fOPP.setGenerateLogging(logging);
    }

    /**
     * Set 'force' attribute
     */
    public void setForce (boolean logging) {
	fOPP.setForceGeneration(logging);
    }
    
    /**
     * set the package name (ant taskdef method)
     */
    public void setPackage (String packagename) {
	fPackage = packagename + ".";
    }

    /**
     * Set the 'printstacktrace' attribute
     */
    public void setPrintstacktrace(boolean printStackTrace) {
	fOPP.setPrintStackTrace(printStackTrace);
    }

    /**
     * Main execution method of the Ant task
     */
    public void execute() throws BuildException {

	if (fQuiet) {
	    Category.getRoot().setPriority(Priority.WARN);
	}

	if (this.getClass().getClassLoader() instanceof AntClassLoader) {
	    if (fClasspath != null) {
		log("execute(): set classpath to " + fClasspath.toString(), Project.MSG_VERBOSE);
		fOPP.setClassPath(fClasspath.toString());
	    }
	}

	DirectoryScanner ds = getDirectoryScanner(fOPP.getSourceDir());
	String[] files = ds.getIncludedFiles();
	String className;
	int index;
	if ((files != null) && (files.length > 0)) {
	    for (int i = 0 ; i < files.length; i++) {
		if ((index = files[i].lastIndexOf(".java")) > 0) {
		    className = fPackage + files[i].substring(0, index);
		    fOPP.addClass(className);
		}
	    }
	    try {
		fOPP.generateProxies();
	    } catch (Exception e) {
		throw new BuildException ("opp error", e);
	    }
	} else {
	    throw new BuildException ("must specify input files");
	}
    }
}