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