You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by st...@apache.org on 2003/05/14 17:21:45 UTC
cvs commit: cocoon-2.1/tools/src/anttasks XConfToolTask.java
stephan 2003/05/14 08:21:45
Modified: src/blocks/lucene/conf lucene.samplesxpipe
src/blocks/python/conf python.samplesxpipe
src/blocks/xmldb/conf xmldb.deprecated.samplesxpipe
xmldb.samplesxpipe
src/targets compile-build.xml samples-build.xml
webapp-build.xml
tools/src blocks-build.xsl
tools/src/anttasks XConfToolTask.java
Log:
Reducing build time by 18%. Using conditional includes instead of
separate targets.
Revision Changes Path
1.2 +1 -1 cocoon-2.1/src/blocks/lucene/conf/lucene.samplesxpipe
Index: lucene.samplesxpipe
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/lucene/conf/lucene.samplesxpipe,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- lucene.samplesxpipe 9 Mar 2003 00:04:26 -0000 1.1
+++ lucene.samplesxpipe 14 May 2003 15:21:44 -0000 1.2
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<samplesxpipe xpath="/sitemap/pipelines/pipeline[@id='optional']"
+<samplesxpipe xpath="/sitemap/pipelines/pipeline[last()]"
unless="match[@pattern='search/**']">
<!-- Mount search pages sitemap, for using indexing & searching -->
1.2 +1 -1 cocoon-2.1/src/blocks/python/conf/python.samplesxpipe
Index: python.samplesxpipe
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/python/conf/python.samplesxpipe,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- python.samplesxpipe 9 Mar 2003 00:05:59 -0000 1.1
+++ python.samplesxpipe 14 May 2003 15:21:44 -0000 1.2
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<samplesxpipe xpath="/sitemap/pipelines/pipeline[@id='optional']"
+<samplesxpipe xpath="/sitemap/pipelines/pipeline[last()]"
unless="match[@pattern='xsp-py/*']">
<!-- XSP pages written in Python -->
<map:match pattern="xsp-py/*">
1.2 +1 -1 cocoon-2.1/src/blocks/xmldb/conf/xmldb.deprecated.samplesxpipe
Index: xmldb.deprecated.samplesxpipe
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/xmldb/conf/xmldb.deprecated.samplesxpipe,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xmldb.deprecated.samplesxpipe 9 Mar 2003 00:06:44 -0000 1.1
+++ xmldb.deprecated.samplesxpipe 14 May 2003 15:21:44 -0000 1.2
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<samplesxpipe xpath="/sitemap/pipelines/pipeline[@id='optional']"
+<samplesxpipe xpath="/sitemap/pipelines/pipeline[last()]"
unless="match[@pattern='xmldb-generator/db/**/']">
<!-- =================== XML:DB Generators ========================= -->
1.2 +2 -2 cocoon-2.1/src/blocks/xmldb/conf/xmldb.samplesxpipe
Index: xmldb.samplesxpipe
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/xmldb/conf/xmldb.samplesxpipe,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xmldb.samplesxpipe 9 Mar 2003 00:06:44 -0000 1.1
+++ xmldb.samplesxpipe 14 May 2003 15:21:44 -0000 1.2
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<samplesxpipe xpath="/sitemap/pipelines/pipeline[@id='optional']"
+<samplesxpipe xpath="/sitemap/pipelines/pipeline[last()]"
unless="match[@pattern='xmldb/**']">
<!-- ======================= XML:DB ============================== -->
@@ -13,4 +13,4 @@
<map:generate src="xmldb:xindice://localhost:4080/db/{1}"/>
<map:serialize type="xml"/>
</map:match>
-</samplesxpipe>
\ No newline at end of file
+</samplesxpipe>
1.9 +5 -5 cocoon-2.1/src/targets/compile-build.xml
Index: compile-build.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/targets/compile-build.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- compile-build.xml 1 Apr 2003 21:48:59 -0000 1.8
+++ compile-build.xml 14 May 2003 15:21:44 -0000 1.9
@@ -76,9 +76,9 @@
<target name="compile-deprecated" depends="prepare" unless="unless.exclude.deprecated">
<mkdir dir="${build.deprecated}"/>
- <xpatch configuration="${build.dest}/org/apache/cocoon/cocoon.roles"
- directory="${deprecated.conf}"
- extension="xroles"/>
+ <xpatch file="${build.dest}/org/apache/cocoon/cocoon.roles"
+ srcdir="${deprecated.conf}"
+ includes="**/*.xroles"/>
<javac srcdir="${deprecated.src}"
destdir="${build.deprecated}"
@@ -96,7 +96,7 @@
<target name="package" depends="package-core, package-scratchpad, package-deprecated"/>
<!-- package the core -->
- <target name="package-core" depends="compile-core,block-roles">
+ <target name="package-core" depends="compile-core, block-roles">
<jar jarfile="${build}/${name}.jar" manifest="${java}/Manifest.mf">
<fileset dir="${build.dest}"/>
</jar>
@@ -133,7 +133,7 @@
<ant antfile="${build.temp}/blocks-build.xml"
inheritAll="true"
inheritRefs="false"
- target="roles"/>
+ target="patch-roles"/>
</target>
<!-- compiles and packages all blocks -->
1.7 +6 -2 cocoon-2.1/src/targets/samples-build.xml
Index: samples-build.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/targets/samples-build.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- samples-build.xml 8 May 2003 20:42:17 -0000 1.6
+++ samples-build.xml 14 May 2003 15:21:44 -0000 1.7
@@ -41,7 +41,9 @@
</copy>
<!-- patch the welcome page to tell we have samples to show -->
- <xpatch directory="${webapp.samples}" extension="xwelcome" configuration="${build.webapp}/welcome.xml"/>
+ <xpatch file="${build.webapp}/welcome.xml"
+ srcdir="${webapp.samples}"
+ includes="**/*.xwelcome"/>
</target>
<target name="scratchpad-samples" depends="prepare" unless="unless.exclude.scratchpad">
@@ -64,7 +66,9 @@
</copy>
<!-- patch the samples page to tell we have scratchpad samples to show -->
- <xpatch directory="${scratchpad.samples}" extension="xsamples" configuration="${build.webapp.samples}/samples.xml"/>
+ <xpatch file="${build.webapp.samples}/samples.xml"
+ srcdir="${scratchpad.samples}"
+ includes="**/*.xsamples"/>
</target>
<target name="block-samples" depends="prepare" unless="unless.exclude.webapp.samples">
1.15 +13 -5 cocoon-2.1/src/targets/webapp-build.xml
Index: webapp-build.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/targets/webapp-build.xml,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- webapp-build.xml 6 Apr 2003 04:13:22 -0000 1.14
+++ webapp-build.xml 14 May 2003 15:21:44 -0000 1.15
@@ -65,7 +65,7 @@
<ant antfile="${build.temp}/blocks-build.xml"
inheritAll="true"
inheritRefs="false"
- target="patch"/>
+ target="patch-conf"/>
</target>
<target name="prepare-webapp-samples" depends="prepare-webapp, samples, block-samples, scratchpad-samples" unless="unless.exclude.webapp.samples"/>
@@ -82,7 +82,9 @@
<target name="prepare-webapp-deprecated" depends="prepare-webapp" unless="unless.exclude.deprecated">
<copy file="${build}/${name}-deprecated.jar" tofile="${build.webapp.lib}/${name}-${version}-deprecated.jar"/>
- <xpatch directory="${deprecated.conf}" extension="xconf" configuration="${build.webapp}/WEB-INF/cocoon.xconf"/>
+ <xpatch file="${build.webapp}/WEB-INF/cocoon.xconf"
+ srcdir="${deprecated.conf}"
+ includes="**/*.xconf"/>
</target>
<target name="prepare-webapp-idldocs" depends="idldocs" unless="unless.exclude.webapp.idldocs">
@@ -93,7 +95,9 @@
</copy>
<!-- patch the welcome page to tell we have idldocs to show -->
- <xpatch directory="${idl}" extension="xwelcome" configuration="${build.webapp}/welcome.xml"/>
+ <xpatch file="${build.webapp}/welcome.xml"
+ srcdir="${idl}"
+ extension="**/*.xwelcome"/>
</target>
<target name="prepare-webapp-javadocs" depends="javadocs" unless="unless.exclude.webapp.javadocs">
@@ -104,7 +108,9 @@
</copy>
<!-- patch the welcome page to tell we have javadocs to show -->
- <xpatch directory="${resources.javadoc}" extension="xwelcome" configuration="${build.webapp}/welcome.xml"/>
+ <xpatch file="${build.webapp}/welcome.xml"
+ srcdir="${resources.javadoc}"
+ includes="**/*.xwelcome"/>
</target>
<target name="prepare-webapp-docs" depends="validate-xdocs" unless="unless.exclude.webapp.documentation">
@@ -137,7 +143,9 @@
</copy>
<!-- patch the welcome page to tell we have documentation to show -->
- <xpatch directory="${documentation}" extension="xwelcome" configuration="${build.webapp}/welcome.xml"/>
+ <xpatch file="${build.webapp}/welcome.xml"
+ srcdir="${documentation}"
+ includes="**/*.xwelcome"/>
</target>
<target name="webapp" depends="prepare-webapp,prepare-webapp-samples,prepare-webapp-docs,prepare-webapp-javadocs,prepare-webapp-idldocs,prepare-webapp-deprecated,prepare-webapp-scratchpad,validate-jars,validate-config" description="Builds web application folder"/>
1.18 +54 -38 cocoon-2.1/tools/src/blocks-build.xsl
Index: blocks-build.xsl
===================================================================
RCS file: /home/cvs/cocoon-2.1/tools/src/blocks-build.xsl,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- blocks-build.xsl 5 May 2003 08:55:50 -0000 1.17
+++ blocks-build.xsl 14 May 2003 15:21:44 -0000 1.18
@@ -53,16 +53,8 @@
<xsl:attribute name="depends">init<xsl:for-each select="project[contains(@name,'cocoon-block-')]"><xsl:text>,</xsl:text><xsl:value-of select="@name"/>-compile</xsl:for-each></xsl:attribute>
</target>
- <target name="patch">
- <xsl:attribute name="depends">init<xsl:for-each select="project[contains(@name,'cocoon-block-')]"><xsl:text>,</xsl:text><xsl:value-of select="@name"/>-patch</xsl:for-each></xsl:attribute>
- </target>
-
- <target name="roles">
- <xsl:attribute name="depends">init<xsl:for-each select="project[contains(@name,'cocoon-block-')]"><xsl:text>,</xsl:text><xsl:value-of select="@name"/>-roles</xsl:for-each></xsl:attribute>
- </target>
-
<target name="samples">
- <xsl:attribute name="depends">init<xsl:for-each select="project[contains(@name,'cocoon-block-')]"><xsl:text>,</xsl:text><xsl:value-of select="@name"/>-samples</xsl:for-each></xsl:attribute>
+ <xsl:attribute name="depends">init<xsl:text>,</xsl:text>patch-samples<xsl:for-each select="project[contains(@name,'cocoon-block-')]"><xsl:text>,</xsl:text><xsl:value-of select="@name"/>-samples</xsl:for-each></xsl:attribute>
</target>
<target name="lib">
@@ -74,6 +66,59 @@
</target>
<xsl:apply-templates select="project[contains(@name,'-block')]" />
+
+ <target name="patch-roles" depends="init">
+ <xpatch file="{string('${build.dest}/org/apache/cocoon/cocoon.roles')}"
+ srcdir="{string('${blocks}')}">
+ <xsl:for-each select="project[contains(@name,'cocoon-block-')]">
+ <xsl:variable name="block-name" select="substring-after(@name,'cocoon-block-')"/>
+ <include name="{$block-name}/conf/**/*.xroles" unless="unless.exclude.block.{$block-name}"/>
+ </xsl:for-each>
+ </xpatch>
+ </target>
+
+ <target name="patch-conf" depends="init">
+ <xpatch file="{string('${build.webapp}')}/sitemap.xmap"
+ srcdir="{string('${blocks}')}">
+ <xsl:for-each select="project[contains(@name,'cocoon-block-')]">
+ <xsl:variable name="block-name" select="substring-after(@name,'cocoon-block-')"/>
+ <include name="{$block-name}/conf/**/*.xmap" unless="unless.exclude.block.{$block-name}"/>
+ <include name="{$block-name}/conf/**/*.xpipe" unless="unless.exclude.block.{$block-name}"/>
+ </xsl:for-each>
+ </xpatch>
+ <xpatch file="{string('${build.webapp}')}/WEB-INF/cocoon.xconf"
+ srcdir="{string('${blocks}')}">
+ <xsl:for-each select="project[contains(@name,'cocoon-block-')]">
+ <xsl:variable name="block-name" select="substring-after(@name,'cocoon-block-')"/>
+ <include name="{$block-name}/conf/**/*.xconf" unless="unless.exclude.block.{$block-name}"/>
+ </xsl:for-each>
+ </xpatch>
+ <xpatch file="{string('${build.webapp}')}/WEB-INF/logkit.xconf"
+ srcdir="{string('${blocks}')}">
+ <xsl:for-each select="project[contains(@name,'cocoon-block-')]">
+ <xsl:variable name="block-name" select="substring-after(@name,'cocoon-block-')"/>
+ <include name="{$block-name}/conf/**/*.xlog" unless="unless.exclude.block.{$block-name}"/>
+ </xsl:for-each>
+ </xpatch>
+ </target>
+
+ <target name="patch-samples" depends="init">
+ <xpatch file="{string('${build.webapp}')}/samples/block-samples.xml"
+ srcdir="{string('${blocks}')}">
+ <xsl:for-each select="project[contains(@name,'cocoon-block-')]">
+ <xsl:variable name="block-name" select="substring-after(@name,'cocoon-block-')"/>
+ <include name="{$block-name}/conf/**/*.xsamples" unless="unless.exclude.block.{$block-name}"/>
+ </xsl:for-each>
+ </xpatch>
+ <xpatch file="{string('${build.webapp}')}/samples/sitemap.xmap"
+ srcdir="{string('${blocks}')}">
+ <xsl:for-each select="project[contains(@name,'cocoon-block-')]">
+ <xsl:variable name="block-name" select="substring-after(@name,'cocoon-block-')"/>
+ <include name="{$block-name}/conf/**/*.samplesxpipe" unless="unless.exclude.block.{$block-name}"/>
+ </xsl:for-each>
+ </xpatch>
+ </target>
+
</xsl:template>
<xsl:template match="project">
@@ -103,22 +148,6 @@
<antcall target="{$block-name}-compile"/>
</target>
- <target name="{@name}-patch" unless="unless.exclude.block.{$block-name}">
- <xsl:if test="depend">
- <xsl:attribute name="depends"><xsl:value-of select="@name"/><xsl:for-each select="depend[contains(@project,'cocoon-block-')]"><xsl:text>,</xsl:text><xsl:value-of select="@project"/>-patch</xsl:for-each></xsl:attribute>
- </xsl:if>
-
- <antcall target="{$block-name}-patches"/>
- </target>
-
- <target name="{@name}-roles" unless="unless.exclude.block.{$block-name}">
- <xsl:if test="depend">
- <xsl:attribute name="depends"><xsl:value-of select="@name"/><xsl:for-each select="depend[contains(@project,'cocoon-block-')]"><xsl:text>,</xsl:text><xsl:value-of select="@project"/>-roles</xsl:for-each></xsl:attribute>
- </xsl:if>
-
- <antcall target="{$block-name}-roles"/>
- </target>
-
<target name="{@name}-samples" unless="unless.exclude.block.{$block-name}">
<xsl:if test="depend">
<xsl:attribute name="depends"><xsl:value-of select="@name"/><xsl:for-each select="depend[contains(@project,'cocoon-block-')]"><xsl:text>,</xsl:text><xsl:value-of select="@project"/>-samples</xsl:for-each></xsl:attribute>
@@ -281,23 +310,10 @@
</copy>
</target>
- <target name="{$block-name}-roles">
- <xpatch directory="{string('${blocks}')}/{$block-name}/conf" extension="xroles" configuration="{string('${build.dest}/org/apache/cocoon/cocoon.roles')}"/>
- </target>
-
- <target name="{$block-name}-patches" depends="{$block-name}-prepare">
- <xpatch directory="{string('${build.blocks}')}/{$block-name}/conf" extension="xmap" configuration="{string('${build.webapp}')}/sitemap.xmap"/>
- <xpatch directory="{string('${build.blocks}')}/{$block-name}/conf" extension="xpipe" configuration="{string('${build.webapp}')}/sitemap.xmap"/>
- <xpatch directory="{string('${build.blocks}')}/{$block-name}/conf" extension="xconf" configuration="{string('${build.webapp}')}/WEB-INF/cocoon.xconf"/>
- <xpatch directory="{string('${build.blocks}')}/{$block-name}/conf" extension="xlog" configuration="{string('${build.webapp}')}/WEB-INF/logkit.xconf"/>
- </target>
-
<target name="{$block-name}-samples" if="{$block-name}.has.samples">
<copy filtering="on" todir="{string('${build.webapp}')}/samples/{$block-name}">
<fileset dir="{string('${blocks}')}/{$block-name}/samples"/>
</copy>
- <xpatch directory="{string('${build.blocks}')}/{$block-name}/conf" extension="xsamples" configuration="{string('${build.webapp}')}/samples/block-samples.xml"/>
- <xpatch directory="{string('${build.blocks}')}/{$block-name}/conf" extension="samplesxpipe" configuration="{string('${build.webapp}')}/samples/sitemap.xmap"/>
<!-- copy sample classes -->
<copy todir="{string('${build.webapp.classes}')}" filtering="off">
1.3 +171 -109 cocoon-2.1/tools/src/anttasks/XConfToolTask.java
Index: XConfToolTask.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/tools/src/anttasks/XConfToolTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XConfToolTask.java 11 Mar 2003 15:29:13 -0000 1.2
+++ XConfToolTask.java 14 May 2003 15:21:44 -0000 1.3
@@ -1,13 +1,59 @@
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
+/*
+
+ ============================================================================
+ The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, 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 "Apache Cocoon" 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 (INCLU-
+ DING, 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 created by
+ Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
+ Software Foundation, please see <http://www.apache.org/>.
+
+*/
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -32,115 +78,117 @@
import java.io.IOException;
/**
- * Add components to the cocoon.xconf.
- * This is an ugly second shot.
+ * Ant task to patch xmlfiles.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @author <a href="mailto:crafterm@fztig938.bank.dresdner.net">Marcus Crafter</a>
* @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
+ * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
* @version CVS $Revision$ $Date$
*/
+public final class XConfToolTask extends MatchingTask {
-public final class XConfToolTask extends Task {
-
- private String configuration;
- private String directory;
- private String extension;
+ private File file;
+ private File directory;
+ private File srcdir;
- public void setConfiguration(String configuration) {
- this.configuration = configuration;
- }
-
- public void setDirectory(String directory) {
- this.directory = directory;
+ /**
+ * Set file, which should be patched.
+ *
+ * @param file File, which should be patched.
+ */
+ public void setFile(File file) {
+ this.file = file;
}
- public void setExtension(String extension) {
- this.extension = extension;
+ /**
+ * Set base directory for the patch files.
+ *
+ * @param srcdir Base directory for the patch files.
+ */
+ public void setSrcdir(File srcdir) {
+ this.srcdir = srcdir;
}
+ /**
+ * Execute task.
+ */
public void execute() throws BuildException {
- if (this.configuration == null) {
- throw new BuildException("configuration attribute is required", location);
- }
- if (this.extension == null) {
- throw new BuildException("extension attribute is required", location);
- }
- if (this.directory == null) {
- throw new BuildException("directory attribute is required", location);
+ if (this.file==null) {
+ throw new BuildException("file attribute is required",
+ location);
}
try {
final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
- final String file = this.project.resolveFile(this.configuration).getCanonicalPath();
// load xml
- // System.out.println("Reading: " + file);
- final Document configuration = builder.parse((new File(file)).toURL().toExternalForm());
+ log("Reading: " + this.file, Project.MSG_DEBUG);
+ final Document document = builder.parse(this.file.toURL().toExternalForm());
+
+ if (this.srcdir==null)
+ this.srcdir = project.resolveFile(".");
+
+ DirectoryScanner scanner = getDirectoryScanner(this.srcdir);
+
+ String[] list = scanner.getIncludedFiles();
+ boolean hasChanged = false;
// process recursive
- if (process(builder, configuration, this.project.resolveFile(this.directory), this.extension)) {
- // save xml
- System.out.println("Writing: " + file);
- transformer.transform(new DOMSource(configuration), new StreamResult(file));
+ File patchfile;
+ for (int i = 0; i<list.length; i++) {
+ patchfile = new File(this.srcdir, list[i]);
+ try {
+ // Adds configuration snippet from the file to the configuration
+ hasChanged |= patch(document,
+ builder.parse(patchfile.toURL().toExternalForm()),
+ patchfile.toString());
+ } catch (SAXException e) {
+ log("Ignoring: "+patchfile+"\n(not a valid XML)");
+ }
+ }
+
+ if (hasChanged) {
+ log("Writing: "+this.file);
+ transformer.transform(new DOMSource(document),
+ new StreamResult(this.file));
} else {
- // System.out.println("No Changes: " + file);
+ log("No Changes: " + this.file, Project.MSG_DEBUG);
}
} catch (TransformerException e) {
- throw new BuildException("TransformerException: " + e);
+ throw new BuildException("TransformerException: "+e);
} catch (SAXException e) {
- throw new BuildException("SAXException: " + e);
+ throw new BuildException("SAXException: "+e);
} catch (ParserConfigurationException e) {
- throw new BuildException("ParserConfigurationException: " + e);
+ throw new BuildException("ParserConfigurationException: "+e);
} catch (IOException ioe) {
- throw new BuildException("IOException: " + ioe);
+ throw new BuildException("IOException: "+ioe);
}
}
/**
- * Scan recursive
+ * Patch XML document with a given patch file.
+ *
+ * @param configuration Orginal document
+ * @param component Patch document
+ * @param file Patch file
+ *
+ * @return True, if the document was successfully patched
*/
- private boolean process(final DocumentBuilder builder,
- final Document configuration,
- final File directoryFile,
- final String ext)
- throws IOException, BuildException, ParserConfigurationException, TransformerException, SAXException {
-
- boolean hasChanged = false;
- final File[] files = directoryFile.listFiles();
- if (files != null) {
- for(int i = 0; i < files.length; i++) {
- if (files[i].isDirectory()) {
- hasChanged |= process(builder, configuration, files[i], ext);
- } else if (files[i].getName().endsWith("." + ext)) {
- String file = files[i].getCanonicalPath();
- try {
- // Adds configuration snippet from the file to the configuration
- hasChanged |= add(configuration, builder.parse((new File(file)).toURL().toExternalForm()), file);
- } catch (SAXException e) {
- System.out.println("Ignoring: " + file + "\n(not a valid XML)");
- }
- }
- }
- }
-
- return hasChanged;
- }
-
- /**
- * Add entry to cocoon.xconf
- */
- private boolean add(final Document configuration,
- final Document component,
- String file)
- throws TransformerException, IOException {
+ private boolean patch(final Document configuration,
+ final Document component,
+ String file)
+ throws TransformerException, IOException {
// Check to see if Document is an xconf-tool document
Element elem = component.getDocumentElement();
- if (!elem.getTagName().equals(extension)) {
- System.out.println("Skipping non xconf-tool file: " + file);
+
+ String extension = file.lastIndexOf(".")>0?file.substring(file.lastIndexOf(".")+1):"";
+
+ if ( !elem.getTagName().equals(extension)) {
+ log("Skipping non xconf-tool file: "+file);
return false;
}
@@ -148,30 +196,35 @@
String xpath = elem.getAttribute("xpath");
NodeList nodes = XPathAPI.selectNodeList(configuration, xpath);
- if (nodes.getLength() != 1) {
- System.out.println("Error in: " + file);
- throw new IOException("XPath (" + xpath + ") returned not one node, but "
- + nodes.getLength() + " nodes");
+
+ if (nodes.getLength()!=1) {
+ log("Error in: "+file);
+ throw new IOException("XPath ("+xpath+
+ ") returned not one node, but "+
+ nodes.getLength()+" nodes");
}
Node root = nodes.item(0);
// Test that 'root' node satisfies 'component' insertion criteria
String test = component.getDocumentElement().getAttribute("unless");
- if (test != null && test.length() > 0 &&
- XPathAPI.selectNodeList(root, test).getLength() != 0) {
- // System.out.println("Skipping: " + file);
+
+ if ((test!=null) && (test.length()>0) &&
+ (XPathAPI.selectNodeList(root, test).getLength()!=0)) {
+ log("Skipping: " + file, Project.MSG_DEBUG);
return false;
} else {
// Test if component wants us to remove a list of nodes first
xpath = component.getDocumentElement().getAttribute("remove");
Node remove = null;
- if (xpath != null && xpath.length() > 0) {
+
+ if ((xpath!=null) && (xpath.length()>0)) {
nodes = XPathAPI.selectNodeList(configuration, xpath);
- for (int i = 0, length = nodes.getLength(); i < length; i++) {
+ for (int i = 0, length = nodes.getLength(); i<length; i++) {
Node node = nodes.item(i);
Node parent = node.getParentNode();
+
parent.removeChild(node);
}
}
@@ -179,44 +232,53 @@
// Test for an attribute that needs to be added to an element
String name = component.getDocumentElement().getAttribute("add-attribute");
String value = component.getDocumentElement().getAttribute("value");
- if (name != null && name.length() > 0) {
- if (value == null)
- throw new IOException("No attribute value specified for 'add-attribute' " + xpath);
- if (root instanceof Element)
- ((Element)root).setAttribute(name, value);
- }
+ if ((name!=null) && (name.length()>0)) {
+ if (value==null) {
+ throw new IOException("No attribute value specified for 'add-attribute' "+
+ xpath);
+ }
+ if (root instanceof Element) {
+ ((Element) root).setAttribute(name, value);
+ }
+ }
// Test if 'component' provides desired insertion point
xpath = component.getDocumentElement().getAttribute("insert-before");
Node before = null;
- if (xpath != null && xpath.length() > 0) {
+
+ if ((xpath!=null) && (xpath.length()>0)) {
nodes = XPathAPI.selectNodeList(root, xpath);
- if (nodes.getLength() != 1) {
- System.out.println("Error in: " + file);
- throw new IOException("XPath (" + xpath + ") returned not one node, but "
- + nodes.getLength() + " nodes");
+ if (nodes.getLength()!=1) {
+ log("Error in: "+file);
+ throw new IOException("XPath ("+xpath+
+ ") returned not one node, but "+
+ nodes.getLength()+" nodes");
}
before = nodes.item(0);
} else {
xpath = component.getDocumentElement().getAttribute("insert-after");
- if (xpath != null && xpath.length() > 0) {
+ if ((xpath!=null) && (xpath.length()>0)) {
nodes = XPathAPI.selectNodeList(root, xpath);
- if (nodes.getLength() != 1) {
- System.out.println("Error in: " + file);
- throw new IOException("XPath (" + xpath + ") returned not one node, but "
- + nodes.getLength() + " nodes");
+ if (nodes.getLength()!=1) {
+ log("Error in: "+file);
+ throw new IOException("XPath ("+xpath+
+ ") returned not one node, but "+
+ nodes.getLength()+" nodes");
}
before = nodes.item(0).getNextSibling();
}
}
// Add 'component' data into 'root' node
- System.out.println("Processing: " + file);
+ log("Processing: "+file);
NodeList componentNodes = component.getDocumentElement().getChildNodes();
- for (int i = 0; i < componentNodes.getLength(); i++ ){
- Node node = configuration.importNode(componentNodes.item(i), true);
- if (before == null) {
+
+ for (int i = 0; i<componentNodes.getLength(); i++) {
+ Node node = configuration.importNode(componentNodes.item(i),
+ true);
+
+ if (before==null) {
root.appendChild(node);
} else {
root.insertBefore(node, before);