changeset 6:2a5f38eb25a9

migrated to saxon8 as xslt processor fixed dependency calculation when a container has a dependency on his grandchild
author cin
date Wed, 02 Sep 2015 20:43:38 +0300
parents d2efec56373f
children 29309bc8d932
files .hgignore bug-list.xsl translate.pl
diffstat 3 files changed, 123 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Sep 02 20:43:38 2015 +0300
@@ -0,0 +1,3 @@
+syntax: glob
+config.yaml
+resources.xml
--- a/bug-list.xsl	Tue Sep 01 19:47:30 2015 +0300
+++ b/bug-list.xsl	Wed Sep 02 20:43:38 2015 +0300
@@ -51,6 +51,7 @@
 	<xsl:template match="bug" mode="relations">
 		<xsl:variable name="bugid" select="string(bug_id)" />
 		<bug id="{$bugid}">
+			<!-- calculate all palaces where the same node appears -->
 			<xsl:apply-templates select="exsl:node-set($tree)//bug[@id = $bugid]"
 				mode="traverse-relations">
 			</xsl:apply-templates>
@@ -61,12 +62,14 @@
 		<xsl:variable name="bugid" select="@id" />
 		<xsl:variable name="path" select="ancestor::bug" />
 		<xsl:variable name="level" select="count($path)" />
+		<!-- for the specified path calculate the distances to the preceding container -->
 		<xsl:for-each select="$path[@group]">
 			<xsl:variable name="pos" select="position()" />
 			<xsl:variable name="rank" select="$level - $pos" />
 			<rel container="{@id}" rank="{$rank}" level="{$level}">
-				<xsl:for-each select="$path[position() >= $pos and @group]">
-					<bug id="{@id}" />
+				<!-- record the full path -->
+				<xsl:for-each select="$path[@group]">
+					<parent id="{@id}" bugid="{$bugid}" />
 				</xsl:for-each>
 			</rel>
 		</xsl:for-each>
@@ -83,22 +86,25 @@
 		<xsl:variable name="parent"
 			select="rel[ not(../rel/@rank &lt; @rank) ][1]" />
 		<bug id="{@id}" parent="{$parent/@container}" rank="{$parent/@rank}"
-			level="{$parent/@level}" />
+			level="{$parent/@level}">
+			<xsl:copy-of select="$parent/node()" />
+		</bug>
 	</xsl:template>
 
 	<xsl:variable name="structure">
 		<xsl:choose>
 			<xsl:when test="$root_task">
 				<bug id="_root" desc="{$root_task}" group="true">
-					<xsl:apply-templates select="$roots" mode="structure"/>
+					<xsl:apply-templates select="$roots" mode="structure" />
 				</bug>
 			</xsl:when>
 			<xsl:otherwise>
-				<xsl:apply-templates select="$roots" mode="structure"/>
+				<xsl:apply-templates select="$roots" mode="structure" />
 			</xsl:otherwise>
 		</xsl:choose>
 	</xsl:variable>
 
+	<!-- applied in context of the bugzilla document -->
 	<xsl:template match="bug" mode="structure">
 		<xsl:variable name="id" select="string(bug_id)" />
 		<xsl:variable name="self" select="." />
@@ -120,8 +126,9 @@
 			</xsl:if>
 
 			<!-- filter out dependencies -->
+			<!-- exclude children, and missing bugs -->
 			<xsl:variable name="dependencies"
-				select="dependson[not(text() = exsl:node-set($parents)/bug[@parent = $id]/@id)]" />
+				select="dependson[not(text() = exsl:node-set($parents)/bug/parent[@id=$id]/@bugid)][key('bugid', .)]" />
 			<xsl:for-each select="$dependencies">
 				<dependency id="{.}" />
 			</xsl:for-each>
@@ -132,7 +139,7 @@
 	<xsl:template match="/">
 		<xsl:apply-templates select="exsl:node-set($structure)/bug">
 			<xsl:with-param name="indent" select="0" />
-			<xsl:with-param name="chargeset" select="$chargeset"/>
+			<xsl:with-param name="chargeset" select="$chargeset" />
 		</xsl:apply-templates>
 	</xsl:template>
 
