Author: reinhard
Date: Sun Feb 20 10:04:07 2005
New Revision: 154545
URL: http://svn.apache.org/viewcvs?view=rev&rev=154545
Log:
Initial commit of the BlockBuilder
Added:
cocoon/trunk/tools/block-builder/
cocoon/trunk/tools/block-builder/java/
cocoon/trunk/tools/block-builder/java/org/
cocoon/trunk/tools/block-builder/java/org/apache/
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Block.java
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Cocoon.java
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Descriptor.java
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/EclipseClasspathBuilderTask.java
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Library.java
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Source.java
cocoon/trunk/tools/block-builder/targets/
cocoon/trunk/tools/block-builder/targets/block-descriptor2ant-script.xsl
cocoon/trunk/tools/block-builder/targets/block-descriptor2eclipse-project.xsl
cocoon/trunk/tools/block-builder/targets/global.build.properties
Added:
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Block.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Block.java?view=auto&rev=154545
==============================================================================
---
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Block.java
(added)
+++
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Block.java
Sun Feb 20 10:04:07 2005
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blockbuilder.ant;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+/**
+ * @since 0.1
+ */
+public class Block {
+
+ private String name;
+ private String relativeJardir;
+ private String blockPath;
+
+ public Block() {
+
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setPath(String path) {
+ this.blockPath = path;
+ }
+
+ public void setJardir(String dir) {
+ this.relativeJardir = dir;
+ }
+
+ public File[] getJarFile(File basedir) {
+ File jarDir = new File(basedir, blockPath + File.separator +
this.relativeJardir);
+ return jarDir.listFiles(new FilenameFilter() {
+ public boolean accept(File f, String name) {
+ return name.toLowerCase().endsWith("jar");
+ }
+ });
+ }
+}
Added:
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Cocoon.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Cocoon.java?view=auto&rev=154545
==============================================================================
---
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Cocoon.java
(added)
+++
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Cocoon.java
Sun Feb 20 10:04:07 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blockbuilder.ant;
+
+/**
+ * @since 0.1
+ */
+public class Cocoon {
+
+ private String jar;
+
+ /**
+ * @return Returns the dir.
+ */
+ public String getJar() {
+ return jar;
+ }
+ /**
+ * @param dir The dir to set.
+ */
+ public void setJar(String jar) {
+ this.jar = jar;
+ }
+}
Added:
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Descriptor.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Descriptor.java?view=auto&rev=154545
==============================================================================
---
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Descriptor.java
(added)
+++
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Descriptor.java
Sun Feb 20 10:04:07 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blockbuilder.ant;
+
+import java.io.File;
+
+/**
+ * @since 0.1
+ */
+public class Descriptor {
+
+ File file;
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+ public File getFile() {
+ return this.file;
+ }
+}
Added:
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/EclipseClasspathBuilderTask.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/EclipseClasspathBuilderTask.java?view=auto&rev=154545
==============================================================================
---
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/EclipseClasspathBuilderTask.java
(added)
+++
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/EclipseClasspathBuilderTask.java
Sun Feb 20 10:04:07 2005
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blockbuilder.ant;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.xerces.dom.DocumentImpl;
+import org.apache.xerces.parsers.DOMParser;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+/**
+ * @since 0.1
+ */
+public class EclipseClasspathBuilderTask extends Task {
+
+ private static final String EL_JARS = "jars";
+ private static final String EL_FILE = "file";
+ private static final String ATTR_ID = "id";
+ private static final String EL_LIB = "lib";
+ private static final String EL_CLASSPATH = "classpath";
+ private static final String EL_CLASSPATHENTRY = "classpathentry";
+ private static final String ATTR_PATH = "path";
+ private static final String ATTR_KIND = "kind";
+ private static final String ATTR_OUT = "output";
+ private static final String LIT_ATTR_KIND_SRC = "src";
+ private static final String LIT_ATTR_KIND_CON = "con";
+ private static final String LIT_ATTR_KIND_LIB = "lib";
+ private static final String LIT_ATTR_KIND_OUT = "output";
+ private static final String CORE_LIB = "core";
+ private static final String DEFAULT_ECLIPSE_CONTAINER =
"org.eclipse.jdt.launching.JRE_CONTAINER";
+
+ private List blocks = new ArrayList();
+ private Map coreJarMap = new HashMap();
+ private List libs = new ArrayList();
+ private List sources = new ArrayList();
+ private List cocoonJars = new ArrayList();
+ private File corejarsFile;
+ private File outFile;
+ private File coreJarDir;
+ private String eclipseContainer = DEFAULT_ECLIPSE_CONTAINER;
+
+
+ public void execute() throws BuildException {
+ try {
+
+ // create a new document
+ Document doc= new DocumentImpl();
+ Element root = doc.createElement(EL_CLASSPATH);
+
+ // append all source directories
+ Iterator sourceIterator = this.sources.iterator();
+ while(sourceIterator.hasNext()) {
+ Source source = ((Source) sourceIterator.next());
+ Element entry = doc.createElement(EL_CLASSPATHENTRY);
+ entry.setAttribute(ATTR_KIND, LIT_ATTR_KIND_SRC);
+ entry.setAttribute(ATTR_PATH, source.getDir());
+ entry.setAttribute(ATTR_OUT, source.getOut());
+ root.appendChild(entry);
+ }
+
+ // append cocoon libraries
+ Iterator cocoonIterator = this.cocoonJars.iterator();
+ while(cocoonIterator.hasNext()) {
+ Cocoon cocoonEntry = (Cocoon) cocoonIterator.next();
+ File jar = new File(this.getProject().getBaseDir(),
cocoonEntry.getJar());
+ Element entry = doc.createElement(EL_CLASSPATHENTRY);
+ entry.setAttribute(ATTR_KIND, LIT_ATTR_KIND_LIB);
+ entry.setAttribute(ATTR_PATH, jar.getCanonicalPath());
+ root.appendChild(entry);
+ }
+
+ // append all public block jars
+ Iterator blockIterator = this.blocks.iterator();
+ while(blockIterator.hasNext()) {
+ File[] f =
((Block)blockIterator.next()).getJarFile(this.getProject().getBaseDir());
+ if(f!=null) for(int i = 0; i < f.length; i++) {
+ Element entry = doc.createElement(EL_CLASSPATHENTRY);
+ entry.setAttribute(ATTR_KIND, LIT_ATTR_KIND_LIB);
+ entry.setAttribute(ATTR_PATH, f[i].getCanonicalPath());
+ root.appendChild(entry);
+ }
+ }
+
+ // append all libraries
+ Iterator libIterator = this.libs.iterator();
+ while(libIterator.hasNext()) {
+ Library lib = (Library) libIterator.next();
+ if(CORE_LIB.equals(lib.getLocation())) {
+ String libFromRepository = (String)
this.coreJarMap.get(lib.getId());
+ if(libFromRepository == null) {
+ throw new BuildException("Library '" + lib.getId() +
"' can't be found! Make sure it is available in " +
corejarsFile.getCanonicalPath() + ".");
+ }
+ String jar = (new File(this.coreJarDir,
libFromRepository)).getCanonicalPath();
+ Element entry = doc.createElement(EL_CLASSPATHENTRY);
+ entry.setAttribute(ATTR_KIND, LIT_ATTR_KIND_LIB);
+ entry.setAttribute(ATTR_PATH, jar);
+ root.appendChild(entry);
+ }
+ }
+
+ // append default output dir
+ Element outputEntry = doc.createElement(EL_CLASSPATHENTRY);
+ outputEntry.setAttribute(ATTR_KIND, LIT_ATTR_KIND_OUT);
+ outputEntry.setAttribute(ATTR_PATH, "");
+ root.appendChild(outputEntry);
+
+ // append container
+ Element containerEntry = doc.createElement(EL_CLASSPATHENTRY);
+ containerEntry.setAttribute(ATTR_KIND, LIT_ATTR_KIND_CON);
+ containerEntry.setAttribute(ATTR_PATH, this.eclipseContainer);
+ root.appendChild(containerEntry);
+
+ // append root element to document
+ doc.appendChild(root);
+
+ // serialize document
+ FileOutputStream fos = new FileOutputStream(outFile);
+ OutputFormat of = new OutputFormat("XML","UTF-8",true);
+ of.setIndent(1);
+ of.setIndenting(true);
+ XMLSerializer serializer = new XMLSerializer(fos,of);
+
+ serializer.asDOMSerializer();
+ serializer.serialize( doc.getDocumentElement() );
+ fos.close();
+ this.log("Wrote Eclipse .classpath file sucessfully.");
+
+ } catch(BuildException ex) {
+ throw ex;
+ }catch(Exception ex) {
+ throw new BuildException("error while serializing dom tree: " +
ex.getMessage());
+ }
+
+
+ }
+
+
+ /**
+ * Parse the jars.xml file and use addCoreJar() method to create an
ArrayList with
+ * all available jars.
+ *
+ * @param file
+ * @throws Exception
+ */
+ private void parseJarXML(File file) throws Exception {
+ DOMParser parser = new DOMParser();
+ parser.parse(new InputSource(new FileInputStream(file)));
+ Document doc = parser.getDocument();
+
+ // read in all available libraries
+ NodeList rootNodeList = doc.getChildNodes();
+ for(int i = 0; i <= rootNodeList.getLength(); i++ ) {
+ Node rootChildNode = rootNodeList.item(i);
+ if(rootChildNode != null &&
EL_JARS.equals(rootChildNode.getLocalName())) {
+ NodeList jarsNodeList = rootChildNode.getChildNodes();
+ for(int x = 0; x <= jarsNodeList.getLength(); x++) {
+ Node fileNode = jarsNodeList.item(x);
+ if(fileNode != null &&
EL_FILE.equals(fileNode.getLocalName())) {
+ addCoreJar(fileNode, this.coreJarMap);
+ }
+ }
+ }
+ }
+
+ }
+
+ private void addCoreJar(Node fileNode, Map jarMap) {
+ String id =
fileNode.getAttributes().getNamedItem(ATTR_ID).getNodeValue();
+ NodeList fileNodeList = fileNode.getChildNodes();
+ for(int x = 0; x <= fileNodeList.getLength(); x++) {
+ Node childNode = fileNodeList.item(x);
+ if(childNode != null && EL_LIB.equals(childNode.getLocalName())) {
+ String libValue = childNode.getFirstChild().getNodeValue();
+ jarMap.put(id, libValue);
+ }
+ }
+ }
+
+ public void setCorejardir(File dir) {
+ this.coreJarDir = dir;
+ }
+
+ public void setCorejars(File corejars) throws Exception {
+ this.corejarsFile = corejars;
+ if(!this.corejarsFile.exists()) {
+ throw new BuildException(this.corejarsFile.getCanonicalPath() + "
can't be found.");
+ }
+ parseJarXML(this.corejarsFile);
+ }
+
+ public void setContainer(String container) {
+ this.eclipseContainer = container;
+ }
+
+ public void setOutfile(File outfile) {
+ this.outFile = outfile;
+ }
+
+ public void addLib(Library lib) throws BuildException {
+ this.libs.add(lib);
+ }
+
+ public void addBlock(Block block) {
+ blocks.add(block);
+ }
+
+ public void addSource(Source source) {
+ sources.add(source);
+ }
+
+ public void addCocoon(Cocoon cocoon) {
+ this.cocoonJars.add(cocoon);
+ }
+
+}
Added:
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Library.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Library.java?view=auto&rev=154545
==============================================================================
---
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Library.java
(added)
+++
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Library.java
Sun Feb 20 10:04:07 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blockbuilder.ant;
+
+/**
+ * @since 0.1
+ */
+public class Library {
+
+ private String id;
+ private String location;
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public String getLocation() {
+ return this.location;
+ }
+
+}
Added:
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Source.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Source.java?view=auto&rev=154545
==============================================================================
---
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Source.java
(added)
+++
cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Source.java
Sun Feb 20 10:04:07 2005
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blockbuilder.ant;
+
+/**
+ * @since 0.1
+ */
+public class Source {
+
+ String dir;
+ String out;
+
+
+ public String getOut() {
+ return out;
+ }
+
+ public void setOut(String out) {
+ this.out = out;
+ }
+ public String getDir() {
+ return dir;
+ }
+
+ public void setDir(String dir) {
+ this.dir = dir;
+ }
+}
Added: cocoon/trunk/tools/block-builder/targets/block-descriptor2ant-script.xsl
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/targets/block-descriptor2ant-script.xsl?view=auto&rev=154545
==============================================================================
--- cocoon/trunk/tools/block-builder/targets/block-descriptor2ant-script.xsl
(added)
+++ cocoon/trunk/tools/block-builder/targets/block-descriptor2ant-script.xsl
Sun Feb 20 10:04:07 2005
@@ -0,0 +1,254 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:block="http://apache.org/cocoon/blocks/cob/1.0" version="1.0">
+ <xsl:output standalone="yes"/>
+ <xsl:output indent="yes"/>
+
+ <!-- paths -->
+ <xsl:variable name="blockbuilder.root">${blockbuilder.root}</xsl:variable>
+ <xsl:variable
name="default.block.output.path">/build/public/classes</xsl:variable>
+ <xsl:variable
name="default.core.output.path">/build/cocoon/classes</xsl:variable>
+ <xsl:variable
name="build.public.classes">${build.public.classes}</xsl:variable>
+ <xsl:variable name="build.public">${build.public}</xsl:variable>
+ <xsl:variable name="src.public">${src.public}</xsl:variable>
+ <xsl:variable name="lib.core.dir">${lib.core.dir}</xsl:variable>
+ <xsl:variable name="root.core">${root.core}</xsl:variable>
+ <xsl:variable
name="path.to.cocoon.public.jar">build/cocoon/cocoon.jar</xsl:variable>
+ <xsl:variable name="build.temp.tasks">${build.root}/temp/tasks</xsl:variable>
+
+ <!-- compiler -->
+ <xsl:variable name="compiler.debug">${compiler.debug}</xsl:variable>
+ <xsl:variable name="compiler.optimize">${compiler.optimize}</xsl:variable>
+ <xsl:variable
name="compiler.deprecation">${compiler.deprecation}</xsl:variable>
+ <xsl:variable name="target.vm">${target.vm}</xsl:variable>
+ <xsl:variable name="source.vm">${source.vm}</xsl:variable>
+ <xsl:variable name="compiler.nowarn">${compiler.nowarn}</xsl:variable>
+ <xsl:variable name="compiler">${compiler}</xsl:variable>
+
+
+ <!-- conditions -->
+ <xsl:variable name="cond.toplevelcall">${cond.toplevelcall}</xsl:variable>
+
+ <xsl:template match="block:block">
+
+ <project default="compile" name="Building block {name}">
+
+ <target name="init">
+ <!-- read local user properties -->
+ <property file="local.build.properties"/>
+
+ <!-- read block default properties -->
+ <property file="build.properties"/>
+
+ <!-- read global default properties -->
+ <property
file="{$blockbuilder.root}/targets/global.build.properties"/>
+
+ <!-- if the value toplevelcall is set, unnecessary recursions
can be avoided -->
+ <xsl:variable name="toplevelcall">${toplevelcall}</xsl:variable>
+ <condition property="cond.toplevelcall">
+ <not><isset property="toplevelcall"/></not>
+ </condition>
+
+ </target>
+
+ <target depends="init" name="compile"
+ description="Compile this block and all blocks it depends on"
+ >
+
+ <!-- check whether parameters are set, unless stop script execution
-->
+ <condition property="cond.root.core">
+ <isset property="root.core"/>
+ </condition>
+ <fail unless="cond.root.core" message="Property root.core has to be
set."/>
+ <xsl:for-each select="block:requirements/block:requires">
+ <xsl:variable name="prop">root.block.<xsl:value-of
select="@name"/></xsl:variable>
+ <condition property="cond.{$prop}">
+ <isset property="{$prop}"/>
+ </condition>
+ <fail unless="cond.{$prop}" message="Property {$prop} has to be
set."/>
+ </xsl:for-each>
+
+ <!-- first compile all blocks this block depends on -->
+ <antcall target="compile-required-blocks">
+ <param name="toplevelcall" value="{$cond.toplevelcall}"/>
+ </antcall>
+
+ <xsl:call-template name="info">
+ <xsl:with-param name="msg">Compiling block <xsl:value-of
select="block:name"/></xsl:with-param>
+ </xsl:call-template>
+
+ <!-- setup the classpath
+ for convenience reasons not the exact classpath is built
but all
+ libraries are used -->
+ <path id="classpath">
+ <xsl:variable
name="lib.core.dir">${lib.core.dir}</xsl:variable>
+ <fileset dir="{$lib.core.dir}">
+ <include name="core/*.jar"/>
+ <include name="endorsed/*.jar"/>
+ <include name="blocks/*.jar"/>
+ </fileset>
+ <xsl:variable
name="output.core.classes">${root.core}<xsl:value-of
select="$default.core.output.path"/></xsl:variable>
+ <dirset dir="{$output.core.classes}"/>
+ <!-- add classes of blocks this block depends on -->
+ <xsl:for-each
select="block:requirements/block:requires">
+ <xsl:variable
name="output.block.classes">${root.block.<xsl:value-of
select="@name"/>}<xsl:value-of
select="$default.block.output.path"/></xsl:variable>
+ <dirset dir="{$output.block.classes}"/>
+ </xsl:for-each>
+ </path>
+
+ <!-- compile this block -->
+ <mkdir dir="{$build.public.classes}"/>
+ <javac srcdir="{$src.public}"
+ destdir="{$build.public.classes}"
+ debug="{$compiler.debug}"
+ optimize="{$compiler.optimize}"
+ deprecation="{$compiler.deprecation}"
+ target="{$target.vm}"
+ source="{$source.vm}"
+ nowarn="{$compiler.nowarn}"
+ compiler="{$compiler}"
+ classpathref="classpath"/>
+ </target>
+
+ <target name="package" depends="init">
+ <!-- here is the root of a small bug: because of recursive calls
this is also called on
+ targets that block depends on what's unnecessary but doesn't
really harm because
+ the javac task recognizes that nothing has changed and doesn't
compile again -->
+ <antcall target="compile"/>
+
+ <antcall target="package-required-blocks">
+ <param name="toplevelcall" value="{$cond.toplevelcall}"/>
+ </antcall>
+
+ <xsl:call-template name="info">
+ <xsl:with-param name="msg">Packaging block <xsl:value-of
select="block:name"/></xsl:with-param>
+ </xsl:call-template>
+
+ <jar
jarfile="{$build.public}/cocoon-block-{/block:block/block:name/@short}-{/block:block/block:name/@version}.jar"
index="true">
+ <fileset dir="{$build.public.classes}"/>
+ </jar>
+ </target>
+
+ <target depends="init" name="clean" description="Clean the build
directory of this block and all blocks it depends on">
+ <!-- clean all dependand blocks -->
+ <antcall target="clean-required-blocks">
+ <param name="toplevelcall" value="{$cond.toplevelcall}"/>
+ </antcall>
+
+ <antcall target="clean-block"/>
+
+ </target>
+
+ <target depends="init" name="clean-block" description="Clean the build
directory of this block only">
+ <xsl:variable name="build.root">${build.root}</xsl:variable>
+ <xsl:call-template name="info">
+ <xsl:with-param name="msg">Cleaning block <xsl:value-of
select="block:name"/></xsl:with-param>
+ </xsl:call-template>
+ <delete dir="{$build.root}"/>
+ </target>
+
+ <xsl:call-template name="multi-block-operation">
+ <xsl:with-param name="action">compile</xsl:with-param>
+ </xsl:call-template>
+
+ <xsl:call-template name="multi-block-operation">
+ <xsl:with-param name="action">package</xsl:with-param>
+ </xsl:call-template>
+
+ <xsl:call-template name="multi-block-operation">
+ <xsl:with-param name="action">clean</xsl:with-param>
+ </xsl:call-template>
+
+ <target name="compile-eclipse-task" depends="package">
+ <mkdir dir="{$build.temp.tasks}"/>
+ <javac srcdir="{$blockbuilder.root}/java"
+ destdir="{$build.temp.tasks}"
+ debug="{$compiler.debug}"
+ optimize="{$compiler.optimize}"
+ deprecation="{$compiler.deprecation}"
+ target="{$target.vm}"
+ source="{$source.vm}"
+ nowarn="{$compiler.nowarn}"
+ compiler="{$compiler}"
+ classpathref="classpath"/>
+ </target>
+
+ <target depends="compile-eclipse-task" name="eclipse-project"
description="Create Eclipse project files">
+
+ <!-- include custom build task that generates the .classpath
+ That is necessary as the library paths are decoupled from block
descriptor.
+ Using XSLT would require writing an XSLT that creates an XSLT
that generates an Ant script *grrr* -->
+ <path id="task.classpath">
+ <pathelement location="{$build.temp.tasks}"/>
+ </path>
+
+ <!-- define the task -->
+ <taskdef name="eclipse"
+
classname="org.apache.cocoon.blockbuilder.ant.EclipseClasspathBuilderTask"
+ classpathref="task.classpath"/>
+
+ <!-- calling the task -->
+ <eclipse
+ corejars="{$lib.core.dir}/jars.xml"
+ corejardir="{$lib.core.dir}"
+ outfile=".classpath"
+ container="org.eclipse.jdt.launching.JRE_CONTAINER"
+ >
+
+ <!-- all external libraries - simply copied from descriptor -->
+ <xsl:for-each select="block:libraries/block:lib">
+ <lib>
+ <xsl:for-each select="@*">
+ <xsl:attribute name="{name(.)}"><xsl:value-of
select="."/></xsl:attribute>
+ </xsl:for-each>
+ </lib>
+ </xsl:for-each>
+
+ <!-- list all blocks that this block depends on - this creates
references to
+ these blocks public jars -->
+ <xsl:for-each select="block:requirements/block:requires">
+ <block name="[EMAIL PROTECTED]" jardir="build/public">
+ <xsl:attribute name="path">${root.block.<xsl:value-of
select="@name"/>}</xsl:attribute>
+ </block>
+ </xsl:for-each>
+
+ <!-- local soure files -->
+ <source dir="{$src.public}" out="{$build.public.classes}"/>
+
+ <!-- name the cocoon JARs -->
+ <cocoon jar="{$root.core}/{$path.to.cocoon.public.jar}"/>
+
+ </eclipse>
+
+ <!-- create .project file -->
+ <xslt in="block.xml" out=".project"
+
style="{$blockbuilder.root}/targets/block-descriptor2eclipse-project.xsl"/>
+ </target>
+ </project>
+
+ </xsl:template>
+
+ <xsl:template name="info">
+ <xsl:param name="msg"/>
+
<echo>+-----------------------------------------------------------------+</echo>
+ <echo>| <xsl:value-of select="$msg"/>
</echo>
+
<echo>+-----------------------------------------------------------------+</echo>
+ </xsl:template>
+
+ <!-- create a target for multi-block operations - necessary for recursions
-->
+ <xsl:template name="multi-block-operation">
+ <xsl:param name="action"/>
+ <target name="{$action}-required-blocks" depends="init, {$action}-core">
+ <xsl:for-each select="block:requirements/block:requires">
+ <xsl:variable name="root.block">${root.block.<xsl:value-of
select="@name"/>}</xsl:variable>
+ <ant antfile="{$root.block}/build.xml" target="{$action}"
inheritall="false">
+ <property name="toplevelcall" value="false"/>
+ </ant>
+ </xsl:for-each>
+ </target>
+ <target name="{$action}-core" depends="init" if="cond.toplevelcall">
+ <xsl:variable name="root.core">${root.core}</xsl:variable>
+ <ant antfile="{$root.core}/build.xml" target="{$action}"
inheritall="false"/>
+ </target>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
Added:
cocoon/trunk/tools/block-builder/targets/block-descriptor2eclipse-project.xsl
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/targets/block-descriptor2eclipse-project.xsl?view=auto&rev=154545
==============================================================================
---
cocoon/trunk/tools/block-builder/targets/block-descriptor2eclipse-project.xsl
(added)
+++
cocoon/trunk/tools/block-builder/targets/block-descriptor2eclipse-project.xsl
Sun Feb 20 10:04:07 2005
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="block"
xmlns:block="http://apache.org/cocoon/blocks/cob/1.0" version="1.0">
+ <xsl:template match="/">
+ <projectDescription>
+ <name><xsl:value-of select="/block:block/block:name"/></name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+ </projectDescription>
+ </xsl:template>
+</xsl:stylesheet>
Added: cocoon/trunk/tools/block-builder/targets/global.build.properties
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/tools/block-builder/targets/global.build.properties?view=auto&rev=154545
==============================================================================
--- cocoon/trunk/tools/block-builder/targets/global.build.properties (added)
+++ cocoon/trunk/tools/block-builder/targets/global.build.properties Sun Feb 20
10:04:07 2005
@@ -0,0 +1,34 @@
+# Copyright 1999-2004 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#----------------------------------------------
+# Build Properties
+#----------------------------------------------
+
+# ---- Paths
-------------------------------------------------------------------
+src.public=java
+
+# ---- Build
-------------------------------------------------------------------
+build.root=build
+build.public=${build.root}/public
+build.public.classes=${build.public}/classes
+
+# ---- Compiler
----------------------------------------------------------------
+compiler=modern
+compiler.debug=on
+compiler.optimize=on
+compiler.deprecation=off
+compiler.nowarn=on
+source.vm=1.3
+target.vm=1.3
\ No newline at end of file