xref: /aosp_15_r20/external/apache-xml/test/tests/bugzilla/Bugzilla3489.xsl (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1<xsl:stylesheet version="1.0"
2		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3	    xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
4		extension-element-prefixes="redirect">
5<!-- Reproducing Bugzilla 3489 -->
6	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
7	<xsl:strip-space elements="*"/>
8	<xsl:param name="output-dir"/>
9	<xsl:template match="*|@*"/>
10	<xsl:template match="/workspace">
11		<xsl:apply-templates/>
12	</xsl:template>
13
14
15	<xsl:template match="/workspace/project">
16		<xsl:variable name="basedir" select="/workspace/@basedir"/>
17		<xsl:variable name="outputdir" select="/workspace/@outputdir"/>
18		<xsl:variable name="cvsdir">
19		  <xsl:value-of select="concat(/workspace/@cvsdir, '/')"/>
20		  <xsl:choose>
21		    <xsl:when test="cvs/@module">
22		      <xsl:value-of select="cvs/@module"/>
23		    </xsl:when>
24		    <xsl:otherwise>
25		      <xsl:value-of select="@srcdir"/>
26		    </xsl:otherwise>
27		  </xsl:choose>
28		</xsl:variable>
29		<xsl:message terminate="no">
30		  <xsl:value-of select="concat('Creating Gump buildfile for ', @name)"/>
31		</xsl:message>
32
33		<redirect:write file="{$outputdir}/{@name}-gumpbuild.xml">
34			<project name="{@name} Gump build file" default="gumpify" basedir="{$basedir}/{@srcdir}">
35
36				<!-- initialize time stamp and replace it in the html page -->
37				<target name="init">
38					<tstamp>
39						<format property="TIMESTAMP" pattern="HH:mm:ss"/>
40					</tstamp>
41					<replace file="{$outputdir}/status.xml" token="TAG-{@name}-TIME" value="${{TIMESTAMP}}"/>
42					<touch file="{$outputdir}/{@name}.FAILED"/>
43
44					<!--style in="{$basedir}/status.xml"
45						out="{$basedir}/{@name}.html"
46						destdir="{$basedir}"
47						style="{$basedir}/source-index-style.xsl">
48						<param name="filename" expression="{@name}.xml"/>
49					</style-->
50				</target>
51
52				<!-- check for all dependencies -->
53				<target name="dependency-check">
54					<xsl:apply-templates select="depend" mode="dependency-check"/>
55				</target>
56
57				<!-- generate the dependency failure targets -->
58				<xsl:apply-templates select="depend" mode="failed-dependency"/>
59
60				<!-- generate the main target that does everything -->
61				<target name="gumpify" depends="init,dependency-check" unless="dependency-failure">
62					<available file="{$cvsdir}" property="cvsmodule.{@name}.present"/>
63					<echo message="In GUMP project: {@name}"/>
64					<xsl:if test="cvs">
65						<antcall target="cvscheckout"/>
66						<!--<antcall target="cvsupdate"/>-->
67						<copy todir="{$basedir}/{@srcdir}">
68							<fileset dir="{$cvsdir}"/>
69						</copy>
70					</xsl:if>
71					<replace file="{$outputdir}/status.xml" token="TAG-{@name}-CVS-TIME" value="${{TIMESTAMP}}"/>
72					<antcall target="build"/>
73					<antcall target="status-pages"/>
74					<move file="{$outputdir}/{@name}.FAILED" tofile="{$outputdir}/{@name}.SUCCESS"/>
75				</target>
76
77				<xsl:apply-templates select="cvs">
78					<xsl:with-param name="target" select="'cvscheckout'"/>
79					<xsl:with-param name="command" select="'-z3 checkout -P'"/>
80				</xsl:apply-templates>
81
82				<xsl:apply-templates select="cvs">
83					<xsl:with-param name="target" select="'cvsupdate'"/>
84					<xsl:with-param name="command" select="'-z3 update -P -d -A'"/>
85				</xsl:apply-templates>
86
87				<!-- build targets -->
88				<target name="build" depends="init">
89					<xsl:apply-templates select="ant | script"/>
90				</target>
91
92				<!-- called if the build went fine it sets the status to SUCCESS in the html file -->
93				<target name="status-pages">
94				<replace file="{$outputdir}/status.xml" token="TAG-{@name}-STATUS" value="SUCCESS"/>
95				  <!-- <style in="" out="{/workspace/@basedir}/{@name}.html" style="" destdir="{/workspace/@basedir}"/> -->
96				</target>
97			</project>
98		</redirect:write>
99	</xsl:template>
100
101
102	<!-- ===========================================================================================
103		Execute a Ant build file/target as specified by the project
104		 =========================================================================================== -->
105	<xsl:template match="/workspace/project/ant">
106		<!-- Ant build file directory -->
107		<xsl:variable name="build.dir">
108			<xsl:value-of select="concat(/workspace/@basedir, '/', ../@srcdir)"/>
109			<xsl:if test="@basedir">
110				<xsl:value-of select="concat('/', @basedir)"/>
111			</xsl:if>
112		</xsl:variable>
113
114		<!-- copy project files -->
115		<!--copy todir="{/workspace/@basedir}/{../@srcdir}">
116			<fileset dir="{/workspace/@viewdir}/{../@srcdir}"/>
117		</copy-->
118
119		<!-- execute the target needed to build the project -->
120		<java classname="org.apache.tools.ant.Main" fork="yes" failonerror="yes"
121			output="{/workspace/@outputdir}/{../@name}-buildresult.txt"
122			dir="{$build.dir}">
123
124			<!-- transmit the worspace's properties -->
125			<xsl:for-each select="/workspace/property">
126				<arg value="-D{@name}={@value}"/>
127			</xsl:for-each>
128
129			<!-- a buildfile might be specified otherwise Ant will use its default -->
130			<xsl:if test="@buildfile">
131				<arg line="-buildfile {$build.dir}/{@buildfile}"/>
132			</xsl:if>
133			<arg line="-listener org.apache.tools.ant.XmlLogger -Dant.home={/workspace/@basedir}/dtools/ant -DXmlLogger.file={/workspace/@outputdir}/{../@name}-buildresult.xml"/>
134
135			<!-- specific target name to perform the build -->
136			<xsl:if test="@target">
137				<arg value="{@target}"/>
138			</xsl:if>
139			<xsl:apply-templates select="property"/>
140
141			<!-- Do the classpath thing here -->
142			<classpath>
143				<xsl:for-each select="../depend | ../option">
144					<xsl:variable name="name" select="@project"/>
145					<xsl:for-each select="/workspace/project[@name=$name]/jar">
146						<pathelement location="{../home}/{@name}"/>
147					</xsl:for-each>
148				</xsl:for-each>
149				<pathelement path="${{java.class.path}}"/>
150			</classpath>
151		</java>
152	</xsl:template>
153
154
155	<!-- ===========================================================================================
156		Execute a script
157		 =========================================================================================== -->
158	<xsl:template match="/workspace/project/script">
159		<xsl:variable name="script.dir" select="concat(/workspace/@basedir, '/', ../@srcdir)"/>
160		<xsl:variable name="script.sh" select="concat($script.dir, '/', ../@name, '.sh')"/>
161		<chmod perm="ugo+rx" file="{$script.sh}"/>
162		<exec dir="{$script.dir}" executable="{$script.sh}"
163			output="{/workspace/@outputdir}/{../@name}-buildresult.txt"/>
164	</xsl:template>
165
166
167	<!-- ===========================================================================================
168		CVS stuff, not sure what it is doing
169		 =========================================================================================== -->
170	<xsl:template match="/workspace/project/cvs">
171		<xsl:param name="target"/>
172		<xsl:param name="command"/>
173		<xsl:variable name="repo" select="@repository"/>
174		<xsl:variable name="cvsmodule.present" select="concat('cvsmodule.', ../@name, '.present')"/>
175		<target name="{$target}">
176			<xsl:if test="$target='cvscheckout'">
177				<xsl:attribute name="unless">
178					<xsl:value-of select="$cvsmodule.present"/>
179				</xsl:attribute>
180			</xsl:if>
181			<xsl:if test="$target='cvsupdate'">
182				<xsl:attribute name="if">
183					<xsl:value-of select="$cvsmodule.present"/>
184				</xsl:attribute>
185			</xsl:if>
186			<replace file="{/workspace/@outputdir}/status.xml" token="TAG-{../@name}-CVS-TIME" value="${TIMESTAMP}"/>
187			<cvs command="{$command}" quiet="true">
188				<xsl:attribute name="cvsroot">
189					<xsl:value-of select="/workspace/cvs-repository/tree[@name=$repo]/@root"/>
190					<xsl:if test="@dir">
191						<xsl:value-of select="concat('/', @dir)"/>
192					</xsl:if>
193				</xsl:attribute>
194				<xsl:attribute name="dest">
195					<xsl:value-of select="/workspace/@cvsdir"/>
196				</xsl:attribute>
197				<xsl:attribute name="package">
198					<xsl:choose>
199						<xsl:when test="@module">
200							<xsl:value-of select="@module"/>
201						</xsl:when>
202						<xsl:otherwise>
203							<xsl:value-of select="../@name"/>
204						</xsl:otherwise>
205					</xsl:choose>
206				</xsl:attribute>
207				<xsl:if test="@tag">
208					<xsl:attribute name="tag">
209						<xsl:value-of select="@tag"/>
210					</xsl:attribute>
211				</xsl:if>
212				<xsl:attribute name="output">
213					<xsl:value-of select="concat(/workspace/@outputdir, '/', ../@name, '-cvsresult.txt')"/>
214				</xsl:attribute>
215			</cvs>
216			<replace file="{/workspace/@outputdir}/status.xml" token="TAG-{../@name}-CVS-STATUS" value="SUCCESS"/>
217		</target>
218	</xsl:template>
219
220
221	<!-- ===========================================================================================
222		Check for a dependency availability and immediately call its
223		dependency-check related target.
224		 =========================================================================================== -->
225	<xsl:template match="/workspace/project/depend" mode="dependency-check">
226		<xsl:variable name="project" select="@project"/>
227		<xsl:variable name="dependfilename" select="concat(/workspace/@outputdir, '/', $project, '.SUCCESS')"/>
228		<available file="{$dependfilename}" property="dependency.{$project}.present"/>
229		<antcall target="{$project}-dependency"/>
230	</xsl:template>
231
232
233	<!-- ===========================================================================================
234		Target called only if the related property is not set (ie the dependency
235		is not verified) since it will fail and replace its tag status by a Prereq
236		information in the html index file.
237		 =========================================================================================== -->
238	<xsl:template match="/workspace/project/depend" mode="failed-dependency">
239		<xsl:variable name="failed-project" select="@project"/>
240		<target name="{$failed-project}-dependency" unless="dependency.{$failed-project}.present">
241			<echo message="PREREQ Failure: Project depends on {$failed-project}"/>
242			<available file="{/workspace/@outputdir}/{../@name}.FAILED" property="dependency-failure"/>
243			<replace file="{/workspace/@outputdir}/status.xml" token="TAG-{../@name}-STATUS" value="Prereq Failure: {$failed-project}"/>
244			<fail message="PREREQ Failure: Dependency on {$failed-project} could not be satisfied."/>
245		</target>
246	</xsl:template>
247
248
249	<xsl:template match="/workspace/project/ant/property">
250		<arg>
251			<xsl:attribute name="value">
252				<xsl:text>-D</xsl:text>
253				<xsl:value-of select="@name"/>
254				<xsl:text>=</xsl:text>
255				<xsl:choose>
256					<xsl:when test="@value">
257						<xsl:value-of select="@value"/>
258					</xsl:when>
259					<xsl:otherwise>
260						<xsl:if test="@reference and @project">
261			              <xsl:variable name="projname" select="@project"/>
262			              <xsl:variable name="refname" select="@reference"/>
263			              <xsl:choose>
264			                <xsl:when test="@id">
265			                  <xsl:variable name="propid" select="@id"/>
266			                  <xsl:value-of select="/workspace/project[@name=$projname]/*[name()=$refname and @id=$propid]"/>
267			                </xsl:when>
268			                <xsl:otherwise>
269			                  <xsl:value-of select="/workspace/project[@name=$name]/*[name()=$refname]"/>
270			                </xsl:otherwise>
271			              </xsl:choose>
272						</xsl:if>
273					</xsl:otherwise>
274				</xsl:choose>
275			</xsl:attribute>
276		</arg>
277	</xsl:template>
278
279  <!--
280   * Licensed to the Apache Software Foundation (ASF) under one
281   * or more contributor license agreements. See the NOTICE file
282   * distributed with this work for additional information
283   * regarding copyright ownership. The ASF licenses this file
284   * to you under the Apache License, Version 2.0 (the  "License");
285   * you may not use this file except in compliance with the License.
286   * You may obtain a copy of the License at
287   *
288   *     http://www.apache.org/licenses/LICENSE-2.0
289   *
290   * Unless required by applicable law or agreed to in writing, software
291   * distributed under the License is distributed on an "AS IS" BASIS,
292   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
293   * See the License for the specific language governing permissions and
294   * limitations under the License.
295  -->
296
297</xsl:stylesheet>
298