ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject AW: script task using java
Date Tue, 07 Dec 2004 12:22:42 GMT
You have to use the "Packages"-prefix only if you´re not using
classes under the java.*-Packages. So java.io.File would work, but
org.apache.tools.ant.util.FileUtils not. See manual to <script> task.

I couldnt see the syntax error quickly. If I get syntax errors I comment
out the whole block inside the script task and test. Then adding the first
or first few lines. ... until the whole block is added. Somewhen during that
the error should occur and you´ll get the right place.

I think when importing a package using importPackage, you must not specify
the *. Otherwise you would use the importClass statement.

Ok, the error message should be better there. It´s the line where the
>>task<< is (<script>), not the error-line inside that task.

I hope your comments are only in the mail, not in the code. Or in the
code in the right comment signs.

You cant "cast" to a BuildException because an IOExc is not a BE. Usually
(in Java) you´ll catch the IOE, create a new BE and throw that.
     } catch (IOException ex) {
         throw new BuildException(ex);
Not sure, if BE provides such a constructor ... yep, it does [1].

There is no "right" way for multiple values. Usually Ant tasks doesnt
perform
on lists - they perform on <path>s ... But thinking about Ant-Contribs
<for>-family: they´re using a comma separated list. So why not.


Jan

[1]
http://cvs.apache.org/viewcvs.cgi/ant/src/main/org/apache/tools/ant/BuildExc
eption.java?rev=1.19.2.4&view=markup



> -----Ursprüngliche Nachricht-----
> Von: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
> Gesendet am: Dienstag, 7. Dezember 2004 13:09
> An: Ant Users List
> Betreff: RE: script task using java
> 
> 
> hm, 
> 
> 	 importPackage(Packages.java.lang);
>        importPackage(Packages.java.util.regex.*);
>        importPackage(Packagesjava.io.*);
> 
> gives me the same error:
> 
> : SyntaxError: missing name after . operator (ANT; line 3)
> 
> line 3 =  <script language="javascript"> <![CDATA[
> 
> and
> 
> 	importPackage(Packages.java.lang);
>       importPackage(Packages.java.util.regex);
>       importPackage(Packagesjava.io);
> 
> gives me :
> 
>  [script] BUILD FAILED: C:\Programme\IBM\WebSphere 
> Studio\Application Developer\WSADworkspace\Ant_Test\regexp.xml:
> 3: SyntaxError: missing ; before statement (ANT; line 6)
> 
> line 6 = importPackage(Packages.java.util.regex);
> 
> any ideas ?
> 
> Gilbert
> 
> -----Original Message-----
> From: Keith Hatton [mailto:khatton@axiomsystems.com]
> Sent: Tuesday, December 07, 2004 12:50 PM
> To: Ant Users List
> Subject: RE: script task using java
> 
> 
> importPackage(Packages.java.lang);
> etc.
> 
> Keith
> 
> 
> -----Original Message-----
> From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
> Sent: 07 December 2004 11:47
> To: ant_user (E-Mail)
> Subject: script task using java
> 
> 
> 
> Hi, i want to use an existing regex class into my build script.
> 
> This is my first try using script/java with ant, so please 
> don't laugh ;-)
> 
> See my questions marked with ***
> 
> Tried like that =
> 
> <project name="MyProject" basedir="." default="main">
>    <target name="main2">
>      <script language="javascript"> <![CDATA[
> 
>        
> 	*** i also tried without .* in packagedeclaration 
> without success	
> 	
> 	 importPackage(java.lang);
>        importPackage(java.util.regex.*);
>        importPackage(java.io.*);
>        
>        		BufferedReader f;
> 		String line;
> 		StringBuffer content = new StringBuffer();
> 		String lineSep = System.getProperty("line.separator");
> 
> 		//		pattern  projectname
> 		String pattern = "^testproject";
> 		Pattern p = Pattern.compile(pattern);
> 
> 		//		pattern deploytarget
> 		String patternt1 = "^test";
> 		String patternt2 = "^test1";
> 		Pattern p1 = Pattern.compile(patternt1);
> 		Pattern p2 = Pattern.compile(patternt2);
> 		
> 
> 		try
> 		{
> 			f =
> 				new BufferedReader(
> 					new FileReader("logfile.txt"));
> 			while ((line = f.readLine()) != null)
> 			{
> 				content.append(line).append(lineSep);
> 			}
> 			f.close();
> 
> 		*** -> how to 'cast' to a build exception ? ***
> 
> 		} catch (IOException e)
> 		{
> 			System.out.println("Oops ..." + e);
> 		}
> 
> 		Matcher m = p.matcher(content);
> 		Matcher m1 = p1.matcher(content);
> 		Matcher m2 = p2.matcher(content);
> 		
> 		if (m.find())
> 		project.setNewProperty("projectname", "testproject");
> 				
> 		if (m1.find()& m2.find())
> 		
> 		*** -> OK to use coma separated values for one 
> property ? ***
> 
> 		project.setNewProperty("email", "list1,list2");
> 		
> 		if (m1.find() & (!m2.find()))
> 		
> 		project.setNewProperty("email", "list1");
> 		
> 		if (m2.find() & (!m1.find()))
> 		
> 		project.setNewProperty("email", "list2");
> 						
>      ]]></script>
>    </target>
>    
>    <target name="main" depends="main2>
>    		<echo message="${projectname}"></echo>
>    		<echo message="${email}"></echo>
>    </target>
> </project>
> 
> But it gave me an error right at the beginning =
> 
> [script] BUILD FAILED: C:\Programme\IBM\WebSphere 
> Studio\Application Developer\WSADworkspace\Ant_Test\regexp.xml:3
> : SyntaxError: missing name after . operator (ANT; line 3)
> 
> line 3 =  <script language="javascript"> <![CDATA[
> 
> I believe there are much more errors ?!
> 
> Thanks for any advice!!
> 
> Regards, Gilbert
> 
> 
>  
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message