Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 67339 invoked from network); 5 Jan 2003 08:11:45 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 5 Jan 2003 08:11:45 -0000 Received: (qmail 13066 invoked by uid 97); 5 Jan 2003 08:13:11 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 13049 invoked by uid 97); 5 Jan 2003 08:13:11 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 13032 invoked by uid 97); 5 Jan 2003 08:13:10 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 5 Jan 2003 08:11:37 -0000 Message-ID: <20030105081137.14302.qmail@icarus.apache.org> From: dion@apache.org To: jakarta-commons-sandbox-cvs@apache.org Subject: cvs commit: jakarta-commons-sandbox/jelly/jelly-tags/antlr/src/java/org/apache/commons/jelly/tags/antlr package.html AntlrTagLibrary.java GrammarTag.java AntlrTag.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N dion 2003/01/05 00:11:37 Added: jelly/jelly-tags/antlr/src/java/org/apache/commons/jelly/tags/antlr package.html AntlrTagLibrary.java GrammarTag.java AntlrTag.java Log: Moved xmlunit out of core Revision Changes Path 1.1 jakarta-commons-sandbox/jelly/jelly-tags/antlr/src/java/org/apache/commons/jelly/tags/antlr/package.html Index: package.html ===================================================================

A tag library for working with the Antlr library

1.1 jakarta-commons-sandbox/jelly/jelly-tags/antlr/src/java/org/apache/commons/jelly/tags/antlr/AntlrTagLibrary.java Index: AntlrTagLibrary.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/antlr/src/java/org/apache/commons/jelly/tags/antlr/AntlrTagLibrary.java,v 1.1 2003/01/05 08:11:36 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/05 08:11:36 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * $Id: AntlrTagLibrary.java,v 1.1 2003/01/05 08:11:36 dion Exp $ */ package org.apache.commons.jelly.tags.antlr; import org.apache.commons.jelly.TagLibrary; /** Implements tags that are useful for working with ANTLR. * * @author bob mcwhirter * @version $Revision: 1.1 $ */ public class AntlrTagLibrary extends TagLibrary { public AntlrTagLibrary() { registerTag("antlr", AntlrTag.class); registerTag("grammar", GrammarTag.class); } } 1.1 jakarta-commons-sandbox/jelly/jelly-tags/antlr/src/java/org/apache/commons/jelly/tags/antlr/GrammarTag.java Index: GrammarTag.java =================================================================== /* * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * */ package org.apache.commons.jelly.tags.antlr; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.JellyException; public class GrammarTag extends TagSupport { public GrammarTag() { } // Tag interface //------------------------------------------------------------------------- public void doTag(final XMLOutput output) throws Exception { String grammar = getBodyText(); AntlrTag antlr = (AntlrTag) findAncestorWithClass( AntlrTag.class ); if ( antlr == null ) { throw new JellyException( " should only be used within an block." ); } antlr.addGrammar( grammar ); } } 1.1 jakarta-commons-sandbox/jelly/jelly-tags/antlr/src/java/org/apache/commons/jelly/tags/antlr/AntlrTag.java Index: AntlrTag.java =================================================================== /* * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * */ package org.apache.commons.jelly.tags.antlr; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.MissingAttributeException; import org.apache.commons.jelly.JellyException; import antlr.Tool; import java.io.File; import java.io.FileReader; import java.io.BufferedReader; import java.security.Permission; import java.util.List; import java.util.ArrayList; import java.util.Iterator; public class AntlrTag extends TagSupport { private List grammars; private File outputDir; public AntlrTag() { this.grammars = new ArrayList( 1 ); } // Tag interface //------------------------------------------------------------------------- /** * Evaluate the body to register all the various goals and pre/post conditions * then run all the current targets */ public void doTag(final XMLOutput output) throws Exception { if ( this.outputDir == null ) { throw new MissingAttributeException( "outputDir" ); } invokeBody( output ); Iterator grammarIter = this.grammars.iterator(); String eachGrammar = null; String sourceDir = (String) getContext().getVariable( "maven.antlr.src.dir" ); File grammar = null; while ( grammarIter.hasNext() ) { eachGrammar = ((String) grammarIter.next()).trim(); grammar = new File( sourceDir, eachGrammar ); File generated = getGeneratedFile( grammar.getPath() ); if ( generated.exists() ) { if ( generated.lastModified() > grammar.lastModified() ) { // it's more recent, skip. return; } } if ( ! generated.getParentFile().exists() ) { generated.getParentFile().mkdirs(); } String[] args = new String[] { "-o", generated.getParentFile().getPath(), grammar.getPath(), }; SecurityManager oldSm = System.getSecurityManager(); System.setSecurityManager( NoExitSecurityManager.INSTANCE ); try { Tool.main( args ); } catch (SecurityException e) { if ( ! e.getMessage().equals( "exitVM-0" ) ) { throw new JellyException( e ); } } finally { System.setSecurityManager( oldSm ); } } } protected File getGeneratedFile(String grammar) throws JellyException { File grammarFile = new File( grammar ); String generatedFileName = null; String className = null; String packageName = ""; try { BufferedReader in = new BufferedReader(new FileReader(grammar)); String line; while ((line = in.readLine()) != null) { line = line.trim(); int extendsIndex = line.indexOf(" extends "); if (line.startsWith("class ") && extendsIndex > -1) { generatedFileName = line.substring(6, extendsIndex).trim(); break; } else if ( line.startsWith( "package" ) ) { packageName = line.substring( 8 ).trim(); } } in.close(); } catch (Exception e) { throw new JellyException("Unable to determine generated class", e); } if (generatedFileName == null) { return null; } File genFile = null; if ( "".equals( packageName ) ) { genFile = new File( getOutputDir(), generatedFileName + ".java" ); } else { String packagePath = packageName.replace( '.', File.separatorChar ); packagePath = packagePath.replace( ';', File.separatorChar ); genFile = new File( new File( getOutputDir(), packagePath), generatedFileName + ".java" ); } return genFile; } void addGrammar(String grammar) { this.grammars.add( grammar ); } public void setOutputDir(File outputDir) { this.outputDir = outputDir; } public File getOutputDir() { return this.outputDir; } } class NoExitSecurityManager extends SecurityManager { static final NoExitSecurityManager INSTANCE = new NoExitSecurityManager(); private NoExitSecurityManager() { } public void checkPermission(Permission permission) { } public void checkExit(int status) { throw new SecurityException( "exitVM-" + status ); } } -- To unsubscribe, e-mail: For additional commands, e-mail: