You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Furingstad <kl...@furingstad.nu> on 2009/02/10 20:51:07 UTC

Catch compile error with trycatch

Hi

We are trying to catch our compile errors with Ant Contrim trycatch task but
for some reason we cant it to catch any errors.

Im grateful for all ideas!!

this is our testscript:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Copille-dbDef" default="cmp-def"
xmlns:ac="antlib:net.sf.antcontrib">
	
  <path id="build.class.path">
	<fileset dir="${proj.externals.dir}/FND">
		<include name="**/*.jar"/>
	</fileset>
	<pathelement path="${proj.bin.dir}/${be.component}/bindbg"/>
	<pathelement path="${base.root}"/>
  </path>
  <target name="cmp-def" description="Compilling DB Def">
	<pathconvert property="build.classpath.prop" refid="build.class.path"
targetos="windows" />
	<echo message="Current classpath: ${build.classpath.prop}"/>

	<ac:for param="obj">
	     <path>
		<fileset dir="${proj.src.dir}/${be.component}/src/mvx/db/def">
			<include name="**/*.java"/>
		</fileset>
	     </path>

	     <sequential>
		<ac:propertyregex override="yes" 
		property="obj" input="@{obj}"
	             regexp="(.+\\)(.+\.java)"
	             replace="\2"
                          casesensitive="false" />
				
             <ac:trycatch property="exception.message"
reference="exception.ref">
		<ac:try>
		           <javac taskname="compile.def"
			sourcepath=""
			srcdir="${proj.src.dir}/${be.component}/src/mvx/db/def" 
			destdir="${proj.bin.dir}/${be.component}/bindbg"
			includes="${obj}"
			classpathref="build.class.path"
			compiler="org.eclipse.jdt.core.JDTCompilerAdapter" 
			target="1.6"
			source="1.6"
			debug="on"
			failonerror="false"
			fork="no"
		           />
		</ac:try>
		<ac:catch>
			<echo message="Compile error on: ${obj}  Error message:       
                                       
${exception.message}${line.separator}" 
			  file="${ProjBaseDir}\Compille.error" 
			  append="true" level="warning"
                                       />
		</ac:catch>
	</ac:trycatch>
    </sequential>
  </ac:for>
</target>
</project>
-- 
View this message in context: http://www.nabble.com/Catch-compile-error-with-trycatch-tp21939518p21939518.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


RE: Catch compile error with trycatch

Posted by Furingstad <kl...@furingstad.nu>.
Thanks Lucas

Il have a look on this one, but I would prefer to find a solution for the
Ant Contrib variant as we are using there library for quite a few of our
other tasks.


