Update site.xml (Gaia Framework) with ANT

I put a small change in the build.xml file, to update the parameters seoBytes and bytes in site.xml file, now only updates the tag page, I’ve also updated the gaia framework to version 3.2.0.

To update the site.xml file is only necessary to run the new target refresh-site-xml and automatically update the xml file. It overwrites the file site.xml, below shows the code for the target and other macros.

	<target name="refresh-site-xml">
		<echo message="refresh-site-xml"/>
	    <update-page-site-xml/>
	</target>

	<macrodef name="update-bytes-page">
		<attribute name="input" default="home"/>
		<attribute name="bytes" default="0"/>
		<attribute name="seoBytes" default="0"/>
		<sequential>
			<echo message="@{input}"/>
			<if>
			 	<equals arg1="${seoBytes}" arg2="0" />
				<then>
					<xmltask  source="${bin}/site.xml" dest="${bin}/site3.xml">
						<attr path="//page[@id='@{input}']" attr="bytes" value="@{bytes}"/>
						<attr path="//page[@id='@{input}']" attr="seoBytes" remove="true"/>
					</xmltask>
				</then>
				<else>
					<xmltask  source="${bin}/site.xml" dest="${bin}/site3.xml">
						<attr path="//page[@id='@{input}']" attr="bytes" value="@{bytes}"/>
						<attr path="//page[@id='@{input}']" attr="seoBytes" value="@{seoBytes}"/>
					</xmltask>
				</else>
			</if>
			<copy file="${bin}/site3.xml" tofile="${bin}/site.xml"
						overwrite="true"/>
			<delete file="${bin}/site3.xml"/>
		</sequential>
	</macrodef>

	<macrodef name="update-page-site-xml">
		<sequential>
			<xmltask source="${bin}/site.xml" dest="${bin}/site2.xml">
				<call path="//page">
					<param name="swffile" path="@src"/>
					<param name="htmlfile" path="@seo" default="false"/>
					<param name="ident" path="@id" default="false"/>
					<actions>
						<var name="branch" value="" unset="true"/>
						<var name="existSwf" value="" unset="true"/>
						<var name="existHtmlSeo" value="" unset="true"/>
						<var name="existHtmlId" value="" unset="true"/>
						<var name="bytes" unset="true"/>
						<var name="seoBytes" value="0" unset="true"/>
						<available file="${bin}\@{swffile}" property="existSwf"/>
						<available file="${bin}\@{htmlfile}.html" property="existHtmlSeo"/>
						<available file="${bin}\@{ident}.html" property="existHtmlId"/>
						<if>
						 	<equals arg1="${existSwf}" arg2="true" />
						 	<then>
						 		<length file="${bin}/@{swffile}" property="bytes" />
								<get-branch-page input="site" page="@{ident}"/>
								<if>
								 	<equals arg1="${existHtmlSeo}" arg2="true" />
								 	<then>
										<length file="${bin}/@{htmlfile}.html" property="seoBytes" />
								 	</then>
								<elseif>
									<equals arg1="${existHtmlId}" arg2="true" />
								  	<then>
										<length file="${bin}/@{ident}.html" property="seoBytes" />
								  	</then>
								</elseif>
								<else>
									<var name="seoBytes" value="0"/>
								</else>
								</if>
						 		<update-bytes-page input="@{ident}" bytes="${bytes}" seoBytes="${seoBytes}"/>
						 	</then>
						</if>
					</actions>
				</call>
			</xmltask>
			<delete file="${bin}/site2.xml"/>
		</sequential>
	</macrodef>

Download project

This entry was posted in ANT, gaia and tagged , . Bookmark the permalink.

8 Responses to Update site.xml (Gaia Framework) with ANT

  1. kyoji says:

    Thank you for your superb job. I like it very much.
    While working with your script, I’ve found an issue in “get-branch” macro.
    Here is my test site.xml:

    After scaffolding, I’ve got an error in Page.as, seems like it has a wrong page structure. May I asking you to fix that? Thanks in advance.

  2. panaewa says:

    Hello kyoji, thanks you. i change this macro to solve that issue, change the “get-branch” macro in build.xml file for:

    	<macrodef name="get-branch">
    		<attribute name="input" default=""/>
    		<attribute name="parent" default=""/>
    		<sequential>
    			<echo message="get-branch: @{input} | @{parent}"/>
    			<xmltask source="${sitexml}">
    				<call path="@{input}/page">
    					<param name="class" path="@id"/>
    					<actions>
    						<var name="uppercase" unset="true"/>
    						<var name="lowercase" unset="true"/>
    						<var name="ruta" unset="true"/>
    						<var name="parentid" unset="true"/>
    						<uppercase property="uppercase" input="@{class}"/>
    						<lowercase property="lowercase" input="@{class}"/>
    						<drop-first-character property="ruta" input="@{parent}/${lowercase}"/>
    					 	<var name="pagesconst" value="${pagesconst}${line.separator}        public static const ${uppercase}:String = '${ruta}';"/>
    					 	<get-branch input="@{input}/page[@id='@{class}']" parent="@{parent}/${lowercase}"/>
    					</actions>
    				</call>
    			</xmltask>
    		</sequential>
    	</macrodef>
    
  3. kyoji says:

    Hello Sobre Mi, I have customized your code to meet my own needs, and upload it to git.
    Please check this out:
    http://github.com/kyoji2/RobotGaiaAnt
    Feel free to inform me if there is a better way to give you a credit info.
    Really appreciate your help.

  4. panaewa says:

    Hello kyoji, thanks for the credit. I add a new link in the blog to that project.

  5. Angel Anton says:

    wow!!.. keep up the good job!!

  6. admin says:

    Thanks angel

  7. kyoji says:

    Hi Sobre Mi, how’s the thing going on.
    I updated the ant file to support assets bytes updating basically base on your “update-page-site-xml” function. It work fine unless if there are assets using the same id. Any ideas to fix that?
    btw, I also fixed some bugs in “seo-scaffolding”, and add a “xml-remove-bytes” function to suit my need.
    check http://github.com/kyoji2/RobotGaiaAnt

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>