comparison translate.pl @ 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
comparison
equal deleted inserted replaced
5:d2efec56373f 6:2a5f38eb25a9
2 2
3 use JSON; 3 use JSON;
4 use YAML::XS qw(LoadFile Dump); 4 use YAML::XS qw(LoadFile Dump);
5 use URI; 5 use URI;
6 use XML::Writer; 6 use XML::Writer;
7 use IPC::Run qw(run); 7 use IPC::Run qw(start finish);
8 8
9 our @ClassPath = qw( 9 our @ClassPath = qw(
10 /usr/share/java/xalan-j2-serializer.jar 10 /usr/share/java/xalan-j2-serializer.jar
11 /usr/share/java/xalan-j2.jar 11 /usr/share/java/xalan-j2.jar
12 /usr/share/java/xerces-j2.jar 12 /usr/share/java/xerces-j2.jar
23 my $bz = BzRest->new( 23 my $bz = BzRest->new(
24 url => $config->{bugzilla}{url}, 24 url => $config->{bugzilla}{url},
25 apikey => $config->{bugzilla}{apikey} 25 apikey => $config->{bugzilla}{apikey}
26 ); 26 );
27 27
28 my $bugs = $bz->GetBugs( { ids => [ 283, 284 ] } );
29
30 my @fields = qw( 28 my @fields = qw(
31 id 29 id
32 creation_time 30 summary
33 last_change_time 31 creation_time
34 creator 32 last_change_time
35 assigned_to 33 creator
36 34 assigned_to
37 status 35
38 resolution 36 status
39 37 resolution
40 priority 38
41 severity 39 priority
42 url 40 severity
43 41 url
44 blocks 42
45 depends_on 43 blocks
46 cc 44 depends_on
47 45 cc
48 component 46
49 product 47 component
50 classification 48 product
51 version 49 classification
52 50 version
53 actual_time 51
54 estimated_time 52 actual_time
55 remainig_time 53 estimated_time
56 deadline 54 remainig_time
55 deadline
57 ); 56 );
58 57
59 my %fieldsMap = ( 58 my %fieldsMap = (
60 id => 'bug_id', 59 summary => 'short_desc',
61 creator => 'reporter', 60 id => 'bug_id',
62 status => 'bug_status', 61 creator => 'reporter',
63 severity => 'bug_severity', 62 status => 'bug_status',
64 blocks => 'blocked', 63 severity => 'bug_severity',
65 depends_on => 'dependson', 64 blocks => 'blocked',
66 creation_time => 'creation_ts', 65 depends_on => 'dependson',
66 creation_time => 'creation_ts',
67 last_change_time => 'delta_ts' 67 last_change_time => 'delta_ts'
68 ); 68 );
69 69
70 my $writer = XML::Writer->new( OUTPUT => \*STDOUT, ENCODING => 'utf-8' ); 70 local (*HIN);
71
72 my $proc = start( [ 'saxon8', '-novw', '-', 'bug-list.xsl' ],
73 '<pipe', \*HIN, '>', \*STDOUT )
74 or die "failed to create pipe: $!";
75
76 my $writer = XML::Writer->new( OUTPUT => \*HIN, ENCODING => 'utf-8' );
71 77
72 $writer->xmlDecl("UTF-8"); 78 $writer->xmlDecl("UTF-8");
73 $writer->startTag("bugzilla"); 79 $writer->startTag("bugzilla");
74 80
75 foreach my $bug ( @$bugs ) { 81 my %visited;
76 $writer->startTag("bug"); 82 my @queue = (283);
77 foreach my $field ( @fields ) { 83
78 next unless $bug->{$field}; 84 while (@queue) {
79 85 @queue = grep not( $visited{$_}++ ), @queue;
80 my $tagName = $fieldsMap{$field} || $field; 86
81 my @values = ref($bug->{$field}) && ref($bug->{$field}) eq 'ARRAY' ? @{$bug->{$field}} : $bug->{$field}; 87 last unless @queue;
82 88
83 foreach my $v (@values) { 89 print "#Fetching: ", join( ', ', @queue ), "\n";
84 $writer->dataElement($tagName, $v); 90
91 my $bugs = $bz->GetBugs( { ids => \@queue } );
92
93 @queue = ();
94
95 foreach my $bug (@$bugs) {
96
97 push @queue, @{ $bug->{depends_on} }
98 if ( $bug->{depends_on} );
99
100 $writer->startTag("bug");
101 foreach my $field (@fields) {
102 next unless $bug->{$field};
103
104 my $tagName = $fieldsMap{$field} || $field;
105 my @values =
106 ref( $bug->{$field} )
107 && ref( $bug->{$field} ) eq 'ARRAY'
108 ? @{ $bug->{$field} }
109 : $bug->{$field};
110
111 foreach my $v (@values) {
112 $writer->dataElement( $tagName, $v );
113 }
85 } 114 }
115 $writer->endTag();
116
86 } 117 }
87 $writer->endTag();
88 } 118 }
89 119
90 $writer->endTag(); 120 $writer->endTag();
91 121
92 122 close HIN;
123 finish($proc);
93 124
94 #xalan( 125 #xalan(
95 # -IN => "bug-list2.xml", 126 # in => \*OUT,
96 # -XSL => "bug-list.xsl", 127 # out => \*STDOUT,
97 # -URIRESOLVER => "org.apache.xml.resolver.tools.CatalogResolver", 128 # params => [
98 # -ENTITYRESOLVER => "org.apache.xml.resolver.tools.CatalogResolver", 129 #
99 # -PARAM => (chargeset => "dev") 130 # ]
100 #); 131 #);
101 132
102 sub xalan { 133 sub xalan {
103 my @params = @_; 134 my @params = @_;
104 return system 'java', 135 return system 'java',