metatools/sysdeftools/rootsysdef.pl
author Bob Rosenberg <bob.rosenberg@nokia.com>
Thu, 12 Aug 2010 15:59:45 +0100
changeset 636 29e6a24e9521
parent 624 f70b728ea30c
child 639 0e65f93be3cb
permissions -rw-r--r--
More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     1
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     2
# All rights reserved.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     3
# This component and the accompanying materials are made available
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     5
# which accompanies this distribution, and is available
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     7
#
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     8
# Initial Contributors:
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    10
#
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    11
# Contributors:
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    12
#
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    13
# Description:
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    14
#  This will create a new root system definition file based on the provided template
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    15
#!/usr/bin/perl
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    16
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    17
use strict;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    18
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    19
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    20
use FindBin;		# for FindBin::Bin
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    21
use lib $FindBin::Bin;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    22
use lib "$FindBin::Bin/lib";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    23
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    24
use Cwd;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    25
use Cwd 'abs_path';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    26
use Getopt::Long;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    27
use File::Basename;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    28
use File::Spec;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    29
use XML::DOM;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    30
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    31
my $output;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    32
my $path;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    33
my $defaultns = 'http://www.symbian.org/system-definition';	# needed if no DTD
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    34
my @searchpaths;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    35
my @searchroots;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    36
my %additional;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    37
my %add;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    38
my %newNs;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    39
my $warning = "Error";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    40
my $placeholders=0;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    41
my $sysmodelname;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    42
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    43
my @tdOrder =("hb","se", "lo","dc", "vc" , "pr", "dm", "de", "mm", "ma" , "ui",  "rt", "to" );
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    44
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    45
sub help
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    46
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    47
	my $name= $0; $name=~s,^.*[\\/],,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    48
	print STDERR "usage: $name  [options...] template\n\nThis will create a new root system definition file based on the provided template by globbing for pkgdefs in the filesystem. Any found pkgdef files are added to the end of their layer or at the end of their tech domain section, if one is defined",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    49
	"\nvalid options are:\n",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    50
		"  -path [dir]\tspecifies the full system-model path to the file which is being processed. By default this is  \"/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml\"\n",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    51
		"\t\tThis is only needed when creating a stand-alone sysdef as the output",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    52
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    53
		"  -output [file]\tspecifies the file to save the output to. If set, all hrefs will set to be relative to this location. If not specified all href will be absolute file URIs and this will write to stdout\n\n",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    54
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    55
		"  -w [Note|Warning|Error]\tspecifies prefix text for any notifications. Defautls to Error\n\n",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    56
		"  -root [dir]\tspecifies the root directory of the filesystem. All globbing will be done relative to this path\n\n",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    57
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
    58
		"  -glob [wildcard path]\tThe wildcard search to look for pkgdef files. eg  \"\\*\\*\\package_definition.xml\". Can specify any number of these.\n",
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    59
		"  -placeholders [bool]\tif set, all packages not found in the template will be left in as empty placeholders\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    60
		"  -name [text]\tthe name in <systemModel> to use for the generated root sysdef. If not present, this will use the name from the templat\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    61
	exit(1);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    62
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    63
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    64
GetOptions
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    65
	(
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    66
	 'path=s' => \$path,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    67
	 'name=s' => \$sysmodelname,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    68
	'output=s' => \$output,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    69
	'w=s' => \$warning,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    70
	'root=s' => \@searchroots,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    71
	'glob=s' => \@searchpaths,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    72
	'placeholders=s' => \$placeholders
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    73
	);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    74
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    75
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    76
 if($path eq '') {$path = '/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml'}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    77
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    78
if(!($warning =~/^(Note|Warning|Error)$/)) {$warning="Error"}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    79
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    80
# path is the system model path of the processed sysdef file. This is only used when creating a stand-alone sysdef as the output
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    81
# output specifies the file this is saved in. If specified, all (relative) paths will be modified to be relative to it. If not, all paths will be absolute
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    82
# w is the warning level: Note, Warning or Error.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    83
# root = -root g:\sf
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    84
# glob = -glob "\*\*\package_definition.xml"
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    85
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    86
#Example command lines:
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    87
#rootsysdef.pl -root F:\sftest\mcl\sf  -glob "\*\*\package_definition.xml"  -output  F:\sftest\mcl\build\system_definition.sf.xml   F:\sftest\mcl\sf\os\deviceplatformrelease\foundation_system\system_model\system_definition.xml
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    88
#rootsysdef.pl -root F:\sftest\mcl\sf  -glob "\*\*\*\*\package_definition.xml"  -output  F:\sftest\mcl\build\system_definition.mine.xml   F:\sftest\mcl\sf\os\deviceplatformrelease\foundation_system\system_model\system_definition.xml
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    89
if(!scalar @ARGV && !scalar @searchpaths) {&help()};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    90
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    91
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    92
my %replacefile;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    93
my $dir;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    94
foreach(@searchpaths)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    95
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    96
	my $ndir = shift(@searchroots);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    97
	if($ndir ne '') {$dir=$ndir}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    98
	foreach my $file (glob "$dir$_")
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    99
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   100
		my $map =substr($file,length($dir));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   101
		$map=~tr/\\/\//;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   102
		$additional{$map}=$file;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   103
		$replacefile{&abspath($file)}=$map;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   104
		$add{&abspath($file)}=1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   105
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   106
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   107
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   108
my $parser = new XML::DOM::Parser;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   109
my $sysdef;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   110
my %rootmap;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   111
my  $sysdefdoc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   112
if(scalar @ARGV)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   113
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   114
	$sysdef = &abspath(shift);	# resolve the location of the root sysdef
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   115
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   116
	# rootmap is a mapping from the filesystem to the paths in the doc
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   117
	%rootmap = &rootMap($path,$sysdef);	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   118
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   119
	$sysdefdoc = $parser->parsefile ($sysdef);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   120
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   121
else 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   122
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   123
	$sysdefdoc = $parser->parse('<SystemDefinition schema="3.0.1"><systemModel name="System Model"/></SystemDefinition>');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   124
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   125
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   126
my %nsmap;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   127
my %urimap;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   128
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   129
my $mapmeta;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   130
my $modpath;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   131
if($output eq '')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   132
	{ #figure out mapping path
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   133
	my @fspath = split(/[\\\/]/,$sysdef);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   134
	my @smpath = split(/[\\\/]/,$path);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   135
	while(lc($smpath[$#smpath]) eq lc($fspath[$#fspath] )) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   136
		pop(@smpath);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   137
		pop(@fspath);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   138
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   139
	my $mappath = join('/',@fspath);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   140
	my $topath = join('/',@smpath);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   141
	$mappath=~s,^/?,file:///,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   142
	$mapmeta = $sysdefdoc->createElement('meta');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   143
	$mapmeta->setAttribute('rel','link-mapping');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   144
	my $node = $sysdefdoc->createElement('map-prefix');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   145
	$node->setAttribute('link',$mappath);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   146
	$topath ne '' && $node->setAttribute('to',$topath);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   147
	$mapmeta->appendChild($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   148
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   149
else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   150
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   151
	$modpath = &relativeTo(&abspath($output), $sysdef);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   152
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   153
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   154
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   155
# find all the namespaces used in all the fragments and use that 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   156
# to set the namespaces in the root element of the created doc
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   157
#   should be able to optimise by only parsing each doc once and 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   158
#	maybe skipping the contends of <meta>
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   159
my @nslist = &namespaces($sysdef,$sysdefdoc->getDocumentElement());
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   160
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   161
my %replacing;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   162
my %newContainer;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   163
my %foundDescendants;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   164
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   165
foreach(keys %add)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   166
	{
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   167
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   168
	my   $fragment;
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   169
	
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   170
	eval {
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   171
		$fragment  = $parser->parsefile ($_);
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   172
	};
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   173
	$fragment || die "could not parse $_";
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   174
	my $fdoc = $fragment->getDocumentElement();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   175
	my $topmost =&firstElement($fdoc);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   176
	if(!$topmost) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   177
		print STDERR "$warning: $_ has no content. Skipping\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   178
		next;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   179
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   180
	my $type = $topmost->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   181
	my $id = $topmost->getAttribute('id');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   182
	my ($localid,$ns) = &idns($topmost,$id);	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   183
	my @path = &guessIdInPath($localid,$_);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   184
	if($type eq 'layer') {@path=@path[0]}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   185
	elsif($type eq 'package')  {@path=@path[0..1]}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   186
	elsif($type eq 'collection')  {@path=@path[0..2]}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   187
	elsif($type eq 'component')  {@path=@path[0..3]}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   188
	@path = reverse(@path);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   189
	$add{$_}=join('/',@path)." $localid $ns";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   190
	$replacing{$type}->{"$localid $ns"} = $_;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   191
	# keys with a space are namespaced and fully identified, and contain the filename as the content.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   192
	# keys with no space have unknown namespace and contain a hash of the content
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   193
	$newContainer{join('/',@path[0..$#path-1])}->{"$localid $ns"} = $_;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   194
	for(my $i=-1;$i<$#path-1;$i++)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   195
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   196
		$foundDescendants{$path[$i+1]}=1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   197
		$newContainer{join('/',@path[0..$i])}->{$path[$i+1]}=1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   198
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   199
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   200
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   201
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   202
while(@nslist)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   203
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   204
	my $uri = shift(@nslist);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   205
	my $prefix =shift(@nslist);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   206
	if($prefix eq 'id namespace'){$prefix=''}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   207
	if(defined $urimap{$uri}) {next} # already done this uri
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   208
	$urimap{$uri} = $prefix;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   209
	if($nsmap{$prefix})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   210
		{ # need a new prefix for this, guess from the URI (for readability)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   211
		if($uri=~/http:\/\/(www\.)?([^.\/]+)\./) {$prefix = $2}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   212
		my $i=0;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   213
		while($nsmap{$prefix})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   214
			{ # still no prefix, just make up 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   215
			$prefix="ns$i";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   216
			$i++;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   217
			# next line not really necessary, but it's a good safety to stop infinite loops
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   218
			$i eq 1000 && die "ERROR: cannot create namespace prefix for $uri";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   219
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   220
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   221
	$nsmap{$prefix}=$uri;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   222
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   223
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   224
my $docroot =  $sysdefdoc->getDocumentElement;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   225
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   226
my $ns = $docroot->getAttribute('id-namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   227
if(!$ns && $nsmap{''})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   228
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   229
	$docroot->setAttribute('id-namespace',$nsmap{''});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   230
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   231
while(my($pre,$uri) = each(%nsmap))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   232
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   233
	$pre ne '' || next ;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   234
	$docroot->setAttribute("xmlns:$pre",$uri);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   235
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   236
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   237
&walk($sysdef,$docroot);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   238
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   239
if($output eq '') 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   240
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   241
	print $sysdefdoc->toString;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   242
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   243
else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   244
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   245
	$sysdefdoc->printToFile($output);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   246
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   247
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   248
 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   249
sub abspath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   250
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   251
	# normalize the path into an absolute one
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   252
	my  ($name,$path) = fileparse($_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   253
	if($path eq '' && $name eq '') {return};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   254
	$path=~tr,\\,/,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   255
	if( -e $path)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   256
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   257
		return abs_path($path)."/$name";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   258
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   259
	my @dir = split('/',$_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   260
	my @new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   261
	foreach my $d (@dir)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   262
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   263
		if($d eq '.') {next}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   264
		if($d eq '..')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   265
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   266
			pop(@new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   267
			next;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   268
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   269
		push(@new,$d)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   270
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   271
	return join('/',@new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   272
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   273
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   274
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   275
 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   276
sub normpath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   277
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   278
	# normalize the path 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   279
	my @norm;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   280
	foreach my $dir(split(/[\\\/]/,shift)) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   281
		if($dir eq '.') {next}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   282
		if($dir eq '..')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   283
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   284
			if($#norm == -1 || $norm[$#norm] eq '..')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   285
				{ # keep  as is
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   286
				push(@norm,$dir);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   287
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   288
			elsif($#norm == 0 && $norm[0] eq '')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   289
				{  # path begins with /, interpret /.. as just / -- ie toss out
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   290
				next
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   291
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   292
			else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   293
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   294
				pop(@norm);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   295
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   296
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   297
		else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   298
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   299
			push(@norm,$dir);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   300
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   301
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   302
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   303
	return join('/',@norm)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   304
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   305
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   306
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   307
sub rootMap {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   308
	my @pathdirs = split(/\//,$_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   309
	my @rootdirs = split(/\//,$_[1]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   310
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   311
	while(lc($rootdirs[$#rootdirs])  eq lc($pathdirs[$#pathdirs])  )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   312
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   313
		pop(@rootdirs);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   314
		pop(@pathdirs);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   315
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   316
	return (join('/',@rootdirs)  => join('/',@pathdirs) );
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   317
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   318
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   319
sub replacedBy
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   320
	{ # can only check once. Destroys data
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   321
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   322
	my $fullid= join(' ',&idns($node));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   323
	my $type =  $node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   324
	my $repl = $replacing{$type}->{$fullid};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   325
	delete $replacing{$type}->{$fullid};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   326
	return $repl;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   327
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   328
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   329
sub walk
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   330
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   331
	#' walk through the doc, resolving all links
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   332
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   333
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   334
	my $type = $node->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   335
	if($type!=1) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   336
	my $tag = $node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   337
	if($tag=~/^(layer|package|collection|component)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   338
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   339
		if($file eq $sysdef)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   340
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   341
			&fixIDs($node);	# normalise all IDs in the root doc.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   342
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   343
		my $override = &replacedBy($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   344
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   345
		if($override eq '' )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   346
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   347
			my ($id,$ns)=&idns($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   348
			if($foundDescendants{$id})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   349
				{ # keep this node, it'll be populated by what we found
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   350
				if($link)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   351
					{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   352
					$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   353
					}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   354
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   355
			elsif($link || !$placeholders)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   356
				{ # not going to be used, remove
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   357
				$node->getParentNode->removeChild($node) ; # not present, remove
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   358
				return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   359
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   360
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   361
		else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   362
			{	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   363
			my $href = $node->getAttribute('href');	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   364
			my $ppath =  join('/',&parentPath($node->getParentNode));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   365
			delete $newContainer{$ppath}->{join(' ',&idns($node))};		# remove this from list of things which need to be added
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   366
			if(&resolvePath($file,$href) ne $override)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   367
				{ # file has changed, update
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   368
				print STDERR "$warning: Replacing $tag ",$node->getAttribute('id')," with $override\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   369
				&setHref($node,$override);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   370
				return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   371
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   372
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   373
		my @curpath = &parentPath($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   374
		my $curitem = $curpath[$#curpath];
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   375
		my $curp = join('/',@curpath[0..$#curpath-1]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   376
		delete $newContainer{$curp}->{$curitem};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   377
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   378
		if($link)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   379
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   380
			foreach my $child (@{$node->getChildNodes}) {$node->removeChild($child)} # can't have children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   381
			&fixHref($node,$file);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   382
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   383
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   384
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   385
	elsif($tag eq 'systemModel' && $mapmeta)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   386
		{ # need absolute paths for all links
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   387
		$node->insertBefore ($mapmeta,$node->getFirstChild);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   388
		$sysmodelname eq '' || $node->setAttribute('name',$sysmodelname);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   389
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   390
	elsif($tag=~/^(SystemDefinition|systemModel)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   391
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   392
		($sysmodelname ne '' && $tag eq 'systemModel') && $node->setAttribute('name',$sysmodelname);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   393
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   394
	elsif($tag eq 'unit')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   395
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   396
		foreach my $atr ('bldFile','mrp','base','proFile')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   397
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   398
			my $link= $node->getAttribute($atr);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   399
			if($link && !($link=~/^\//))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   400
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   401
				if($mapmeta)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   402
					{ # use absolute paths
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   403
					$link= &abspath(File::Basename::dirname($file)."/$link");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   404
					foreach my $a (keys %rootmap)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   405
						{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   406
						$link=~s,^$a,$rootmap{$a},ie;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   407
						}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   408
					}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   409
				else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   410
					{ # modified relative path 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   411
					$link = &normpath($modpath.$link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   412
					}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   413
				$node->setAttribute($atr,$link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   414
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   415
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   416
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   417
	elsif($tag eq 'meta')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   418
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   419
		&fixHref($node,$file);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   420
		foreach my $child (@{$node->getChildNodes}) {$node->removeChild($child)} # can't have children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   421
		&processMeta($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   422
		next;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   423
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   424
	else {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   425
	foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   426
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   427
		#print $item->getNodeType,"\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   428
		&walk($file,$item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   429
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   430
	if($tag=~/^(systemModel|layer|package|collection|component)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   431
		{ # check for appending
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   432
		my $ppath =  join('/',&parentPath($node));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   433
		if($newContainer{$ppath}) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   434
			foreach my $item (sort keys %{$newContainer{$ppath}})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   435
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   436
				&appendNewItem($node,$item,$newContainer{$ppath}->{$item});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   437
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   438
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   439
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   440
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   441
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   442
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   443
sub getNs
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   444
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   445
	# find the ns URI that applies to the specified prefix.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   446
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   447
	my $pre = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   448
	my $uri = $node->getAttribute("xmlns:$pre");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   449
	if($uri) {return $uri}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   450
	my $parent = $node->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   451
	if($parent && $parent->getNodeType==1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   452
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   453
		return getNs($parent,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   454
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   455
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   456
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   457
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   458
sub fixIDs
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   459
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   460
	# translate the ID to use the root doc's namespaces 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   461
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   462
	foreach my $id ('id','before')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   463
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   464
		&fixID($node,$id);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   465
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   466
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   467
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   468
sub idns
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   469
	{ # return the namespace of an ID
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   470
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   471
	my $id = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   472
	if($id eq '' ) {$id = $node->getAttribute('id'); }
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   473
	if($id=~s/^(.*)://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   474
		{ # it's got a ns, find out what it is
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   475
		my $pre = $1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   476
		return ($id,&getNs($node,$pre));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   477
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   478
		return ($id,$node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") ||	$defaultns);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   479
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   480
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   481
sub fixID
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   482
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   483
	# translate the ID to use the root doc's namespaces 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   484
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   485
	my $attr = shift || 'id';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   486
	my $id = $node->getAttribute($attr);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   487
	if($id eq '') {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   488
	my $ns;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   489
	if($id=~s/^(.*)://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   490
		{ # it's got a ns, find out what it is
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   491
		my $pre = $1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   492
		$ns=&getNs($node,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   493
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   494
	else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   495
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   496
		$ns = $node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") ||
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   497
			$defaultns;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   498
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   499
	$ns = $urimap{$ns};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   500
	$id = ($ns eq '') ? $id : "$ns:$id";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   501
	return $node->setAttribute($attr,$id);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   502
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   503
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   504
sub firstElement {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   505
	# return the first element in this node
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   506
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   507
	foreach my $item (@{$node->getChildNodes}) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   508
		if($item->getNodeType==1) {return $item}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   509
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   510
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   511
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   512
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   513
sub atts {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   514
	# return a hash of all attribtues defined for this element
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   515
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   516
	my %at = $node->getAttributes;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   517
	my %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   518
	foreach my $a (keys %{$node->getAttributes}) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   519
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   520
		if($a ne '')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   521
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   522
			$list{$a} = $node->getAttribute ($a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   523
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   524
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   525
	return %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   526
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   527
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   528
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   529
sub ns 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   530
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   531
	# return a hash of ns prefix and uri -- the xmlns: part is stripped off
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   532
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   533
	my %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   534
	foreach my $a (keys %{$node->getAttributes}) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   535
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   536
		my $pre = $a;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   537
		if($pre=~s/^xmlns://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   538
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   539
			$list{$pre} = $node->getAttribute ($a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   540
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   541
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   542
	return %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   543
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   544
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   545
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   546
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   547
sub namespaces
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   548
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   549
	# return a list of namespace URI / prefix pairs, in the order they're defined
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   550
	# these need to be used to define namespaces in the root element
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   551
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   552
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   553
	my $type = $node->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   554
	if($type!=1) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   555
	my $tag = $node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   556
	my @res;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   557
	my %nslist = &ns($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   558
	while(my($pre,$uri)=each(%nslist))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   559
		{ # push all namespaces defined here onto the list
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   560
		push(@res,$uri,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   561
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   562
	if($tag=~/^(layer|package|collection|component)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   563
		{ # these have the potential of linking, so check for that
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   564
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   565
	elsif($tag eq 'SystemDefinition' )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   566
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   567
		my $default = $node->getAttribute('id-namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   568
		if($default)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   569
			{# mangle with a space so it's clear it's not a qname
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   570
			push(@res,$default,'id namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   571
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   572
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   573
	foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   574
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   575
		push(@res,&namespaces($file,$item));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   576
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   577
	return @res;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   578
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   579
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   580
sub  processMeta
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   581
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   582
	my $metanode = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   583
	# do nothing. Not supported yet
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   584
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   585
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   586
sub guessIdInPath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   587
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   588
	my $id = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   589
	my @path = reverse(split(/\//,$_[0]));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   590
	while(@path)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   591
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   592
		my $dir = shift(@path);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   593
		if($dir eq $id)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   594
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   595
			return ($id,@path);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   596
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   597
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   598
	print STDERR "$warning: Non-standard ID $id in $_[0]\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   599
	@path = reverse(split(/\//,$_[0]));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   600
	if($path[0] eq 'package_definition.xml')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   601
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   602
		return @path[1..$#path];
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   603
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   604
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   605
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   606
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   607
sub parentPath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   608
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   609
	my $node=shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   610
	my @path;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   611
	while($node)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   612
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   613
		if(!$node) {return @path}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   614
		my $id=$node->getAttribute('id');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   615
		if($id eq '') {return @path}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   616
		$id=~s/^.*://;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   617
		@path = ($id,@path);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   618
		$node = $node->getParentNode();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   619
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   620
	return @path;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   621
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   622
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   623
sub childTag
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   624
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   625
	my $tag = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   626
	if($tag eq 'systemModel') {return 'layer'}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   627
	if($tag eq 'layer') {return 'package'}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   628
	if($tag eq 'package') {return 'collection'}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   629
	if($tag eq 'collection') {return 'component'}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   630
	die "ERROR: no child for $tag";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   631
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   632
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   633
sub appendNewItem
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   634
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   635
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   636
	my $doc = $node->getOwnerDocument;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   637
	my $id = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   638
	if($id eq '') {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   639
	my $fullid=$id;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   640
	my $contents = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   641
	my $tag = &childTag($node->getTagName());
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   642
	my $new = $doc->createElement($tag);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   643
	if($id=~/^(.*) (.*)/)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   644
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   645
		$id=$1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   646
		$ns = getNamespacePrefix($node,$2);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   647
		if($ns ne '') {$id="$ns:$id"}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   648
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   649
	else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   650
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   651
		$contents = '';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   652
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   653
	$new->setAttribute('id',$id);		# default namespace
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   654
	$node->appendChild($new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   655
	my $ppath =  join('/',&parentPath($new));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   656
	if($contents eq '')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   657
		{ # look for additions
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   658
		print STDERR "$warning: Adding new $tag: $id\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   659
		if($newContainer{$ppath}) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   660
			foreach my $item (sort keys %{$newContainer{$ppath}})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   661
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   662
				&appendNewItem($new,$item,$newContainer{$ppath}->{$item});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   663
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   664
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   665
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   666
	else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   667
		{ # this one item is defined in the specified file
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   668
		if($tag eq 'package') 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   669
			{ #include some package data in root
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   670
			my $fragment = $parser->parsefile ($contents);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   671
			my $fdoc = $fragment->getDocumentElement();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   672
			my $topmost =&firstElement($fdoc);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   673
			my %at = &atts($topmost);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   674
			foreach my $arg ('tech-domain','level','span')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   675
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   676
				if($at{$arg}) {	$new->setAttribute($arg,$at{$arg})}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   677
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   678
			if($at{'tech-domain'}) {&positionByTechDomain($new)}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   679
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   680
		&setHref($new,$contents);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   681
		print STDERR "$warning: Adding found $tag $id from $contents\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   682
		delete $replacing{$tag}->{$fullid};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   683
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   684
	# newline after each new tag so output's not ugly
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   685
	if($new->getNextSibling)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   686
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   687
		$node->insertBefore($doc->createTextNode ("\n"),$new->getNextSibling);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   688
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   689
	else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   690
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   691
		$node->appendChild($doc->createTextNode ("\n"));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   692
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   693
	delete $newContainer{$ppath};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   694
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   695
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   696
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   697
sub getNamespacePrefix
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   698
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   699
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   700
	my $ns = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   701
	my $root = $node->getOwnerDocument->getDocumentElement;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   702
	my $idns = $root->getAttribute("id-namespace");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   703
	if($idns && $idns eq $ns) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   704
	if(!$idns && $defaultns eq $ns) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   705
	foreach my $a (keys %{$root->getAttributes}) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   706
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   707
		my $pre = $a;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   708
		if($pre=~s/^xmlns://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   709
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   710
			if($root->getAttribute ($a) eq $ns)  {return $pre}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   711
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   712
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   713
	die "ERROR: no namespace prefix defined for $ns";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   714
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   715
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   716
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   717
sub resolvePath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   718
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   719
	# return full path to 2nd arg relative to first (path or absolute URI)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   720
	my $base = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   721
	my $path = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   722
	if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   723
	if($path=~s,^file:///([a-zA-Z]:/),$1,) {return $path } # file URI with drive letter
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   724
	if($path=~m,^file://,) {return $path } # file URI with no drive letter (unit-style). Just pass on as is with leading / and let OS deal with it
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   725
	if($path=~m,^[a-z0-9][a-z0-9]+:,i) {return $path } # absolute URI -- no idea how to handle, so just return
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   726
	return &abspath(File::Basename::dirname($base)."/$path");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   727
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   728
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   729
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   730
sub fixHref {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   731
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   732
	my $base = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   733
	my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   734
	if($link=~/^(ftp|http)s:\/\//) {return} # remote link, do nothing
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   735
	my $path = &resolvePath($base,$link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   736
	if(!-e $path) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   737
		{ # no such file, delete
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   738
		my $tag  =$node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   739
		my $id = $node->getAttribute('id');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   740
		print STDERR "$warning: $tag $id not found at $link\n";	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   741
		$node->getParentNode->removeChild($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   742
		return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   743
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   744
	foreach my $child (@{$node->getChildNodes}) {$node->removeChild($child)} # can't have children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   745
	if($output eq '')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   746
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   747
		$path=~s,^/?,file:///,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   748
		$node->setAttribute('href',$path);	# replace with absolute URI
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   749
		return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   750
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   751
	$node->setAttribute('href',&normpath($modpath.$link));	# make relative path to output file
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   752
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   753
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   754
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   755
sub setHref {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   756
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   757
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   758
	if($output eq '') 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   759
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   760
		$path = &abspath($file);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   761
		$path=~s,^/?,file:///,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   762
		$node->setAttribute('href',$path);	# replace with absolute URI
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   763
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   764
	else 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   765
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   766
		$node->setAttribute('href',&relativeTo(&abspath($output),$file,'file'));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   767
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   768
	while(my $child =  $node->getFirstChild ) {$node->removeChild($child)}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   769
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   770
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   771
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   772
sub relativeTo {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   773
	if($_[0] eq '') {return &abspath($_[1])}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   774
	my @outfile = split(/[\\\/]/,lc(shift));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   775
	my @infile  = split(/[\\\/]/,lc(shift));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   776
	my $asdir = shift ne 'file';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   777
	while($outfile[0] eq $infile[0])
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   778
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   779
		shift(@outfile);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   780
		shift(@infile);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   781
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   782
	$modpath = '../' x (scalar(@outfile) - 1);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   783
	if($asdir) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   784
		if(scalar @infile > 1)  {$modpath .=  join('/',@infile[0..$#infile - 1]).'/'}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   785
	} else   {$modpath .=  join('/',@infile)}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   786
	return $modpath;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   787
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   788
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   789
sub positionByTechDomain 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   790
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   791
	my $node=shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   792
	my $td = $node->getAttribute('tech-domain');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   793
	my %before;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   794
	foreach my $t (@tdOrder)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   795
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   796
		$before{$t}=1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   797
		if($t eq $td) {last}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   798
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   799
	my $prev = $node->getPreviousSibling;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   800
	foreach my $child (reverse @{$node->getParentNode->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   801
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   802
		if($child->getNodeType==1 && $child->getTagName eq 'package' && $child!=$node)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   803
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   804
			if($before{$child->getAttribute('tech-domain')})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   805
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   806
				my $next = $child->getNextSibling;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   807
				while($next &&  $next->getNodeType!=1) {$next = $next->getNextSibling}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   808
				if($next) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   809
					$node->getParentNode->insertBefore ($node,$next);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   810
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   811
				last;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   812
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   813
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   814
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   815
	}