@@ -141,6 +148,8 @@
 		<xsl:param name="chargeset" />
 		<xsl:variable name="id" select="@id" />
 		<xsl:variable name="details" select="$bugs[bug_id = $id]" />
+		<xsl:variable name="hasTime"
+			select="number($details/estimated_time) or number($details/actual_time) or number($details/remaining_time)" />
 
 		<!-- task header -->
 		<xsl:call-template name="start-task">
@@ -152,11 +161,12 @@
 			</xsl:with-param>
 			<xsl:with-param name="desc" select="@desc" />
 		</xsl:call-template>
-		
+
 		<xsl:if test="$chargeset">
 			<xsl:call-template name="println">
-				<xsl:with-param name="indent" select="$indent + 1"/>
-				<xsl:with-param name="text" select="concat('chargeset ', $chargeset)"/>
+				<xsl:with-param name="indent" select="$indent + 1" />
+				<xsl:with-param name="text"
+					select="concat('chargeset ', $chargeset)" />
 			</xsl:call-template>
 		</xsl:if>
 
@@ -175,8 +185,7 @@
 					<xsl:with-param name="indent" select="$indent + 1" />
 				</xsl:apply-templates>
 
-				<xsl:if
-					test="number($details/estimated_time) or number($details/actual_time) or number($details/remaining_time)">
+				<xsl:if test="$hasTime">
 					<xsl:call-template name="start-task">
 						<xsl:with-param name="indent" select="$indent + 1" />
 						<xsl:with-param name="id" select="'manage'" />
@@ -186,6 +195,7 @@
 						select="$details/estimated_time | $details/actual_time | $details/remaining_time | $details/assigned_to"
 						mode="task-details">
 						<xsl:with-param name="indent" select="$indent + 2" />
+						<xsl:with-param name="hasTime" select="$hasTime" />
 					</xsl:apply-templates>
 					<xsl:call-template name="end-task">
 						<xsl:with-param name="indent" select="$indent + 1" />
@@ -196,6 +206,7 @@
 				<xsl:apply-templates select="$details/node()"
 					mode="task-details">
 					<xsl:with-param name="indent" select="$indent + 1" />
+					<xsl:with-param name="hasTime" select="$hasTime" />
 				</xsl:apply-templates>
 			</xsl:otherwise>
 		</xsl:choose>
@@ -243,13 +254,17 @@
 
 	<xsl:template match="assigned_to" mode="task-details">
 		<xsl:param name="indent" />
-		<xsl:variable name="email" select="string(.)" />
-		<xsl:variable name="resource" select="$resources[@email = $email]/@id" />
-		<xsl:if test="$resource">
-			<xsl:call-template name="println">
-				<xsl:with-param name="indent" select="$indent" />
-				<xsl:with-param name="text" select="concat('allocate ', $resource)" />
-			</xsl:call-template>
+		<xsl:param name="hasTime" />
+		<xsl:if test="$hasTime">
+			<xsl:variable name="email" select="string(.)" />
+			<xsl:variable name="resource" select="$resources[@email = $email]/@id" />
+			<xsl:if test="$resource">
+				<xsl:call-template name="println">
+					<xsl:with-param name="indent" select="$indent" />
+					<xsl:with-param name="text"
+						select="concat('allocate ', $resource)" />
+				</xsl:call-template>
+			</xsl:if>
 		</xsl:if>
 	</xsl:template>
 	<xsl:template match="text()" mode="task-details">
@@ -376,7 +391,7 @@
 		<xsl:param name="count" select="0" />
 
 		<xsl:if test="number($count)">
-			<xsl:copy-of select="$value" />
+			<xsl:value-of select="$value" />
 			<xsl:call-template name="repeat">
 				<xsl:with-param name="value" select="$value" />
 				<xsl:with-param name="count" select="$count - 1" />
--- a/translate.pl	Tue Sep 01 19:47:30 2015 +0300
+++ b/translate.pl	Wed Sep 02 20:43:38 2015 +0300
@@ -4,7 +4,7 @@
 use YAML::XS qw(LoadFile Dump);
 use URI;
 use XML::Writer;
-use IPC::Run qw(run);
+use IPC::Run qw(start finish);
 
 our @ClassPath = qw(
   /usr/share/java/xalan-j2-serializer.jar
@@ -25,78 +25,109 @@
 	apikey => $config->{bugzilla}{apikey}
 );
 
