updates to validation scripts and bugfixes for rootsysdef HighFidelityModel
authorBob Rosenberg <bob.rosenberg@nokia.com>
Tue, 22 Jun 2010 10:59:57 +0100
branchHighFidelityModel
changeset 312 9527bd30de64
parent 311 e9d0240c3e66
child 314 e2c657c13ee2
updates to validation scripts and bugfixes for rootsysdef
sysdeftools/rootsysdef.pl
sysdeftools/validate/checklinks.pl
sysdeftools/validate/test-model.xsl
--- a/sysdeftools/rootsysdef.pl	Fri Jun 18 09:49:13 2010 +0100
+++ b/sysdeftools/rootsysdef.pl	Tue Jun 22 10:59:57 2010 +0100
@@ -38,6 +38,7 @@
 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" );
 
@@ -54,14 +55,16 @@
 		"  -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",
+		"  -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 <systemModel> 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,
@@ -83,7 +86,7 @@
 #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) {&help()};
+if(!scalar @ARGV && !scalar @searchpaths) {&help()};
 
 
 my %replacefile;
@@ -102,19 +105,27 @@
 		}
 	}
 
-my $sysdef = &abspath(shift);	# resolve the location of the root sysdef
-
+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
-my %rootmap = &rootMap($path,$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('<SystemDefinition schema="3.0.1"><systemModel name="System Model"/></SystemDefinition>');
+	}
+
 my %nsmap;
 my %urimap;
 
-
-
-my $parser = new XML::DOM::Parser;
-my   $sysdefdoc = $parser->parsefile ($sysdef);
-
 my $mapmeta;
 my $modpath;
 if($output eq '')
@@ -368,9 +379,11 @@
 	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')
 		{
--- a/sysdeftools/validate/checklinks.pl	Fri Jun 18 09:49:13 2010 +0100
+++ b/sysdeftools/validate/checklinks.pl	Tue Jun 22 10:59:57 2010 +0100
@@ -81,7 +81,14 @@
 my %urimap;
 
 my $parser = new XML::DOM::Parser;
-my   $sysdefdoc = $parser->parsefile ($sysdef);
+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.
@@ -212,6 +219,7 @@
 			if($link ne '')
 				{
 				my $ok = 0;
+				my $trylink;
 				if($link && !($link=~/^\//))
 					{
 					$link= &abspath(File::Basename::dirname($file)."/$link");
@@ -231,7 +239,7 @@
 					{
 					foreach my $a (keys %unitmap) {
 						if($a eq substr($link,0,length($a))) {
-							my $trylink = $unitmap{$a}.substr($link,length($a));
+							$trylink = $unitmap{$a}.substr($link,length($a));
 							if(-e "$trylink$ext") {
 								$ok=1;
 								$link = $trylink;
@@ -242,7 +250,7 @@
 					}
 				if(!$ok)
 					{
-					print "Error: $atr not found in $link$filter\n";
+					print "Error: $atr not found in ",($trylink ne '') ? $trylink : $link,"$filter\n";
 					}				
 				}
 			}
@@ -310,24 +318,20 @@
 	my $file = shift;
 	my $getfromfile = &localfile($file);
 	$getfromfile eq '' && return;  # already raised warning, no need to repeat
-	my  $doc = $parser->parsefile ($getfromfile);
+	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";	
-	&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})
-		{
-		&copyInto($node,$child);
-		}
-	&walk($file,$node);
+	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);
 	}
 
 
@@ -341,7 +345,6 @@
 	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')
@@ -375,6 +378,26 @@
 		}
 	}
 
+
+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.
@@ -390,38 +413,6 @@
 	}
 
 
-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
--- a/sysdeftools/validate/test-model.xsl	Fri Jun 18 09:49:13 2010 +0100
+++ b/sysdeftools/validate/test-model.xsl	Tue Jun 22 10:59:57 2010 +0100
@@ -13,6 +13,7 @@
 	Module containing the validation logic for system definition 3.0.0 syntax
 -->
 	<xsl:key name="named" match="*[ancestor::systemModel]" use="@name"/>
+	<xsl:param name="path-errors" select="0"/>
 	<xsl:param name="Filename"/>
 	<xsl:variable name="info" select="document(/model//info[@type='extra']/@href,/model)//c"/>
 
@@ -90,7 +91,7 @@
 	<xsl:call-template name="Error"><xsl:with-param name="text">Attribute <xsl:value-of select="name()"/>="<xsl:value-of select="."/>" is not valid for <xsl:value-of select="name(..)"/></xsl:with-param></xsl:call-template>
 </xsl:template>
 
-<xsl:template match="@before|@id|package/@span|collection/@level|package/@level|package/@levels|layer/@levels" mode="valid"/> <!-- really should check syntax -->
+<xsl:template match="@before|@id|package/@span|layer/@span|collection/@level|package/@level|package/@levels|layer/@levels" mode="valid"/> <!-- really should check syntax -->
 
 <xsl:template match="@name|@href|@filter" mode="valid"/> 
 
