1*cdf0e10cSrcweirpackage graphical_compare; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir#************************************************************************* 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 8*cdf0e10cSrcweir# 9*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 10*cdf0e10cSrcweir# 11*cdf0e10cSrcweir# This file is part of OpenOffice.org. 12*cdf0e10cSrcweir# 13*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 14*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 15*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 16*cdf0e10cSrcweir# 17*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 18*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 19*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 21*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 22*cdf0e10cSrcweir# 23*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 24*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 25*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 26*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 27*cdf0e10cSrcweir# 28*cdf0e10cSrcweir#************************************************************************* 29*cdf0e10cSrcweir 30*cdf0e10cSrcweiruse CallExternals; 31*cdf0e10cSrcweiruse stringhelper; 32*cdf0e10cSrcweiruse timehelper; 33*cdf0e10cSrcweiruse filehelper; 34*cdf0e10cSrcweiruse loghelper; 35*cdf0e10cSrcweiruse oshelper; 36*cdf0e10cSrcweiruse cwstestresulthelper; 37*cdf0e10cSrcweiruse solarenvhelper; 38*cdf0e10cSrcweiruse ConvwatchHelper; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweiruse strict; 41*cdf0e10cSrcweiruse Cwd; 42*cdf0e10cSrcweir# use File::Basename; 43*cdf0e10cSrcweiruse Getopt::Long; 44*cdf0e10cSrcweiruse English; # $OSNAME, ... 45*cdf0e10cSrcweiruse File::Path; 46*cdf0e10cSrcweiruse Cwd 'chdir'; 47*cdf0e10cSrcweiruse Sys::Hostname; 48*cdf0e10cSrcweiruse Time::localtime; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir# my $cwd = getcwd(); 51*cdf0e10cSrcweir 52*cdf0e10cSrcweirBEGIN { 53*cdf0e10cSrcweir use Exporter (); 54*cdf0e10cSrcweir our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir $VERSION = 1.00; 57*cdf0e10cSrcweir # if using RCS/CVS, this may be preferred 58*cdf0e10cSrcweir $VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker 59*cdf0e10cSrcweir @ISA = qw(Exporter); 60*cdf0e10cSrcweir @EXPORT = qw(&SingleDocumentCompare &setPrefix &setConnectionString); 61*cdf0e10cSrcweir %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], 62*cdf0e10cSrcweir # your exported package globals go here, 63*cdf0e10cSrcweir # as well as any optionally exported functions 64*cdf0e10cSrcweir @EXPORT_OK = ( ); # qw($Var1 %Hashit &func3); 65*cdf0e10cSrcweir} 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweirour $nTimeOut = 300 * 1000; 69*cdf0e10cSrcweirour $viewable = 1; 70*cdf0e10cSrcweirour $port; 71*cdf0e10cSrcweirour $resolution; 72*cdf0e10cSrcweirour $overwritereference; 73*cdf0e10cSrcweirour $fixreference; 74*cdf0e10cSrcweirour $sConncectionString; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweirsub setConnectionString($) 77*cdf0e10cSrcweir{ 78*cdf0e10cSrcweir $sConncectionString=shift; 79*cdf0e10cSrcweir} 80*cdf0e10cSrcweir 81*cdf0e10cSrcweirsub getOOoRunnerClasspath() 82*cdf0e10cSrcweir{ 83*cdf0e10cSrcweir my $sSourceRoot; 84*cdf0e10cSrcweir my $sUPDExtensions = ""; 85*cdf0e10cSrcweir if (defined ($ENV{SOL_TMP}) && defined ($ENV{SOLARVERSION})) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir $sSourceRoot = $ENV{SOLARVERSION}; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir elsif (defined $ENV{SOURCE_ROOT}) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir $sSourceRoot = $ENV{SOURCE_ROOT}; 92*cdf0e10cSrcweir $sSourceRoot = appendPath($sSourceRoot, $ENV{WORK_STAMP}); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir else 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir $sSourceRoot = $ENV{SOLARVERSION}; 97*cdf0e10cSrcweir $sUPDExtensions = ".$ENV{UPDMINOR}"; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir $sSourceRoot = appendPath($sSourceRoot, $ENV{INPATH}); 100*cdf0e10cSrcweir my $sSourceRootBin = appendPath($sSourceRoot, "bin" . $sUPDExtensions); 101*cdf0e10cSrcweir my $sSourceRootLib = appendPath($sSourceRoot, "lib" . $sUPDExtensions); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir if (! -d $sSourceRoot ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir log_print( "SourceRoot not found, search it in '$sSourceRoot'\n"); 106*cdf0e10cSrcweir return ""; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir my $sOOoRunnerPath = $sSourceRootBin; 110*cdf0e10cSrcweir my $sUnoilPath = $sSourceRootBin; 111*cdf0e10cSrcweir my $sRidlPath = $sSourceRootBin; 112*cdf0e10cSrcweir my $sJurtPath = $sSourceRootBin; 113*cdf0e10cSrcweir my $sJuhPath = $sSourceRootBin; 114*cdf0e10cSrcweir my $sJavaUnoPath = $sSourceRootBin; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir my $sOOoRunnerClasspath = 117*cdf0e10cSrcweir appendPath( $sRidlPath, "ridl.jar") . getJavaPathSeparator() . 118*cdf0e10cSrcweir appendPath( $sUnoilPath, "unoil.jar") . getJavaPathSeparator() . 119*cdf0e10cSrcweir appendPath( $sJurtPath, "jurt.jar") . getJavaPathSeparator() . 120*cdf0e10cSrcweir appendPath( $sJuhPath, "juh.jar") . getJavaPathSeparator() . 121*cdf0e10cSrcweir appendPath( $sJavaUnoPath, "java_uno.jar") . getJavaPathSeparator() . 122*cdf0e10cSrcweir appendPath( $sOOoRunnerPath, "OOoRunnerLight.jar"); 123*cdf0e10cSrcweir if (isWindowsEnvironment()) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir $sOOoRunnerClasspath .= getJavaPathSeparator() . $sSourceRootBin; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir else 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir $sOOoRunnerClasspath .= getJavaPathSeparator() . $sSourceRootLib; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir return $sOOoRunnerClasspath; 132*cdf0e10cSrcweir} 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 135*cdf0e10cSrcweirsub getTempPath() 136*cdf0e10cSrcweir{ 137*cdf0e10cSrcweir my $sTempPath; 138*cdf0e10cSrcweir if (isWindowsEnvironment()) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir $sTempPath = "C:/temp"; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir elsif (isUnixEnvironment()) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir $sTempPath = "/tmp"; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir else 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir die "getTempPath() Failed, due to unsupported environment.\n"; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir return $sTempPath; 151*cdf0e10cSrcweir} 152*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 153*cdf0e10cSrcweir 154*cdf0e10cSrcweirsub getProjectOutput() 155*cdf0e10cSrcweir{ 156*cdf0e10cSrcweir my $sOutput = appendPath(getProjectRoot(), $ENV{INPATH}); 157*cdf0e10cSrcweir $sOutput = appendPath($sOutput, "misc"); 158*cdf0e10cSrcweir return $sOutput; 159*cdf0e10cSrcweir} 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 162*cdf0e10cSrcweirsub getProjectOutputReference() 163*cdf0e10cSrcweir{ 164*cdf0e10cSrcweir my $sOutput = appendPath(getProjectRoot(), $ENV{INPATH}); 165*cdf0e10cSrcweir $sOutput = appendPath($sOutput, "reference"); 166*cdf0e10cSrcweir return $sOutput; 167*cdf0e10cSrcweir} 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir 170*cdf0e10cSrcweirsub searchForReference($) 171*cdf0e10cSrcweir{ 172*cdf0e10cSrcweir my $sFile = shift; 173*cdf0e10cSrcweir if ( -e $sFile ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir return 0; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir if ( -e $sFile . ".ps") 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir return 0; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir if ( -e $sFile . ".pdf") 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir return 0; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir return 1; 186*cdf0e10cSrcweir} 187*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir# my $sOfficeName = $officeprefixname . $officename; 190*cdf0e10cSrcweirsub SingleDocumentCompare($$$$$$) 191*cdf0e10cSrcweir{ 192*cdf0e10cSrcweir # get all about the document to compare 193*cdf0e10cSrcweir my $sDocumentPoolPath = shift; 194*cdf0e10cSrcweir my $sDocumentPool = shift; 195*cdf0e10cSrcweir my $sDocumentName = shift; 196*cdf0e10cSrcweir my $sDebug = ""; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir # get all about the destination office 199*cdf0e10cSrcweir my $sCreatorType = shift; 200*cdf0e10cSrcweir if (! $sCreatorType) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir # log_print( "parameter -creatortype not given. Use 'OOo'\n"); 203*cdf0e10cSrcweir $sCreatorType = "ps"; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir my $prepareonly = shift; 206*cdf0e10cSrcweir my $show = shift; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir # my $nSimpleCompareTime = getTime(); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir my $nConvwatchFailed = 0; 211*cdf0e10cSrcweir set_logfile( appendPath(getProjectOutput(), $sDocumentName . ".txt" )); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir print("$sDocumentName"); 214*cdf0e10cSrcweir log_print("\n"); 215*cdf0e10cSrcweir log_print("Graphical compare on document: '$sDocumentName'\n"); 216*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 217*cdf0e10cSrcweir # create postscript or pdf from first installed office 218*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir my $sOOoRunnerClasspath = quoteIfNeed(getOOoRunnerClasspath()); 221*cdf0e10cSrcweir if ($OSNAME eq "cygwin") 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir if (!startswith($sOOoRunnerClasspath, "\"")) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir $sOOoRunnerClasspath = quote($sOOoRunnerClasspath); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir if (length($sOOoRunnerClasspath) == 0) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir $nConvwatchFailed == 1; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 233*cdf0e10cSrcweir # create postscript or pdf from second installed office 234*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir my $sPathesIni = appendPath(getProjectOutput(), "pathes.ini"); 237*cdf0e10cSrcweir my $gspath = getFromPathes($sPathesIni, "gs.path"); 238*cdf0e10cSrcweir my $gsexe = getFromPathes($sPathesIni, "gs.exe"); 239*cdf0e10cSrcweir my $impath = getFromPathes($sPathesIni, "imagemagick.path"); 240*cdf0e10cSrcweir my $javaexe = getFromPathes($sPathesIni, "java.exe"); 241*cdf0e10cSrcweir setJavaExecutable($javaexe); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir log_print("----- CREATE POSTSCRIPT OR PDF WITH RUNNING OFFICE -----\n"); 244*cdf0e10cSrcweir # my $nPrepareSecondPostscriptTime = getTime(); 245*cdf0e10cSrcweir if ($nConvwatchFailed == 0) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir my $sInputPath = $sDocumentPoolPath; 248*cdf0e10cSrcweir $sInputPath = appendPath($sInputPath, $sDocumentPool); 249*cdf0e10cSrcweir $sInputPath = appendPath($sInputPath, $sDocumentName); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir if (! -f $sInputPath ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir $nConvwatchFailed = 1; 254*cdf0e10cSrcweir log_print("ERROR: File '$sInputPath' doesn't exists.\n"); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir else 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir my $sOutputPath = getProjectOutput(); 259*cdf0e10cSrcweir my $sPropertyFile = appendPath(getProjectOutput() , $sDocumentName . ".build.props"); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir local *PROPERTYFILE; 262*cdf0e10cSrcweir if (open(PROPERTYFILE, ">$sPropertyFile")) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir print PROPERTYFILE "# This file is automatically created by graphical_compare.pl\n"; 265*cdf0e10cSrcweir print PROPERTYFILE "DOC_COMPARATOR_PRINT_MAX_PAGE=9999\n"; 266*cdf0e10cSrcweir print PROPERTYFILE "DOC_COMPARATOR_GFX_OUTPUT_DPI_RESOLUTION=180\n"; 267*cdf0e10cSrcweir print PROPERTYFILE "DOC_COMPARATOR_REFERENCE_CREATOR_TYPE=$sCreatorType\n"; 268*cdf0e10cSrcweir print PROPERTYFILE "TEMPPATH=" . getTempPath() . "\n"; 269*cdf0e10cSrcweir if ($sConncectionString) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir print PROPERTYFILE "ConnectionString=$sConncectionString\n"; 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir else 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir print PROPERTYFILE "ConnectionString=pipe,name=" . getUsername() . "\n"; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir print PROPERTYFILE "OFFICE_VIEWABLE=true\n"; 278*cdf0e10cSrcweir print PROPERTYFILE "CREATE_DEFAULT_REFERENCE=true\n"; 279*cdf0e10cSrcweir print PROPERTYFILE "DOC_COMPARATOR_INPUT_PATH=$sInputPath\n"; 280*cdf0e10cSrcweir print PROPERTYFILE "DOC_COMPARATOR_OUTPUT_PATH=$sOutputPath\n"; 281*cdf0e10cSrcweir if (isWindowsEnvironment()) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir print PROPERTYFILE "DOC_COMPARATOR_PRINTER_NAME=CrossOffice Generic Printer\n"; 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir print PROPERTYFILE "NoOffice=true\n"; 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir close(PROPERTYFILE); 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir else 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir print "Can't open '$sPropertyFile' for write.\n"; 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir if ( -e "$sPropertyFile") 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir # start OOoRunner 296*cdf0e10cSrcweir # sleep 10; 297*cdf0e10cSrcweir # $sOOoRunnerClasspathFromDestinationName = quoteIfNeed(getOOoRunnerClasspath()); 298*cdf0e10cSrcweir my $sParams; 299*cdf0e10cSrcweir if ( $ENV{PERL} ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir $sParams = "-Dperl.exe=" . convertCygwinPath($ENV{PERL}); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir $sParams .= " -cp " . $sOOoRunnerClasspath . 305*cdf0e10cSrcweir " org.openoffice.Runner" . 306*cdf0e10cSrcweir " -TimeOut $nTimeOut" . 307*cdf0e10cSrcweir " -tb java_complex" . 308*cdf0e10cSrcweir " -ini $sPropertyFile" . 309*cdf0e10cSrcweir " -o graphical.PostscriptCreator"; 310*cdf0e10cSrcweir # $sParams .= " -cs pipe,name=$USER"; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y"; 313*cdf0e10cSrcweir my $err = calljava(getJavaExecutable(), $sParams, $sDebug); 314*cdf0e10cSrcweir $sDebug = ""; 315*cdf0e10cSrcweir log_print( "\n\n"); 316*cdf0e10cSrcweir if ($err != 0) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir my $sFailure = "Failed after try to create Postscript/pdf document for " . $sDocumentName; 319*cdf0e10cSrcweir log_print("ERROR: $sFailure\n"); 320*cdf0e10cSrcweir $nConvwatchFailed = 1; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir else 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir my $sFailure = "There is no propertyfile: $sPropertyFile"; 326*cdf0e10cSrcweir log_print( "ERROR: $sFailure\n"); 327*cdf0e10cSrcweir $nConvwatchFailed=1; 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir # set prepareonly and it is possible to only create ps or pdf files 332*cdf0e10cSrcweir if ($prepareonly) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir print(" [only create "); 335*cdf0e10cSrcweir if ($sCreatorType eq "ps" || $sCreatorType eq "pdf") 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir print(" $sCreatorType"); 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir else 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir print(" (${sCreatorType}?)"); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir if ($nConvwatchFailed == 0) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir print(" ok"); 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir else 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir print(" failed") 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir print("]\n"); 352*cdf0e10cSrcweir return $nConvwatchFailed; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 357*cdf0e10cSrcweir # create jpeg from postscript or pdf from second installed office 358*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir if ($nConvwatchFailed == 0) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir log_print("----- CREATE JPEG FROM POSTSCRIPT OR PDF FROM RUNNING OFFICE -----\n"); 363*cdf0e10cSrcweir # start OOoRunner 364*cdf0e10cSrcweir my $sInputPath = getProjectOutput(); 365*cdf0e10cSrcweir $sInputPath = appendPath($sInputPath, $sDocumentName); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir my $sOutputPath = getProjectOutput(); 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir my $sParams = "-cp " . $sOOoRunnerClasspath . 370*cdf0e10cSrcweir " org.openoffice.Runner" . 371*cdf0e10cSrcweir " -TimeOut $nTimeOut" . 372*cdf0e10cSrcweir " -tb java_complex" . 373*cdf0e10cSrcweir " -DOC_COMPARATOR_INPUT_PATH " . quoteIfNeed($sInputPath) . 374*cdf0e10cSrcweir " -DOC_COMPARATOR_OUTPUT_PATH " . quoteIfNeed($sOutputPath) . 375*cdf0e10cSrcweir " -DOC_COMPARATOR_REFERENCE_CREATOR_TYPE $sCreatorType" . 376*cdf0e10cSrcweir " -NoOffice" . 377*cdf0e10cSrcweir " -NoSmallPictures" . 378*cdf0e10cSrcweir " -o graphical.JPEGCreator"; 379*cdf0e10cSrcweir if ($gspath) 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir $sParams .= " -gs.path " . quoteIfNeed($gspath); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir if ($gsexe) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir $sParams .= " -gs.exe $gsexe"; 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y"; 389*cdf0e10cSrcweir my $err = calljava(getJavaExecutable(), $sParams, $sDebug); 390*cdf0e10cSrcweir $sDebug = ""; 391*cdf0e10cSrcweir # log_print( "\n\n"); 392*cdf0e10cSrcweir if ($err != 0) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir my $sFailure = "Failed after try to create JPEG from Postscript/pdf document for " . $sDocumentName; 395*cdf0e10cSrcweir log_print("ERROR: $sFailure\n"); 396*cdf0e10cSrcweir $nConvwatchFailed = 1; 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 402*cdf0e10cSrcweir # create jpeg from postscript or pdf from references 403*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir if ($nConvwatchFailed == 0) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir log_print("----- CREATE JPEG FROM POSTSCRIPT OR PDF FROM REFERENCE -----\n"); 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir # start OOoRunner 410*cdf0e10cSrcweir my $sInputPath = appendPath(getProjectRoot(), "references"); 411*cdf0e10cSrcweir $sInputPath = appendPath($sInputPath, getEnvironment()); 412*cdf0e10cSrcweir $sInputPath = appendPath($sInputPath, $sDocumentPool); 413*cdf0e10cSrcweir $sInputPath = appendPath($sInputPath, $sDocumentName); 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir my $err = searchForReference($sInputPath); 416*cdf0e10cSrcweir if ($err != 0) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir log_print("ERROR: Can't find Postscript or PDF reference for '$sInputPath'\n"); 419*cdf0e10cSrcweir $nConvwatchFailed = 1; 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir else 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir my $sOutputPath = getProjectOutputReference(); 424*cdf0e10cSrcweir rmkdir $sOutputPath; 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir my $sIndexFile = appendPath($sOutputPath, "index.ini"); 427*cdf0e10cSrcweir # we need the index.ini for better run through 428*cdf0e10cSrcweir local *INDEXINI; 429*cdf0e10cSrcweir if ( ! -e $sIndexFile) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir if (open(INDEXINI, ">$sIndexFile")) 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir # print INDEXINI "[$sDocumentName]\n"; 434*cdf0e10cSrcweir close(INDEXINI); 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir my $sParams = "-cp " . $sOOoRunnerClasspath . 438*cdf0e10cSrcweir " org.openoffice.Runner" . 439*cdf0e10cSrcweir " -TimeOut $nTimeOut" . 440*cdf0e10cSrcweir " -tb java_complex" . 441*cdf0e10cSrcweir " -DOC_COMPARATOR_INPUT_PATH " . quoteIfNeed($sInputPath) . 442*cdf0e10cSrcweir " -DOC_COMPARATOR_OUTPUT_PATH " . quoteIfNeed($sOutputPath) . 443*cdf0e10cSrcweir " -DOC_COMPARATOR_REFERENCE_CREATOR_TYPE $sCreatorType" . 444*cdf0e10cSrcweir " -NoOffice" . 445*cdf0e10cSrcweir " -NoSmallPictures" . 446*cdf0e10cSrcweir " -o graphical.JPEGCreator"; 447*cdf0e10cSrcweir if ($gspath) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir $sParams .= " -gs.path " . quoteIfNeed($gspath); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir if ($gsexe) 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir $sParams .= " -gs.exe $gsexe"; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y"; 457*cdf0e10cSrcweir my $err = calljava(getJavaExecutable(), $sParams, $sDebug); 458*cdf0e10cSrcweir $sDebug = ""; 459*cdf0e10cSrcweir # log_print( "\n\n"); 460*cdf0e10cSrcweir if ($err != 0) 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir my $sFailure = "Failed after try to create JPEG from Postscript/pdf document for references."; 463*cdf0e10cSrcweir log_print("ERROR: $sFailure\n"); 464*cdf0e10cSrcweir $nConvwatchFailed = 1; 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 469*cdf0e10cSrcweir # compare JPEGs 470*cdf0e10cSrcweir # ------------------------------------------------------------------------------ 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir if ($nConvwatchFailed == 0) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir log_print("----- COMPARE JPEGS -----\n"); 475*cdf0e10cSrcweir my $sInputPath = appendPath(getProjectOutputReference(), $sDocumentName); 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir my $sOutputPath = getProjectOutput(); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir my $sParams = "-Xmx512m" . 480*cdf0e10cSrcweir " -cp " . $sOOoRunnerClasspath . 481*cdf0e10cSrcweir " org.openoffice.Runner" . 482*cdf0e10cSrcweir " -TimeOut $nTimeOut" . 483*cdf0e10cSrcweir " -tb java_complex" . 484*cdf0e10cSrcweir " -DOC_COMPARATOR_INPUT_PATH " . quoteIfNeed($sInputPath) . 485*cdf0e10cSrcweir " -DOC_COMPARATOR_OUTPUT_PATH " . quoteIfNeed($sOutputPath) . 486*cdf0e10cSrcweir " -NoOffice" . 487*cdf0e10cSrcweir " -NoSmallPictures" . 488*cdf0e10cSrcweir " -o graphical.JPEGComparator"; 489*cdf0e10cSrcweir if ($impath) 490*cdf0e10cSrcweir { 491*cdf0e10cSrcweir $sParams .= " -imagemagick.path " . quoteIfNeed($impath); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir # start OOoRunner 495*cdf0e10cSrcweir # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y"; 496*cdf0e10cSrcweir my $err = calljava(getJavaExecutable(), $sParams, $sDebug); 497*cdf0e10cSrcweir $sDebug = ""; 498*cdf0e10cSrcweir log_print( "\n\n"); 499*cdf0e10cSrcweir if ($err != 0) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir my $sFailure = "Failed after compare JPEGs $sDocumentName\n"; 502*cdf0e10cSrcweir log_print("ERROR: $sFailure\n"); 503*cdf0e10cSrcweir $nConvwatchFailed = 1; 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir if ($show) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir # try to execute new java tool to show graphical compare 508*cdf0e10cSrcweir my $sJavaProgram = appendPath(getProjectRoot(), $ENV{INPATH}); 509*cdf0e10cSrcweir $sJavaProgram = appendPath($sJavaProgram, "class"); 510*cdf0e10cSrcweir $sJavaProgram = appendPath($sJavaProgram, "ConvwatchGUIProject.jar"); 511*cdf0e10cSrcweir if ( -e "$sJavaProgram") 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir my $sInputPath = appendPath(getProjectOutput(), $sDocumentName . ".ps.ini"); 514*cdf0e10cSrcweir if (! -e $sInputPath) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir $sInputPath = appendPath(getProjectOutput(), $sDocumentName . ".pdf.ini"); 517*cdf0e10cSrcweir if (! -e $sInputPath) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir $sInputPath = 0; 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir if ($sInputPath) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir my $sParams = "-Xms128m -Xmx512m -jar $sJavaProgram $sInputPath"; 525*cdf0e10cSrcweir # $sParams .= " -cs pipe,name=$USER"; 526*cdf0e10cSrcweir # my $sJavaExe = "C:/Program Files/Java/jdk1.6.0_16/bin/java.exe"; # getJavaExecutable() 527*cdf0e10cSrcweir my $sJavaExe = getJavaExecutable(); 528*cdf0e10cSrcweir # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y"; 529*cdf0e10cSrcweir my $err = calljava($sJavaExe, $sParams, $sDebug); 530*cdf0e10cSrcweir # $sDebug = ""; 531*cdf0e10cSrcweir # log_print( "\n\n"); 532*cdf0e10cSrcweir # if ($err != 0) 533*cdf0e10cSrcweir # { 534*cdf0e10cSrcweir # my $sFailure = "Failed after try to create Postscript/pdf document for " . $sDocumentName; 535*cdf0e10cSrcweir # log_print("ERROR: $sFailure\n"); 536*cdf0e10cSrcweir # $nConvwatchFailed = 1; 537*cdf0e10cSrcweir # } 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir else 541*cdf0e10cSrcweir { 542*cdf0e10cSrcweir print "WARNING: The show program '$sJavaProgram' doesn't exists.\n"; 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir } 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir log_print( "\n\n"); 549*cdf0e10cSrcweir close_logfile(); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir if ($nConvwatchFailed == 0) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir print(" [ok]\n"); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir else 556*cdf0e10cSrcweir { 557*cdf0e10cSrcweir print(" [FAILED]\n"); 558*cdf0e10cSrcweir print("\nPrint output of test: $sDocumentName\n"); 559*cdf0e10cSrcweir my $sLogFile = appendPath(getProjectOutput(), $sDocumentName . ".txt"); 560*cdf0e10cSrcweir showFile($sLogFile); 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir # printTime(endTime($nSimpleCompareTime)); 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir return $nConvwatchFailed; 565*cdf0e10cSrcweir} 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 568*cdf0e10cSrcweir# cat $file 569*cdf0e10cSrcweirsub showFile($) 570*cdf0e10cSrcweir{ 571*cdf0e10cSrcweir my $logfile = shift; 572*cdf0e10cSrcweir local *LOGFILE; 573*cdf0e10cSrcweir if (open(LOGFILE, "$logfile")) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir my $line; 576*cdf0e10cSrcweir while ($line = <LOGFILE>) 577*cdf0e10cSrcweir { 578*cdf0e10cSrcweir chomp($line); 579*cdf0e10cSrcweir print $line ."\n"; 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir close(LOGFILE); 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir} 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir1; 587