-my $bugs = $bz->GetBugs( { ids => [ 283, 284 ] } );
+my @fields = qw(
+  id
+  summary
+  creation_time
+  last_change_time
+  creator
+  assigned_to
+
+  status
+  resolution
 
-my @fields = qw(
-    id
-    creation_time
-    last_change_time
-    creator
-    assigned_to
-    
-    status
-    resolution
-    
-    priority
-    severity
-    url
-    
-    blocks
-    depends_on
-    cc
-    
-    component
-    product
-    classification
-    version
-    
-    actual_time
-    estimated_time
-    remainig_time
-    deadline
+  priority
+  severity
+  url
+
+  blocks
+  depends_on
+  cc
+
+  component
+  product
+  classification
+  version
+
+  actual_time
+  estimated_time
+  remainig_time
+  deadline
 );
 
 my %fieldsMap = (
-	id => 'bug_id',
-	creator => 'reporter',
-	status => 'bug_status',
-	severity => 'bug_severity',
-	blocks => 'blocked',
-	depends_on => 'dependson',
-	creation_time => 'creation_ts',
+	summary          => 'short_desc',
+	id               => 'bug_id',
+	creator          => 'reporter',
+	status           => 'bug_status',
+	severity         => 'bug_severity',
+	blocks           => 'blocked',
+	depends_on       => 'dependson',
+	creation_time    => 'creation_ts',
 	last_change_time => 'delta_ts'
 );
 
-my $writer = XML::Writer->new( OUTPUT => \*STDOUT, ENCODING => 'utf-8' );
+local (*HIN);
+
+my $proc = start( [ 'saxon8', '-novw', '-', 'bug-list.xsl' ],
+	'<pipe', \*HIN, '>', \*STDOUT )
+  or die "failed to create pipe: $!";
+
+my $writer = XML::Writer->new( OUTPUT => \*HIN, ENCODING => 'utf-8' );
 
 $writer->xmlDecl("UTF-8");
 $writer->startTag("bugzilla");
 
-foreach my $bug ( @$bugs ) {
-	$writer->startTag("bug");
-	foreach my $field ( @fields ) {
-		next unless $bug->{$field};
-		
-		my $tagName = $fieldsMap{$field} || $field;
-		my @values = ref($bug->{$field}) && ref($bug->{$field}) eq 'ARRAY' ? @{$bug->{$field}} : $bug->{$field};
-		
-		foreach my $v (@values) {
-			$writer->dataElement($tagName, $v);
+my %visited;
+my @queue = (283);
+
+while (@queue) {
+	@queue = grep not( $visited{$_}++ ), @queue;
+
+	last unless @queue;
+
+	print "#Fetching: ", join( ', ', @queue ), "\n";
+
+	my $bugs = $bz->GetBugs( { ids => \@queue } );
+
+	@queue = ();
+
+	foreach my $bug (@$bugs) {
+
+		push @queue, @{ $bug->{depends_on} }
+		  if ( $bug->{depends_on} );
+
+		$writer->startTag("bug");
+		foreach my $field (@fields) {
+			next unless $bug->{$field};
+
+			my $tagName = $fieldsMap{$field} || $field;
+			my @values =
+			     ref( $bug->{$field} )
+			  && ref( $bug->{$field} ) eq 'ARRAY'
+			  ? @{ $bug->{$field} }
+			  : $bug->{$field};
+
+			foreach my $v (@values) {
+				$writer->dataElement( $tagName, $v );
+			}
 		}
+		$writer->endTag();
+
 	}
-	$writer->endTag();
 }
 
 $writer->endTag();
 
-
+close HIN;
+finish($proc);
 
 #xalan(
-#	-IN          => "bug-list2.xml",
-#	-XSL         => "bug-list.xsl",
-#	-URIRESOLVER => "org.apache.xml.resolver.tools.CatalogResolver",
-#	-ENTITYRESOLVER => "org.apache.xml.resolver.tools.CatalogResolver",
-#	-PARAM => (chargeset => "dev")
+#    in => \*OUT,
+#    out => \*STDOUT,
+#    params => [
+#
+#   ]
 #);
 
 sub xalan {