# HG changeset patch # User Bob Rosenberg # Date 1280319646 -3600 # Node ID f70b728ea30c4a4ad5c951f584544cfafab7942d # Parent 96fee2635b19654931f631b34097c4d3984d9b19 Move sysdeftools from buildtools package into build package diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/checklinks.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/checklinks.bat Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,17 @@ +@rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +@rem All rights reserved. +@rem This component and the accompanying materials are made available +@rem under the terms of the License "Eclipse Public License v1.0" +@rem which accompanies this distribution, and is available +@rem at the URL "http://www.eclipse.org/legal/epl-v10.html". +@rem +@rem Initial Contributors: +@rem Nokia Corporation - initial contribution. +@rem +@rem Contributors: +@rem +@rem Description: +@rem +@setlocal +@perl %~dpn0.pl %* + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/checklinks.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/checklinks.pl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,525 @@ +# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# Script to validate the unit links in a system definition or package definition XML file +#!/usr/bin/perl + +use strict; + + +use FindBin; # for FindBin::Bin +use lib $FindBin::Bin; +use lib "$FindBin::Bin/lib"; + +use Cwd; +use Cwd 'abs_path'; +use Getopt::Long; +use File::Basename; +use File::Spec; +use XML::DOM; + +my $output; +my $path; +my %defineParams; +my %defines; +my $defaultns = 'http://www.symbian.org/system-definition'; # needed if no DTD +my $realloc; + +# need to add options for controlling which metas are filtered out and which are included inline +GetOptions + ( + 'path=s' => $path, + 'effective-sysdef=s' => \$realloc + ); + +# -path specifies the full system-model path to the file which is being processed. +# This must be an absolute path if you're processing a root sysdef. +# If processing a pkgdef file, you can use "./package_definition.xml" to leave all links relative. Though I can't really see the use case for this. + + +# if config is not set, no confguration will be done. +# If it is set, all configuration metadata will be processed and stripped from the output, even if the confguration data is empty + + if($path eq '') {$path = '/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml'} + +($#ARGV == -1 ) && &help(); +my $sysdef = &abspath(shift); # resolve the location of the root sysdef + +$realloc = $realloc || $sysdef; + +my %unitmap; +my @p1=reverse(split(/[\\\/]/,$path)); +my @p2=reverse(split(/[\\\/]/,$realloc)); + +shift(@p1);shift(@p2); # don't care abt file name +while(lc($p1[0]) eq lc($p2[0])) {shift(@p1);shift(@p2)} + +$unitmap{join('/',reverse(@p1))} = join("/",reverse(@p2)); + +my @p1=reverse(split(/[\\\/]/,$sysdef)); +my @p2=reverse(split(/[\\\/]/,$realloc)); + +shift(@p1);shift(@p2); # don't care abt file name +while(lc($p1[0]) eq lc($p2[0]) && scalar(@p1)) {shift(@p1);shift(@p2)} + +$unitmap{join('/',reverse(@p1))} = join("/",reverse(@p2)); + + +# rootmap is a mapping from the filesystem to the paths in the doc +my %rootmap = &rootMap($path,$sysdef); +my %nsmap; +my %urimap; + +my $parser = new XML::DOM::Parser; +my $sysdefdoc; +eval { + $sysdefdoc = $parser->parsefile ($sysdef); +}; +if(!$sysdefdoc) { + die "ERROR: could not open $sysdef\n"; +} + + + +my $maxschema = $sysdefdoc->getDocumentElement()->getAttribute('schema'); # don't check value, just store it. + +my $docroot = $sysdefdoc->getDocumentElement; + +my $ns = $docroot->getAttribute('id-namespace'); +if(!$ns && $nsmap{''}) + { + $docroot->setAttribute('id-namespace',$nsmap{''}); + } + +$docroot->setAttribute('schema',$maxschema); # output has the largest syntax version of all includes + + +while(my($pre,$uri) = each(%nsmap)) + { + $pre ne '' || next ; + $docroot->setAttribute("xmlns:$pre",$uri); + } + +&walk($sysdef,$docroot); # process the XML + + +sub abspath + { # normalize the path into an absolute one + my ($name,$path) = fileparse($_[0]); + $path=~tr,\\,/,; + if( -e $path) + { + return abs_path($path)."/$name"; + } + my @dir = split('/',$_[0]); + my @new; + foreach my $d (@dir) + { + if($d eq '.') {next} + if($d eq '..') + { + pop(@new); + next; + } + push(@new,$d) + } + return join('/',@new); + } + +sub rootMap { + my @pathdirs = split(/\//,$_[0]); + my @rootdirs = split(/\//,$_[1]); + + while(lc($rootdirs[$#rootdirs]) eq lc($pathdirs[$#pathdirs]) ) + { + pop(@rootdirs); + pop(@pathdirs); + } + return (join('/',@rootdirs) => join('/',@pathdirs) ); + } + +sub rootMapMeta { + # find all the explict path mapping from the link-mapping metadata + my $node = shift; + foreach my $child (@{$node->getChildNodes}) + { + if ($child->getNodeType==1 && $child->getTagName eq 'map-prefix') + { + my $from = $child->getAttribute('link'); + my $to = $child->getAttribute('to'); # optional, but blank if not set + $rootmap{$from} = $to; + } + } + # once this is processed we have no more need for it. Remove from output + $node->getParentNode->removeChild($node); + } + + +sub walk + { # walk through the doc, resolving all links + my $file = shift; + my $node = shift; + my $type = $node->getNodeType; + if($type!=1) {return} + my $tag = $node->getTagName; + if($tag=~/^(layer|package|collection|component)$/ ) + { + my $link= $node->getAttribute('href'); + if($link) + { + my $file = &resolvePath($file,$link); + if(-e $file) + { + &combineLink($node,$file); + } + else + { + print "Note: $file not found\n"; + $node->removeAttribute('href'); + } + return; + } + } + elsif($tag=~/^(SystemDefinition|systemModel)$/ ) + { + } + elsif($tag eq 'unit') + { + my %at = &atts($node); + my $pro; + foreach my $o (keys(%at)) + { + if($o eq 'proFile' || $o=~/:proFile$/) + { + $pro = $at{$o}; + last; + } + } + my $filter=$node->getParentNode()->getAttribute('filter'); + if($filter ne '' && $at{'filter'}) {$filter.=','.$at{'filter'}} + elsif($at{'filter'}) {$filter=$at{'filter'}} + if($filter ne '') {$filter="\t($filter)"} + foreach my $atr ('bldFile','mrp','base') + { + my $ext; + my $link= $at{$atr}; + if($atr eq 'bldFile') { + $ext = ($pro ne '') ? "/$pro" : '/bld.inf' + } + if($link ne '') + { + my $ok = 0; + my $trylink; + if($link && !($link=~/^\//)) + { + $link= &abspath(File::Basename::dirname($file)."/$link"); + $ok = (-e "$link$ext"); + if(!$ok) + { + foreach my $a (keys %rootmap) + { + $link=~s,^$a,$rootmap{$a},ie; + # remove leading ./ which is used to indicate that paths should remain relative + $link=~s,^\./([^/]),$1,; + } + + } + } + if(!$ok) + { + foreach my $a (keys %unitmap) { + if($a eq substr($link,0,length($a))) { + $trylink = $unitmap{$a}.substr($link,length($a)); + if(-e "$trylink$ext") { + $ok=1; + $link = $trylink; + last; + } + } + } + } + if(!$ok) + { + print "Error: $atr not found in ",($trylink ne '') ? $trylink : $link,"$filter\n"; + } + } + } + } + elsif($tag eq 'meta') + { + my $rel= $node->getAttribute('rel') || 'Generic'; + my $link= $node->getAttribute('href'); + $link=~s,^file://(/([a-z]:/))?,$2,; # convert file URI to absolute path + if ($link ne '' ) + { + if($link=~/^[\/]+:/) + { + print "Note: Remote URL $link not validated\n"; + next; # do not alter children + } + if(! ($link=~/^\//)) + { + $link= &abspath(File::Basename::dirname($file)."/$link"); + } + if(! -e $link) + { + if(! -e &realPath($link)) { + print "Warning: Local metadata file not found: $link\n"; + } + next; # do not alter children + } + } + if($node->getAttribute('rel') eq 'link-mapping') + {# need to process this now + &rootMapMeta($node); + } + return; + } + else {return} + my $checkversion=0; + foreach my $item (@{$node->getChildNodes}) + { + #print $item->getNodeType,"\n"; + &walk($file,$item); + } + + + + } + + +sub realPath + { + my $link = shift; + foreach my $a (keys %unitmap) + { + if($a eq substr($link,0,length($a))) + { + my $trylink = $unitmap{$a}.substr($link,length($a)); + if(-e $trylink) {return $trylink} + } + } + } + +sub combineLink + { + # combine data from linked sysdef fragment w/ equivalent element in parent document + my $node = shift; + my $file = shift; + my $getfromfile = &localfile($file); + $getfromfile eq '' && return; # already raised warning, no need to repeat + my $doc; + eval { + $doc = $parser->parsefile ($getfromfile); + }; + if(!$doc) { + print "ERROR: could not open $getfromfile\n"; + return; + } + my $item =&firstElement($doc->getDocumentElement); + $item || die "badly formatted $file"; + my @upid = &getNamespaceAndValue($node,'id'); + my @downid = &getNamespaceAndValue($item,'id'); + (($upid[0] eq $downid[0]) && ($upid[1] eq $downid[1])) || die "$upid[1] ($upid[0]) differs from $downid[1] ($downid[0]) "; # make sure the link is valid + &walk($getfromfile,$item); + } + + +sub copyInto + { + # make a deep copy the node (2nd arg) into the element (1st arg) + my $parent=shift; + my $item = shift; + my $doc = $parent->getOwnerDocument; + my $type = $item->getNodeType; + my $new; + if($type==1) + { + $new = $doc->createElement($item->getTagName); + my %down = &atts($item); + foreach my $ordered ('id','name','bldFile','mrp','level','levels','introduced','deprecated','filter') + { + if($down{$ordered}) + { + $new->setAttribute($ordered,$down{$ordered}); + delete $down{$ordered} + } + } + while(my($a,$b) = each(%down)) + { + $new->setAttribute($a,$b); + } + foreach my $child (@{$item->getChildNodes}) + { + ©Into($new,$child); + } + } + elsif($type==3) + { + $new = $doc->createTextNode ($item->getData); + } + elsif($type==8) + { + $new = $doc->createComment ($item->getData); + } + if($new) + { + $parent->appendChild($new); + } + } + + +sub getNamespaceAndValue + { + my $node = shift; + my $attr = shift || 'id'; + my $id = $node->getAttribute($attr); + if($id eq '') {return} + my $ns; + if($id=~s/^(.*)://) + { # it's got a ns, find out what it is + $ns=&getNs($node,$1); + } + else + { + $ns = $node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") || + $defaultns; + } + return ($ns,$id);; + } + +sub getNs + { + # find the namespace URI that applies to the specified prefix. + my $node = shift; + my $pre = shift; + my $uri = $node->getAttribute("xmlns:$pre"); + if($uri) {return $uri} + my $parent = $node->getParentNode; + if($parent && $parent->getNodeType==1) + { + return getNs($parent,$pre); + } + } + + + +sub firstElement { + # return the first element in this node + my $node = shift; + foreach my $item (@{$node->getChildNodes}) { + if($item->getNodeType==1) {return $item} + } +} + + +sub atts { + # return a hash of all attribtues defined for this element + my $node = shift; + my %at = $node->getAttributes; + my %list; + foreach my $a (keys %{$node->getAttributes}) + { + if($a ne '') + { + $list{$a} = $node->getAttribute ($a); + } + } + return %list; +} + + +sub ns + { + # return a hash of ns prefix and uri -- the xmlns: part is stripped off + my $node = shift; + my %list; + foreach my $a (keys %{$node->getAttributes}) + { + my $pre = $a; + if($pre=~s/^xmlns://) + { + $list{$pre} = $node->getAttribute ($a); + } + } + return %list; + } + + +sub resolvePath + { + # return full path to 2nd arg relative to first (path or absolute URI) + my $base = shift; + my $path = shift; + if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it. + if($path=~s,^file:///([a-zA-Z]:/),$1,) {return $path } # file URI with drive letter + 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 + if($path=~m,^[a-z0-9][a-z0-9]+:,i) {return $path } # absolute URI -- no idea how to handle, so just return + return &abspath(File::Basename::dirname($base)."/$path"); + } + + +sub resolveURI + { + # return full path to 2nd arg relative to first (path or absolute URI) + my $base = shift; + my $path = shift; + if($path=~m,[a-z0-9][a-z0-9]+:,i) {return $path } # absolute URI -- just return + if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it. + return &abspath(File::Basename::dirname($base)."/$path"); + } + +sub localfile + { + my $file = shift; + if($file=~s,file:///([a-zA-Z]:/),$1,) {return $file } # file URI with drive letter + if($file=~m,file://,) {return $file } # file URI with no drive letter (unit-style). Just pass on as is with leading / and let OS deal with it + if($file=~m,^([a-z0-9][a-z0-9]+):,i) + { + print "ERROR: $1 scheme not supported\n"; + return; # return empty string if not supported. + } + return $file + } + + + + + +sub help + { + my $name= $0; $name=~s,^.*[\\/],,; +my $text; +format STDERR = + ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + $text, + ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ + $text +. +print STDERR "usage: $name [options...] sysdef\n valid options are:\n\n"; + foreach ( + "-path [sm-path]\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\"", + " This must be an absolute path if you're processing a root sysdef.", + " If processing a pkgdef file, you can use \"./package_definition.xml\" to leave all links relative.", + "effective-sysdef [local-file]\tspecifies another local filesystem location the sysdef should be considered when resolving linked metas and unit paths, but not system model item hrefs. This is mainly used for testing system-wide changes to pkgdefs since it allows the pkgdefs to exist in a separate location to the rest of the codeline" + ) { + $text = $_; + write STDERR; + print STDERR "\n"; + } + + exit(1); + } + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/docs/readme.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/docs/readme.txt Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,64 @@ +# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# Contributors: +# Description: + +Run any .bat or .pl file with no arguments to get syntax and command line options. + +*Directory structure* + +Main directory contains XLST and Perl scripts and the .bat files that call them +docs contains this file +lib contains common XSLT modules +xalanj contains an implementation of Xalan-J, an XSLT processor implemented in Java + + +*The tools* + +Filtering tools: +filtering.xsl - Filter a sysdef in the 2.0 or 3.0 syntax +filtering.bat - Call filtering.xsl using xalan-j + +Joining tools: +joinsysdef.pl - Create a stand-alone sysdef from a linked set of fragments. Supports confguring via an .hrh file. By default this also embeds any linked metadata. +joinsysdef.bat - Call joinsysdef.pl +joinsysdef.xsl - Create a stand-alone sysdef from a linked set of fragments +joinandparesysdef.xsl - Create a stand-alone sysdef from a linked set of fragments, paring down to just a set of items of the desired rank. + +Merging tools: +mergesysdef.xsl - Merge two 3.x syntax stand-alone system definitions. It can process two standalone sysdefs or two sysdef fragments which describe the same system model item. +mergesysdef.bat - Call mergesysdef.xsl using xalan-j + +Other tools: +sysdefdowngrade.xsl - Convert a 3.0.x sysdef to 2.0.1 sytnax +sysdefdowngrade.bat - Call sysdefdowngrade.xsl using xalan-j +rootsysdef.pl - Generate a root system definition from a template root sysdef and a set of wildcard paths to look for pkgdef files +rootsysdef.bat - Call rootsysdef.pl + +Validation tools: +checklinks.pl - Checks that all referenced files in a system definition exist at the specified locations. If there are any linked system definition fragments, it will recursively check them as well. +checklinks.bat - call checklinks.pl +validate-sysdef.xsl - Validate a sysdef file, reporting any errors as plain text +validate-sysdef.bat - Call validate-sysdef.xsl using xalan-j + +Modules (in lib): +filter-module.xsl - XSLT module which contains the logic to process the filter attribute in the system definition +joinsysdef-module.xsl - XSLT module which contains the logic to join a system definition file +mergesysdef-module.xsl - XSLT module for merging only two sysdef files according to the 3.0.0 rules +test-model.xsl - XSLT module for validating sysdef files +modelcheck.xsl - Validates a sysdef file, reporting any errors in HTM format. Can validate a sysdef in a web browser by using + + +XSLT Processing (in xalanj): +xalan.jar +xercesImpl.jar +xml-apis.jar +serializer.jar + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/filtering.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/filtering.bat Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,21 @@ +@rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +@rem All rights reserved. +@rem This component and the accompanying materials are made available +@rem under the terms of the License "Eclipse Public License v1.0" +@rem which accompanies this distribution, and is available +@rem at the URL "http://www.eclipse.org/legal/epl-v10.html". +@rem +@rem Initial Contributors: +@rem Nokia Corporation - initial contribution. +@rem +@rem Contributors: +@rem +@rem Description: +@rem +@setlocal +@if .%1==. goto use +@ java -jar %~dp0xalanj\xalan.jar -xsl %~dpn0.xsl %* +@goto end +:use +@ java -jar %~dp0xalanj\xalan.jar -in %~dpn0.xsl -xsl %~dp0lib\usage.xsl -param usage "%~n0" +:end \ No newline at end of file diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/filtering.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/filtering.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,293 @@ + + + + + + + + + + + + +only + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]> +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]> +]]> + + \ No newline at end of file diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/group/bld.inf Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +PRJ_PLATFORMS +TOOLS2 + +/** +@file + +@SYMPurpose Tool for manipulating and verifying system definition files +*/ + +PRJ_EXPORTS + +// raw scripts + +../checklinks.pl /epoc32/tools/build/checklinks.pl +../filtering.xsl /epoc32/tools/build/filtering.xsl +../joinandparesysdef.xsl /epoc32/tools/build/joinandparesysdef.xsl +../joinsysdef.pl /epoc32/tools/build/joinsysdef.pl +../joinsysdef.xsl /epoc32/tools/build/joinsysdef.xsl +../mergesysdef.xsl /epoc32/tools/build/mergesysdef.xsl +../rootsysdef.pl /epoc32/tools/build/rootsysdef.pl +../sysdefdowngrade.xsl /epoc32/tools/build/sysdefdowngrade.xsl +../validate-sysdef.xsl /epoc32/tools/build/validate-sysdef.xsl + + +// reusable modules and internal utilities + +../lib/filter-module.xsl /epoc32/tools/build/lib/filter-module.xsl +../lib/joinsysdef-module.xsl /epoc32/tools/build/lib/joinsysdef-module.xsl +../lib/mergesysdef-module.xsl /epoc32/tools/build/lib/mergesysdef-module.xsl +../lib/modelcheck.xsl /epoc32/tools/build/lib/modelcheck.xsl +../lib/path-module.xsl /epoc32/tools/build/lib/path-module.xsl +../lib/test-model.xsl /epoc32/tools/build/lib/test-model.xsl +../lib/usage.xsl /epoc32/tools/build/lib/usage.xsl + +// Xalan jar files +../xalanj/serializer.jar /epoc32/tools/build/xalanj/serializer.jar +../xalanj/xalan.jar /epoc32/tools/build/xalanj/xalan.jar +../xalanj/xercesImpl.jar /epoc32/tools/build/xalanj/xercesImpl.jar +../xalanj/xml-apis.jar /epoc32/tools/build/xalanj/xml-apis.jar + + + + +// Perl-calling .bat files (identical, can export from any single one of these). +../checklinks.bat /epoc32/tools/build/checklinks.bat +../joinsysdef.bat /epoc32/tools/build/joinsysdef.bat +../rootsysdef.bat /epoc32/tools/build/rootsysdef.bat + +// Xalan-calling .bat/unix files (identical, can export from single file) +../joinandparesysdef.bat /epoc32/tools/build/joinandparesysdef.bat +../filtering.bat /epoc32/tools/build/filtering.bat +../validate-sysdef.bat /epoc32/tools/build/validate-sysdef.bat +unixxslcmd /epoc32/tools/build/joinandparesysdef +unixxslcmd /epoc32/tools/build/filtering +unixxslcmd /epoc32/tools/build/validate-sysdef + +// Xalan-calling .bat/unix files that use XSLTC (identical, can export from single file) +../mergesysdef.bat /epoc32/tools/build/mergesysdef.bat +../sysdefdowngrade.bat /epoc32/tools/build/sysdefdowngrade.bat +unixxsltccmd /epoc32/tools/build/mergesysdef +unixxsltccmd /epoc32/tools/build/sysdefdowngrade + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/group/unixxslcmd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/group/unixxslcmd Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Contributors: +# Nokia Corporation - initial contribution. +# +# Description: +# XSLT wrapper for Unix + +BASEDIR=`dirname $0` + +if [ $# != 0 ] +then + exec java -jar $BASEDIR/xalanj/xalan.jar -xsl $0.xsl $@ +fi + +java -jar $BASEDIR/xalanj/xalan.jar -xsl $BASEDIR/lib/usage.xsl -in $0.xsl -param usage $0 + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/group/unixxsltccmd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/group/unixxsltccmd Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Contributors: +# Nokia Corporation - initial contribution. +# +# Description: +# XSLT wrapper for Unix + +BASEDIR=`dirname $0` + +if [ $# != 0 ] +then + exec java -jar $BASEDIR/xalanj/xalan.jar -xsl $0.xsl -XSLTC $@ +fi + +java -jar $BASEDIR/xalanj/xalan.jar -xsl $BASEDIR/lib/usage.xsl -in $0.xsl -param usage $0 + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/joinandparesysdef.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/joinandparesysdef.bat Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,21 @@ +@rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +@rem All rights reserved. +@rem This component and the accompanying materials are made available +@rem under the terms of the License "Eclipse Public License v1.0" +@rem which accompanies this distribution, and is available +@rem at the URL "http://www.eclipse.org/legal/epl-v10.html". +@rem +@rem Initial Contributors: +@rem Nokia Corporation - initial contribution. +@rem +@rem Contributors: +@rem +@rem Description: +@rem +@setlocal +@if .%1==. goto use +@ java -jar %~dp0xalanj\xalan.jar -xsl %~dpn0.xsl %* +@goto end +:use +@ java -jar %~dp0xalanj\xalan.jar -in %~dpn0.xsl -xsl %~dp0lib\usage.xsl -param usage "%~n0" +:end diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/joinandparesysdef.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/joinandparesysdef.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,49 @@ + + + + + + + + + +package + + + + + + + + + + + + + + + + hide + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/joinsysdef.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/joinsysdef.bat Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,17 @@ +@rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +@rem All rights reserved. +@rem This component and the accompanying materials are made available +@rem under the terms of the License "Eclipse Public License v1.0" +@rem which accompanies this distribution, and is available +@rem at the URL "http://www.eclipse.org/legal/epl-v10.html". +@rem +@rem Initial Contributors: +@rem Nokia Corporation - initial contribution. +@rem +@rem Contributors: +@rem +@rem Description: +@rem +@setlocal +@perl %~dpn0.pl %* + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/joinsysdef.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/joinsysdef.pl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,850 @@ +# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# +#!/usr/bin/perl + +use strict; + + +use FindBin; # for FindBin::Bin +use lib $FindBin::Bin; +use lib "$FindBin::Bin/lib"; + +use Cwd; +use Cwd 'abs_path'; +use Getopt::Long; +use File::Basename; +use File::Spec; +use XML::DOM; + +my $output; +my $path; +my @config; +my @includes; +my %defineParams; +my %defines; +my $defaultns = 'http://www.symbian.org/system-definition'; # needed if no DTD +my @excludeMetaList; +my @cannotExclude= ('link-mapping', 'config'); +my %ID; # list of all IDs + +my @newarg; +foreach my $a (@ARGV) + { #extract all -I parameters from the parameter list + if($a=~s/^-I//) + { + push(@includes,$a); + } + else + { + push(@newarg,$a); + } + } +@ARGV=@newarg; + +# need to add options for controlling which metas are filtered out and which are included inline +GetOptions + ( + 'path=s' => \$path, + 'output=s' => \$output, + 'config=s' => \@config, + 'exclude-meta=s' => \@excludeMetaList + ); + +# -path specifies the full system-model path to the file which is being processed. +# This must be an absolute path if you're processing a root sysdef. +# If processing a pkgdef file, you can use "./package_definition.xml" to leave all links relative. Though I can't really see the use case for this. + +# -output specifies the file to save the output to. If not specified this will write to stdout + +# -config specifies the name of an .hrh file in which the configuration data is acquired from. If not set, no confguration will be done. + +# -I[path] specifies the include paths to use when resolving #includes in the .hrh file. Same syntax as cpp command uses. Any number of these can be provided. + + +# if config is not set, no confguration will be done. +# If it is set, all configuration metadata will be processed and stripped from the output, even if the confguration data is empty + + if($path eq '') {$path = '/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml'} + +($#ARGV == -1 ) && &help(); +my $sysdef = &abspath(shift); # resolve the location of the root sysdef + + +my %excludeMeta; +foreach (@excludeMetaList) {$excludeMeta{$_}=1} # make list a hash table +foreach (@cannotExclude) + { + $excludeMeta{$_} && print STDERR "Error: Cannot exclude meta rel=\"$_\"\n"; + $excludeMeta{$_}=0 + } # cannot exclude any of these rel types + + +# rootmap is a mapping from the filesystem to the paths in the doc +my %rootmap = &rootMap($path,$sysdef); +my %nsmap; +my %urimap; + +foreach my $conf (@config) + { # run cpp to get all #defines + &getDefines($conf); + } + +my $parser = new XML::DOM::Parser; +my $sysdefdoc = $parser->parsefile ($sysdef); + + +my $maxschema = $sysdefdoc->getDocumentElement()->getAttribute('schema'); # don't check value, just store it. + + +# find all the namespaces used in all trhe fragments and use that +# to set the namespaces ni the root element of the created doc +# should be able to optimise by only parsing each doc once and +# maybe skipping the contends of +my @nslist = &namespaces($sysdef,$sysdefdoc->getDocumentElement()); + + +while(@nslist) + { + my $uri = shift(@nslist); + my $prefix =shift(@nslist); + if($prefix eq 'id namespace'){$prefix=''} + if(defined $urimap{$uri}) {next} # already done this uri + $urimap{$uri} = $prefix; + if($nsmap{$prefix}) + { # need a new prefix for this, guess from the URI (for readability) + if($uri=~/http:\/\/(www\.)?([^.\/]+)\./) {$prefix = $2} + my $i=0; + while($nsmap{$prefix}) + { # still no prefix, just make up + $prefix="ns$i"; + $i++; + # next line not really necessary, but it's a good safety to stop infinite loops + $i eq 1000 && die "cannot create namespace prefix for $uri"; + } + } + $nsmap{$prefix}=$uri; + } + +my $docroot = $sysdefdoc->getDocumentElement; + +my $ns = $docroot->getAttribute('id-namespace'); +if(!$ns && $nsmap{''}) + { + $docroot->setAttribute('id-namespace',$nsmap{''}); + } + +$docroot->setAttribute('schema',$maxschema); # output has the largest syntax version of all includes + + +while(my($pre,$uri) = each(%nsmap)) + { + $pre ne '' || next ; + $docroot->setAttribute("xmlns:$pre",$uri); + } + +&walk($sysdef,$docroot); # process the XML + + +# print to file or stdout +if($output eq '') + { + print $sysdefdoc->toString; + } +else + { + $sysdefdoc->printToFile($output); + } + + +sub abspath + { # normalize the path into an absolute one + my ($name,$path) = fileparse($_[0]); + $path=~tr,\\,/,; + if( -e $path) + { + return abs_path($path)."/$name"; + } + my @dir = split('/',$_[0]); + my @new; + foreach my $d (@dir) + { + if($d eq '.') {next} + if($d eq '..') + { + pop(@new); + next; + } + push(@new,$d) + } + return join('/',@new); + } + +sub rootMap { + my @pathdirs = split(/\//,$_[0]); + my @rootdirs = split(/\//,$_[1]); + + while(lc($rootdirs[$#rootdirs]) eq lc($pathdirs[$#pathdirs]) ) + { + pop(@rootdirs); + pop(@pathdirs); + } + return (join('/',@rootdirs) => join('/',@pathdirs) ); + } + +sub rootMapMeta { + # find all the explict path mapping from the link-mapping metadata + my $node = shift; + foreach my $child (@{$node->getChildNodes}) + { + if ($child->getNodeType==1 && $child->getTagName eq 'map-prefix') + { + my $from = $child->getAttribute('link'); + my $to = $child->getAttribute('to'); # optional, but blank if not set + $rootmap{$from} = $to; + } + } + # once this is processed we have no more need for it. Remove from output + $node->getParentNode->removeChild($node); + } + + +sub walk + { # walk through the doc, resolving all links + my $file = shift; + my $node = shift; + my $type = $node->getNodeType; + if($type!=1) {return} + my $tag = $node->getTagName; + if($tag=~/^(layer|package|collection|component)$/ ) + { + if($file eq $sysdef) + { + &fixIDs($node); # normalise all IDs in the root doc. Child docs are handled elsewhere. + } + my $link= $node->getAttribute('href'); + if($link) + { + my $file = &resolvePath($file,$link); + if(-e $file) + { + &combineLink($node,$file); + } + else + { + print STDERR "Note: $file not found\n"; + $node->removeAttribute('href'); + } + return; + } + else + { # only check for duplicate IDs on the implementation + my $id= $node->getAttribute('id'); + my $p = $node->getParentNode(); + my $ptext = $p->getTagName()." \"".$p->getAttribute('id')."\""; + if(defined $ID{$id}) + { + print STDERR "Error: duplicate ID: $tag \"$id\" in $ptext matches $ID{$id}\n"; + } + else + { + my $p = $node->getParentNode(); + $ID{$id}="$tag in $ptext"; + } + } + } + elsif($tag=~/^(SystemDefinition|systemModel)$/ ) + { + } + elsif($tag eq 'unit') + { + foreach my $atr ('bldFile','mrp','base','proFile') + { + my $link= $node->getAttribute($atr); + if($link && !($link=~/^\//)) + { + $link= &abspath(File::Basename::dirname($file)."/$link"); + foreach my $a (keys %rootmap) { + $link=~s,^$a,$rootmap{$a},ie; + } + # remove leading ./ which is used to indicate that paths should remain relative + $link=~s,^\./([^/]),$1,; + $node->setAttribute($atr,$link); + } + } + } + elsif($tag eq 'meta') + { + my $rel= $node->getAttribute('rel') || 'Generic'; + if($excludeMeta{$rel}) + { + $node->getParentNode->removeChild($node); + return; + } + my $link= $node->getAttribute('href'); + $link=~s,^file://(/([a-z]:/))?,$2,; # convert file URI to absolute path + if ($link ne '' ) + { + if($link=~/^[\/]+:/) + { + print STDERR "Note: Remote URL $link not embedded\n"; + next; # do not alter children + } + if(! ($link=~/^\//)) + { + $link= &abspath(File::Basename::dirname($file)."/$link"); + } + if(! -e $link) + { + print STDERR "Warning: Local metadata file not found: $link\n"; + next; # do not alter children + } + # if we're here we can just embed the file + # no processing logic is done! It's just embedded blindly + my $item; + eval { + my $metadoc = $parser->parsefile ($link); + $item = $metadoc->getDocumentElement; + }; + if(!$item) + { + print STDERR "Error: Could not process metadata file: $link\n"; + next; # do not alter children + } + $node->removeAttribute('href'); + &blindCopyInto($node,$item); + } + if($node->getAttribute('rel') eq 'link-mapping') + {# need to process this now + &rootMapMeta($node); + } + return; + } + else {return} + my $checkversion=0; + foreach my $item (@{$node->getChildNodes}) + { + #print $item->getNodeType,"\n"; + &walk($file,$item); + $checkversion = $checkversion || ($tag eq 'component' && $item->getNodeType==1 && $item->getAttribute('version') ne ''); + } + + if($checkversion && scalar(@config)) + { # need to check the conf metadata on the units in this component + &doCmpConfig($node); + } + foreach my $item (@{$node->getChildNodes}) + { + if ($item->getNodeType==1 && $item->getTagName eq 'meta') + { + &processMeta($item); + } + } + } + + +sub combineLink + { + # combine data from linked sysdef fragment w/ equivalent element in parent document + my $node = shift; + my $file = shift; + my $getfromfile = &localfile($file); + $getfromfile eq '' && return; # already raised warning, no need to repeat + my $doc = $parser->parsefile ($getfromfile); + my $item =&firstElement($doc->getDocumentElement); + $item || die "badly formatted $file"; + &fixIDs($item); + my %up = &atts($node); + my %down = &atts($item); + $up{'id'} eq $down{'id'} || die "$up{id} differs from $down{id}"; + $node->removeAttribute('href'); + foreach my $v (keys %up) {delete $down{$v}} + foreach my $v (keys %down) + { + $node->setAttribute($v,$down{$v}) + } + foreach my $child (@{$item->getChildNodes}) + { + ©Into($node,$child); + } + &walk($file,$node); + } + + +sub blindCopyInto + { + # make a deep copy the node (2nd arg) into the element (1st arg) + my $parent=shift; + my $item = shift; + my $doc = $parent->getOwnerDocument; + my $type = $item->getNodeType; + my $new; + if($type==1) + { + $new = $doc->createElement($item->getTagName); + my %down = &atts($item); + while(my($a,$b) = each(%down)) + { + $new->setAttribute($a,$b); + } + foreach my $child (@{$item->getChildNodes}) + { + &blindCopyInto($new,$child); + } + } + elsif($type==3) + { + $new = $doc->createTextNode ($item->getData); + } + elsif($type==8) + { + $new = $doc->createComment ($item->getData); + } + if($new) + { + $parent->appendChild($new); + } + } + +sub copyInto + { + # make a deep copy the node (2nd arg) into the element (1st arg) + my $parent=shift; + my $item = shift; + my $doc = $parent->getOwnerDocument; + my $type = $item->getNodeType; + my $new; + if($type==1) + { + &fixIDs($item); + $new = $doc->createElement($item->getTagName); + my %down = &atts($item); + foreach my $ordered ('id','name','bldFile','mrp','level','levels','introduced','deprecated','filter') + { + if($down{$ordered}) + { + $new->setAttribute($ordered,$down{$ordered}); + delete $down{$ordered} + } + } + while(my($a,$b) = each(%down)) + { + $new->setAttribute($a,$b); + } + foreach my $child (@{$item->getChildNodes}) + { + ©Into($new,$child); + } + } + elsif($type==3) + { + $new = $doc->createTextNode ($item->getData); + } + elsif($type==8) + { + $new = $doc->createComment ($item->getData); + } + if($new) + { + $parent->appendChild($new); + } + } + +sub getNs + { + # find the namespace URI that applies to the specified prefix. + my $node = shift; + my $pre = shift; + my $uri = $node->getAttribute("xmlns:$pre"); + if($uri) {return $uri} + my $parent = $node->getParentNode; + if($parent && $parent->getNodeType==1) + { + return getNs($parent,$pre); + } + } + + +sub fixIDs + { + # translate the ID to use the root doc's namespaces + my $node = shift; + foreach my $id ('id','before') + { + &fixID($node,$id); + } +} + +sub fixID + { + # translate the ID to use the root doc's namespaces + my $node = shift; + my $attr = shift || 'id'; + my $id = $node->getAttribute($attr); + if($id eq '') {return} + my $ns; + if($id=~s/^(.*)://) + { # it's got a ns, find out what it is + my $pre = $1; + $ns=&getNs($node,$pre); + } + else + { + $ns = $node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") || + $defaultns; + } + $ns = $urimap{$ns}; + $id = ($ns eq '') ? $id : "$ns:$id"; + return $node->setAttribute($attr,$id); +} + +sub firstElement { + # return the first element in this node + my $node = shift; + foreach my $item (@{$node->getChildNodes}) { + if($item->getNodeType==1) {return $item} + } +} + + +sub atts { + # return a hash of all attribtues defined for this element + my $node = shift; + my %at = $node->getAttributes; + my %list; + foreach my $a (keys %{$node->getAttributes}) + { + if($a ne '') + { + $list{$a} = $node->getAttribute ($a); + } + } + return %list; +} + + +sub ns + { + # return a hash of ns prefix and uri -- the xmlns: part is stripped off + my $node = shift; + my %list; + foreach my $a (keys %{$node->getAttributes}) + { + my $pre = $a; + if($pre=~s/^xmlns://) + { + $list{$pre} = $node->getAttribute ($a); + } + } + return %list; + } + + +sub resolvePath + { + # return full path to 2nd arg relative to first (path or absolute URI) + my $base = shift; + my $path = shift; + if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it. + if($path=~s,^file:///([a-zA-Z]:/),$1,) {return $path } # file URI with drive letter + 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 + if($path=~m,^[a-z0-9][a-z0-9]+:,i) {return $path } # absolute URI -- no idea how to handle, so just return + return &abspath(File::Basename::dirname($base)."/$path"); + } + + +sub resolveURI + { + # return full path to 2nd arg relative to first (path or absolute URI) + my $base = shift; + my $path = shift; + if($path=~m,[a-z0-9][a-z0-9]+:,i) {return $path } # absolute URI -- just return + if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it. + return &abspath(File::Basename::dirname($base)."/$path"); + } + +sub localfile + { + my $file = shift; + if($file=~s,file:///([a-zA-Z]:/),$1,) {return $file } # file URI with drive letter + if($file=~m,file://,) {return $file } # file URI with no drive letter (unit-style). Just pass on as is with leading / and let OS deal with it + if($file=~m,^([a-z0-9][a-z0-9]+):,i) + { + print STDERR "ERROR: $1 scheme not supported\n"; + return; # return empty string if not supported. + } + return $file + } + +sub namespaces + { + # return a list of namespace URI / prefix pairs, in the order they're defined + # these need to be used to define namespaces in the root element + my $file = shift; + my $node = shift; + my $type = $node->getNodeType; + if($type!=1) {return} + my $tag = $node->getTagName; + my @res; + my %nslist = &ns($node); + while(my($pre,$uri)=each(%nslist)) + { # push all namespaces defined here onto the list + push(@res,$uri,$pre); + } + if($tag=~/^(layer|package|collection|component)$/ ) + { # these have the potential of linking, so check for that + my $link= $node->getAttribute('href'); + if($link) + { + $link=&resolvePath($file,$link); + if(-e $link) + { + my $doc; + eval { + $doc = $parser->parsefile ($link); + }; + if($doc) + { + &checkSyntaxVersion($doc->getDocumentElement->getAttribute('schema')); # ensure we track we highest syntax number + my @docns = &namespaces($link,$doc->getDocumentElement); + undef $doc; + return (@res,@docns); + #ignore any children nodes if this is a link + } + print STDERR "Error: Malformed XML. Could not process $link\n"; + } + # print STDERR "Note: $link not found\n"; -- no need to warm now. Do so later when trying to join + } + } + elsif($tag eq 'SystemDefinition' ) + { + my $default = $node->getAttribute('id-namespace'); + if($default) + {# mangle with a space so it's clear it's not a qname + push(@res,$default,'id namespace'); + } + } + foreach my $item (@{$node->getChildNodes}) + { + push(@res,&namespaces($file,$item)); + } + return @res; + } + +sub processMeta + { # acts upon any known and strips it from the output if it's used + my $metanode = shift; + + my $rel = $metanode->getAttribute('rel') || 'Generic'; + if($rel eq 'config' && scalar(@config)) + { # only process if there is something to configure + &doconfig($metanode); + } + else + { + # do nothing. Not supported yet + } + } + +sub doCmpConfig + { # configure in or out the units in a component + my $cmp = shift; # the component node + my @unversioned; # list of all units with no version attribute (if more than one, they should all have filters defined) + my %versioned; # hash table of all units with a specified version, it's a fatal error to hav the same verison twice in one component + foreach my $item (@{$cmp->getChildNodes}) + { # populate %versioned and @unversioned to save processsing later + if($item->getNodeType==1 && $item->getTagName eq 'unit') + { + my $ver = $item->getAttribute('version'); + if($ver eq '') {push(@unversioned,$item)} + else + { + defined $versioned{$ver} && die "Cannot have more than one unit with version $ver in the same component ".$cmp->getAttribute('id'); + $versioned{$ver}=$item; + } + } + } + my @picks = &getMetaConfigPick($cmp); # the list, in order, of all elements that affect this component + foreach my $pick (@picks) + { + my $ver = $pick->getAttribute('version'); + if(!$versioned{$ver}) + { + print STDERR "ERROR: Reference to invalid unit version $ver in component ",$cmp->getAttribute('id'),". Ignoring.\n"; + return; + } + if(&definedMatches($pick)) + { # remove all other units; + delete $versioned{$ver}; # to avoid removing in loop + foreach my $unit (@unversioned, values(%versioned)) + { + $cmp->removeChild($unit); + print STDERR "Note: unit ",$unit->getAttribute('version')," in component " ,$cmp->getAttribute('id')," configured out\n"; + } + last; # done. No more processing after first match + } + else + { # remove this unit and continue + $cmp->removeChild($versioned{$ver}); + print STDERR "Note: unit $ver in component " ,$cmp->getAttribute('id')," configured out\n"; + delete $versioned{$ver}; # gone, don't process anymore; + } + } + if (scalar(@unversioned, values(%versioned)) > 1) + { + print STDERR "Warning: component ",$cmp->getAttribute('id')," has more than one unit after configuration\n"; + } + } + + +sub getMetaConfigPick + { # return an array of all elements that affect the specified element + my $node = shift; + my @pick; + while($node->getParentNode->getNodeType==1) + { + foreach my $item (@{$node->getChildNodes}) + { + my @picks; + if($item->getNodeType==1 && $item->getAttribute('rel') eq 'config') + { # it's conf metadata + foreach my $p (@{$item->getChildNodes}) + { + if($p->getNodeType==1 && $p->getTagName eq 'pick') {push(@picks,$p)} + } + } + @pick=(@picks,@pick); # prepend this to the start; + } + $node=$node->getParentNode; + } + return @pick; + } + +sub definedMatches + { # process all and the specified element and return true or false if the combination matches + my $node = shift; + my $match = 1; + foreach my $def (@{$node->getChildNodes}) + { + if($def->getNodeType == 1) + { + my $tag = $def->getTagName; + if($tag eq 'defined' or $tag eq 'not-defined') + { + my $var = $def->getAttribute('condition') || die "Must have condition set on all $tag elements"; + $defineParams{$var} && die "Cannot use a macro with parameters as a feature flag: $var(".$defineParams{$var}->[0].")"; + $match = $match && (($tag eq 'defined') ? defined($defines{$var}) : ! defined($defines{$var})); + } + } + } + return $match; + } + +sub doconfig + { # confgure in or out a system model item that owns the specified , remove the when done. + my $meta = shift; + my $keep = definedMatches($meta); + my $parent = $meta->getParentNode; + if(!$keep) + { + print STDERR "Note: ",$parent->getTagName," " ,$parent->getAttribute('id')," configured out\n"; + $parent->getParentNode->removeChild($parent); + return; # it's removed, so there's nothing else we can possibly do + } + + $parent->removeChild($meta); + } + +sub getDefines + { # populate the list of #defines from a specified .hrh file. + my $file = shift; + my $inc; + foreach my $i (@includes) + { + $inc.=" -I$i"; + } + open(CPP,"cpp -dD$inc \"$file\"|"); + while() + { + if(!/\S/){next} # skip blank lines + if(/^# [0-9]+ /) {next} # don't care about these + s/\s+$//; + if(s/^#define\s+(\S+)\((.*?)\)\s+//) + { #parametered define + push(@{$defineParams{$1}},@2,$_); + } + elsif(s/^#define\s+(\S+)//) + { # normal define + my $def = $1; + s/^\s+//; + $defines{$1}=$_; + } + else {die "cannot process $_";} + } + close CPP; + $? && die "Call to cpp produced an error"; + } + +sub checkSyntaxVersion + { # check if supplied version number is greater than $maxschema + my $schema = shift; + my @max=split(/\./,$maxschema); + my @cur=split(/\./,$schema); + while(@max) + { + ($max[0] > $cur[0]) && return; # max is bigger, do nothing + if($cur[0] > $max[0]) + { + $maxschema=$schema; + return; + } + shift @max; + shift @cur; + } + # they are equal - do nothing + } + +sub help + { + my $name= $0; $name=~s,^.*[\\/],,; +my $text; +format STDERR = + ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + $text, + ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ + $text +. +print STDERR "usage: $name [options...] sysdef\n valid options are:\n\n"; + foreach ( + "-path\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\"", + " This must be an absolute path if you're processing a root sysdef.", + " If processing a pkgdef file, you can use \"./package_definition.xml\" to leave all links relative.", + + "-output\tspecifies the file to save the output to. If not specified this will write to stdout", + + "-config\tspecifies the name of an .hrh file in which the configuration data is acquired from. If not set, no confguration will be done.", + " If it is set, all configuration metadata will be processed and stripped from the output, even if the confguration data is empty", + "-I[path]\tspecifies the include paths to use when resolving #includes in the .hrh file. This uses the same syntax as cpp command uses: a captial \"I\" followed by the path with no space in between. Any number of these can be provided.", + "-exclude-meta [rel]\tspecifies the 'rel' value of elements to exclude from the output. Any number of these can be provided. The following meta rel values affect the processing of the system definition and cannot be excluded: ".join(', ',@cannotExclude) + ) { + $text = $_; + write STDERR; + print STDERR "\n"; + } + + exit(1); + } + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/joinsysdef.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/joinsysdef.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,46 @@ + + + + + + + +/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml + + + + + + + + + + + + + + + + + + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/lib/filter-module.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/lib/filter-module.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + x + + + hide + + + + + + + + + + + + + + + + + + + + + + x + x + + + + hide + + + + + + + + + + + + + + + + x + + + hide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/lib/joinsysdef-module.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/lib/joinsysdef-module.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,525 @@ + + + + + http://www.symbian.org/system-definition + + + + + + ERROR: Cannot process this document () + + . Unrecognised syntax schema="" + . Missing schema + . Invalid file type: + + + + + + + + + + + + + + + + + + + + + ERROR: Linked ID "" () must match linking document "" () + + + + + + + + Note: Cannot set "", already set on . Ignoring linked value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Note: The link to from could not be resolved. Perhaps there's an error in the XML? + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz + + + + + + + ERROR: Cannot create namespace prefix for downstream default namespace in + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + + + + + + + + ERROR: Could not find namespace for "" in + + + + + + + + + + + + + + + + + ERROR: Joining error in resolving namespace for "" in + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/lib/mergesysdef-module.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/lib/mergesysdef-module.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,653 @@ + + + +http://www.symbian.org/system-definition + + + ERROR: Syntax not supported + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Warning: need definition for namespace "" for + + + + + + + + + + + ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz + + + + + + + ERROR: Cannot create namespace prefix for downstream default namespace in + + + + + + + + + + + + + + + + + + + + + + + + ERROR: Syntax not supported + + + ERROR: Can only merge system models of the same rank + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Note: levels differ "" vs "" on + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * + + + + + + + + + +<----> + + ="" + + + + rel="Generic" + type="auto" + > + + + + + + + + + + + + + + + + + Note: "" in "" + overridden in downstream sysdef + replaced by "" in "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Warning: "" moved in downstream model. Ignoring moved + + + + + + + + + + + + + + + + Warning: All content in downstream "" is invalid. Ignoring + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Warning: "" moved in downstream model. Ignoring moved + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: Could not resolve relative path in downstream file: relative to absolute URI + + + + + + + + + + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/lib/modelcheck.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/lib/modelcheck.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,74 @@ + + + + + + + + + + Cross-Checking System Model + + + + + + + + +

