-
Notifications
You must be signed in to change notification settings - Fork 0
/
createPlugin.pl
executable file
·106 lines (94 loc) · 3.02 KB
/
createPlugin.pl
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
#!/usr/bin/env perl
# Build, upload and promote ReleaseDemoPlugin
#
# Revision History
# 3.0 - Add multiple tiers, rollback, rolling deploy, reservation
# 2.0 - Renamed. Broke up multiple steps. Resource unique.
# 1.2 - Improved artifact creation, platform independent, separate steps
# 1.1 - Parameterized procedure
# git commit . -m "v1.1 Parameterized procedure, closes #1"
# 1.0 - Initial working version
#
use Getopt::Long;
use XML::Simple qw(:strict);
use Data::Dumper;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Archive::Zip::Tree;
use strict;
use ElectricCommander ();
$| = 1;
my $ec = new ElectricCommander->new();
my $version = "3.0";
my $pluginKey = "Release Demo";
my $description = "Creates a procedure that can be used to create a functional release demo";
GetOptions ("version=s" => \$version,
"pluginKey=s" => \$pluginKey,
"description=s" => \$description
) or die(qq(
Error in command line arguments
createPlugin.pl
[--version <version>]
[--pluginKey <version>]
[--description <version>]
)
);
my $pluginName = "${pluginKey}-${version}";
my $xs = XML::Simple->new(
ForceArray => 1,
KeyAttr => { },
KeepRoot => 1,
);
# Update project.xml with ec_setup.pl
print "[INFO] - Processing 'META-INF/project.xml' file...\n";
my $xmlFile = "META-INF/project.xml";
my $file = "ec_setup.pl";
my $value;
{
local $/ = undef;
open FILE, $file or die "Couldn't open file: $!";
binmode FILE;
$value = <FILE>;
close FILE;
}
my $ref = $xs->XMLin($xmlFile);
$ref->{exportedData}[0]->{project}[0]->{propertySheet}[0]->{property}[0]->{value}[0] = $value;
open(my $fh, '>', $xmlFile) or die "Could not open file '$xmlFile' $!";
print $fh $xs->XMLout($ref);
close $fh;
# Update plugin.xml with key, version, label, description
print "[INFO] - Processing 'META-INF/plugin.xml' file...\n";
$xmlFile = "META-INF/plugin.xml";
$ref = $xs->XMLin($xmlFile);
$ref->{plugin}[0]->{key}[0] = $pluginKey;
$ref->{plugin}[0]->{version}[0] = $version;
$ref->{plugin}[0]->{label}[0] = $pluginKey;
$ref->{plugin}[0]->{description}[0] = $description;
open(my $fh, '>', $xmlFile) or die "Could not open file '$xmlFile' $!";
print $fh $xs->XMLout($ref);
close $fh;
# Create plugin jar file
print "[INFO] - Creating plugin jar file, ${pluginKey}.jar\n";
my $zip = Archive::Zip->new();
my $directory = '.';
opendir (DIR, $directory) or die $!;
while (my $file = readdir(DIR)) {
$zip->addTree( $file, $file ) unless (
$file eq "${pluginKey}.jar" or
$file eq ".git" or
$file eq "." or
$file eq ".."
);
}
# Save the Zip file
unless ( $zip->writeToFileNamed("${pluginKey}.jar") == AZ_OK ) {
die 'write error';
}
# Uninstall old plugin
print "[INFO] - Uninstalling old plugin...\n";
$ec->uninstallPlugin($pluginName) || print "No old plugin\n";
# Install plugin
print "[INFO] - Installing plugin...\n";
$ec->installPlugin("${pluginKey}.jar");
# Promote plugin
print "[INFO] - Promoting plugin...\n";
$ec->promotePlugin($pluginName);