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