Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 74293 invoked from network); 23 Jan 2004 19:53:27 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 23 Jan 2004 19:53:27 -0000 Received: (qmail 70767 invoked by uid 500); 23 Jan 2004 19:53:14 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 70728 invoked by uid 500); 23 Jan 2004 19:53:14 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 70696 invoked from network); 23 Jan 2004 19:53:13 -0000 Received: from unknown (HELO ca-exch01.actional.com) (63.101.113.162) by daedalus.apache.org with SMTP; 23 Jan 2004 19:53:13 -0000 X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: BeanShellDef - java.lang.LinkageError: duplicate class definition: AList Date: Fri, 23 Jan 2004 11:53:18 -0800 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: BeanShellDef - java.lang.LinkageError: duplicate class definition: AList Thread-Index: AcPhkMKbbemzhh1KTBKjEKc7T4spQwAVifEwAADjH9A= From: "Michael Sunde" To: "Ant Developers List" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N My attachement got removed so here it is: beanshelldef.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D import java.io.File; import java.util.Set; import java.util.HashSet; import bsh.EvalError; import bsh.Interpreter; import org.apache.tools.ant.AntTypeDefinition; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.ComponentHelper; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.taskdefs.AntlibDefinition; /** * Class to define an ant definition using a beanshell script. * The beanshell interpreter must be 2.0 or higher. * The beanshell script must contain the class specified * by the "classname" attribute. *

* Note that if there is anything incorrect with the script * the warning message is quite cryptic. *

* * @author Peter Reilly * @since Ant 1.7 * @see AntlibDefinition */ public class BeanShellDef extends AntlibDefinition { private String name; private String definitionString; private File definitionFile; private String classname; /** Only define the types once so that we don't end up with * duplicate class definition errors. */ static private Set definedTypes =3D new HashSet(); /** * Name of the definition * @param name the name of the definition */ public void setName(String name) { this.name =3D name; } /** * Name of the classname that the bean shell * definition contains. * @param classname the name of the class defined in the beanshell = script */ public void setClassname(String classname) { this.classname =3D classname; } /** * Set the definition file. * @param definitionFile a file containing beanshell script */ public void setFile(File definitionFile) { this.definitionFile =3D definitionFile; } /** * Set the definition string. * * @param text a bean shell 2.0 string containing the definition * of the classname */ public void addText(String text) { this.definitionString =3D getProject().replaceProperties(text); } /** * define the beanshell definition. * check the attributes, get the class been defined and * set the definition. */ public void execute() { if (classname =3D=3D null) { throw new BuildException("Missing attribute classname"); } if (name =3D=3D null) { throw new BuildException("Missing attribute name"); } if (definitionString =3D=3D null && definitionFile =3D=3D null) = { throw new BuildException("Missing beanshell script or = file"); } synchronized (definedTypes) { if (!definedTypes.contains(classname)) { definedTypes.add(classname); registerType(); } else { log("Override ignored for type: " + classname, Project.MSG_VERBOSE); } } } /** * define the beanshell definition. * check the attributes, get the class been defined and * set the definition. This method should only be called, * once otherwise we end up with a duplicate class * definition error. */ protected void registerType() { Interpreter i =3D new Interpreter(); // Construct an = interpreter if (definitionFile !=3D null) { try { i.source(definitionFile.getAbsolutePath()); } catch (Throwable t) { throw new BuildException(t); } } try { if (definitionString !=3D null) { i.eval(definitionString); } Object o =3D i.eval("new " + classname + "()"); Class cl =3D o.getClass(); AntTypeDefinition def =3D new AntTypeDefinition(); def.setName(ProjectHelper.genComponentName(getURI(), name)); def.setClassName(classname); def.setClass(cl); ComponentHelper.getComponentHelper(getProject()) .addDataTypeDefinition(def); } catch (BuildException ex) { throw ex; } catch (Throwable t) { throw new BuildException(t); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org