@@ -211,11 +212,12 @@
 <xsl:apply-templates select="@id"/>
 <xsl:if test="self::component">
 	<xsl:choose>
+		<xsl:when test="count(unit[not(@filter | @version)]) = 0 "/>
 		<xsl:when test="count(unit[not(@version)]) &gt; 1 and @filter='s60'">
-			<xsl:call-template name="Warning"><xsl:with-param name="text">S60 Component "<xsl:value-of select="@id"/>" has <xsl:value-of select="count(*)"/> children.</xsl:with-param></xsl:call-template>
+			<xsl:call-template name="Warning"><xsl:with-param name="text">S60 Component "<xsl:value-of select="@id"/>" has <xsl:value-of select="count(unit)"/> units.</xsl:with-param></xsl:call-template>
 		</xsl:when>
 		<xsl:when test="count(unit[not(@version)]) &gt; 1">
-			<xsl:call-template name="Error"><xsl:with-param name="text">Component "<xsl:value-of select="@id"/>" has <xsl:value-of select="count(*)"/> children.</xsl:with-param></xsl:call-template>
+			<xsl:call-template name="Error"><xsl:with-param name="text">Component "<xsl:value-of select="@id"/>" has <xsl:value-of select="count(unit)"/> units.</xsl:with-param></xsl:call-template>
 		</xsl:when>
 	</xsl:choose>
 	<xsl:choose>
@@ -280,7 +282,6 @@
 
 <xsl:template match="meta/@rel | meta/@type | meta/@href"/> <!-- anything is valid -->
 
-
 <xsl:template match="unit">	<xsl:param name="filename"/>
 	<xsl:apply-templates select="@mrp|@bldFile">
 		<xsl:with-param name="filename" select="$filename"/>
@@ -314,8 +315,6 @@
 		<xsl:otherwise><xsl:value-of select="@id"/></xsl:otherwise>
 	</xsl:choose>
 </xsl:template>
-
-
 <xsl:template match="@bldFile|@mrp"><xsl:param name="filename"/>
 <xsl:if test="substring(.,string-length(.))='/'">
 		<xsl:call-template name="Warning"><xsl:with-param name="text"><code><xsl:value-of select="name()"/></code> path "<xsl:value-of select="."/>" should not end in /</xsl:with-param></xsl:call-template>
@@ -353,7 +352,7 @@
 				<xsl:when test="ancestor::collection"/>
 			</xsl:choose>/<xsl:apply-templates select="ancestor::component" mode="localid"/>/</xsl:variable>
 		<xsl:choose>
-			<xsl:when test="not(starts-with(concat(.,'/'),$segment))">
+			<xsl:when test="not(starts-with(concat(.,'/'),$segment)) and $path-errors">
 				<xsl:call-template name="Note"><xsl:with-param name="text">Unexpected <code><xsl:value-of select="name()"/></code> path for <xsl:apply-templates mode="path" select="../../../@id"/> -&gt; <strong><xsl:apply-templates mode="path" select="../../@id"/></strong>: "<xsl:value-of select="$fullpath"/>"</xsl:with-param></xsl:call-template>
 			</xsl:when>
 		</xsl:choose>
@@ -403,13 +402,14 @@
 <xsl:choose>
 	<xsl:when test="contains($filename,':')">
 		<xsl:choose>
-			<xsl:when test="not(starts-with(.,$path) or concat(.,'/')=$path)">
+			<xsl:when test="not(starts-with(.,$path) or concat(.,'/')=$path) and $path-errors">
 				<xsl:call-template name="Note"><xsl:with-param name="text">Unexpected <code><xsl:value-of select="name()"/></code> path for <xsl:apply-templates mode="path" select="../../../@id"/> -&gt; <strong><xsl:apply-templates mode="path" select="../../@id"/></strong>: "<xsl:value-of select="."/>"</xsl:with-param></xsl:call-template>
 			</xsl:when>
 		</xsl:choose>
 	</xsl:when>
 	<xsl:otherwise>
 		<xsl:choose>
+			<xsl:when test="not($path-errors)"/>
 			<xsl:when test="substring-before(substring($segment,2),'/') != substring-before(substring($path,2),'/') and (ancestor::SystemDefinition/@id-namespace!='http://www.symbian.org/system-definition' and not(contains(../../@id,':')))">
 				<xsl:call-template name="Warning"><xsl:with-param name="text">Unexpected <code><xsl:value-of select="name()"/></code> path for <xsl:apply-templates mode="path" select="../../../@id"/> -&gt; <strong><xsl:apply-templates mode="path" select="../../@id"/></strong>: "<xsl:value-of select="$fullpath"/>"</xsl:with-param></xsl:call-template>
 			</xsl:when>