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