ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: Poor support for selectors
Date Fri, 12 Mar 2004 16:02:50 GMT
This is a known problem with beanshell 2.0b1.
You need to just call the script once in a top-level
target (! i.e. do not place the script task at the top-level!)
and then use the antcall's.

<scripttypedef/> solves this problem by checking if the
scripttypedef has been defined before.

Peter
Jose Alberto Fernandez wrote:

>Peter,
>
>I found a problem with your solution. My build uses <antcall/> which
>mens
>the script will be executed several times.
>
>But you can only run the script once per build process. 
>Otherwise, beanshell fails with:
>
>   [script] java.lang.reflect.InvocationTargetException:
>java.lang.LinkageError: trying to redefine class NameSelector (bad class
>loader?)
>   [script] 	at java.lang.ClassLoader.defineClass0(Native Method)
>   [script] 	at
>java.lang.ClassLoader.defineClass(ClassLoader.java:703)
>   [script] 	at
>java.lang.ClassLoader.defineClass(ClassLoader.java:627)
>   [script] 	at java.lang.reflect.Method.invoke(Native Method)
>   [script] 	at bsh.Reflect.invokeOnMethod(Unknown Source)
>   [script] 	at bsh.Reflect.invokeObjectMethod(Unknown Source)
>   [script] 	at bsh.BshClassManager.defineClass(Unknown Source)
>   [script] 	at bsh.ClassGeneratorImpl.generateClassImpl(Unknown
>Source)
>   [script] 	at bsh.ClassGeneratorImpl.generateClass(Unknown Source)
>   [script] 	at bsh.BSHClassDeclaration.eval(Unknown Source)
>   [script] 	at bsh.Interpreter.eval(Unknown Source)
>   [script] 	at bsh.Interpreter.eval(Unknown Source)
>   [script] 	at bsh.Interpreter.eval(Unknown Source)
>   [script] 	at bsh.util.BeanShellBSFEngine.eval(Unknown Source)
>   [script] 	at bsh.util.BeanShellBSFEngine.exec(Unknown Source)
>   [script] 	at org.apache.bsf.BSFManager$6.run(Unknown Source)
>   [script] 	at java.security.AccessController.doPrivileged(Native
>Method)
>   [script] 	at org.apache.bsf.BSFManager.exec(Unknown Source)
>   [script] 	at
>org.apache.tools.ant.util.ScriptRunner.executeScript(ScriptRunner.java:1
>30)
>   [script] 	at
>org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:61)
>   [script] 	at
>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java(Compiled
>Code))
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at
>org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:65)
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at net.sf.antcontrib.logic.TryCatchTask.execute(Unknown
>Source)
>   [script] 	at
>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java(Compiled
>Code))
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at
>org.apache.tools.ant.Target.execute(Target.java(Compiled Code))
>   [script] 	at
>org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:135
>)
>   [script] 	at
>org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:8
>9)
>   [script] 	at
>org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:345)
>   [script] 	at
>org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:107)
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at
>org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:65)
>   [script] 	at
>net.sf.antcontrib.logic.ForEach.executeSequential(Unknown Source)
>   [script] 	at net.sf.antcontrib.logic.ForEach.execute(Unknown
>Source)
>   [script] 	at
>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java(Compiled
>Code))
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at
>org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:65)
>   [script] 	at
>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java(Compiled
>Code))
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at
>org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:3
>40)
>   [script] 	at
>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java(Compiled
>Code))
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at
>org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:65)
>   [script] 	at
>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java(Compiled
>Code))
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at
>org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:3
>40)
>   [script] 	at
>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java(Compiled
>Code))
>   [script] 	at org.apache.tools.ant.Task.perform(Task.java(Compiled
>Code))
>   [script] 	at
>org.apache.tools.ant.Target.execute(Target.java(Compiled Code))
>   [script] 	at
>org.apache.tools.ant.Target.performTasks(Target.java:328)
>   [script] 	at
>org.apache.tools.ant.Project.executeTarget(Project.java:1215)
>   [script] 	at
>org.apache.tools.ant.Project.executeTargets(Project.java:1063)
>   [script] 	at org.apache.tools.ant.Main.runBuild(Main.java:632)
>   [script] 	at org.apache.tools.ant.Main.startAnt(Main.java:183)
>   [script] 	at
>org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
>   [script] 	at
>org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
>
>
>I think for this to work generically, we need a way to create a
>disposable classloader that beanshell can use and discard if necessary.
>I will try to
>solve my problem by defining different classes each time.
>
>Jose Alberto
>
>  
>
>>-----Original Message-----
>>From: Peter Reilly [mailto:peter.reilly@corvil.com] 
>>Sent: 12 March 2004 13:27
>>To: Ant Developers List
>>Subject: Re: Poor support for selectors
>>
>>
>>Ok,
>>an example!
>>
>>you can do:
>><project xmlns:ac="antlib:net.sf.antcontrib">
>>  <script language="beanshell">
>>    import java.io.File;
>>    import org.apache.tools.ant.types.selectors.FileSelector;
>>    public class NameSelector implements FileSelector {
>>        private String match;
>>        public void setMatch(String match) {
>>           this.match = match;
>>        }
>>        public boolean isSelected(File basedir, String 
>>filename, File file) {
>>           return new File(filename).name.matches(match);
>>        }
>>    }
>>    project.addDataTypeDefinition("selectname", NameSelector.class);
>>  </script>
>>
>>  <ac:for param="file">
>>    <ac:path>
>>      <ac:fileset dir=".">
>>        <selectname match="^.*reg.*$"/>
>>      </ac:fileset>
>>    </ac:path>
>>    <ac:sequential>
>>      <echo>file is @{file}</echo>
>>    </ac:sequential>
>>  </ac:for>  
>></project>
>>
>>It would be a little easier using the proposed scripttypedef, 
>>but <script> works fine as well. Peter
>>
>>Peter Reilly wrote:
>>
>>    
>>
>>>If you use beanshell 2.0x (which you do!), you can use
>>>a normal script task to create a selector.
>>>
>>>Peter
>>>Jose Alberto Fernandez wrote:
>>>
>>>      
>>>
>>>>I need to construct a fileset using rules a little bit out of the 
>>>>ordinary and I an having a very hard time trying to do it in ANT.
>>>>
>>>>What I need is to be able to match filenames using egexp rules for 
>>>>the filename. The only regexp things we have for selectors 
>>>>        
>>>>
>>looks at 
>>    
>>
>>>>the content of the file,
>>>>and the only things to select of filenames, use ANT's filename
>>>>expressions.
>>>>
>>>>We do not provide either a scriptselector (like we provide a script
>>>>filter)
>>>>neither.
>>>>Shall we try to close some of this gaps in 1.6.x? Or shall we wait 
>>>>for 1.7 and the new role based code.
>>>>
>>>>I think one thing we should do in 1.7 is take a look at 
>>>>        
>>>>
>>the all the 
>>    
>>
>>>>core
>>>>features: filters, mappers, selectors, conditions, etc. 
>>>>        
>>>>
>>And make sure we
>>    
>>
>>>>provide simillar strength across the board (by prviding 
>>>>        
>>>>
>>scriptXXX for
>>    
>>
>>>>all) at a minimum.
>>>>
>>>>Comments?
>>>>
>>>>Jose Alberto
>>>>
>>>>
>>>>
>>>> 
>>>>
>>>>
>>>>        
>>>>
>>---------------------------------------------------------------------
>>    
>>
>>>>---
>>>>
>>>>
>>>>        
>>>>
>>---------------------------------------------------------------------
>>    
>>
>>>>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>>>>For additional commands, e-mail: dev-help@ant.apache.org
>>>>
>>>>        
>>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>    
>>
>>>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>>>For additional commands, e-mail: dev-help@ant.apache.org
>>>
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>>For additional commands, e-mail: dev-help@ant.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message