<
xsl:
stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xd="
http://www.pnp-software.com/XSLTdoc"
xmlns:util="
http://www.pnp-software.com/util"
version="
2.0"
exclude-result-prefixes="
#all">
<
xd:
doc type="
stylesheet">
<
xd:
short>
This stylesheet converts an XWeaver project (normally named xwproject.xml)
file into an ant files that does the weaving according to the xwproject file.</
xd:
short>
<
xd:
detail>
Several ant targets are created for each woven element.
</
xd:
detail>
<
xd:
cvsId>
$Id: xwproject2ant.xsl 213 2005-10-26 14:30:56Z ibirrer $</
xd:
cvsId>
<
xd:
author>
ibirrer</
xd:
author>
<
xd:
copyright>
2005, P&P Software GmbH</
xd:
copyright>
</
xd:
doc>
<
xsl:
include href="
util.xsl" />
<
xsl:
output indent="
yes"
method="
xml" />
<
xsl:
variable name="
perf_timePattern"
select="
'yyyy/MM/dd HH:mm:ss.SSS'" />
<
xd:
doc>
Main template. Apply templates for woven element
</
xd:
doc>
<
xsl:
template match="
/xwproject">
<
project default="
default"
name="
{base/@name}">
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
Project Name </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
property name="
ProjectName"
value="
{base/@name}" />
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
Install directory of XWeaver</
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
property name="
XWeaverHome"
location="
{@xwHome}" />
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
Log file for XWeaver tests</
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
property name="
XWeaverTest_logFile"
location="
XWeaverTestLog.txt" />
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
Log file for XWeaver performance tests</
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
property name="
XWeaverPerfTest_logFile"
location="
XWeaverPerfTestLog.txt" />
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
Custom targets declarations </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
taskdef name="
src2srcmlc"
classname="
net.sf.xweaver.srcml.ant.Src2SrcMLC" />
<
taskdef name="
srcml2src"
classname="
net.sf.xweaver.srcml.ant.SrcML2Src" />
<
taskdef name="
axw"
classname="
net.sf.xweaver.ant.AXWeave" />
<
taskdef name="
axc"
classname="
net.sf.xweaver.ant.AXCompile" />
<
taskdef name="
axl"
classname="
net.sf.xweaver.ant.AXLocate" />
<
target name="
init">
<
tstamp />
</
target>
<
target name="
default"
depends="
init">
<
echo><
xsl:
text>
The following aspects (targets) can be woven:${line.separator}</
xsl:
text></
echo>
<
xsl:
for-each select="
/xwproject/woven">
<
echo><
xsl:
text>
</
xsl:
text><
xsl:
value-of select="
@name" /></
echo>
</
xsl:
for-each>
<
echo><
xsl:
text>
General Targets: </
xsl:
text></
echo>
<
echo><
xsl:
text>
WeaveAll</
xsl:
text></
echo>
<
echo><
xsl:
text>
Test Suite:</
xsl:
text></
echo>
<
echo><
xsl:
text>
XWeaverTestAll</
xsl:
text></
echo>
<
echo><
xsl:
text>
WeaveAndTestAll</
xsl:
text></
echo>
<
xsl:
for-each select="
/xwproject/woven">
<
echo><
xsl:
text>
</
xsl:
text><
xsl:
value-of select="
concat(@name, '_XWeaverTest')" /></
echo>
</
xsl:
for-each>
</
target>
<
xsl:
for-each select="
woven">
<!---->
<
xsl:
variable name="
aspects">
<
xsl:
choose>
<
xsl:
when test="
@aspect">
<
xsl:
variable name="
aspectName"
select="
substring-before(util:getFile(util:pathToUri(@aspect)),'.')" />
<
xsl:
variable name="
tmpDir"
select="
concat( util:normalizeFolder(util:pathToUri( @path )), '.xwTemp/', $aspectName, '/' )" />
<
aspect aspect="
{util:pathToUri( @aspect )}"
tmpDir="
{$tmpDir}"
locator="
{concat( $tmpDir, 'locators/' ,$aspectName)}.xsl"
wovenDir="
{@path}" />
</
xsl:
when>
<
xsl:
when test="
aspects">
<
xsl:
variable name="
path"
select="
@path" />
<
xsl:
for-each select="
aspects/file">
<
xsl:
variable name="
aspectName"
select="
substring-before(util:getFile(util:pathToUri(@href)),'.')" />
<
xsl:
variable name="
tmpDir"
select="
concat( util:normalizeFolder(util:pathToUri( $path )), '.xwTemp/', $aspectName, '/' )" />
<
xsl:
variable name="
wovenDir"
select="
if( position() = last() ) then $path else concat($tmpDir, 'woven' )" />
<
aspect aspect="
{util:pathToUri( @href )}"
tmpDir="
{$tmpDir}"
locator="
{concat( $tmpDir, 'locators/' ,$aspectName)}.xsl"
wovenDir="
{$wovenDir}" />
</
xsl:
for-each>
</
xsl:
when>
</
xsl:
choose>
</
xsl:
variable>
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
=================================
target: <
xsl:
value-of select="
@name" />
_Clean
================================= </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
target name="
{@name}_Clean"
description="
Clean {@name}">
<
xsl:
for-each select="
$aspects/aspect">
<
delete dir="
{@tmpDir}" />
</
xsl:
for-each>
</
target>
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
=================================
target: <
xsl:
value-of select="
@name" />
================================= </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
target name="
{@name}"
description="
Weave {@name}">
<
echo>
${XWeaverPerfTest_logFile}</
echo>
<!---->
<
xsl:
copy-of select="
util:performanceLogTitle(concat('Weave', @name))" />
<
xsl:
copy-of select="
util:performanceLog(concat('Start Weave', @name))" />
<
xsl:
variable name="
language"
select="
/xwproject/base/@language" />
<!---->
<
xsl:
variable name="
indentCount"
select="
/xwproject/base/@indentCount" />
<
xsl:
variable name="
indentChar"
select="
/xwproject/base/@indentChar" />
<
xsl:
variable name="
weaveElement"
select="
weave" />
<
xsl:
variable name="
wovenElement"
select="
." />
<
xsl:
variable name="
baseElement"
select="
/xwproject/base" />
<
xsl:
for-each select="
$aspects/aspect">
<!---->
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
Create directories </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
mkdir dir="
{@tmpDir}" />
<
mkdir dir="
{@tmpDir}srcML" />
<
mkdir dir="
{@tmpDir}locators" />
<
mkdir dir="
{@tmpDir}srcMLAnnotated" />
<
mkdir dir="
{@tmpDir}srcMLWoven" />
<
mkdir dir="
{@wovenDir}" />
<!---->
<
xsl:
variable name="
isLast"
select="
position() = last()" />
<
xsl:
variable name="
isFirst"
select="
position() = 1" />
<
xsl:
if test="
$isLast">
<
xsl:
choose>
<
xsl:
when test="
$wovenElement/copy">
<
copy todir="
{@wovenDir}">
<
fileset dir="
.">
<
xsl:
copy-of select="
$wovenElement/copy/@*" />
<
xsl:
copy-of select="
$wovenElement/copy/*" />
</
fileset>
</
copy>
</
xsl:
when>
</
xsl:
choose>
<!---->
<
xsl:
copy-of select="
$wovenElement/ant/*" />
</
xsl:
if>
<!---->
<
xsl:
copy-of select="
util:performanceLog('Start src2srcml')" />
<!---->
<
xsl:
variable name="
src2srcmlTaskName">
<
xsl:
choose>
<
xsl:
when test="
$language = 'JavaEclipse'">
<
xsl:
sequence select="
'src2srcmlj'" />
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
sequence select="
'src2srcmlc'" />
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
variable>
<
xsl:
element name="
{$src2srcmlTaskName}">
<!---->
<
xsl:
attribute name="
destdir"
select="
concat(@tmpDir, 'srcML')" />
<!---->
<
xsl:
choose>
<!---->
<
xsl:
when test="
$language != 'JavaEclipse'">
<
xsl:
attribute name="
executable">
${XWeaverHome}/resources/srcML/windows/src2srcml.exe</
xsl:
attribute>
<
xsl:
attribute name="
os">
Windows XP, Windows 98, Windows 95, Windows NT</
xsl:
attribute>
<
xsl:
attribute name="
language"
select="
$language" />
</
xsl:
when>
</
xsl:
choose>
<!---->
<
xsl:
choose>
<
xsl:
when test="
$isFirst">
<
xsl:
attribute name="
srcdir"
select="
'.'" />
<
xsl:
copy-of select="
$weaveElement/@*" />
<
xsl:
copy-of select="
$weaveElement/*" />
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
attribute name="
srcdir"
select="
preceding-sibling::aspect[1]/@wovenDir" />
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
element>
<
xsl:
choose>
<
xsl:
when test="
$language != 'JavaEclipse'">
<
xsl:
element name="
{$src2srcmlTaskName}">
<!---->
<
xsl:
attribute name="
destdir"
select="
concat(@tmpDir, 'srcML')" />
<!---->
<
xsl:
choose>
<!---->
<
xsl:
when test="
$language != 'JavaEclipse'">
<
xsl:
attribute name="
executable">
${XWeaverHome}/resources/srcML/linux/src2srcml</
xsl:
attribute>
<
xsl:
attribute name="
os">
Linux</
xsl:
attribute>
<
xsl:
attribute name="
language"
select="
$language" />
</
xsl:
when>
</
xsl:
choose>
<!---->
<
xsl:
choose>
<
xsl:
when test="
$isFirst">
<
xsl:
attribute name="
srcdir"
select="
'.'" />
<
xsl:
copy-of select="
$weaveElement/@*" />
<
xsl:
copy-of select="
$weaveElement/*" />
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
attribute name="
srcdir"
select="
preceding-sibling::aspect[1]/@wovenDir" />
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
element>
</
xsl:
when>
</
xsl:
choose>
<!---->
<
xsl:
copy-of select="
util:performanceLog('Start axc')" />
<!---->
<
axc xwhome="
${{XWeaverHome}}"
aspect="
{@aspect}"
locator="
{@locator}">
<
param name="
inlineSuffix"
expression="
{$baseElement/filetypes/@inlineSuffix}" />
<
param name="
declarationSuffix"
expression="
{$baseElement/filetypes/@declarationSuffix}" />
<
param name="
definitionSuffix"
expression="
{$baseElement/filetypes/@definitionSuffix}" />
</
axc>
<!---->
<
xsl:
copy-of select="
util:performanceLog('Start axl')" />
<!---->
<
axl xwhome="
${{XWeaverHome}}"
locator="
{@locator}"
srcdir="
{@tmpDir}srcML"
destdir="
{@tmpDir}srcMLAnnotated"
includes="
**/*.xml" />
<!---->
<
xsl:
copy-of select="
util:performanceLog('Start axw')" />
<!---->
<
axw srcdir="
{@tmpDir}srcMLAnnotated"
destdir="
{@tmpDir}srcMLWoven"
indentchar="
{$indentChar}"
indentcount="
{$indentCount}"
includes="
**/*.xml">
<
xsl:
choose>
<
xsl:
when test="
$language = 'Java'">
<
xsl:
attribute name="
xsl">
${XWeaverHome}/src/xsl/main/weaver/main_java.xsl</
xsl:
attribute>
</
xsl:
when>
<
xsl:
when test="
$language = 'C++' or $language = 'C'">
<
xsl:
attribute name="
xsl">
${XWeaverHome}/src/xsl/main/weaver/main_cpp.xsl</
xsl:
attribute>
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
message terminate="
yes">
ERROR: Wrong language property in XWeaver project file: '<
xsl:
value-of select="
$language" />
' are not supported. ( File: <
xsl:
value-of select="
base-uri(.)" />
)</
xsl:
message>
</
xsl:
otherwise>
</
xsl:
choose>
</
axw>
<!---->
<
xsl:
copy-of select="
util:performanceLog('Start srcml2src')" />
<!---->
<
srcml2src xwhome="
${{XWeaverHome}}"
srcdir="
{@tmpDir}srcMLWoven"
destdir="
{@wovenDir}"
includes="
**/*.xml" />
</
xsl:
for-each>
<!---->
<
xsl:
copy-of select="
util:performanceLog(concat('End Weave', @name))" />
</
target>
<
xsl:
if test="
test">
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
=================================
target: <
xsl:
value-of select="
concat(@name, '_XWeaverTest')" />
================================= </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
target name="
{concat(@name, '_XWeaverTest')}"
description="
Tests the weaving by comparing the resulting code with a (manually) verified code.">
<
ant antfile="
build.xml"
dir="
${{XWeaverHome}}"
target="
XWeaverTest"
inheritall="
false">
<
property name="
XWeaverTest_srcDir"
location="
{test/@src}" />
<
property name="
XWeaverTest_verifiedSrcDir"
location="
{test/@verified}" />
<
property name="
XWeaverTest_testName"
value="
{@name}" />
<
property name="
XWeaverTest_logFile"
location="
${{XWeaverTest_logFile}}" />
</
ant>
</
target>
</
xsl:
if>
</
xsl:
for-each>
<!---->
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
=================================
target: WeaveAll
================================= </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
target name="
WeaveAll"
description="
Weaves all defined targets">
<
xsl:
attribute name="
depends"
select="
string-join(woven/@name, ', ')" />
</
target>
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
=================================
target: CleanAll
================================= </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
target name="
CleanAll"
description="
Clean all defined targets">
<
xsl:
attribute name="
depends">
<
xsl:
for-each select="
woven">
<
xsl:
value-of select="
concat(@name,'_Clean')" />
<
xsl:
if test="
position() != last()">
<
xsl:
text>
, </
xsl:
text>
</
xsl:
if>
</
xsl:
for-each>
</
xsl:
attribute>
</
target>
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
=================================
target: XWeaverTestAll
================================= </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
target name="
XWeaverTestAll"
description="
Tests all woven sources">
<
xsl:
attribute name="
depends">
<
xsl:
for-each select="
woven[test]">
<
xsl:
value-of select="
concat(@name, '_XWeaverTest')" />
<
xsl:
if test="
position() != last()">
<
xsl:
text>
, </
xsl:
text>
</
xsl:
if>
</
xsl:
for-each>
</
xsl:
attribute>
</
target>
<
xsl:
text>
</
xsl:
text><
xsl:
comment>
=================================
target: WeaveAndTestAll
================================= </
xsl:
comment><
xsl:
text>
</
xsl:
text>
<
target name="
WeaveAndTestAll"
description="
Weave and tests all"
depends="
WeaveAll, XWeaverTestAll" />
</
project>
</
xsl:
template>
<
xsl:
function name="
util:performanceLog">
<
xsl:
param name="
name"
as="
xs:string" />
<
xsl:
variable name="
random"><
random /></
xsl:
variable>
<
xsl:
variable name="
antPropertyName"
select="
generate-id($random)" />
<
tstamp>
<
format property="
{$antPropertyName}"
pattern="
{$perf_timePattern}" />
</
tstamp>
<
echo append="
true"
file="
${{XWeaverPerfTest_logFile}}">
<
xsl:
value-of select="
concat('${', $antPropertyName, '}', ': ', $name )" />
<
xsl:
text>
${line.separator}</
xsl:
text>
</
echo>
</
xsl:
function>
<
xsl:
function name="
util:performanceLogTitle">
<
xsl:
param name="
title"
as="
xs:string" />
<
echo append="
true"
file="
${{XWeaverPerfTest_logFile}}">
<
xsl:
text>
${line.separator}</
xsl:
text>
<
xsl:
value-of select="
$title" />
<
xsl:
text>
${line.separator}</
xsl:
text>
<
xsl:
value-of select="
string-join(for $i in 1 to string-length($title) return '=', '')" />
<
xsl:
text>
${line.separator}${line.separator}</
xsl:
text>
</
echo>
</
xsl:
function>
</
xsl:
stylesheet>
v