changeset 4:f8f966388b68

xslt: bugzilla -> taskjuggler
author cin
date Mon, 24 Aug 2015 20:50:23 +0300
parents 36ae3ec94442
children d2efec56373f
files bug-list.xsl bug-list1.xml
diffstat 2 files changed, 157 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/bug-list.xsl	Mon Aug 24 10:16:41 2015 +0300
+++ b/bug-list.xsl	Mon Aug 24 20:50:23 2015 +0300
@@ -1,11 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0"
-	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common">
-	<xsl:output method="xml" indent="yes" />
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
+	extension-element-prefixes="exsl">
+	<xsl:output method="text" indent="yes" />
+
+	<xsl:variable name="resources"
+		select="document('resources.xml')/resources/resource" />
+
 	<xsl:variable name="bugs" select="/bugzilla/bug" />
+
 	<xsl:key name="bugid" match="/bugzilla/bug" use="string(bug_id)" />
-	<xsl:variable name="roots"
-		select="$bugs[not(blocked[key('bugid',.)])]" />
+
+	<xsl:variable name="roots" select="$bugs[not(blocked[key('bugid',.)])]" />
 
 	<!-- BUILD BUG TREE -->
 	<xsl:variable name="tree">
@@ -44,9 +50,9 @@
 		<xsl:variable name="level" select="count($path)" />
 		<xsl:for-each select="$path[@product]">
 			<xsl:variable name="pos" select="position()" />
-			<xsl:variable name="rank" select="$level - position()" />
+			<xsl:variable name="rank" select="$level - $pos" />
 			<rel container="{@id}" rank="{$rank}" level="{$level}">
-				<xsl:for-each select="$path[position() >= $pos]">
+				<xsl:for-each select="$path[position() >= $pos and @product]">
 					<bug id="{@id}" />
 				</xsl:for-each>
 			</rel>
@@ -92,85 +98,162 @@
 		</bug>
 	</xsl:template>
 
-	<!-- -->
+	<!-- output -->
 	<xsl:template match="/">
-		<root>
-			<xsl:copy-of select="$tree" />
-			<xsl:copy-of select="$relations" />
-			<xsl:copy-of select="$parents" />
-			<xsl:copy-of select="$structure" />
-		</root>
+		<xsl:apply-templates select="exsl:node-set($structure)/bug">
+			<xsl:with-param name="indent" select="0" />
+		</xsl:apply-templates>
 	</xsl:template>
 
 	<xsl:template match="bug">
-		<xsl:value-of select="bug_id" />
-		<xsl:text>&#xa;</xsl:text>
-	</xsl:template>
-
-	<xsl:template match="bug[component = 'product']">
-		<xsl:value-of select="bug_id" />
-		<xsl:text>:&#xa;</xsl:text>
-		<xsl:for-each select="dependson">
-			<xsl:apply-templates select="key('bugid', .)" />
-		</xsl:for-each>
-		<xsl:text>---END---&#xa;</xsl:text>
-	</xsl:template>
-
-	<xsl:template match="text()" />
-
-	<xsl:template name="bug-template">
 		<xsl:param name="indent" select="0" />
-		<xsl:variable name="isOrganizing" select="component = 'product'"></xsl:variable>
-
+		<xsl:variable name="id" select="@id" />
+		<xsl:variable name="details" select="$bugs[bug_id = $id]" />
 		<xsl:call-template name="start-task">
 			<xsl:with-param name="indent" select="$indent" />
+			<xsl:with-param name="id" select="@id" />
+			<xsl:with-param name="desc" select="$details/short_desc" />
 		</xsl:call-template>
 