Lucas Albers wrote:
> 
> I use antelope.
> 
> <target name="blah-try">
>     <exec dir="./blah" executable="make" osfamily="Windows"
> failonerror="true">
> 
>       <arg line="BLAH=1 configure"/>
> 
>     </exec>
> 
>     <exec dir="./blah" executable="nice" osfamily="Windows"
> failonerror="false">
> 
>       <arg line="make -j4 BLAH=1 all"/>
> 
>     </exec>
>     
>     <antelope:try>
>       <echo message="logging blah compile to:${logdir}/blah.log"></echo>
>       <record name="${logdir}/blah.log" emacsmode="true" append="no"
> action="start"></record>  
> 
>       <exec dir="./blah" executable="make" osfamily="Windows"
> failonerror="true">
> 
>         <arg line="BLAH=1 all"/>
> 
>       </exec>
>       <record name="${logdir}/blah.log"  action="stop"></record>
> 
>       <antelope:catch>
>         <property name="build.failed" value="Blah compile failed"/>
>       </antelope:catch>
>       <antelope:finally>
>         <!-- rollback files -->
>         <fail message="blah  compile failed">
>           <condition >
>             <matches pattern="Blah compile failed"
> string="${build.failed}"/>
>           </condition>
>         </fail>        
>       </antelope:finally>
>     </antelope:try>
>   </target>
> 
> 
> -----Original Message-----
> From: Furingstad [mailto:klas@furingstad.nu] 
> Sent: Tuesday, February 10, 2009 12:51 PM
> To: user@ant.apache.org
> Subject: Catch compile error with trycatch
> 
> 
> Hi
> 
> We are trying to catch our compile errors with Ant Contrim trycatch task
> but
> for some reason we cant it to catch any errors.
> 
> Im grateful for all ideas!!
> 
> this is our testscript:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <project name="Copille-dbDef" default="cmp-def"
> xmlns:ac="antlib:net.sf.antcontrib">
> 	
>   <path id="build.class.path">
> 	<fileset dir="${proj.externals.dir}/FND">
> 		<include name="**/*.jar"/>
> 	</fileset>
> 	<pathelement path="${proj.bin.dir}/${be.component}/bindbg"/>
> 	<pathelement path="${base.root}"/>
>   </path>
>   <target name="cmp-def" description="Compilling DB Def">
> 	<pathconvert property="build.classpath.prop"
> refid="build.class.path"
> targetos="windows" />
> 	<echo message="Current classpath: ${build.classpath.prop}"/>
> 
> 	<ac:for param="obj">
> 	     <path>
> 		<fileset
> dir="${proj.src.dir}/${be.component}/src/mvx/db/def">
> 			<include name="**/*.java"/>
> 		</fileset>
> 	     </path>
> 
> 	     <sequential>
> 		<ac:propertyregex override="yes" 
> 		property="obj" input="@{obj}"
> 	             regexp="(.+\\)(.+\.java)"
> 	             replace="\2"
>                           casesensitive="false" />
> 				
>              <ac:trycatch property="exception.message"
> reference="exception.ref">
> 		<ac:try>
> 		           <javac taskname="compile.def"
> 			sourcepath=""
> 	
> srcdir="${proj.src.dir}/${be.component}/src/mvx/db/def" 
> 			destdir="${proj.bin.dir}/${be.component}/bindbg"
> 			includes="${obj}"
> 			classpathref="build.class.path"
> 			compiler="org.eclipse.jdt.core.JDTCompilerAdapter" 
> 			target="1.6"
> 			source="1.6"
> 			debug="on"
> 			failonerror="false"
> 			fork="no"
> 		           />
> 		</ac:try>
> 		<ac:catch>
> 			<echo message="Compile error on: ${obj}  Error
> message:       
>                                        
> ${exception.message}${line.separator}" 
> 			  file="${ProjBaseDir}\Compille.error" 
> 			  append="true" level="warning"
>                                        />
> 		</ac:catch>
> 	</ac:trycatch>
>     </sequential>
>   </ac:for>
> </target>
> </project>
> -- 
> View this message in context:
> http://www.nabble.com/Catch-compile-error-with-trycatch-tp21939518p21939518.
> html
> Sent from the Ant - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Catch-compile-error-with-trycatch-tp21939518p21949778.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


RE: Catch compile error with trycatch

Posted by Lucas Albers <sm...@hotmail.com>.
I use antelope.

<target name="blah-try">
    <exec dir="./blah" executable="make" osfamily="Windows"
failonerror="true">

      <arg line="BLAH=1 configure"/>

    </exec>

    <exec dir="./blah" executable="nice" osfamily="Windows"
failonerror="false">

      <arg line="make -j4 BLAH=1 all"/>

    </exec>
    
    <antelope:try>
      <echo message="logging blah compile to:${logdir}/blah.log"></echo>
      <record name="${logdir}/blah.log" emacsmode="true" append="no"
action="start"></record>  

      <exec dir="./blah" executable="make" osfamily="Windows"
failonerror="true">

        <arg line="BLAH=1 all"/>

      </exec>
      <record name="${logdir}/blah.log"  action="stop"></record>

      <antelope:catch>
        <property name="build.failed" value="Blah compile failed"/>
      </antelope:catch>
      <antelope:finally>
        <!-- rollback files -->
        <fail message="blah  compile failed">
          <condition >
            <matches pattern="Blah compile failed"
string="${build.failed}"/>
          </condition>
        </fail>        
      </antelope:finally>
    </antelope:try>
  </target>


-----Original Message-----
From: Furingstad [mailto:klas@furingstad.nu] 
Sent: Tuesday, February 10, 2009 12:51 PM
To: user@ant.apache.org
Subject: Catch compile error with trycatch


