ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peterrei...@apache.org>
Subject Re: script task using java
Date Tue, 07 Dec 2004 12:53:59 GMT
I would suggest you use beanshell instead of javascript.
BeanShell is *much* more java like.

Also use the "src" attribute to referece a file instead of
an inline script, the line numbers will then match up.
Any script longer than a couple of lines should be in
its own file. (IMO).

Peter
Keith Hatton wrote:

>JavaScript is an untyped language, so you don't give an object a type.
>You just say
>
>content = new StringBuffer();
>
>I'm not sure what happens to the previous two declarations in your script (f and line),
but it may not be what you expected.
>
>Likewise, you may find your catch(IOException e) should just be catch(e).
>
>Keith
>
>
>-----Original Message-----
>From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
>Sent: 07 December 2004 12:40
>To: Ant Users List
>Subject: RE: script task using java
>
>
>
>Hi, thank you all for your quick response !
>
>The comments (and the syntax error !) were only in the mail, not in the code actually
- sorry.
>  
>       importPackage(Packages.java.lang);
>       importPackage(Packages.java.util);
>       importPackage(Packages.java.io);
>       
>       	BufferedReader f;
>		String line;
>		StringBuffer content = new StringBuffer();
>		String lineSep = System.getProperty("line.separator");
>
>		...
>
>So now it gave me :
>
>...\WSADworkspace\Ant_Test\regexp.xml:3: SyntaxError: missing ; before statement (ANT;
line 6)
>
>So what's wrong with -> StringBuffer content = new StringBuffer(); ???
>
>Gilbert
>
>-----Original Message-----
>From: Peter Reilly [mailto:peterreilly@apache.org]
>Sent: Tuesday, December 07, 2004 1:23 PM
>To: Ant Users List
>Subject: Re: script task using java
>
>
>Also line 3 means the third line in the script block, not the thired 
>line in the build script.
>
>	*** -> how to 'cast' to a build exception ? ***
>
>throw new BuildException(e);
>
>		*** -> OK to use coma separated values for one property ? ***
>yes
>
>Peter
>
>
>
>
>
>Keith Hatton wrote:
>
>  
>
>>Yeah, the .* is wrong and you have a typo in the third import (no . between Packages
and java).
>>
>>Keith
>>
>>
>>-----Original Message-----
>>From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
>>Sent: 07 December 2004 12:09
>>To: Ant Users List
>>Subject: 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
>>
>>
>>---------------------------------------------------------------------
>>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
>
>
>---------------------------------------------------------------------
>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
View raw message