ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: Ant / Javacsript : copy trouble
Date Thu, 15 May 2003 15:10:12 GMT
You are missing a couple of setProjects.
The following example works: (using createTask("copy")
instead of a direct new Copy(), createTask also sets
the project on the task).

  <target name="t">
    <delete quiet="yes" dir="export"/>
    <mkdir dir="export"/>
    <script language="javascript">
      importPackage(Packages.org.apache.tools.ant.types);
      importClass(java.io.File);

      fs = new FileSet();
      fs.setProject(project);
      fs.setDir(new File("."));
      fs.setIncludes("build.xml");
      
      c = project.createTask("copy");
      c.setTodir(new File("export"));
      c.addFileset(fs);
      c.execute();
    </script>
  </target>

Peter.

On Thursday 15 May 2003 15:23, EXT / STERIA CHAUVINEAU wrote:
> Hi, I'm trying to use an Ant copy task in a snippet of javascript code.
>
> the <copy> task works well when I call it in normal "ANT" syntax, but when
> I call the "copy" task in javascript, it throws a NullPointerException on
> the execute() method.
>
> I wonder if there is a problem with the FileSet class because it founds no
> file to copy, whereas the ant fileset task copies 49 files.
>
> Here is my buildfile and the output of the debug below.
>
> Thanks for helping.
>
> By the way, I'm using the copy task in JavaScript because I need to loop
>
> Vianney
>
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <project name="SurfChargement" default="main">
>   <property file="application.properties"/>
>   <target name="main">
>   	<copy todir="${base}/${moisAn}/${flux_5160}/datas" flatten="yes">
>   		<fileset dir="${acquisition}/Surf_0212/FichiersEtab"
> casesensitive="yes" >
>   			<include name="**/*SURF${flux_5160}.csv"/>
> 		</fileset>
> 	</copy>
>         <script language="javascript">
>       <![CDATA[
>       	 importPackage(Packages.org.apache.tools.ant.types);
>       	 importPackage(Packages.org.apache.tools.ant.taskdefs);
>       	 importClass(java.io.File);
>       	 echo = SurfChargement.createTask("echo");
>
>             fileDatas = new FileSet();
>             repSrc =
> SurfChargement.getProperty("acquisition")+"/Surf_0212/FichiersEtab";
>             fileDatas.setDir(new File(repSrc));
>             filter = "**/*SURF5160*.csv";
>             fileDatas.setIncludes(filter);
>
>             copyDatas = new Copy();
>             repDest =
> SurfChargement.getProperty("base")+"/"+SurfChargement.getProperty("moisAn")
>+ "/5160/datas";
>             copyDatas.setTodir(new File(repDest));
>             copyDatas.setFlatten(true);
>             copyDatas.addFileset(fileDatas);
>             copyDatas.execute();
>             echo.setMessage("copyDatas.execute() OK");
>             echo.execute();
>       ]]>
>    </script>
>   </target>
> </project>
>
>
>
> BUILD FAILED
> file:D:/SURF/JBPROJECT/CHARGEMENTSURF/buildTest.xml:10:
> java.lang.NullPointerException
> 	at
> org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:143)
> 	at org.apache.tools.ant.Task.perform(Task.java:317)
> 	at org.apache.tools.ant.Target.execute(Target.java:309)
> 	at org.apache.tools.ant.Target.performTasks(Target.java:334)
> 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1250)
> 	at org.apache.tools.ant.Main.runBuild(Main.java:610)
> 	at org.apache.tools.ant.Main.start(Main.java:196)
> 	at org.apache.tools.ant.Main.main(Main.java:235)
> --- Nested Exception ---
> java.lang.NullPointerException
> 	at
> org.apache.tools.ant.types.AbstractFileSet.setupDirectoryScanner(AbstractFi
>l eSet.java:360)
> 	at
> org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFile
>S et.java:341)
> 	at org.apache.tools.ant.taskdefs.Copy.execute(Copy.java:354)
> 	at java.lang.reflect.Method.invoke(Native Method)
> 	at org.mozilla.javascript.NativeJavaMethod.call(Unknown Source)
> 	at org.mozilla.javascript.ScriptRuntime.call(Unknown Source)
> 	at org.mozilla.javascript.Interpreter.interpret(Unknown Source)
> 	at org.mozilla.javascript.InterpretedScript.call(Unknown Source)
> 	at org.mozilla.javascript.InterpretedScript.exec(Unknown Source)
> 	at org.mozilla.javascript.Context.evaluateReader(Unknown Source)
> 	at org.mozilla.javascript.Context.evaluateString(Unknown Source)
> 	at
> com.ibm.bsf.engines.javascript.JavaScriptEngine.eval(JavaScriptEngine.java:
>8 3)
> 	at com.ibm.bsf.util.BSFEngineImpl.exec(BSFEngineImpl.java:106)
> 	at com.ibm.bsf.BSFManager.exec(BSFManager.java:479)
> 	at
> org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:132)
> 	at org.apache.tools.ant.Task.perform(Task.java:317)
> 	at org.apache.tools.ant.Target.execute(Target.java:309)
> 	at org.apache.tools.ant.Target.performTasks(Target.java:334)
> 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
> 	at org.apache.tools.ant.Project.executeTargets(Project.java:1250)
> 	at org.apache.tools.ant.Main.runBuild(Main.java:610)
> 	at org.apache.tools.ant.Main.start(Main.java:196)
> 	at org.apache.tools.ant.Main.main(Main.java:235)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message