+ ()

+
+ + +

+ Note: + + + ()

+
+ + +

+ Warning: + + + ()

+
+ + +

+ Error: + + + ()

+
+ +
\ No newline at end of file diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/lib/path-module.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/lib/path-module.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + + + + + + + + + + + + + + + + + + + + + + ../ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + + + + + + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/lib/test-model.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/lib/test-model.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,578 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + System Definition: + items + + + + + + + + + + + + Definition: + units + + + + systemModel element should have a name + + + + + + + + + Attribute ="" is not valid for + + + + + + + + + + + + Attribute is deprecated + + + + + Extension attribute ="" in namespace + + + + + + + Should avoid using extension attribute ="" in namespace + + + + + + Attribute ="" not valid in schema . Must use schema 3.0.1 or higher + + + + + + + plugin + doc + tool + config + api + test + + + + mandatory + optional + development + + + other + desktop + device + + + + + lo + hb + mm + ma + pr + vc + se + ui + dc + de + dm + rt + to + ocp + + + + + + + + + + + + + + + + + + + + + Illegal value ="" + + + + value in ="" + + + + + + + + + + + + + + + + + Illegal value ="" + + + + value in ="" + + + + + + + + + + Element "" is not valid in the context of "" + + + + "" has invalid parent "" + + + + + + + + + + + + S60 Component "" has units. + + + Component "" has units. + + + + + + + Component "" is empty. + + + Component "" is empty and has no comment + + + + + + + "" must match ID in linked file "" + + + linked "" cannot be a link + + + + linked "" has duplicate attribute to linking document. Duplicate ignored. + + + + "" cannot have both link and content. Content ignored. + + + + "" must match item in linked file "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Duplicate ID: "" + + + + Undefined namespace for ID "" + + + + + + + + / + + + + + + path "" should not end in / + + + path "" must use only forward slashes + + + + + + + + + + + + + + + + + // + / + + + + + + / + + + + + + // + + + Unexpected path for -> : "" + + + + + + + + path "" should not end in / + + + path "" must use only forward slashes + + + + + + + + + + + + + + + // + / + + + + + + + + + + + + + + + + + + + + + + + Unexpected path for -> : "" + + + + + + + + Unexpected path for -> : "" + + + Unexpected path for -> : "" + + + Unexpected path for -> : "" + + + + + + + + + + + + + has no match in . + + + + + + + : + + + + + + + + + + + not identical. [|] + + + + + + + + + + + + not identical. [|] + + + + () + + +vp cross-check + + + + + + + + + VP component "" v not in SysDef + + + + + + + Found + Found + + + + + + + + + + + + + +System Build cross-check + + + + + + + + Build item "" not in SysDef + + + + + + Build list "" not defined + + + + + + + + + + + () + () + (? - ) + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + \ No newline at end of file diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/lib/usage.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/lib/usage.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + usage: + + [>] [params ...] > + + +The input file must be last. Other arguments can be in any order. +Parameters are case-sensitive. Text parameter values must be in single quotes. + + +Arguments can be in any order. +Parameters are case-sensitive. + + +The input file must be last. Other arguments can be in any order. +Parameters are case-sensitive. + + + + + + + + + + + + + + + + + + + + + + -p + + + -param + + + --string-param + + + + + + + + + + Defaults to + '' + "" + "" + + + + + + +Description + + + + + + + + + + + + + + + + + + + + + + + + + + -in + + + <xml> - (required) The input XML file + + + + + + + + + + + + + -o + + + -out + + + -o + + + <file> - (optional) The file to save the output as. If not present it will write to stdout. + + + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/mergesysdef.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/mergesysdef.bat Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,21 @@ +@rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +@rem All rights reserved. +@rem This component and the accompanying materials are made available +@rem under the terms of the License "Eclipse Public License v1.0" +@rem which accompanies this distribution, and is available +@rem at the URL "http://www.eclipse.org/legal/epl-v10.html". +@rem +@rem Initial Contributors: +@rem Nokia Corporation - initial contribution. +@rem +@rem Contributors: +@rem +@rem Description: +@rem +@setlocal +@if .%1==. goto use +@ java -jar %~dp0xalanj\xalan.jar -xsl %~dpn0.xsl %* -XSLTC +@goto end +:use +@ java -jar %~dp0xalanj\xalan.jar -in %~dpn0.xsl -xsl %~dp0lib\usage.xsl -param usage "%~n0" +:end diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/mergesysdef.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/mergesysdef.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,142 @@ + + + + + + + + + mcl/System_Definition_Template.xml + + + + + + + Syntax not supported + + + Can only merge fragments of the same rank + + + + + Upstream + + + + + + + + + + + + Downstream + + + + Can only merge fragments of the same rank + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/rootsysdef.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/rootsysdef.bat Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,17 @@ +@rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +@rem All rights reserved. +@rem This component and the accompanying materials are made available +@rem under the terms of the License "Eclipse Public License v1.0" +@rem which accompanies this distribution, and is available +@rem at the URL "http://www.eclipse.org/legal/epl-v10.html". +@rem +@rem Initial Contributors: +@rem Nokia Corporation - initial contribution. +@rem +@rem Contributors: +@rem +@rem Description: +@rem +@setlocal +@perl %~dpn0.pl %* + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/rootsysdef.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/rootsysdef.pl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,809 @@ +# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# This will create a new root system definition file based on the provided template +#!/usr/bin/perl + +use strict; + + +use FindBin; # for FindBin::Bin +use lib $FindBin::Bin; +use lib "$FindBin::Bin/lib"; + +use Cwd; +use Cwd 'abs_path'; +use Getopt::Long; +use File::Basename; +use File::Spec; +use XML::DOM; + +my $output; +my $path; +my $defaultns = 'http://www.symbian.org/system-definition'; # needed if no DTD +my @searchpaths; +my @searchroots; +my %additional; +my %add; +my %newNs; +my $warning = "Error"; +my $placeholders=0; +my $sysmodelname; + +my @tdOrder =("hb","se", "lo","dc", "vc" , "pr", "dm", "de", "mm", "ma" , "ui", "rt", "to" ); + +sub help + { + my $name= $0; $name=~s,^.*[\\/],,; + 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", + "\nvalid options are:\n", + " -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", + "\t\tThis is only needed when creating a stand-alone sysdef as the output", + + " -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", + + " -w [Note|Warning|Error]\tspecifies prefix text for any notifications. Defautls to Error\n\n", + " -root [dir]\tspecifies the root directory of the filesystem. All globbing will be done relative to this path\n\n", + + " -glob [wildcard path]\tThe wildcard search to look for pkgdef files. eg \"\\*\\*\package_definition.xml\". Can specify any number of these.\n", + " -placeholders [bool]\tif set, all packages not found in the template will be left in as empty placeholders\n"; + " -name [text]\tthe name in to use for the generated root sysdef. If not present, this will use the name from the templat\n"; + exit(1); + } + +GetOptions + ( + 'path=s' => \$path, + 'name=s' => \$sysmodelname, + 'output=s' => \$output, + 'w=s' => \$warning, + 'root=s' => \@searchroots, + 'glob=s' => \@searchpaths, + 'placeholders=s' => \$placeholders + ); + + + if($path eq '') {$path = '/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml'} + +if(!($warning =~/^(Note|Warning|Error)$/)) {$warning="Error"} + +# path is the system model path of the processed sysdef file. This is only used when creating a stand-alone sysdef as the output +# 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 +# w is the warning level: Note, Warning or Error. +# root = -root g:\sf +# glob = -glob "\*\*\package_definition.xml" + +#Example command lines: +#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 +#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 +if(!scalar @ARGV && !scalar @searchpaths) {&help()}; + + +my %replacefile; +my $dir; +foreach(@searchpaths) + { + my $ndir = shift(@searchroots); + if($ndir ne '') {$dir=$ndir} + foreach my $file (glob "$dir$_") + { + my $map =substr($file,length($dir)); + $map=~tr/\\/\//; + $additional{$map}=$file; + $replacefile{&abspath($file)}=$map; + $add{&abspath($file)}=1; + } + } + +my $parser = new XML::DOM::Parser; +my $sysdef; +my %rootmap; +my $sysdefdoc; +if(scalar @ARGV) + { + $sysdef = &abspath(shift); # resolve the location of the root sysdef + + # rootmap is a mapping from the filesystem to the paths in the doc + %rootmap = &rootMap($path,$sysdef); + + $sysdefdoc = $parser->parsefile ($sysdef); + } +else + { + $sysdefdoc = $parser->parse(''); + } + +my %nsmap; +my %urimap; + +my $mapmeta; +my $modpath; +if($output eq '') + { #figure out mapping path + my @fspath = split(/[\\\/]/,$sysdef); + my @smpath = split(/[\\\/]/,$path); + while(lc($smpath[$#smpath]) eq lc($fspath[$#fspath] )) { + pop(@smpath); + pop(@fspath); + } + my $mappath = join('/',@fspath); + my $topath = join('/',@smpath); + $mappath=~s,^/?,file:///,; + $mapmeta = $sysdefdoc->createElement('meta'); + $mapmeta->setAttribute('rel','link-mapping'); + my $node = $sysdefdoc->createElement('map-prefix'); + $node->setAttribute('link',$mappath); + $topath ne '' && $node->setAttribute('to',$topath); + $mapmeta->appendChild($node); + } +else + { + $modpath = &relativeTo(&abspath($output), $sysdef); + } + + +# find all the namespaces used in all the fragments and use that +# to set the namespaces in the root element of the created doc +# should be able to optimise by only parsing each doc once and +# maybe skipping the contends of +my @nslist = &namespaces($sysdef,$sysdefdoc->getDocumentElement()); + +my %replacing; +my %newContainer; +my %foundDescendants; + +foreach(keys %add) + { + my $fragment = $parser->parsefile ($_); + my $fdoc = $fragment->getDocumentElement(); + my $topmost =&firstElement($fdoc); + if(!$topmost) { + print STDERR "$warning: $_ has no content. Skipping\n"; + next; + } + my $type = $topmost->getTagName; + my $id = $topmost->getAttribute('id'); + my ($localid,$ns) = &idns($topmost,$id); + my @path = &guessIdInPath($localid,$_); + if($type eq 'layer') {@path=@path[0]} + elsif($type eq 'package') {@path=@path[0..1]} + elsif($type eq 'collection') {@path=@path[0..2]} + elsif($type eq 'component') {@path=@path[0..3]} + @path = reverse(@path); + $add{$_}=join('/',@path)." $localid $ns"; + $replacing{$type}->{"$localid $ns"} = $_; + # keys with a space are namespaced and fully identified, and contain the filename as the content. + # keys with no space have unknown namespace and contain a hash of the content + $newContainer{join('/',@path[0..$#path-1])}->{"$localid $ns"} = $_; + for(my $i=-1;$i<$#path-1;$i++) + { + $foundDescendants{$path[$i+1]}=1; + $newContainer{join('/',@path[0..$i])}->{$path[$i+1]}=1; + } + } + + +while(@nslist) + { + my $uri = shift(@nslist); + my $prefix =shift(@nslist); + if($prefix eq 'id namespace'){$prefix=''} + if(defined $urimap{$uri}) {next} # already done this uri + $urimap{$uri} = $prefix; + if($nsmap{$prefix}) + { # need a new prefix for this, guess from the URI (for readability) + if($uri=~/http:\/\/(www\.)?([^.\/]+)\./) {$prefix = $2} + my $i=0; + while($nsmap{$prefix}) + { # still no prefix, just make up + $prefix="ns$i"; + $i++; + # next line not really necessary, but it's a good safety to stop infinite loops + $i eq 1000 && die "ERROR: cannot create namespace prefix for $uri"; + } + } + $nsmap{$prefix}=$uri; + } + +my $docroot = $sysdefdoc->getDocumentElement; + +my $ns = $docroot->getAttribute('id-namespace'); +if(!$ns && $nsmap{''}) + { + $docroot->setAttribute('id-namespace',$nsmap{''}); + } +while(my($pre,$uri) = each(%nsmap)) + { + $pre ne '' || next ; + $docroot->setAttribute("xmlns:$pre",$uri); + } + +&walk($sysdef,$docroot); + +if($output eq '') + { + print $sysdefdoc->toString; + } +else + { + $sysdefdoc->printToFile($output); + } + + +sub abspath + { + # normalize the path into an absolute one + my ($name,$path) = fileparse($_[0]); + if($path eq '' && $name eq '') {return}; + $path=~tr,\\,/,; + if( -e $path) + { + return abs_path($path)."/$name"; + } + my @dir = split('/',$_[0]); + my @new; + foreach my $d (@dir) + { + if($d eq '.') {next} + if($d eq '..') + { + pop(@new); + next; + } + push(@new,$d) + } + return join('/',@new); + } + + + +sub normpath + { + # normalize the path + my @norm; + foreach my $dir(split(/[\\\/]/,shift)) { + if($dir eq '.') {next} + if($dir eq '..') + { + if($#norm == -1 || $norm[$#norm] eq '..') + { # keep as is + push(@norm,$dir); + } + elsif($#norm == 0 && $norm[0] eq '') + { # path begins with /, interpret /.. as just / -- ie toss out + next + } + else + { + pop(@norm); + } + } + else + { + push(@norm,$dir); + } + } + + return join('/',@norm) + } + + +sub rootMap { + my @pathdirs = split(/\//,$_[0]); + my @rootdirs = split(/\//,$_[1]); + + while(lc($rootdirs[$#rootdirs]) eq lc($pathdirs[$#pathdirs]) ) + { + pop(@rootdirs); + pop(@pathdirs); + } + return (join('/',@rootdirs) => join('/',@pathdirs) ); + } + +sub replacedBy + { # can only check once. Destroys data + my $node = shift; + my $fullid= join(' ',&idns($node)); + my $type = $node->getTagName; + my $repl = $replacing{$type}->{$fullid}; + delete $replacing{$type}->{$fullid}; + return $repl; + } + +sub walk + { + #' walk through the doc, resolving all links + my $file = shift; + my $node = shift; + my $type = $node->getNodeType; + if($type!=1) {return} + my $tag = $node->getTagName; + if($tag=~/^(layer|package|collection|component)$/ ) + { + if($file eq $sysdef) + { + &fixIDs($node); # normalise all IDs in the root doc. + } + my $override = &replacedBy($node); + my $link= $node->getAttribute('href'); + if($override eq '' ) + { + my ($id,$ns)=&idns($node); + if($foundDescendants{$id}) + { # keep this node, it'll be populated by what we found + if($link) + { + $node->removeAttribute('href'); + } + } + elsif($link || !$placeholders) + { # not going to be used, remove + $node->getParentNode->removeChild($node) ; # not present, remove + return; + } + } + else + { + my $href = $node->getAttribute('href'); + my $ppath = join('/',&parentPath($node->getParentNode)); + delete $newContainer{$ppath}->{join(' ',&idns($node))}; # remove this from list of things which need to be added + if(&resolvePath($file,$href) ne $override) + { # file has changed, update + print STDERR "$warning: Replacing $tag ",$node->getAttribute('id')," with $override\n"; + &setHref($node,$override); + return; + } + } + my @curpath = &parentPath($node); + my $curitem = $curpath[$#curpath]; + my $curp = join('/',@curpath[0..$#curpath-1]); + delete $newContainer{$curp}->{$curitem}; + + if($link) + { + foreach my $child (@{$node->getChildNodes}) {$node->removeChild($child)} # can't have children + &fixHref($node,$file); + return; + } + } + elsif($tag eq 'systemModel' && $mapmeta) + { # need absolute paths for all links + $node->insertBefore ($mapmeta,$node->getFirstChild); + $sysmodelname eq '' || $node->setAttribute('name',$sysmodelname); + } + elsif($tag=~/^(SystemDefinition|systemModel)$/ ) + { + ($sysmodelname ne '' && $tag eq 'systemModel') && $node->setAttribute('name',$sysmodelname); + } + elsif($tag eq 'unit') + { + foreach my $atr ('bldFile','mrp','base','proFile') + { + my $link= $node->getAttribute($atr); + if($link && !($link=~/^\//)) + { + if($mapmeta) + { # use absolute paths + $link= &abspath(File::Basename::dirname($file)."/$link"); + foreach my $a (keys %rootmap) + { + $link=~s,^$a,$rootmap{$a},ie; + } + } + else + { # modified relative path + $link = &normpath($modpath.$link); + } + $node->setAttribute($atr,$link); + } + } + } + elsif($tag eq 'meta') + { + &fixHref($node,$file); + foreach my $child (@{$node->getChildNodes}) {$node->removeChild($child)} # can't have children + &processMeta($node); + next; + } + else {return} + foreach my $item (@{$node->getChildNodes}) + { + #print $item->getNodeType,"\n"; + &walk($file,$item); + } + if($tag=~/^(systemModel|layer|package|collection|component)$/ ) + { # check for appending + my $ppath = join('/',&parentPath($node)); + if($newContainer{$ppath}) { + foreach my $item (sort keys %{$newContainer{$ppath}}) + { + &appendNewItem($node,$item,$newContainer{$ppath}->{$item}); + } + } + } + } + + +sub getNs + { + # find the ns URI that applies to the specified prefix. + my $node = shift; + my $pre = shift; + my $uri = $node->getAttribute("xmlns:$pre"); + if($uri) {return $uri} + my $parent = $node->getParentNode; + if($parent && $parent->getNodeType==1) + { + return getNs($parent,$pre); + } + } + + +sub fixIDs + { + # translate the ID to use the root doc's namespaces + my $node = shift; + foreach my $id ('id','before') + { + &fixID($node,$id); + } +} + +sub idns + { # return the namespace of an ID + my $node = shift; + my $id = shift; + if($id eq '' ) {$id = $node->getAttribute('id'); } + if($id=~s/^(.*)://) + { # it's got a ns, find out what it is + my $pre = $1; + return ($id,&getNs($node,$pre)); + } + return ($id,$node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") || $defaultns); + } + +sub fixID + { + # translate the ID to use the root doc's namespaces + my $node = shift; + my $attr = shift || 'id'; + my $id = $node->getAttribute($attr); + if($id eq '') {return} + my $ns; + if($id=~s/^(.*)://) + { # it's got a ns, find out what it is + my $pre = $1; + $ns=&getNs($node,$pre); + } + else + { + $ns = $node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") || + $defaultns; + } + $ns = $urimap{$ns}; + $id = ($ns eq '') ? $id : "$ns:$id"; + return $node->setAttribute($attr,$id); +} + +sub firstElement { + # return the first element in this node + my $node = shift; + foreach my $item (@{$node->getChildNodes}) { + if($item->getNodeType==1) {return $item} + } +} + + +sub atts { + # return a hash of all attribtues defined for this element + my $node = shift; + my %at = $node->getAttributes; + my %list; + foreach my $a (keys %{$node->getAttributes}) + { + if($a ne '') + { + $list{$a} = $node->getAttribute ($a); + } + } + return %list; +} + + +sub ns + { + # return a hash of ns prefix and uri -- the xmlns: part is stripped off + my $node = shift; + my %list; + foreach my $a (keys %{$node->getAttributes}) + { + my $pre = $a; + if($pre=~s/^xmlns://) + { + $list{$pre} = $node->getAttribute ($a); + } + } + return %list; + } + + + +sub namespaces + { + # return a list of namespace URI / prefix pairs, in the order they're defined + # these need to be used to define namespaces in the root element + my $file = shift; + my $node = shift; + my $type = $node->getNodeType; + if($type!=1) {return} + my $tag = $node->getTagName; + my @res; + my %nslist = &ns($node); + while(my($pre,$uri)=each(%nslist)) + { # push all namespaces defined here onto the list + push(@res,$uri,$pre); + } + if($tag=~/^(layer|package|collection|component)$/ ) + { # these have the potential of linking, so check for that + } + elsif($tag eq 'SystemDefinition' ) + { + my $default = $node->getAttribute('id-namespace'); + if($default) + {# mangle with a space so it's clear it's not a qname + push(@res,$default,'id namespace'); + } + } + foreach my $item (@{$node->getChildNodes}) + { + push(@res,&namespaces($file,$item)); + } + return @res; + } + +sub processMeta + { + my $metanode = shift; + # do nothing. Not supported yet + } + +sub guessIdInPath + { + my $id = shift; + my @path = reverse(split(/\//,$_[0])); + while(@path) + { + my $dir = shift(@path); + if($dir eq $id) + { + return ($id,@path); + } + } + print STDERR "$warning: Non-standard ID $id in $_[0]\n"; + @path = reverse(split(/\//,$_[0])); + if($path[0] eq 'package_definition.xml') + { + return @path[1..$#path]; + } + } + + +sub parentPath + { + my $node=shift; + my @path; + while($node) + { + if(!$node) {return @path} + my $id=$node->getAttribute('id'); + if($id eq '') {return @path} + $id=~s/^.*://; + @path = ($id,@path); + $node = $node->getParentNode(); + } + return @path; + } + +sub childTag + { + my $tag = shift; + if($tag eq 'systemModel') {return 'layer'} + if($tag eq 'layer') {return 'package'} + if($tag eq 'package') {return 'collection'} + if($tag eq 'collection') {return 'component'} + die "ERROR: no child for $tag"; + } + +sub appendNewItem + { + my $node = shift; + my $doc = $node->getOwnerDocument; + my $id = shift; + if($id eq '') {return} + my $fullid=$id; + my $contents = shift; + my $tag = &childTag($node->getTagName()); + my $new = $doc->createElement($tag); + if($id=~/^(.*) (.*)/) + { + $id=$1; + $ns = getNamespacePrefix($node,$2); + if($ns ne '') {$id="$ns:$id"} + } + else + { + $contents = ''; + } + $new->setAttribute('id',$id); # default namespace + $node->appendChild($new); + my $ppath = join('/',&parentPath($new)); + if($contents eq '') + { # look for additions + print STDERR "$warning: Adding new $tag: $id\n"; + if($newContainer{$ppath}) { + foreach my $item (sort keys %{$newContainer{$ppath}}) + { + &appendNewItem($new,$item,$newContainer{$ppath}->{$item}); + } + } + } + else + { # this one item is defined in the specified file + if($tag eq 'package') + { #include some package data in root + my $fragment = $parser->parsefile ($contents); + my $fdoc = $fragment->getDocumentElement(); + my $topmost =&firstElement($fdoc); + my %at = &atts($topmost); + foreach my $arg ('tech-domain','level','span') + { + if($at{$arg}) { $new->setAttribute($arg,$at{$arg})} + } + if($at{'tech-domain'}) {&positionByTechDomain($new)} + } + &setHref($new,$contents); + print STDERR "$warning: Adding found $tag $id from $contents\n"; + delete $replacing{$tag}->{$fullid}; + } + # newline after each new tag so output's not ugly + if($new->getNextSibling) + { + $node->insertBefore($doc->createTextNode ("\n"),$new->getNextSibling); + } + else + { + $node->appendChild($doc->createTextNode ("\n")); + } + delete $newContainer{$ppath}; + } + + +sub getNamespacePrefix + { + my $node = shift; + my $ns = shift; + my $root = $node->getOwnerDocument->getDocumentElement; + my $idns = $root->getAttribute("id-namespace"); + if($idns && $idns eq $ns) {return} + if(!$idns && $defaultns eq $ns) {return} + foreach my $a (keys %{$root->getAttributes}) + { + my $pre = $a; + if($pre=~s/^xmlns://) + { + if($root->getAttribute ($a) eq $ns) {return $pre} + } + } + die "ERROR: no namespace prefix defined for $ns"; + } + + +sub resolvePath + { + # return full path to 2nd arg relative to first (path or absolute URI) + my $base = shift; + my $path = shift; + if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it. + if($path=~s,^file:///([a-zA-Z]:/),$1,) {return $path } # file URI with drive letter + 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 + if($path=~m,^[a-z0-9][a-z0-9]+:,i) {return $path } # absolute URI -- no idea how to handle, so just return + return &abspath(File::Basename::dirname($base)."/$path"); + } + + +sub fixHref { + my $node = shift; + my $base = shift; + my $link= $node->getAttribute('href'); + if($link=~/^(ftp|http)s:\/\//) {return} # remote link, do nothing + my $path = &resolvePath($base,$link); + if(!-e $path) + { # no such file, delete + my $tag =$node->getTagName; + my $id = $node->getAttribute('id'); + print STDERR "$warning: $tag $id not found at $link\n"; + $node->getParentNode->removeChild($node); + return; + } + foreach my $child (@{$node->getChildNodes}) {$node->removeChild($child)} # can't have children + if($output eq '') + { + $path=~s,^/?,file:///,; + $node->setAttribute('href',$path); # replace with absolute URI + return; + } + $node->setAttribute('href',&normpath($modpath.$link)); # make relative path to output file + } + + +sub setHref { + my $node = shift; + my $file = shift; + if($output eq '') + { + $path = &abspath($file); + $path=~s,^/?,file:///,; + $node->setAttribute('href',$path); # replace with absolute URI + } + else + { + $node->setAttribute('href',&relativeTo(&abspath($output),$file,'file')); + } + while(my $child = $node->getFirstChild ) {$node->removeChild($child)} +} + + +sub relativeTo { + if($_[0] eq '') {return &abspath($_[1])} + my @outfile = split(/[\\\/]/,lc(shift)); + my @infile = split(/[\\\/]/,lc(shift)); + my $asdir = shift ne 'file'; + while($outfile[0] eq $infile[0]) + { + shift(@outfile); + shift(@infile); + } + $modpath = '../' x (scalar(@outfile) - 1); + if($asdir) { + if(scalar @infile > 1) {$modpath .= join('/',@infile[0..$#infile - 1]).'/'} + } else {$modpath .= join('/',@infile)} + return $modpath; +} + +sub positionByTechDomain + { + my $node=shift; + my $td = $node->getAttribute('tech-domain'); + my %before; + foreach my $t (@tdOrder) + { + $before{$t}=1; + if($t eq $td) {last} + } + my $prev = $node->getPreviousSibling; + foreach my $child (reverse @{$node->getParentNode->getChildNodes}) + { + if($child->getNodeType==1 && $child->getTagName eq 'package' && $child!=$node) + { + if($before{$child->getAttribute('tech-domain')}) + { + my $next = $child->getNextSibling; + while($next && $next->getNodeType!=1) {$next = $next->getNextSibling} + if($next) { + $node->getParentNode->insertBefore ($node,$next); + } + last; + } + } + } + } diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/sysdefdowngrade.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/sysdefdowngrade.bat Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,21 @@ +@rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +@rem All rights reserved. +@rem This component and the accompanying materials are made available +@rem under the terms of the License "Eclipse Public License v1.0" +@rem which accompanies this distribution, and is available +@rem at the URL "http://www.eclipse.org/legal/epl-v10.html". +@rem +@rem Initial Contributors: +@rem Nokia Corporation - initial contribution. +@rem +@rem Contributors: +@rem +@rem Description: +@rem +@setlocal +@if .%1==. goto use +@ java -jar %~dp0xalanj\xalan.jar -xsl %~dpn0.xsl %* -XSLTC +@goto end +:use +@ java -jar %~dp0xalanj\xalan.jar -in %~dpn0.xsl -xsl %~dp0lib\usage.xsl -param usage "%~n0" +:end diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/sysdefdowngrade.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/sysdefdowngrade.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,438 @@ + + + + + + + + + + + + os/deviceplatformrelease/foundation_system/system_model + + + + + + + + ERROR: Cannot process this document + + + + + + + + + + + + + + + + + + + + ERROR: Package definition () cannot link another package + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: Package IDs do not match: vs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WARNING: Excessive nesting of packages: Ignoring + + + + + + + + + + + + + + + + + + + + + Y + + + plugin + + placeholder + PC + + + + + + + + + + + + + + + + + + + + + + + + + + + + Y + N + + + + + + + + + + + / + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]> +]]> + + diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/validate-sysdef.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/validate-sysdef.bat Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,21 @@ +@rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +@rem All rights reserved. +@rem This component and the accompanying materials are made available +@rem under the terms of the License "Eclipse Public License v1.0" +@rem which accompanies this distribution, and is available +@rem at the URL "http://www.eclipse.org/legal/epl-v10.html". +@rem +@rem Initial Contributors: +@rem Nokia Corporation - initial contribution. +@rem +@rem Contributors: +@rem +@rem Description: +@rem +@setlocal +@if .%1==. goto use +@ java -jar %~dp0xalanj\xalan.jar -xsl %~dpn0.xsl %* +@goto end +:use +@ java -jar %~dp0xalanj\xalan.jar -in %~dpn0.xsl -xsl %~dp0lib\usage.xsl -param usage "%~n0" +:end diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/validate-sysdef.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/validate-sysdef.xsl Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + () + + + + + + Note: + + () + + + + + + Warning: + + () + + + + + Error: + + () + + + \ No newline at end of file diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/xalanj/LICENSE.xalan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metatools/sysdeftools/xalanj/LICENSE.xalan Wed Jul 28 13:20:46 2010 +0100 @@ -0,0 +1,55 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Xalan", "Xerces", and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation and was + * originally based on software copyright (c) 1999, International + * Business Machines, Inc., http://www.apache.org. For more + * information on the Apache Software Foundation, please see + * . + */ diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/xalanj/serializer.jar Binary file metatools/sysdeftools/xalanj/serializer.jar has changed diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/xalanj/xalan.jar Binary file metatools/sysdeftools/xalanj/xalan.jar has changed diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/xalanj/xercesImpl.jar Binary file metatools/sysdeftools/xalanj/xercesImpl.jar has changed diff -r 96fee2635b19 -r f70b728ea30c metatools/sysdeftools/xalanj/xml-apis.jar Binary file metatools/sysdeftools/xalanj/xml-apis.jar has changed diff -r 96fee2635b19 -r f70b728ea30c package_definition.xml --- a/package_definition.xml Tue Jul 27 13:00:43 2010 +0800 +++ b/package_definition.xml Wed Jul 28 13:20:46 2010 +0100 @@ -8,18 +8,23 @@ - + - + - + + + + + +