Hi

We are trying to catch our compile errors with Ant Contrim trycatch task but
for some reason we cant it to catch any errors.

Im grateful for all ideas!!

this is our testscript:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Copille-dbDef" default="cmp-def"
xmlns:ac="antlib:net.sf.antcontrib">
	
  <path id="build.class.path">
	<fileset dir="${proj.externals.dir}/FND">
		<include name="**/*.jar"/>
	</fileset>
	<pathelement path="${proj.bin.dir}/${be.component}/bindbg"/>
	<pathelement path="${base.root}"/>
  </path>
  <target name="cmp-def" description="Compilling DB Def">
	<pathconvert property="build.classpath.prop"
refid="build.class.path"
targetos="windows" />
	<echo message="Current classpath: ${build.classpath.prop}"/>

	<ac:for param="obj">
	     <path>
		<fileset
dir="${proj.src.dir}/${be.component}/src/mvx/db/def">
			<include name="**/*.java"/>
		</fileset>
	     </path>

	     <sequential>
		<ac:propertyregex override="yes" 
		property="obj" input="@{obj}"
	             regexp="(.+\\)(.+\.java)"
	             replace="\2"
                          casesensitive="false" />
				
             <ac:trycatch property="exception.message"
reference="exception.ref">
		<ac:try>
		           <javac taskname="compile.def"
			sourcepath=""
	
srcdir="${proj.src.dir}/${be.component}/src/mvx/db/def" 
			destdir="${proj.bin.dir}/${be.component}/bindbg"
			includes="${obj}"
			classpathref="build.class.path"
			compiler="org.eclipse.jdt.core.JDTCompilerAdapter" 
			target="1.6"
			source="1.6"
			debug="on"
			failonerror="false"
			fork="no"
		           />
		</ac:try>
		<ac:catch>
			<echo message="Compile error on: ${obj}  Error
message:       
                                       
${exception.message}${line.separator}" 
			  file="${ProjBaseDir}\Compille.error" 
			  append="true" level="warning"
                                       />
		</ac:catch>
	</ac:trycatch>
    </sequential>
  </ac:for>
</target>
</project>
-- 
View this message in context:
http://www.nabble.com/Catch-compile-error-with-trycatch-tp21939518p21939518.
html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
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


RE: Catch compile error with trycatch

Posted by Furingstad <kl...@furingstad.nu>.
Thanks, that solved my problem!!

/Klas

Rinehart, Raleigh wrote:
> 
>> 
>> 
>> Hi
>> 
>> We are trying to catch our compile errors with Ant Contrim trycatch task
>> but
>> for some reason we cant it to catch any errors.
>> 
>> Im grateful for all ideas!!
>> 
>> this is our testscript:
>> 
>> <?xml version="1.0" encoding="UTF-8"?>
>> <project name="Copille-dbDef" default="cmp-def"
>> xmlns:ac="antlib:net.sf.antcontrib">
>> 
>>   <path id="build.class.path">
>> 	<fileset dir="${proj.externals.dir}/FND">
>> 		<include name="**/*.jar"/>
>> 	</fileset>
>> 	<pathelement path="${proj.bin.dir}/${be.component}/bindbg"/>
>> 	<pathelement path="${base.root}"/>
>>   </path>
>>   <target name="cmp-def" description="Compilling DB Def">
>> 	<pathconvert property="build.classpath.prop"
>> refid="build.class.path"
>> targetos="windows" />
>> 	<echo message="Current classpath: ${build.classpath.prop}"/>
>> 
>> 	<ac:for param="obj">
>> 	     <path>
>> 		<fileset dir="${proj.src.dir}/${be.component}/src/mvx/db/def">
>> 			<include name="**/*.java"/>
>> 		</fileset>
>> 	     </path>
>> 
>> 	     <sequential>
>> 		<ac:propertyregex override="yes"
>> 		property="obj" input="@{obj}"
>> 	             regexp="(.+\\)(.+\.java)"
>> 	             replace="\2"
>>                           casesensitive="false" />
>> 
>>              <ac:trycatch property="exception.message"
>> reference="exception.ref">
>> 		<ac:try>
>> 		           <javac taskname="compile.def"
>> 			sourcepath=""
>> 			srcdir="${proj.src.dir}/${be.component}/src/mvx/db/def"
>> 			destdir="${proj.bin.dir}/${be.component}/bindbg"
>> 			includes="${obj}"
>> 			classpathref="build.class.path"
>> 			compiler="org.eclipse.jdt.core.JDTCompilerAdapter"
>> 			target="1.6"
>> 			source="1.6"
>> 			debug="on"
>> 			failonerror="false"
>> 			fork="no"
>> 		           />
>> 		</ac:try>
>> 		<ac:catch>
>> 			<echo message="Compile error on: ${obj}  Error message:
>> 
>> ${exception.message}${line.separator}"
>> 			  file="${ProjBaseDir}\Compille.error"
>> 			  append="true" level="warning"
>>                                        />
>> 		</ac:catch>
>> 	</ac:trycatch>
>>     </sequential>
>>   </ac:for>
>> </target>
>> </project>
>> 
> 
> You have failonerror in your javac task set to false, so there is nothing
> to catch since the error doesn't get propagated up.  It should work as you
> expect if you set failonerror=true.
> 
> If you don't want to do this then you can use the errorProperty attribute
> and use antcontrib's <if> <then> tasks.
> 
> -raleigh
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Catch-compile-error-with-trycatch-tp21939518p21977094.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


