-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteComponents.pl
More file actions
executable file
·164 lines (120 loc) · 4.81 KB
/
writeComponents.pl
File metadata and controls
executable file
·164 lines (120 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env perl
# This is based on work that is in the public domain
# and modified by Marc Boudreau
#use strict;
use warnings;
use File::Path;
use XML::LibXML;
use Getopt::Long ();
use Pod::Usage;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Data::Dumper;
my $xmlFilename = "-"; # Use STDIN as the default
my $help;
my $componentName;
my $cmdName;
my $quiet;
my $nuke;
my $skip;
# The following xPath gives all the component commands that are in a given
# workflow JTL as of version 9 (and probably version 8)
# NOTE: there are some strangenesses of Signiant JTLs that require the '//'
my $xpath = "//task";
sub makeApplicationXML {
my $name = $_[0];
my $version = $_[1];
my $xml =<<"__XML__";
<?xml version="1.0" encoding="UTF-8"?>
<application display="$name" dtm_version="10.0.0.0"
name="$name Application" version="$version">
<install>
<component display="$name" plugin="components/$name.xml"/>
</install>
<uninstall>
<component display="$name" plugin="components/$name.xml"/>
</uninstall>
<feature_id/>
</application>
__XML__
return $xml;
}
pod2usage(-verbose => 2, -noperldoc => 1) if (
! Getopt::Long::GetOptions(
"j|jtl:s" => \$xmlFilename, # The xml containing the JTL (defaults to STDIN)
"comp:s" => \$componentName, # The components desired (default all)
"q|quiet" => \$quiet, # Don't output STDERR messages (except for Usage)
"n|nuke" => \$nuke, # Don't create backup files
"h|help|?" => \$help ) or
defined $help);
open XMLFILE, "<$xmlFilename" or die "ERROR: Unable to open $xmlFilename";
my @lines = <XMLFILE>;
close XMLFILE;
my $parser = XML::LibXML->new();
my $xmlDoc = $parser->parse_string( "@lines" );
my $xmlContext = XML::LibXML::XPathContext->new( $xmlDoc );
my $nodes = $xmlContext->findnodes( $xpath );
if ( $nodes->size() ) {
foreach my $node ( $nodes->get_nodelist ) {
my $currentComponentName = $node->findvalue("\@componentType"); # Use the relative operators to get around the property within a property issue
my $prettyName = $node->findvalue("\@description");
my $name = $node->findvalue("\@name");
my $version = $node->findvalue("\@version");
my $text = $node->findvalue("self::value");
if (defined $componentName) {
next if ($componentName ne $currentComponentName);
}
$DB::single = 1;
my $file = "$currentComponentName"."_$version.zip";
print STDERR "Writing: $file | $currentComponentName | $prettyName\n" unless (defined $quiet);
# Write the code to a file - Backup the old one
if (-e $file) {
rename "$file", "$file.bak" unless (defined $nuke);
}
my $zip = Archive::Zip->new();
# Create the application.xml file
my $appXML = $zip->addString( makeApplicationXML($currentComponentName,$version), 'application.xml' );
$appXML->desiredCompressionMethod( COMPRESSION_DEFLATED );
# Make the component sub-directory
my $componentDir = $zip->addDirectory( 'components/' );
$DB::single = 1;
my $nodeText = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n" . $node;
$nodeText =~ s/\<task/\<component/g;
$nodeText =~ s/\<\/task/\<\/component/g;
# Gets ride of Wide Characters - happens occasionally
$nodeText =~ s/[^\x00-\x7f]//g;
# Create the application.xml file
my $componentXML = $zip->addString( $nodeText, "components/$currentComponentName.xml" );
$componentXML->desiredCompressionMethod( COMPRESSION_DEFLATED );
unless ($zip->writeToFileNamed($file) == AZ_OK) {
die "Unable to write Zip file\n";
}
}
}
__END__
=head1 NAME
writeComponents.pl - create installable components from a Job Template Library
=head1 SYNOPSIS
writeComponents.pl [options]
Options:
-j -jtl xml containing the JTL (defaults to STDIN)
-comp desired component (default all)
-n -nuke skip creation of backup files
-q -quiet don't output STDERR messages
-help brief help message
=head1 OPTIONS
=over 8
=item B<-jtl>
The xml file containing the Job Template library (STDIN by default).
=item B<-comp>
The name of the specific component to be extracted. By default all components are extracted.
=item B<-nuke>
Do not create a backup of any existing Perl files.
=item B<-quiet>
Don't output error messages.
=item B<-help>
Prints this page and exits.
=back
=head1 DESCRIPTION
B<This program> will read the specified JTL file and extract the requested components.
If files already exist in the folder, a backup is made of the code file and any NEW inputs in the JTL are merged with any existing input file.
=cut