Author: reinhard Date: Mon Feb 21 12:50:05 2005 New Revision: 154718 URL: http://svn.apache.org/viewcvs?view=rev&rev=154718 Log: allow block eclipse project depending on another block eclipse project
Modified: cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Block.java cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/EclipseClasspathBuilderTask.java cocoon/trunk/tools/block-builder/targets/block-descriptor2ant-script.xsl Modified: 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=diff&r1=154717&r2=154718 ============================================================================== --- cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Block.java (original) +++ cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/Block.java Mon Feb 21 12:50:05 2005 @@ -16,8 +16,16 @@ package org.apache.cocoon.blockbuilder.ant; import java.io.File; +import java.io.FileInputStream; import java.io.FilenameFilter; +import org.apache.tools.ant.BuildException; +import org.apache.xerces.parsers.DOMParser; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + /** * @since 0.1 */ @@ -26,6 +34,7 @@ private String name; private String relativeJardir; private String blockPath; + private boolean dynamicEclipseReference = false; public Block() { @@ -47,6 +56,18 @@ this.relativeJardir = dir; } + public void setDynamicEclipseReference(boolean dynamicEclipseReference) { + System.out.println("dynamic reference: " + dynamicEclipseReference); + } + + public boolean isDynamicEclipseReference() { + return this.dynamicEclipseReference; + } + + public String getEclipseProjectName() throws Exception { + return getProjectName(new File(this.blockPath, ".project")); + } + public File[] getJarFile(File basedir) { File jarDir = new File(basedir, blockPath + File.separator + this.relativeJardir); return jarDir.listFiles(new FilenameFilter() { @@ -54,5 +75,37 @@ return name.toLowerCase().endsWith("jar"); } }); + } + + private String getProjectName(File eclipseProjectFile) throws Exception { + String projectName = ""; + try { + System.out.println("eclipseProjectfile: " + eclipseProjectFile); + String EL_PROJECTDESCRIPTION = "projectDescription"; + String EL_NAME = "name"; + + DOMParser parser = new DOMParser(); + parser.parse(new InputSource(new FileInputStream(eclipseProjectFile))); + 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_PROJECTDESCRIPTION.equals(rootChildNode.getLocalName())) { + NodeList projectDescriptor = rootChildNode.getChildNodes(); + for(int x = 0; x <= projectDescriptor.getLength(); x++) { + Node nameNode = projectDescriptor.item(x); + if(nameNode != null && EL_NAME.equals(nameNode.getLocalName())) { + projectName = nameNode.getFirstChild().getNodeValue(); + } + } + } + } + } catch(Exception e) { + throw new BuildException("Make sure that a valid Eclipse project file can be found at " + + eclipseProjectFile.getCanonicalPath()); + } + return projectName; } } Modified: 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=diff&r1=154717&r2=154718 ============================================================================== --- cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/EclipseClasspathBuilderTask.java (original) +++ cocoon/trunk/tools/block-builder/java/org/apache/cocoon/blockbuilder/ant/EclipseClasspathBuilderTask.java Mon Feb 21 12:50:05 2005 @@ -53,7 +53,7 @@ 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 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"; @@ -100,12 +100,20 @@ // 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++) { + Block block = (Block)blockIterator.next(); + if(block.isDynamicEclipseReference()) { + File[] f = block.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); + } + } else { Element entry = doc.createElement(EL_CLASSPATHENTRY); - entry.setAttribute(ATTR_KIND, LIT_ATTR_KIND_LIB); - entry.setAttribute(ATTR_PATH, f[i].getCanonicalPath()); - root.appendChild(entry); + entry.setAttribute(ATTR_KIND, LIT_ATTR_KIND_SRC); + entry.setAttribute(ATTR_PATH, "/" + block.getEclipseProjectName()); + root.appendChild(entry); } } @@ -127,10 +135,12 @@ } // append default output dir + /* RP: is it really necessary? 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); Modified: 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=diff&r1=154717&r2=154718 ============================================================================== --- cocoon/trunk/tools/block-builder/targets/block-descriptor2ant-script.xsl (original) +++ cocoon/trunk/tools/block-builder/targets/block-descriptor2ant-script.xsl Mon Feb 21 12:50:05 2005 @@ -208,6 +208,7 @@ <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> + <xsl:attribute name="dynamicEclipseReference">${root.block.<xsl:value-of select="@name"/>.eclipse.dynamic}</xsl:attribute> </block> </xsl:for-each>