forked from electric-cloud/EC-AuditReports
/
ec_setup.pl
executable file
·159 lines (137 loc) · 5.17 KB
/
ec_setup.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
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
## DO NOT EDIT THIS BLOCK === ec_setup starts ===
# This is auto-generated ec_setup file provided for you by ecpdf utility <3
# Please do not edit this code manually, if you need to write your own code, please add it in the end of this file
use Cwd;
use File::Spec;
use POSIX;
use MIME::Base64;
use File::Temp qw(tempfile tempdir);
use Archive::Zip;
use Digest::MD5 qw(md5_hex);
my $dir = getcwd;
my $logfile ="";
my $pluginDir;
if ( defined $ENV{QUERY_STRING} ) { # Promotion through UI
$pluginDir = $ENV{COMMANDER_PLUGINS} . "/$pluginName";
}
else {
my $commanderPluginDir = $commander->getProperty('/server/settings/pluginsDirectory')->findvalue('//value');
# We are not checking for the directory, because we can run this script on a different machine
$pluginDir = "$commanderPluginDir/$pluginName";
}
$logfile .= "Plugin directory is $pluginDir";
$commander->setProperty("/plugins/$pluginName/project/pluginDir", {value=>$pluginDir});
$logfile .= "Plugin Name: $pluginName\n";
$logfile .= "Current directory: $dir\n";
# Evaluate promote.groovy or demote.groovy based on whether plugin is being promoted or demoted ($promoteAction)
local $/ = undef;
my $demoteDsl = q{
# demote.groovy placeholder
};
my $promoteDsl = q{
# promote.groovy placeholder
};
my $dsl;
if ($promoteAction eq 'promote') {
$dsl = $promoteDsl;
}
else {
$dsl = $demoteDsl;
}
my $dslReponse = $commander->evalDsl(
$dsl, {
parameters => qq(
{
"pluginName":"$pluginName",
"upgradeAction":"$upgradeAction",
"otherPluginName":"$otherPluginName"
}
),
debug => 'false',
serverLibraryPath => "$pluginDir/dsl"
},
);
$logfile .= $dslReponse->findnodes_as_string("/");
warn $logfile;
my $errorMessage = $commander->getError();
if ( !$errorMessage ) {
# This is here because we cannot do publishArtifactVersion in dsl today
# delete artifact if it exists first
my $dependenciesProperty = '/projects/@PLUGIN_NAME@/ec_groovyDependencies';
my $base64 = '';
my $xpath;
eval {
$xpath = $commander->getProperties({path => $dependenciesProperty});
1;
};
unless($@) {
my $blocks = {};
my $checksum = '';
for my $prop ($xpath->findnodes('//property')) {
my $name = $prop->findvalue('propertyName')->string_value;
my $value = $prop->findvalue('value')->string_value;
if ($name eq 'checksum') {
$checksum = $value;
}
else {
my ($number) = $name =~ /ec_dependencyChunk_(\d+)$/;
$blocks->{$number} = $value;
}
}
for my $key (sort {$a <=> $b} keys %$blocks) {
$base64 .= $blocks->{$key};
}
my $resultChecksum = md5_hex($base64);
unless($checksum) {
die "No checksum found in dependendencies property, please reinstall the plugin";
}
if ($resultChecksum ne $checksum) {
die "Wrong dependency checksum: original checksum is $checksum";
}
}
if ($base64) {
my $grapesVersion = '1.0.0';
my $cleanup = 1;
my $groupId = 'com.electriccloud';
$commander->deleteArtifactVersion($groupId . ':@PLUGIN_KEY@-Grapes:' . $grapesVersion);
my $binary = decode_base64($base64);
my ($tempFh, $tempFilename) = tempfile(CLEANUP => $cleanup);
binmode($tempFh);
print $tempFh $binary;
close $tempFh;
my ($tempDir) = tempdir(CLEANUP => $cleanup);
my $zip = Archive::Zip->new();
unless($zip->read($tempFilename) == Archive::Zip::AZ_OK()) {
die "Cannot read .zip dependencies: $!";
}
$zip->extractTree("", $tempDir . "/");
if ( $promoteAction eq "promote" ) {
#publish jars to the repo server if the plugin project was created successfully
my $am = new ElectricCommander::ArtifactManagement($commander);
my $artifactVersion = $am->publish(
{ groupId => $groupId,
artifactKey => '@PLUGIN_KEY@-Grapes',
version => $grapesVersion,
includePatterns => "**",
fromDirectory => File::Spec->catfile($tempDir, 'lib/grapes'),
description => 'JARs that @PLUGIN_KEY@ plugin procedures depend on'
}
);
# Print out the xml of the published artifactVersion.
$logfile .= $artifactVersion->xml() . "\n";
if ( $artifactVersion->diagnostics() ) {
$logfile .= "\nDetails:\n" . $artifactVersion->diagnostics();
}
}
}
}
# Create output property for plugin setup debug logs
my $nowString = localtime;
$commander->setProperty( "/plugins/$pluginName/project/logs/$nowString", { value => $logfile } );
die $errorMessage unless !$errorMessage;
# Please do not remove the line below, it marks the auto-generated code and is used by the ecpdf tool
## DO NOT EDIT THIS BLOCK === ec_setup ends, checksum: 67063a7039dc062ff9e1da5eeae95985 ===
# Please place your custom code between two markers below:
# EC Setup Custom Starts
# EC Setup Custom Ends
# If you don't like the markers, write your custom code into ec_setup_custom.pl