update dev300-m58
[ooovba.git] / solenv / bin / cwstestresult.pl
blob1a672c9ee6647bd00f235f17eb4bb4de5349a83e
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: cwsattach.pl,v $
14 # $Revision: 1.3 $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
35 # cwstestresult.pl - publish results of CWS tests to EIS
38 use strict;
39 use Getopt::Long;
40 use Cwd;
42 #### module lookup
43 my @lib_dirs;
44 BEGIN {
45 if ( !defined($ENV{SOLARENV}) ) {
46 die "No environment found (environment variable SOLARENV is undefined)";
48 push(@lib_dirs, "$ENV{SOLARENV}/bin/modules");
49 push(@lib_dirs, "$ENV{COMMON_ENV_TOOLS}/modules") if defined($ENV{COMMON_ENV_TOOLS});
51 use lib (@lib_dirs);
53 use Cws;
55 #### global #####
56 ( my $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
58 my $is_debug = 1; # enable debug
59 my $opt_master; # option: master workspace
60 my $opt_child; # option: child workspace
61 my $opt_milestone; # option: milestone
62 my $opt_testrunName; # option: testrunName
63 my $opt_testrunPlatform; # option: testrunPlatfrom
64 my $opt_resultPage; # option: resultPage
67 #### main #####
69 my $arg_status= parse_options();
70 testresult($arg_status);
71 exit(0);
73 #### subroutines ####
75 sub testresult
77 my $status = shift;
78 # get master and child workspace
79 my $masterws = $opt_master ? uc($opt_master) : $ENV{WORK_STAMP};
80 my $milestone = $opt_milestone ? $opt_milestone : $ENV{UPDMINOR};
81 my $childws = $opt_milestone ? undef : ( $opt_child ? $opt_child : $ENV{CWS_WORK_STAMP} );
83 if ( !defined($masterws) ) {
84 print_error("Can't determine master workspace environment.\n"
85 . "Please initialize environment with setsolar ...", 1);
88 if ( !defined($childws) && !defined($milestone) ) {
89 print_error("Can't determine child workspace environment or milestone.\n"
90 . "Please initialize environment with setsolar ...", 1);
92 if ( !defined($opt_resultPage) ) {
93 $opt_resultPage="";
95 my $cws = Cws->new();
96 if ( defined($childws) ) {
97 $cws->child($childws);
99 $cws->master($masterws);
100 my $eis = $cws->eis();
102 no strict;
103 my $result='';
105 if ( defined($childws) ) {
106 $opt_resultPage=SOAP::Data->type(string => $opt_resultPage);
107 my $id = $cws->eis_id();
108 if ( is_valid_cws($cws) ) {
109 $result=$eis->submitTestResult($id,$opt_testrunName,$opt_testrunPlatform, $opt_resultPage, $status);
110 } else {
111 print STDERR "cws is not valid";
113 } else {
114 $opt_resultPage=SOAP::Data->type(string => $opt_resultPage);
115 $result=$eis->submitTestResultMWS($masterws,$milestone,$opt_testrunName,$opt_testrunPlatform, $opt_resultPage, $status);
118 exit(0)
122 sub is_valid_cws
124 my $cws = shift;
126 my $masterws = $cws->master();
127 my $childws = $cws->child();
128 # check if we got a valid child workspace
129 my $id = $cws->eis_id();
130 if ( !$id ) {
131 print_error("Child workspace '$childws' for master workspace '$masterws' not found in EIS database.", 2);
133 return 1;
136 sub parse_options
138 # parse options and do some sanity checks
139 Getopt::Long::Configure("no_ignore_case");
140 my $help = 0;
141 my $success = GetOptions('h' => \$help, 'M=s' => \$opt_master, 'm=s' => \$opt_milestone, 'c=s' => \$opt_child, 'n=s' => \$opt_testrunName, 'p=s' => \$opt_testrunPlatform , 'r=s' => \$opt_resultPage );
142 if ( $help || !$success || $#ARGV < 0 || (!defined($opt_testrunName)) || ( !defined($opt_testrunPlatform)) ) {
143 usage();
144 exit(1);
146 if ( defined($opt_milestone) && defined($opt_child) ) {
147 print_error("-m and -c are mutually exclusive options",1);
150 return $ARGV[0];
153 sub print_message
155 my $message = shift;
157 print STDERR "$script_name: ";
158 print STDERR "$message\n";
159 return;
162 sub print_error
164 my $message = shift;
165 my $error_code = shift;
167 print STDERR "$script_name: ";
168 print STDERR "ERROR: $message\n";
170 if ( $error_code ) {
171 print STDERR "\nFAILURE: $script_name aborted.\n";
172 exit($error_code);
174 return;
177 sub usage
179 print STDERR "Usage: cwstestresult[-h] [-m masterws] [-m milestone|-c childws] <-n testrunName> <-p testrunPlatform> <-r resultPage> statusName\n";
180 print STDERR "\n";
181 print STDERR "Publish result of CWS- or milestone-test to EIS\n";
182 print STDERR "\n";
183 print STDERR "Options:\n";
184 print STDERR "\t-h\t\t\thelp\n";
185 print STDERR "\t-M master\t\toverride MWS specified in environment\n";
186 print STDERR "\t-m milestone\t\toverride milestone specified in environment\n";
187 print STDERR "\t-c child\t\toverride CWS specified in environment\n";
188 print STDERR "\t-n testrunName\t\tspecifiy name of the test\n";
189 print STDERR "\t-p testrunPlatform\tspecify platform where the test ran on\n";
190 print STDERR "\t-r resultPage\t\tspecify name of attachment or hyperlink\n";
191 print STDERR "\t\t\t\tfor resultPage\n";
194 print STDERR "\nExample:\n";
195 print STDERR "\tcwstestresult -c mycws -n Performance -p Windows -r PerfomanceTestWindows.html ok\n";