-		<xsl:if test="$isOrganizing">
-
-		</xsl:if>
+		<xsl:for-each select="$details/*">
+			<xsl:variable name="directive">
+				<xsl:apply-templates select="." mode="task-details" />
+			</xsl:variable>
+			<xsl:if test="string($directive)">
+				<xsl:call-template name="begin-line">
+					<xsl:with-param name="indent" select="$indent + 1" />
+				</xsl:call-template>
+				<xsl:value-of select="$directive" />
+				<xsl:call-template name="end-line" />
+			</xsl:if>
+		</xsl:for-each>
 
-		<xsl:choose>
-			<xsl:when test="$isOrganizing">
-				<xsl:for-each select="dependson">
-					<xsl:for-each select="key('bugs-key', .)">
-						<xsl:call-template name="bug-template">
-							<xsl:with-param name="indent" select="$indent + 1" />
-						</xsl:call-template>
-					</xsl:for-each>
-				</xsl:for-each>
-			</xsl:when>
-			<xsl:otherwise>
-				<xsl:if test="number(estimated_time)">
-					<xsl:call-template name="begin-line">
-						<xsl:with-param name="indent" select="$indent + 1" />
-					</xsl:call-template>
-					<xsl:value-of select="concat('effort ', estimated_time, 'h')" />
-					<xsl:call-template name="end-line" />
-				</xsl:if>
-			</xsl:otherwise>
-		</xsl:choose>
+		<xsl:apply-templates>
+			<xsl:with-param name="indent" select="$indent + 1" />
+		</xsl:apply-templates>
 
 		<xsl:call-template name="end-task">
 			<xsl:with-param name="indent" select="$indent" />
 		</xsl:call-template>
 	</xsl:template>
 
-	<xsl:template name="make-bug-id">
-		<xsl:param name="id"></xsl:param>
-		<xsl:value-of select="concat('bug', $id)"></xsl:value-of>
+	<xsl:template match="estimated_time" mode="task-details">
+		<xsl:if test="number(.)">
+			<xsl:value-of select="concat('effort ', .,'h')" />
+		</xsl:if>
+	</xsl:template>
+
+	<xsl:template match="assigned_to" mode="task-details">
+		<xsl:variable name="email" select="string(.)" />
+		<xsl:variable name="resource" select="$resources[@email = $email]/@id" />
+		<xsl:if test="$resource">
+			<xsl:value-of select="concat('allocate ', $resource)" />
+		</xsl:if>
+	</xsl:template>
+	<xsl:template match="text()" mode="task-details">
+	</xsl:template>
+
+	<xsl:template match="depends">
+		<xsl:param name="indent" select="0" />
+		<xsl:call-template name="begin-line">
+			<xsl:with-param name="indent" select="$indent" />
+		</xsl:call-template>
+		<xsl:text>depends </xsl:text>
+		<xsl:apply-templates>
+			<xsl:with-param name="referer" select=".." />
+		</xsl:apply-templates>
+		<xsl:call-template name="end-line" />
+	</xsl:template>
+
+	<xsl:template match="depends/bug">
+		<xsl:param name="referer" />
+		<xsl:call-template name="bug-reference">
+			<xsl:with-param name="id" select="@id" />
+			<xsl:with-param name="referer" select="$referer" />
+		</xsl:call-template>
+		<xsl:if test="position() != last()">
+			<xsl:text>, </xsl:text>
+		</xsl:if>
+	</xsl:template>
+
+
+	<xsl:template match="text()" />
+
+
+
+	<xsl:template name="bug-local-name">
+		<xsl:param name="id" />
+		<xsl:value-of select="concat('bug',$id)" />
+	</xsl:template>
+
+
+	<xsl:template name="bug-reference">
+		<xsl:param name="id" />
+		<xsl:param name="referer" />
+
+		<xsl:variable name="refererPathFragment">
+			<bug id="#root" />
+			<xsl:for-each select="$referer/ancestor-or-self::bug">
+				<bug id="{@id}" />
+			</xsl:for-each>
+		</xsl:variable>
+		<xsl:variable name="targetPathFragment">
+			<bug id="#root" />
+			<xsl:for-each
+				select="exsl:node-set($structure)//bug[local-name(..) != 'depends' and @id = $id]/ancestor-or-self::bug">
+				<bug id="{@id}" />
+			</xsl:for-each>
+		</xsl:variable>
+		<xsl:variable name="path"
+			select="exsl:node-set($refererPathFragment)/bug" />
+		<xsl:variable name="targetPath"
+			select="exsl:node-set($targetPathFragment)/bug" />
+
+		<!-- find closest shared container id -->
+		<xsl:variable name="join"
+			select="($path[@id = $targetPath/@id])[position() = last() ]/@id" />
+
+		<!-- how many levels we need to up -->
+		<xsl:variable name="depth"
+			select="count($path[@id = $join]/following-sibling::node())" />
+
+		<!-- DEBUG -->
+		<!-- <xsl:value-of select="concat('id=', $id, ',referer=', $referer/@id)" 
+			/> <xsl:text>, path=</xsl:text> <xsl:for-each select="$targetPath"> <xsl:value-of 
+			select="concat(name(),@id)" /> <xsl:if test="position() != last()"> <xsl:text>-</xsl:text> 
+			</xsl:if> </xsl:for-each> -->
+		<!-- DEBUG -->
+		<!-- <xsl:value-of select="concat(', join=', $join,', depth=', $depth,' 
+			')" /> -->
+
+		<!-- PRINT REFERENCE -->
+		<xsl:call-template name="repeat">
+			<xsl:with-param name="value" select="'!'" />
+			<xsl:with-param name="count" select="$depth" />
+		</xsl:call-template>
+		<xsl:for-each select="$targetPath[@id = $join]/following-sibling::node()">
+			<xsl:call-template name="bug-local-name">
+				<xsl:with-param name="id" select="@id" />
+			</xsl:call-template>
+			<xsl:if test="position() != last()">
+				<xsl:text>.</xsl:text>
+			</xsl:if>
+		</xsl:for-each>
+
 	</xsl:template>
 
 	<xsl:template name="start-task">
 		<xsl:param name="indent" />
