1package cwstestresulthelper;
2
3#*************************************************************************
4#
5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6#
7# Copyright 2000, 2010 Oracle and/or its affiliates.
8#
9# OpenOffice.org - a multi-platform office productivity suite
10#
11# This file is part of OpenOffice.org.
12#
13# OpenOffice.org is free software: you can redistribute it and/or modify
14# it under the terms of the GNU Lesser General Public License version 3
15# only, as published by the Free Software Foundation.
16#
17# OpenOffice.org is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20# GNU Lesser General Public License version 3 for more details
21# (a copy is included in the LICENSE file that accompanied this code).
22#
23# You should have received a copy of the GNU Lesser General Public License
24# version 3 along with OpenOffice.org.  If not, see
25# <http://www.openoffice.org/license.html>
26# for a copy of the LGPLv3 License.
27#
28#*************************************************************************
29
30use English;
31use warnings;
32use strict;
33use Cwd;
34use Cwd 'chdir';
35
36use stringhelper;
37use loghelper;
38use oshelper;
39use filehelper;
40use CallExternals;
41
42BEGIN {
43    use Exporter   ();
44    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
45
46    $VERSION     = 1.00;
47    # if using RCS/CVS, this may be preferred
48    $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
49    @ISA         = qw(Exporter);
50    @EXPORT      = qw(&cwstestresult);
51    %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
52    # your exported package globals go here,
53    # as well as any optionally exported functions
54    @EXPORT_OK   = ( ); # qw($Var1 %Hashit &func3);
55}
56
57sub cwstestresult($$$$$$)
58{
59    my $sStatus = shift;
60    my $sDBdistinct = shift;
61    my $sourceversion = shift;
62    my $destinationversion = shift;
63
64    my $sSOLARENV; # = getSolenvPath();
65    my $nSOLARENV_fake = 0;
66    my $sCOMMON_ENV_TOOLS;
67    my $nCOMMON_ENV_TOOLS_fake = 0;
68
69    my $MAJOR;
70    my $MINOR;
71    # we need an extra state in DB
72    # if this state is given here, we need to add information in cws back.
73    if ( ! $sSOLARENV)
74    {
75        my @MAJORMINOR=split('_', $sourceversion);
76        if ($#MAJORMINOR < 1)
77        {
78            print "Failure with sourceversion '$sourceversion' not splitable.\n";
79            return;
80        }
81        $MAJOR=$MAJORMINOR[0]; # DEV300, OOH310, ...
82        $MINOR=$MAJORMINOR[1]; # m45, ...
83        if (getEnvironment() eq "wntmsci")
84        {
85            $sSOLARENV="o:/$MAJOR/ooo.$MINOR/solenv";
86            if (! -e $sSOLARENV)
87            {
88                # fallback to old before ause103 (treeconfig)
89                $sSOLARENV="o:/$MAJOR/src.$MINOR/solenv";
90            }
91        }
92        elsif (getEnvironment() eq "unxlngi" ||
93               getEnvironment() eq "unxsoli")
94        {
95            $sSOLARENV="/so/ws/$MAJOR/ooo.$MINOR/solenv";
96            # automount
97            system("ls -al $sSOLARENV >/dev/null");
98            sleep(1);
99            if (! -e $sSOLARENV)
100            {
101                # fallback to old before ause103 (treeconfig)
102                $sSOLARENV="/so/ws/$MAJOR/src.$MINOR/solenv";
103            }
104        }
105        else
106        {
107            log_print("cwstestresult(): This environment is not supported.");
108            return;
109        }
110    }
111    if ( !defined($ENV{SOLARENV}) || length($ENV{SOLARENV}) == 0 )
112    {
113        $ENV{SOLARENV} = $sSOLARENV;
114        log_print("        SOLARENV is: $ENV{SOLARENV} faked\n");
115        $nSOLARENV_fake = 1;
116    }
117    if ( ! $sCOMMON_ENV_TOOLS)
118    {
119        if (isWindowsEnvironment())
120        {
121            $sCOMMON_ENV_TOOLS="r:/etools";
122        }
123        elsif (isUnixEnvironment() )
124        {
125            $sCOMMON_ENV_TOOLS="/so/env/etools";
126            # automount
127            system("ls -al $sCOMMON_ENV_TOOLS >/dev/null");
128            sleep(1);
129        }
130        else
131        {
132            log_print("cwstestresult(): This environment is not supported. (variable COMMON_ENV_TOOLS not set.)");
133            return;
134        }
135    }
136    if ( !defined($ENV{COMMON_ENV_TOOLS}) || length($ENV{COMMON_ENV_TOOLS}) == 0 )
137    {
138        $ENV{COMMON_ENV_TOOLS} = $sCOMMON_ENV_TOOLS;
139        log_print( "COMMON_ENV_TOOLS is: $ENV{COMMON_ENV_TOOLS} faked\n");
140        $nCOMMON_ENV_TOOLS_fake = 1;
141    }
142
143    # if ( !defined($ENV{WORK_STAMP}) )
144    # {
145    #     $ENV{WORK_STAMP} = $MAJOR;
146    #     log_print( "      WORK_STAMP is: $ENV{WORK_STAMP} faked\n");
147    # }
148    # if ( !defined($ENV{UPDMINOR}) )
149    # {
150    #     $ENV{UPDMINOR} = $MINOR;
151    #     log_print( "        UPDMINOR is: $ENV{UPDMINOR} faked\n");
152    # }
153
154    my $nWORK_STAMP_fake = 0;
155    my $nUPDMINOR_fake = 0;
156
157    if ( !defined($ENV{WORK_STAMP}) || length($ENV{WORK_STAMP}) == 0 )
158    {
159        $ENV{WORK_STAMP} = $MAJOR;
160        log_print("        WORK_STAMP is: $ENV{WORK_STAMP} faked\n");
161        $nWORK_STAMP_fake = 1;
162    }
163    if ( !defined($ENV{UPDMINOR}) || length($ENV{WORK_STAMP}) == 0 )
164    {
165        $ENV{UPDMINOR} = $MINOR;
166        log_print("        UPDMINOR is: $ENV{UPDMINOR} faked\n");
167        $nUPDMINOR_fake = 1;
168    }
169
170    # my $sStatus = "ok";
171    # if ($nFailure == 0)
172    # {
173    #     $sStatus = $sInfo;
174    # }
175    # elsif ($nFailure == 1)
176    # {
177    #     $sStatus = "failed";
178    # }
179    # elsif ($nFailure == 2)
180    # {
181    #     $sStatus = "incomplete";
182    # }
183
184    # system("cwstestresult -c mycws -n Performance -p Windows ok");
185    my $sPerlProgram = appendPath($sSOLARENV, "bin/cwstestresult.pl");
186    # if ( -e "cwstestresult.pl" )
187    # {
188    #     # use a local version instead
189    #     $sPerlProgram = "cwstestresult.pl";
190    # }
191    # else
192    # {
193    #     my $currentdir =cwd();
194    #     log_print( "We are in $currentdir\n");
195    # }
196
197    my $sPerlParam;
198    # $sPerlParam  = " -m $MAJOR"; # master CWS
199    $sPerlParam .= " -c $destinationversion"; # name of CWS
200    $sPerlParam .= " -n ConvWatch"; # ConvWatch need to be capitalised for cwstestresult
201    my $sCWSEnv;
202    if (isWindowsEnvironment())
203    {
204        $sCWSEnv = "Windows";
205    }
206    elsif (getEnvironment() eq "unxlngi")
207    {
208        $sCWSEnv = "Linux";
209    }
210    elsif (getEnvironment() eq "unxsoli")
211    {
212        $sCWSEnv = "SolarisX86";
213    }
214    else
215    {
216        log_print("cwstestresult(): This environment is not supported. (getEnvironment() returns wrong value?)");
217        return;
218    }
219    $sPerlParam .= " -p " . $sCWSEnv;
220    $sPerlParam .= " -r http://so-gfxcmp-lin.germany.sun.com/gfxcmp_ui/status_new.php?distinct=$sDBdistinct";
221
222    $sPerlParam .= " ";
223    $sPerlParam .= $sStatus;
224
225
226    # my $sSetcwsAndPerl = "setcws $destinationversion; " . getPerlExecutable();
227
228    my $err = callperl(getPerlExecutable(), $sPerlProgram, $sPerlParam);
229    if ($err != 0)
230    {
231        log_print( "Can't call cwstestresult.pl\n");
232    }
233    if ($nSOLARENV_fake == 1)
234    {
235        $ENV{SOLARENV} = "";
236        undef( $ENV{SOLARENV} );
237        $nSOLARENV_fake = 0;
238        # if ( defined($ENV{SOLARENV}) )
239        # {
240        #     print "SOLARENV always defined.\n";
241        # }
242    }
243    if ($nCOMMON_ENV_TOOLS_fake == 1)
244    {
245        $ENV{COMMON_ENV_TOOLS} = "";
246        undef( $ENV{COMMON_ENV_TOOLS} );
247        $nCOMMON_ENV_TOOLS_fake = 0;
248    }
249
250    if ( $nWORK_STAMP_fake == 1 )
251    {
252        # undef($ENV{WORK_STAMP});
253        $ENV{WORK_STAMP} = "";
254        undef($ENV{WORK_STAMP});
255        $nWORK_STAMP_fake = 0;
256    }
257    if ( $nUPDMINOR_fake == 1 )
258    {
259        $ENV{UPDMINOR} = "";
260        undef($ENV{UPDMINOR});
261        $nUPDMINOR_fake = 0;
262    }
263
264
265}
266
267
2681;
269