common/sysdefdowngrade/sysdefdowngrade.pl
changeset 319 257557b39754
equal deleted inserted replaced
260:13596dc42a47 319:257557b39754
       
     1 # Copyright (c) 2009 Symbian Foundation Ltd
       
     2 # This component and the accompanying materials are made available
       
     3 # under the terms of the License "Eclipse Public License v1.0"
       
     4 # which accompanies this distribution, and is available
       
     5 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 #
       
     7 # Initial Contributors:
       
     8 # Symbian Foundation Ltd - initial contribution.
       
     9 #
       
    10 # Contributors:
       
    11 #
       
    12 # Description:
       
    13 # Extracts output text in <buildlog> context which doesn't belong to <recipe>'s
       
    14 
       
    15 use strict;
       
    16 use Getopt::Long;
       
    17 
       
    18 my $XALAN_PATH = "xalan-j_2_7_1";
       
    19 my $XSLT_FILE = "sysdefdowngrade.xsl";
       
    20 
       
    21 my $modelfile = '';
       
    22 my $csvsourcesfile = '';
       
    23 my $help = 0;
       
    24 GetOptions((
       
    25 	'model=s' => \$modelfile,
       
    26 	'sources=s' => \$csvsourcesfile,
       
    27 	'help!' => \$help
       
    28 ));
       
    29 
       
    30 $help = 1 if (!$modelfile or !$csvsourcesfile);
       
    31 
       
    32 if ($help)
       
    33 {
       
    34 	print "Checks that a model file is not in version 3.0.0. If it is transforms it to a version usable by Raptor\n";
       
    35 	print "Usage: perl sysdefdowngrade.pl --model=MODELFILE --sources=SOURCESFILE\n\n";
       
    36 	exit(0);
       
    37 }
       
    38 
       
    39 my $isversion3 = 0;
       
    40 open(MODELFILE, "$modelfile") or die("Can't open model file $modelfile");
       
    41 while(<MODELFILE>)
       
    42 {
       
    43 	if ($_ =~ /<SystemDefinition schema="3\.0\.0"/)
       
    44 	{
       
    45 		$isversion3 = 1;
       
    46 		last;
       
    47 	}
       
    48 }
       
    49 close(MODELFILE);
       
    50 
       
    51 if (!$isversion3)
       
    52 {
       
    53 	print "Model file is not version 3.0.0. Nothing to do.";
       
    54 	exit(0);
       
    55 }
       
    56 
       
    57 my $param_path = '';
       
    58 open(SOURCESFILE, "$csvsourcesfile") or die("Can't open sources file $csvsourcesfile");
       
    59 while(<SOURCESFILE>)
       
    60 {
       
    61 	if ($_ =~ m{[^,]*,([\\/]sf[\\/][^,]*),[^,]*,[^,]*,[^,]*})
       
    62 	{
       
    63 		$param_path = $1;
       
    64 		#print "param_path= $param_path\n";
       
    65 		last;
       
    66 	}
       
    67 }
       
    68 close(SOURCESFILE);
       
    69 
       
    70 if (!$param_path)
       
    71 {
       
    72 	print "Error: could not determine path parameter from sources file. Quitting.\n";
       
    73 	exit(0);
       
    74 }
       
    75 
       
    76 $param_path =~ s,\\,/,g;
       
    77 
       
    78 my $transformcmd = "java -jar $XALAN_PATH\\xalan.jar -xsl $XSLT_FILE -in $modelfile -out $modelfile.transformed";
       
    79 $transformcmd .= " -param Path $param_path";
       
    80 
       
    81 print "Executing: $transformcmd\n";
       
    82 system("$transformcmd");
       
    83 
       
    84 # ren doesn't work with forward slashes
       
    85 $modelfile =~ s,/,\\,g;
       
    86 
       
    87 $modelfile =~ m,.*[\\/](.*),;
       
    88 my $modelfile_name = $1;
       
    89 print "Executing: ren $modelfile $modelfile_name.orig\n";
       
    90 system("ren $modelfile $modelfile_name.orig");
       
    91 
       
    92 print "Executing: ren $modelfile.transformed $modelfile_name\n";
       
    93 system("ren $modelfile.transformed $modelfile_name");