| 4455 |
dpurdie |
1 |
########################################################################
|
|
|
2 |
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
|
|
|
3 |
#
|
|
|
4 |
# Module name : jats_gen_releasenote.pl
|
|
|
5 |
# Module type : Makefile system
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): jats
|
|
|
8 |
#
|
|
|
9 |
# Description : Generate the package Release Note
|
|
|
10 |
# Requires
|
|
|
11 |
# 1) Release Note data generated by jats_get_releasenote_data.pl
|
|
|
12 |
# 2) Target package in dpkg_archive
|
|
|
13 |
# 3) One or more built.files.xxx.xml
|
|
|
14 |
#
|
|
|
15 |
# Will:
|
|
|
16 |
# Merge built.files..xml files into the release note data
|
|
|
17 |
# Insert build meta data
|
|
|
18 |
# Save the Release Note MetaData within the package
|
|
|
19 |
# Generate the HTML release note - save within the package
|
|
|
20 |
#
|
|
|
21 |
# Usage: See POD
|
|
|
22 |
#
|
|
|
23 |
#......................................................................#
|
|
|
24 |
|
|
|
25 |
require 5.008_002;
|
|
|
26 |
use strict;
|
|
|
27 |
use warnings;
|
|
|
28 |
|
|
|
29 |
use Pod::Usage;
|
|
|
30 |
use Getopt::Long;
|
|
|
31 |
use XML::Simple;
|
|
|
32 |
use File::Path;
|
|
|
33 |
use File::Copy;
|
|
|
34 |
use XML::Simple;
|
| 4546 |
dpurdie |
35 |
use Digest::MD5;
|
|
|
36 |
use File::Find;
|
| 4455 |
dpurdie |
37 |
|
|
|
38 |
use JatsError;
|
|
|
39 |
use JatsSystem;
|
|
|
40 |
use Getopt::Long;
|
|
|
41 |
use Pod::Usage;
|
|
|
42 |
use FileUtils;
|
|
|
43 |
use JatsEnv;
|
|
|
44 |
|
|
|
45 |
my $VERSION = "1.0.0"; # Update this. Inserted into meta data field
|
|
|
46 |
|
|
|
47 |
# User options
|
|
|
48 |
my $opt_verbose = 1;
|
|
|
49 |
my $opt_help = 0;
|
|
|
50 |
my $opt_archive;
|
|
|
51 |
my $archive_tag;
|
|
|
52 |
my $opt_pname;
|
|
|
53 |
my $opt_pversion;
|
|
|
54 |
my $opt_release_note;
|
|
|
55 |
my $opt_pvid;
|
|
|
56 |
my $opt_outname;
|
|
|
57 |
|
|
|
58 |
# Global vars
|
| 4546 |
dpurdie |
59 |
our $GBE_HOSTNAME;
|
| 4455 |
dpurdie |
60 |
our $GBE_TOOLS;
|
|
|
61 |
my $DPKG_ROOT;
|
|
|
62 |
my $DPKG_DOC;
|
|
|
63 |
my $JATS_RN;
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
#
|
|
|
67 |
# Structure to translate -archive=xxx option to archive variable
|
|
|
68 |
# These are the various dpkg_archives known to JATS
|
|
|
69 |
#
|
|
|
70 |
my %Archive2Var =( 'main' => 'GBE_DPKG',
|
|
|
71 |
'store' => 'GBE_DPKG_STORE',
|
|
|
72 |
'cache' => 'GBE_DPKG_CACHE',
|
|
|
73 |
'local' => 'GBE_DPKG_LOCAL',
|
|
|
74 |
'sandbox' => 'GBE_DPKG_SBOX',
|
|
|
75 |
'deploy' => 'GBE_DPLY',
|
|
|
76 |
);
|
|
|
77 |
|
|
|
78 |
#-------------------------------------------------------------------------------
|
|
|
79 |
# Function : Main Entry
|
|
|
80 |
#
|
|
|
81 |
# Description :
|
|
|
82 |
#
|
|
|
83 |
# Inputs :
|
|
|
84 |
#
|
|
|
85 |
# Returns :
|
|
|
86 |
#
|
|
|
87 |
{
|
|
|
88 |
my $result = GetOptions (
|
|
|
89 |
"help+" => \$opt_help, # flag, multiple use allowed
|
|
|
90 |
"manual:3" => \$opt_help,
|
|
|
91 |
"verbose:+" => \$opt_verbose, # flag
|
|
|
92 |
"archive=s" => \$opt_archive, # string
|
|
|
93 |
# "pname=s" => \$opt_pname, # string
|
|
|
94 |
# "pversion=s" => \$opt_pversion, # string
|
|
|
95 |
"releasenote=s" => \$opt_release_note, # string
|
|
|
96 |
);
|
|
|
97 |
|
|
|
98 |
#
|
|
|
99 |
# Process help and manual options
|
|
|
100 |
#
|
|
|
101 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
102 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
103 |
pod2usage(-verbose => 2) if ($opt_help > 2);
|
|
|
104 |
|
|
|
105 |
ErrorConfig( 'name' =>'GenRn', 'verbose' => $opt_verbose );
|
|
|
106 |
|
|
|
107 |
#
|
|
|
108 |
# Needed EnvVars
|
|
|
109 |
#
|
| 4546 |
dpurdie |
110 |
EnvImport ('GBE_HOSTNAME');
|
| 4455 |
dpurdie |
111 |
EnvImport ('GBE_TOOLS');
|
|
|
112 |
$JATS_RN = catdir($GBE_TOOLS, 'RELEASENOTES');
|
|
|
113 |
Error("Release Note tools not found", $JATS_RN)
|
|
|
114 |
unless (-d $JATS_RN);
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
#
|
|
|
118 |
# Sanity Check
|
|
|
119 |
#
|
|
|
120 |
# Error("Package Name not provided") unless $opt_pname;
|
|
|
121 |
# Error("Package Version not provided") unless $opt_pversion;
|
|
|
122 |
Error("Release Note data not provided") unless $opt_release_note;
|
|
|
123 |
Error("Release Note data not found") unless -f $opt_release_note;
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
#
|
|
|
127 |
# Determine the target archive
|
|
|
128 |
# The default archive is GBE_DPKG, but this may be changed
|
|
|
129 |
#
|
|
|
130 |
$opt_archive = 'main' unless ( $opt_archive );
|
|
|
131 |
my $archive_tag = $Archive2Var{$opt_archive};
|
|
|
132 |
Error("Unknown archive specified: $opt_archive")
|
|
|
133 |
unless ( $archive_tag );
|
|
|
134 |
$DPKG_ROOT = $ENV{$archive_tag} || '';
|
|
|
135 |
Verbose ("Archive Variable: $archive_tag" );
|
|
|
136 |
Verbose2 ("Archive Path: $DPKG_ROOT" );
|
|
|
137 |
|
|
|
138 |
#
|
|
|
139 |
# Process the release note and extract essential information
|
|
|
140 |
#
|
|
|
141 |
processReleaseNote();
|
|
|
142 |
|
|
|
143 |
#
|
|
|
144 |
# Locate the target package
|
|
|
145 |
#
|
|
|
146 |
$DPKG_ROOT = catdir($DPKG_ROOT, $opt_pname, $opt_pversion);
|
| 4546 |
dpurdie |
147 |
Verbose ("Package Path: ", DisplayPath($DPKG_ROOT) );
|
| 4455 |
dpurdie |
148 |
Error ("Package not found in archive", $DPKG_ROOT) unless -d $DPKG_ROOT;
|
|
|
149 |
|
|
|
150 |
#
|
|
|
151 |
# Locate the release note data file
|
|
|
152 |
# This was created as a prerequisite to the build
|
|
|
153 |
# Note: windows requires '/' in the file list
|
|
|
154 |
#
|
|
|
155 |
my @filesList;
|
|
|
156 |
foreach my $item ( glob(catdir($DPKG_ROOT, 'built.files.*.xml'))) {
|
|
|
157 |
$item =~ s~\\~/~g;
|
|
|
158 |
push @filesList, $item;
|
|
|
159 |
}
|
| 4546 |
dpurdie |
160 |
unless (scalar @filesList > 0)
|
|
|
161 |
{
|
|
|
162 |
#
|
|
|
163 |
# No filelist found in the package
|
|
|
164 |
# This may occur for packages that did not go though the build system
|
|
|
165 |
# Create a package-list
|
|
|
166 |
#
|
|
|
167 |
my $item = generateFileList();
|
|
|
168 |
$item =~ s~\\~/~g;
|
|
|
169 |
push @filesList, $item;
|
|
|
170 |
}
|
| 4455 |
dpurdie |
171 |
Error("No file list found within the package") unless (scalar @filesList > 0);
|
|
|
172 |
|
|
|
173 |
#
|
|
|
174 |
# Generate the name of the release note
|
|
|
175 |
# RELEASE_NOTES_PVID_PKGNAME_CLEANV.html
|
|
|
176 |
#
|
|
|
177 |
my $cleanv = $opt_pversion;
|
|
|
178 |
$cleanv =~ s~\.~_~g;
|
|
|
179 |
$opt_outname = join('_',
|
|
|
180 |
'RELEASE_NOTES',
|
|
|
181 |
$opt_pvid,
|
|
|
182 |
$opt_pname,
|
|
|
183 |
$cleanv,
|
|
|
184 |
) . '.html';
|
|
|
185 |
Verbose("Note Name: $opt_outname");
|
|
|
186 |
|
|
|
187 |
#
|
|
|
188 |
# Create output directory within the package
|
|
|
189 |
#
|
|
|
190 |
$DPKG_DOC = catdir($DPKG_ROOT, 'doc');
|
|
|
191 |
mkpath($DPKG_DOC, 0, 0775);
|
|
|
192 |
|
|
|
193 |
#
|
|
|
194 |
# Merge the Release Note and the various file lists into a single
|
|
|
195 |
# XML file. Keep the file local
|
|
|
196 |
#
|
|
|
197 |
System('--NoShell', '--Exit', 'java', '-jar',
|
|
|
198 |
catdir($JATS_RN, 'saxon9he.jar'),
|
|
|
199 |
'-xsl:' . catdir($JATS_RN, 'merge.xslt'),
|
|
|
200 |
"-s:$opt_release_note",
|
|
|
201 |
'fileList=' . join(',', @filesList),
|
|
|
202 |
'-o:' . 'built.files.releasenote.xml'
|
|
|
203 |
);
|
|
|
204 |
|
|
|
205 |
#
|
|
|
206 |
# Generate the HTML Release Note
|
|
|
207 |
# Output directly to the body of the package
|
|
|
208 |
#
|
|
|
209 |
System('--NoShell', '--Exit', 'java', '-jar',
|
|
|
210 |
catdir($JATS_RN, 'saxon9he.jar'),
|
|
|
211 |
'-xsl:' . catdir($JATS_RN, 'releaseNote2html.xslt'),
|
|
|
212 |
'-s:' . 'built.files.releasenote.xml',
|
|
|
213 |
"-o:" . catdir($DPKG_DOC, $opt_outname)
|
|
|
214 |
);
|
|
|
215 |
|
|
|
216 |
#
|
|
|
217 |
# Transfer the XML database directly into the package
|
|
|
218 |
#
|
|
|
219 |
unless( File::Copy::copy('built.files.releasenote.xml', catdir($DPKG_DOC, 'release_note.xml')) )
|
|
|
220 |
{
|
|
|
221 |
Error("Cannot transfer XML release note", $!);
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
#
|
|
|
225 |
# All done
|
|
|
226 |
#
|
| 4546 |
dpurdie |
227 |
Verbose ("Release Note:", DisplayPath(catdir($DPKG_DOC, $opt_outname)));
|
| 4455 |
dpurdie |
228 |
exit 0;
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
#-------------------------------------------------------------------------------
|
|
|
232 |
# Function : processReleaseNote
|
|
|
233 |
#
|
| 4546 |
dpurdie |
234 |
# Description : Extract essential information from the Release Note Data
|
| 4455 |
dpurdie |
235 |
#
|
|
|
236 |
# Inputs :
|
|
|
237 |
#
|
| 4546 |
dpurdie |
238 |
# Returns : Populates global variables
|
| 4455 |
dpurdie |
239 |
#
|
|
|
240 |
sub processReleaseNote
|
|
|
241 |
{
|
|
|
242 |
my $xml = XMLin($opt_release_note);
|
|
|
243 |
|
|
|
244 |
foreach my $item ( qw (name version pvid) ) {
|
|
|
245 |
Error("Unexpected ReleaseNote format: package $item")
|
|
|
246 |
unless (exists $xml->{package}{$item});
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
$opt_pname = $xml->{package}{name};
|
|
|
250 |
$opt_pversion = $xml->{package}{version};
|
|
|
251 |
$opt_pvid = $xml->{package}{pvid};
|
|
|
252 |
|
|
|
253 |
Verbose("Package Name: $opt_pname") ;
|
|
|
254 |
Verbose("Package Version: $opt_pversion") ;
|
|
|
255 |
Verbose("Package Pvid: $opt_pvid") ;
|
|
|
256 |
}
|
|
|
257 |
|
| 4546 |
dpurdie |
258 |
#-------------------------------------------------------------------------------
|
|
|
259 |
# Function : generateFileList
|
|
|
260 |
# generateFileListProc
|
|
|
261 |
#
|
|
|
262 |
# Description : A fileList has not been found in the target package
|
|
|
263 |
# Perhaps the package was not created by the build system
|
|
|
264 |
#
|
|
|
265 |
# Generate a fileList
|
|
|
266 |
#
|
|
|
267 |
# Inputs : None
|
|
|
268 |
#
|
|
|
269 |
# Returns : Path to the generated file list
|
|
|
270 |
#
|
|
|
271 |
my @generateFileListData;
|
|
|
272 |
my $baseLength;
|
|
|
273 |
sub generateFileList
|
|
|
274 |
{
|
|
|
275 |
my $outXmlFile;
|
|
|
276 |
Verbose("Generate internal filelist - none found in package");
|
| 4455 |
dpurdie |
277 |
|
| 4546 |
dpurdie |
278 |
#
|
|
|
279 |
# Scan the package and process each file
|
|
|
280 |
#
|
|
|
281 |
$baseLength = length($DPKG_ROOT);
|
|
|
282 |
File::Find::find( \&generateFileListProc, $DPKG_ROOT );
|
|
|
283 |
|
|
|
284 |
#
|
|
|
285 |
# Write out XML of the Generated file list
|
|
|
286 |
#
|
|
|
287 |
my $data;
|
|
|
288 |
$data->{file} = \@generateFileListData;
|
|
|
289 |
|
|
|
290 |
#
|
|
|
291 |
# Write out sections of XML
|
|
|
292 |
# Want control over the output order
|
|
|
293 |
# Use lots of attributes and only elements for arrays
|
|
|
294 |
# Save as one attribute per line - for readability
|
|
|
295 |
#
|
|
|
296 |
$outXmlFile = catdir($DPKG_ROOT,"built.files.$GBE_HOSTNAME.xml");
|
|
|
297 |
|
|
|
298 |
Verbose2('Meta File', $outXmlFile);
|
|
|
299 |
my $xs = XML::Simple->new( NoAttr =>0, AttrIndent => 1 );
|
|
|
300 |
|
|
|
301 |
open (my $XML, '>', $outXmlFile) || Error ("Cannot create output file: $outXmlFile", $!);
|
|
|
302 |
$xs->XMLout($data,
|
|
|
303 |
'RootName' => 'files',
|
|
|
304 |
'XMLDecl' => '<?xml version="1.0" encoding="UTF-8"?>',
|
|
|
305 |
'OutputFile' => $XML);
|
|
|
306 |
close $XML;
|
|
|
307 |
|
|
|
308 |
return $outXmlFile;
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
sub generateFileListProc
|
|
|
312 |
{
|
|
|
313 |
my %data;
|
|
|
314 |
my $md5sum;
|
|
|
315 |
my $source = $File::Find::name;
|
|
|
316 |
my $type = 'dir';
|
|
|
317 |
|
|
|
318 |
my $target = substr($source, $baseLength);
|
|
|
319 |
$target =~ s~^/~~;
|
|
|
320 |
$target =~ s~/$~~;
|
|
|
321 |
Verbose2("GenFileList: $source, $target");
|
|
|
322 |
return if (length ($target) == 0);
|
|
|
323 |
|
|
|
324 |
if (-l $source)
|
|
|
325 |
{
|
|
|
326 |
$type = 'link';
|
|
|
327 |
}
|
|
|
328 |
elsif ( -f $source)
|
|
|
329 |
{
|
|
|
330 |
$type = 'file';
|
|
|
331 |
Verbose2("Calculate MD5 Digest: $source");
|
|
|
332 |
open(my $fh , $source) or Error ("Can't open '$source': $!");
|
|
|
333 |
binmode $fh, ':crlf';
|
|
|
334 |
$md5sum = Digest::MD5->new->addfile($fh)->hexdigest;
|
|
|
335 |
close $fh;
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
if (-d $source)
|
|
|
340 |
{
|
|
|
341 |
$data{path} = $target;
|
|
|
342 |
}
|
|
|
343 |
else
|
|
|
344 |
{
|
|
|
345 |
$data{path} = StripFileExt($target);
|
|
|
346 |
$data{name} = StripDir($target);
|
|
|
347 |
if (defined $md5sum)
|
|
|
348 |
{
|
|
|
349 |
$data{size} = (stat($source))[7];
|
|
|
350 |
$data{md5sum} = $md5sum;
|
|
|
351 |
}
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
$data{fullname} = $target;
|
|
|
355 |
$data{type} = $type;
|
|
|
356 |
$data{machtype} = 'unknown';
|
|
|
357 |
$data{host} = $GBE_HOSTNAME;
|
|
|
358 |
|
|
|
359 |
# Put a nice '/' on the end of the patch elements
|
|
|
360 |
$data{path} .= '/'
|
|
|
361 |
if ( exists ($data{path}) && length($data{path}) > 0);
|
|
|
362 |
|
|
|
363 |
push @generateFileListData, \%data;
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
|
| 4455 |
dpurdie |
367 |
#-------------------------------------------------------------------------------
|
|
|
368 |
# Documentation
|
|
|
369 |
#
|
|
|
370 |
|
|
|
371 |
=pod
|
|
|
372 |
|
|
|
373 |
=for htmltoc SYSUTIL::
|
|
|
374 |
|
|
|
375 |
=head1 NAME
|
|
|
376 |
|
|
|
377 |
jats_get_releasenote_data - Get Release Note Data
|
|
|
378 |
|
|
|
379 |
=head1 SYNOPSIS
|
|
|
380 |
|
|
|
381 |
jats get_releasenote_data [options]
|
|
|
382 |
|
|
|
383 |
Options:
|
|
|
384 |
-help - Brief help message
|
|
|
385 |
-help -help - Detailed help message
|
|
|
386 |
-man - Full documentation
|
|
|
387 |
-verbose - Display additional progress messages
|
|
|
388 |
-outfile=name - [Optional] Name of the output XML file
|
| 4468 |
dpurdie |
389 |
-archive=name - [Optional] Name package archive
|
|
|
390 |
-releasenote=path - Path to the Release Note Data
|
| 4455 |
dpurdie |
391 |
|
|
|
392 |
|
|
|
393 |
=head1 OPTIONS
|
|
|
394 |
|
|
|
395 |
=over 8
|
|
|
396 |
|
|
|
397 |
=item B<-help>
|
|
|
398 |
|
|
|
399 |
Print a brief help message and exits.
|
|
|
400 |
|
|
|
401 |
=item B<-help -help>
|
|
|
402 |
|
|
|
403 |
Print a detailed help message with an explanation for each option.
|
|
|
404 |
|
|
|
405 |
=item B<-man>
|
|
|
406 |
|
|
|
407 |
Prints the manual page and exits.
|
|
|
408 |
|
|
|
409 |
=item B<-pvid=nn>
|
|
|
410 |
|
|
|
411 |
This option provides identifies the PackageVersion to be processed.
|
|
|
412 |
|
|
|
413 |
This option is mandatory.
|
|
|
414 |
|
|
|
415 |
=item B<-outfile=name>
|
|
|
416 |
|
|
|
417 |
This option specifies the output file name.
|
|
|
418 |
|
|
|
419 |
If not provided by the user the output filename will be created in the current directory
|
|
|
420 |
and it will be named after the package name and package version.
|
|
|
421 |
|
|
|
422 |
If the filename does not end in .xml, then .xml will be appended to the file name.
|
|
|
423 |
|
|
|
424 |
=back
|
|
|
425 |
|
|
|
426 |
=head1 DESCRIPTION
|
|
|
427 |
|
|
|
428 |
This utility program is used to extract sufficient information from Release Manager and other
|
|
|
429 |
associated databases so that a Release Note can be created.
|
|
|
430 |
|
|
|
431 |
The extracted data is stored in an XML format. The intent is that XSLT will be used to create
|
|
|
432 |
an HTML based release note.
|
|
|
433 |
|
|
|
434 |
|
|
|
435 |
=head1 EXAMPLE
|
|
|
436 |
|
|
|
437 |
=head2 jats get_releasenote_data -pvid=983058 -outfile=tmpdata.xml
|
|
|
438 |
|
|
|
439 |
This will locate a package-version with an id of 983058, extrat required information and create
|
|
|
440 |
an XML file called tmpdata.xml.
|
|
|
441 |
|
|
|
442 |
=cut
|