RE: Catch compile error with trycatch

Posted by "Rinehart, Raleigh" <ra...@ti.com>.
> 
> 
> Hi
> 
> We are trying to catch our compile errors with Ant Contrim trycatch task
> but
> for some reason we cant it to catch any errors.
> 
> Im grateful for all ideas!!
> 
> this is our testscript:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <project name="Copille-dbDef" default="cmp-def"
> xmlns:ac="antlib:net.sf.antcontrib">
> 
>   <path id="build.class.path">
> 	<fileset dir="${proj.externals.dir}/FND">
> 		<include name="**/*.jar"/>
> 	</fileset>
> 	<pathelement path="${proj.bin.dir}/${be.component}/bindbg"/>
> 	<pathelement path="${base.root}"/>
>   </path>
>   <target name="cmp-def" description="Compilling DB Def">
> 	<pathconvert property="build.classpath.prop"
> refid="build.class.path"
> targetos="windows" />
> 	<echo message="Current classpath: ${build.classpath.prop}"/>
> 
> 	<ac:for param="obj">
> 	     <path>
> 		<fileset dir="${proj.src.dir}/${be.component}/src/mvx/db/def">
> 			<include name="**/*.java"/>
> 		</fileset>
> 	     </path>
> 
> 	     <sequential>
> 		<ac:propertyregex override="yes"
> 		property="obj" input="@{obj}"
> 	             regexp="(.+\\)(.+\.java)"
> 	             replace="\2"
>                           casesensitive="false" />
> 
>              <ac:trycatch property="exception.message"
> reference="exception.ref">
> 		<ac:try>
> 		           <javac taskname="compile.def"
> 			sourcepath=""
> 			srcdir="${proj.src.dir}/${be.component}/src/mvx/db/def"
> 			destdir="${proj.bin.dir}/${be.component}/bindbg"
> 			includes="${obj}"
> 			classpathref="build.class.path"
> 			compiler="org.eclipse.jdt.core.JDTCompilerAdapter"
> 			target="1.6"
> 			source="1.6"
> 			debug="on"
> 			failonerror="false"
> 			fork="no"
> 		           />
> 		</ac:try>
> 		<ac:catch>
> 			<echo message="Compile error on: ${obj}  Error message:
> 
> ${exception.message}${line.separator}"
> 			  file="${ProjBaseDir}\Compille.error"
> 			  append="true" level="warning"
>                                        />
> 		</ac:catch>
> 	</ac:trycatch>
>     </sequential>
>   </ac:for>
> </target>
> </project>
> 

You have failonerror in your javac task set to false, so there is nothing to catch since the error doesn't get propagated up.  It should work as you expect if you set failonerror=true.

If you don't want to do this then you can use the errorProperty attribute and use antcontrib's <if> <then> tasks.

-raleigh


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