+		<xsl:param name="id" />
+		<xsl:param name="desc" />
 		<xsl:call-template name="begin-line">
 			<xsl:with-param name="indent" select="$indent" />
 		</xsl:call-template>
 		<xsl:text>task </xsl:text>
-		<xsl:call-template name="make-bug-id">
-			<xsl:with-param name="id" select="bug_id" />
+		<xsl:call-template name="bug-local-name">
+			<xsl:with-param name="id" select="$id" />
 		</xsl:call-template>
-		<xsl:value-of select="concat(' &quot;',short_desc,'&quot; {')" />
+		<xsl:value-of select="concat(' &quot;',$desc,'&quot; {')" />
 		<xsl:call-template name="end-line" />
 	</xsl:template>
 
@@ -195,4 +278,17 @@
 	<xsl:template name="end-line">
 		<xsl:text>&#xa;</xsl:text>
 	</xsl:template>
+
+	<xsl:template name="repeat">
+		<xsl:param name="value" />
+		<xsl:param name="count" select="0" />
+
+		<xsl:if test="number($count)">
+			<xsl:copy-of select="$value" />
+			<xsl:call-template name="repeat">
+				<xsl:with-param name="value" select="$value" />
+				<xsl:with-param name="count" select="$count - 1" />
+			</xsl:call-template>
+		</xsl:if>
+	</xsl:template>
 </xsl:stylesheet>
\ No newline at end of file
--- a/bug-list1.xml	Mon Aug 24 10:16:41 2015 +0300
+++ b/bug-list1.xml	Mon Aug 24 20:50:23 2015 +0300
@@ -4640,6 +4640,7 @@
           <bug_severity>enhancement</bug_severity>
           <target_milestone>---</target_milestone>
           <dependson>159</dependson>
+          <dependson>251</dependson>
           <blocked>160</blocked>
     
     <blocked>164</blocked>