You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by jh...@apache.org on 2007/03/01 10:06:15 UTC

svn commit: r513231 - in /ant/sandbox/antlibs/manual4eclipse: ./ docs/ src/main/org/apache/ant/manual4eclipse/

Author: jhm
Date: Thu Mar  1 01:06:12 2007
New Revision: 513231

URL: http://svn.apache.org/viewvc?view=rev&rev=513231
Log:
* Use of Java5
* A target for generating the plugin
* Spaces instead tabs
* M4E-Task: validate() for checking its configuration
* antlib.xml
* docs

Added:
    ant/sandbox/antlibs/manual4eclipse/build.properties
    ant/sandbox/antlibs/manual4eclipse/docs/buildPlugin.html
    ant/sandbox/antlibs/manual4eclipse/docs/cover.html
    ant/sandbox/antlibs/manual4eclipse/docs/favicon.ico   (with props)
    ant/sandbox/antlibs/manual4eclipse/docs/index.html
    ant/sandbox/antlibs/manual4eclipse/docs/m4e.html
    ant/sandbox/antlibs/manual4eclipse/docs/toc.html
    ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/antlib.xml
Modified:
    ant/sandbox/antlibs/manual4eclipse/build.xml
    ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/Manual4EclipseTask.java

Added: ant/sandbox/antlibs/manual4eclipse/build.properties
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/build.properties?view=auto&rev=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/build.properties (added)
+++ ant/sandbox/antlibs/manual4eclipse/build.properties Thu Mar  1 01:06:12 2007
@@ -0,0 +1,6 @@
+# Overwrite JavaC properties
+# This AntLib is not part of the Core and only intended for building
+# an Eclipse help plugin from the manual. This AntLib was not designed
+# for other use. So we could use Java5 here (instead of 1.2).
+javac.-source=1.5
+javac.-target=1.5

Modified: ant/sandbox/antlibs/manual4eclipse/build.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/build.xml?view=diff&rev=513231&r1=513230&r2=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/build.xml (original)
+++ ant/sandbox/antlibs/manual4eclipse/build.xml Thu Mar  1 01:06:12 2007
@@ -18,5 +18,20 @@
 under the License.
 -->
 <project default="distribution" name="m4e">
+
     <import file="common/build.xml"/>
-</project>
\ No newline at end of file
+
+    <target name="m4e" 
+            description="Builds the Eclipse PlugIn from the Ant Manual" 
+            depends="antlib"
+            xmlns:m4e="antlib:org.apache.ant.manual4eclipse">
+        <fail unless="ant.core">You must point property $${ant.core} to Ant's TRUNK directory</fail>
+        <taskdef uri="antlib:org.apache.ant.manual4eclipse"
+                 resource="org/apache/ant/manual4eclipse/antlib.xml"
+                 classpath="${jarname}"/>
+        <m4e:buildPlugin manualDir="${ant.core}/docs/manual" 
+                         buildDir="${build}"
+                         antVersion="1.7.1alpha"
+        />
+    </target>
+</project>

Added: ant/sandbox/antlibs/manual4eclipse/docs/buildPlugin.html
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/docs/buildPlugin.html?view=auto&rev=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/docs/buildPlugin.html (added)
+++ ant/sandbox/antlibs/manual4eclipse/docs/buildPlugin.html Thu Mar  1 01:06:12 2007
@@ -0,0 +1,98 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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.
+-->
+<html>
+
+<head>
+<meta http-equiv="Content-Language" content="en-us">
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
+<title>BuildPlugin Task</title>
+</head>
+
+<body>
+
+
+
+<h2><a name="m4e">BuildPlugin</a></h2>
+<h3>Description</h3>
+<p>
+Building an Eclipse Help plugin is more than creating a <i>toc.xml</i> and a <i>plugin.xml</i>.
+You have to collect all needed files in the needed file structure and create a JAR with OSGi bundle 
+information. Also references between the files should not be go outside the structure in a relative way (you could use links like <i>http://ant.apache.org</i> but no <i>../images</i>). The makro <i>buildPlugin</i> does this work.
+</p>
+<p>
+Mainly the <i>cover.html</i> from the Ant Manual loads an image from the site directory (../images).
+The link will be modified an the graphic will be copied.
+</p>
+
+
+
+<h3>Parameters</h3>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">manualDir</td>
+    <td valign="top">The directory where Ant's manual is.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">antVersion</td>
+    <td valign="top">The version of Ant's Manual.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">buildDir</td>
+    <td valign="top">Where to build the artefacts.</td>
+    <td align="center" valign="top">Yes</i></td>
+  </tr>
+  <tr>
+    <td valign="top">pluginDir</td>
+    <td valign="top">Whether to generate the plugin files.</td>
+    <td align="center" valign="top">No, default &quot;@{buildDir}/manual4eclipse&quot;</i></td>
+  </tr>
+  <tr>
+    <td valign="top">pluginPackage</td>
+    <td valign="top">In which package should the plugin reside.</td>
+    <td align="center" valign="top">No, default &quot;org.apache.ant.manual&quot;</i></td>
+  </tr>
+</table>
+
+
+
+<h3>Examples</h3>
+<pre>
+&lt;target name=&quot;gen&quot; xmlns:m4e=&quot;antlib:org.apache.ant.manual4eclipse&quot;&gt;
+    &lt;property name=&quot;build&quot; value=&quot;build&quot;/&gt;
+    &lt;property name=&quot;ant.trunk&quot; location=&quot;path/to/my/svn/checkout/of/Ant/Core&quot;/&gt;
+    &lt;mkdir dir=&quot;${build}&quot;/&gt;
+    &lt;m4e:buildPlugin manualDir=&quot;${ant.trunk}/docs/manual&quot;
+                     antVersion=&quot;1.7.1alpha&quot;
+                     buildDir=&quot;${build}&quot;
+    /&gt;
+&lt;/target&gt;
+</pre>
+This target generates an Eclipse Help plugin <i>org.apache.ant.manual_1.7.1alpha.v20070301.jar</i>
+(with 20070301 as timestamp) into <i>build</i> with the plugin files and the html manual from 
+<i>path/to/my/svn/checkout/of/Ant/Core/docs/manual</i>.
+
+
+
+</body>
+</html>

Added: ant/sandbox/antlibs/manual4eclipse/docs/cover.html
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/docs/cover.html?view=auto&rev=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/docs/cover.html (added)
+++ ant/sandbox/antlibs/manual4eclipse/docs/cover.html Thu Mar  1 01:06:12 2007
@@ -0,0 +1,18 @@
+<html>
+
+<head>
+<meta http-equiv="Content-Language" content="en-us">
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
+<title>Antlib Manual4Eclipse</title>
+</head>
+
+<body>
+
+<h2>Antlib Manual4Eclipse</h2>
+
+
+<p>This AntLib provides tasks for generating an Eclipse Help PlugIn from Ant's manual.</p>
+
+
+</body>
+</html>

Added: ant/sandbox/antlibs/manual4eclipse/docs/favicon.ico
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/docs/favicon.ico?view=auto&rev=513231
==============================================================================
Binary file - no diff available.

Propchange: ant/sandbox/antlibs/manual4eclipse/docs/favicon.ico
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ant/sandbox/antlibs/manual4eclipse/docs/index.html
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/docs/index.html?view=auto&rev=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/docs/index.html (added)
+++ ant/sandbox/antlibs/manual4eclipse/docs/index.html Thu Mar  1 01:06:12 2007
@@ -0,0 +1,18 @@
+<html>
+
+<head>
+<meta http-equiv="Content-Language" content="en-us">
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
+<title>User Manual - Antlib Manual4Eclipse</title>
+</head>
+
+<frameset cols="26%,74%">
+  <frame src="toc.html" name="navFrame">
+  <frame src="cover.html" name="mainFrame">
+</frameset>
+<noframes>
+  <H2>User Manual - Antlib Manual4Eclipse</H2>
+  <a href="toc.html">User Manual - Antlib Manual4Eclipse</a>
+</noframes>
+
+</html>

Added: ant/sandbox/antlibs/manual4eclipse/docs/m4e.html
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/docs/m4e.html?view=auto&rev=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/docs/m4e.html (added)
+++ ant/sandbox/antlibs/manual4eclipse/docs/m4e.html Thu Mar  1 01:06:12 2007
@@ -0,0 +1,79 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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.
+-->
+<html>
+
+<head>
+<meta http-equiv="Content-Language" content="en-us">
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
+<title>M4E Task</title>
+</head>
+
+<body>
+
+
+
+<h2><a name="m4e">M4E</a></h2>
+<h3>Description</h3>
+<p>
+The m4e task scans the Ant manual table of content files by starting from a given file.
+It acts like a spider. The task is dependent on the frame structure of the manual because 
+it uses all pages opened in the left navigation frame <i>navFrame</i> as references toc file.
+There are build-in ignore lists, but they are not changeable from outside at the moment. 
+</p>
+<p>
+With the scanned information it generates a <i>toc.xml</i> which is needed for 
+<a target="_blank" href="http://help.eclipse.org/help31/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_help_toc.html">Eclipse Help</a>. It writes a plugin.xml with static content, too.
+</p>
+
+
+
+<h3>Parameters</h3>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">dir</td>
+    <td valign="top">The directory where to generate the files.</td>
+    <td align="center" valign="top">yes</td>
+  </tr>
+  <tr>
+    <td valign="top">manualDir</td>
+    <td valign="top">The directory where Ant's manual is.</td>
+    <td align="center" valign="top">yes</td>
+  </tr>
+</table>
+
+
+
+<h3>Examples</h3>
+<pre>
+&lt;target name=&quot;gen&quot; xmlns:m4e=&quot;antlib:org.apache.ant.manual4eclipse&quot;&gt;
+    &lt;property name=&quot;build&quot; value=&quot;build&quot;/&gt;
+    &lt;property name=&quot;ant.trunk&quot; location=&quot;path/to/my/svn/checkout/of/Ant/Core&quot;/&gt;
+    &lt;mkdir dir=&quot;${build}&quot;/&gt;
+    &lt;m4e:m4e dir=&quot;${build}&quot; manualDir=&quot;${ant.trunk}/docs/manual&quot;/&gt;
+&lt;/target&gt;
+</pre>
+This target reads the data from Ant's manual living in <i>path/to/my/svn/checkout/of/Ant/Core/docs/manual</i> and generates a <i>toc.xml</i> and a <i>plugin.xml</i> to <i>build</i>.
+
+
+
+</body>
+</html>

Added: ant/sandbox/antlibs/manual4eclipse/docs/toc.html
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/docs/toc.html?view=auto&rev=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/docs/toc.html (added)
+++ ant/sandbox/antlibs/manual4eclipse/docs/toc.html Thu Mar  1 01:06:12 2007
@@ -0,0 +1,22 @@
+<html>
+
+<head>
+<meta http-equiv="Content-Language" content="en-us">
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
+<title>Antlib Manual4Eclipse</title>
+<base target="mainFrame">
+</head>
+
+<body>
+
+<a href="cover.html">Overview</a><br>
+
+<h2>Tasks</h2>
+
+
+<a href="m4e.html">m4e</a><br>
+<a href="buildPlugin.html">buildPlugin</a><br>
+
+
+</body>
+</html>

Modified: ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/Manual4EclipseTask.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/Manual4EclipseTask.java?view=diff&rev=513231&r1=513230&r2=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/Manual4EclipseTask.java (original)
+++ ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/Manual4EclipseTask.java Thu Mar  1 01:06:12 2007
@@ -41,266 +41,283 @@
  */
 public class Manual4EclipseTask extends Task {
 
-	
-	/** Line Separator. */
-	String BR = System.getProperty("line.separator");
-
-	/** Ant Property: The output directory for generated files. */
-	private File dir;
-
-	/** Ant Property: The directory where the Ant manual (sources) is. */
-	private File manualDir;
-	
-
-	/** List of files which are already processed. */
-	List<File> processedFiles = new ArrayList<File>();
-
-	/** List of Link references <tt><a href="LINK"></tt> to ignore. */
-	List<String> ignoreLinks = new ArrayList<String>();
-
-	/** List of Link references <tt><a href="LINK"></tt> to ignore. */
-	List<String> ignoreTargets = new ArrayList<String>();
-
-	/** List of Link references <tt><a href="LINK"></tt> to ignore. */
-	List<String> ignoreText = new ArrayList<String>();
-
-	
-	public Manual4EclipseTask() {
-		ignoreLinks.add("api/index.html");
-		ignoreTargets.add("_main");
-		ignoreText.add("Ant API");
-		ignoreText.add("Table of Contents");
-	}
-
-	
-	@Override
-	public void execute() throws BuildException {
-		log("Generate Eclipse plugin files");
-		try {
-			createToc(new File(manualDir, "toc.html"));
-			createPluginXml();
-		} catch (Exception e) {
-			throw new BuildException(e, getLocation());
-		}
-	}
-
-	
-	private void createPluginXml() throws IOException {
-		log("generating plugin.xml", Project.MSG_INFO);
-		StringBuffer sb = new StringBuffer();
-		sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>").append(BR);
-		sb.append("<?eclipse version=\"3.2\"?>").append(BR);
-		sb.append("<plugin>").append(BR);
-		sb.append("    <extension point=\"org.eclipse.help.toc\">").append(BR);
-		sb.append("        <toc file=\"toc.xml\" primary=\"true\" />").append(BR);
-		sb.append("        <index path=\"index\"/>").append(BR);
-		sb.append("    </extension>").append(BR);
-		sb.append("    <extension point=\"org.eclipse.help.base.luceneSearchParticipants\">").append(BR);
-		sb.append("        <binding participantId=\"org.eclipse.help.base.xhtml\"/>").append(BR);
-		sb.append("    </extension>").append(BR);
-		sb.append("</plugin>").append(BR);
-		write(sb, new File(dir, "plugin.xml"));
-	}
-
-
-
-	private void createToc(File listHtml) throws IOException, SAXException {
-		log("generating toc.xml", Project.MSG_INFO);
-		StringBuffer toc = new StringBuffer();
-		toc.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>").append(BR);
-		toc.append("<?NLS TYPE=\"org.eclipse.help.toc\"?>").append(BR);
-		toc.append("<toc label=\"Ant Manual\" topic=\"cover.html\">").append(BR);
-		createTopic(toc, listHtml);
-		toc.append("</toc>").append(BR);
-		write(toc, new File(dir, "toc.xml"));
-	}
-
-
-
-	private void createTopic(StringBuffer toc, File listHtml)
-			throws SAXException, IOException {
-		if (processedFiles.contains(listHtml)) {
-			return;
-		}
-		log("Processing " + listHtml, Project.MSG_VERBOSE);
-		processedFiles.add(listHtml);
-		Document document = JAXPUtils.getDocumentBuilder().parse(listHtml);
-		NodeList tagsA = document.getElementsByTagName("a");
-		for (int i = 0; i < tagsA.getLength(); i++) {
-			Topic topic = new Topic(tagsA.item(i));
-			if (topic.isIgnorable()) continue;
-
-			if (topic.hasNestedTopics()) {
-				// start recursion
-				toc.append("<").append(topic).append(">").append(BR);
-				if ("anttaskslist.html".equals(topic.href)) {
-					createTopic4TaskOverview(toc);
-				} else {
-					createTopic(toc, new File(manualDir, topic.href));
-				}
-				toc.append("</topic>").append(BR);
-			} else {
-				toc.append("<").append(topic).append("/>").append(BR);
-			}
-		}
-	}
-
-	
-	
-	/**
-	 * Generate topics for the core and optional tasks.
-	 * Because the task lists (overview, core, optional) have a TOC-header,
-	 * the generic recursion-algorithm does not work. So we have to deal
-	 * with that.
-	 * @param toc    StringBuffer with the toc.xml in progress
-	 * @param label  Label for the root node
-	 * @throws IOException 
-	 * @throws SAXException 
-	 * @throws BuildException 
-	 */
-	private void createTopic4TaskOverview(StringBuffer toc) throws BuildException, SAXException, IOException {
-		File taskListFile = new File(manualDir, "anttaskslist.html");
-		File coreTaskFile = new File(manualDir, "coretasklist.html");
-		File optionalTask = new File(manualDir, "optionaltasklist.html");
-		processedFiles.add(taskListFile);
-		processedFiles.add(coreTaskFile);
-		processedFiles.add(optionalTask);
-
-		log("Using hard coded TOC-structure instead of " + taskListFile, Project.MSG_VERBOSE);
-		
-		toc.append("<topic label=\"Overview of Ant Tasks\" href=\"tasksoverview.html\"/>").append(BR);
-		toc.append("<topic label=\"Core Tasks\">").append(BR);
-		// Core Tasks
-		createTopics4TaskList(toc, coreTaskFile);
-		toc.append("</topic>").append(BR);
-		toc.append("<topic label=\"Optional Tasks\">").append(BR);
-		// Optional Tasks
-		toc.append("<topic label=\"Library Dependencies\" href=\"install.html#librarydependencies\"/>").append(BR);
-		createTopics4TaskList(toc, optionalTask);
-		toc.append("</topic>").append(BR);
-	}
-	
-	
-
-	/**
-	 * Creates a <topic> element (with nested) for Task list.
-	 * The task lists are placed after a &lt;h3> header and there are
-	 * &lt;a> tags before that. So we have to do more work and search
-	 * for the right are.
-	 * @param toc    StringBuffer with the toc.xml in progress
-	 * @param file   The file with the task list
-	 * @throws BuildException
-	 * @throws SAXException
-	 * @throws IOException
-	 */
-	private void createTopics4TaskList(StringBuffer toc, File file) throws BuildException, SAXException, IOException {
-		log("Processing " + file, Project.MSG_VERBOSE);
-		Document doc = JAXPUtils.getDocumentBuilder().parse(file);
-		// Access to the HTML root element
-		Element html = doc.getDocumentElement();
-		// search for the <body> element
-		Element body = null;
-		NodeList childNodes = html.getChildNodes();
-		for (int i=0; i<childNodes.getLength(); i++) {
-			Node n = childNodes.item(i);
-			if (n.getNodeName().equalsIgnoreCase("body")) {
-				body = (Element)n;
-			}
-		}
-		// search in the body for the task listing
-		childNodes = body.getChildNodes();
-		boolean needSection = false;
-		for (int i=0; i<childNodes.getLength(); i++) {
-			Node n = childNodes.item(i);
-			// After the H3-section we'll get the task listing
-			if (needSection) {
-				if (n.getNodeName().equalsIgnoreCase("a")) {
-					Topic t = new Topic(n);
-					toc.append("<").append(t.toString()).append("/>").append(BR);
-				}
-			}
-			if (n.getNodeName().equalsIgnoreCase("h3")) {
-				needSection = true;
-			}
-		}
-	}
-
-
-	
-
-	/**
-	 * Writes a StringBuffer to file.
-	 * @param sb   The StringBuffer to write
-	 * @param file The file to write into
-	 * @throws IOException if writing throws an IOException
-	 */
-	private void write(StringBuffer sb, File file) throws IOException {
-		FileWriter out = new FileWriter(file);
-		out.write(sb.toString());
-		out.close();
-	}
-
-
-
-	public void setDir(File dir) {
-		this.dir = dir;
-	}
-
-	public void setManualDir(File manualDir) {
-		this.manualDir = manualDir;
-	}
-
-	
-	
-	
-	/**
-	 * This class encapsulates the information of a <tt><a></tt> tag from a 
-	 * toc-listing from the Ant manual.
-	 */
-	public class Topic {
-		/** <topic>s label attribute gets the value from &lt;a>s text content. */
-		String label;
-		/** Internal value coming from &lt;a>s target attribute. */
-		String target;
-		/** <topic>s href attribute gets the value from &lt;a>s href attribute. */
-		String href;
-		
-		/**
-		 * Constructor analyzes a DOMNode and creates a Topic object.
-		 * @param n the DOMNode
-		 */
-		public Topic(Node n) {
-			Node item = n.getAttributes().getNamedItem("href");
-			href   = (item!=null) ? item.getTextContent() : "";
-			item = n.getAttributes().getNamedItem("target");
-			target = (item!=null) ? item.getTextContent() : "";
-			label  = n.getTextContent().trim();
-		}
-		/**
-		 * Checks the data against the three ignore-lists.
-		 * @return <i>true</i> if one (or more) of the lists matches
-		 */
-		public boolean isIgnorable() {
-			return ignoreLinks.contains(href)
-			    || ignoreTargets.contains(target)
-			    || ignoreText.contains(label);
-		}
-		/**
-		 * You have to create nested <topic> elements if the link-target
-		 * would open the linked page in the navigation frame. This method
-		 * does the check.
-		 * @return <i>true</i> if nestd <topic> elements could come.
-		 */
-		public boolean hasNestedTopics() {
-			return "navFrame".equals(target);
-		}
-		@Override
-		public String toString() {
-			StringBuffer rv = new StringBuffer("topic");
-			if (label.length()>0) rv.append(" label=\"").append(label).append("\"");
-			if (href.length()>0 && !hasNestedTopics())  rv.append(" href=\"").append(href).append("\"");
-			return rv.toString().replaceAll("&", "&amp;");
-		}
-	}
-	
+
+    /** Line Separator. */
+    String BR = System.getProperty("line.separator");
+
+    /** Ant Property: The output directory for generated files. */
+    private File dir;
+
+    /** Ant Property: The directory where the Ant manual (sources) is. */
+    private File manualDir;
+    
+
+    /** List of files which are already processed. */
+    List<File> processedFiles = new ArrayList<File>();
+
+    /** List of Link references <tt><a href="LINK"></tt> to ignore. */
+    List<String> ignoreLinks = new ArrayList<String>();
+
+    /** List of Link references <tt><a href="LINK"></tt> to ignore. */
+    List<String> ignoreTargets = new ArrayList<String>();
+
+    /** List of Link references <tt><a href="LINK"></tt> to ignore. */
+    List<String> ignoreText = new ArrayList<String>();
+
+
+    public Manual4EclipseTask() {
+        ignoreLinks.add("api/index.html");
+        ignoreTargets.add("_main");
+        ignoreText.add("Ant API");
+        ignoreText.add("Table of Contents");
+    }
+
+
+    @Override
+    public void execute() throws BuildException {
+        validate();
+        log("Generate Eclipse plugin files");
+        try {
+            createToc(new File(manualDir, "toc.html"));
+            createPluginXml();
+        } catch (Exception e) {
+            throw new BuildException(e, getLocation());
+        }
+    }
+
+
+    private void validate() {
+        if (dir==null) {
+            throw new BuildException("'dir' must point to a directory where to generate the files.");
+        }
+        if (manualDir==null) {
+            throw new BuildException("'manualDir' must point to the directory of the Ant Manual.");
+        }
+        if (!dir.canWrite()) {
+            throw new BuildException("Output directory '" + dir + "' is not writable.");
+        }
+        if (!manualDir.canRead()) {
+            throw new BuildException("Manual directory '" + manualDir + "' is not readable.");
+        }
+    }
+
+
+    private void createPluginXml() throws IOException {
+        log("generating plugin.xml", Project.MSG_INFO);
+        StringBuffer sb = new StringBuffer();
+        sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>").append(BR);
+        sb.append("<?eclipse version=\"3.2\"?>").append(BR);
+        sb.append("<plugin>").append(BR);
+        sb.append("    <extension point=\"org.eclipse.help.toc\">").append(BR);
+        sb.append("        <toc file=\"toc.xml\" primary=\"true\" />").append(BR);
+        sb.append("        <index path=\"index\"/>").append(BR);
+        sb.append("    </extension>").append(BR);
+        sb.append("    <extension point=\"org.eclipse.help.base.luceneSearchParticipants\">").append(BR);
+        sb.append("        <binding participantId=\"org.eclipse.help.base.xhtml\"/>").append(BR);
+        sb.append("    </extension>").append(BR);
+        sb.append("</plugin>").append(BR);
+        write(sb, new File(dir, "plugin.xml"));
+    }
+
+
+
+    private void createToc(File listHtml) throws IOException, SAXException {
+        log("generating toc.xml", Project.MSG_INFO);
+        StringBuffer toc = new StringBuffer();
+        toc.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>").append(BR);
+        toc.append("<?NLS TYPE=\"org.eclipse.help.toc\"?>").append(BR);
+        toc.append("<toc label=\"Ant Manual\" topic=\"cover.html\">").append(BR);
+        createTopic(toc, listHtml);
+        toc.append("</toc>").append(BR);
+        write(toc, new File(dir, "toc.xml"));
+    }
+
+
+
+    private void createTopic(StringBuffer toc, File listHtml)
+            throws SAXException, IOException {
+        if (processedFiles.contains(listHtml)) {
+            return;
+        }
+        log("Processing " + listHtml, Project.MSG_VERBOSE);
+        processedFiles.add(listHtml);
+        Document document = JAXPUtils.getDocumentBuilder().parse(listHtml);
+        NodeList tagsA = document.getElementsByTagName("a");
+        for (int i = 0; i < tagsA.getLength(); i++) {
+            Topic topic = new Topic(tagsA.item(i));
+            if (topic.isIgnorable()) continue;
+
+            if (topic.hasNestedTopics()) {
+                // start recursion
+                toc.append("<").append(topic).append(">").append(BR);
+                if ("anttaskslist.html".equals(topic.href)) {
+                    createTopic4TaskOverview(toc);
+                } else {
+                    createTopic(toc, new File(manualDir, topic.href));
+                }
+                toc.append("</topic>").append(BR);
+            } else {
+                toc.append("<").append(topic).append("/>").append(BR);
+            }
+        }
+    }
+
+
+
+    /**
+     * Generate topics for the core and optional tasks.
+     * Because the task lists (overview, core, optional) have a TOC-header,
+     * the generic recursion-algorithm does not work. So we have to deal
+     * with that.
+     * @param toc    StringBuffer with the toc.xml in progress
+     * @param label  Label for the root node
+     * @throws IOException 
+     * @throws SAXException 
+     * @throws BuildException 
+     */
+    private void createTopic4TaskOverview(StringBuffer toc) throws BuildException, SAXException, IOException {
+        File taskListFile = new File(manualDir, "anttaskslist.html");
+        File coreTaskFile = new File(manualDir, "coretasklist.html");
+        File optionalTask = new File(manualDir, "optionaltasklist.html");
+        processedFiles.add(taskListFile);
+        processedFiles.add(coreTaskFile);
+        processedFiles.add(optionalTask);
+
+        log("Using hard coded TOC-structure instead of " + taskListFile, Project.MSG_VERBOSE);
+        
+        toc.append("<topic label=\"Overview of Ant Tasks\" href=\"tasksoverview.html\"/>").append(BR);
+        toc.append("<topic label=\"Core Tasks\">").append(BR);
+        // Core Tasks
+        createTopics4TaskList(toc, coreTaskFile);
+        toc.append("</topic>").append(BR);
+        toc.append("<topic label=\"Optional Tasks\">").append(BR);
+        // Optional Tasks
+        toc.append("<topic label=\"Library Dependencies\" href=\"install.html#librarydependencies\"/>").append(BR);
+        createTopics4TaskList(toc, optionalTask);
+        toc.append("</topic>").append(BR);
+    }
+
+
+
+    /**
+     * Creates a <topic> element (with nested) for Task list.
+     * The task lists are placed after a &lt;h3> header and there are
+     * &lt;a> tags before that. So we have to do more work and search
+     * for the right are.
+     * @param toc    StringBuffer with the toc.xml in progress
+     * @param file   The file with the task list
+     * @throws BuildException
+     * @throws SAXException
+     * @throws IOException
+     */
+    private void createTopics4TaskList(StringBuffer toc, File file) throws BuildException, SAXException, IOException {
+        log("Processing " + file, Project.MSG_VERBOSE);
+        Document doc = JAXPUtils.getDocumentBuilder().parse(file);
+        // Access to the HTML root element
+        Element html = doc.getDocumentElement();
+        // search for the <body> element
+        Element body = null;
+        NodeList childNodes = html.getChildNodes();
+        for (int i=0; i<childNodes.getLength(); i++) {
+            Node n = childNodes.item(i);
+            if (n.getNodeName().equalsIgnoreCase("body")) {
+                body = (Element)n;
+            }
+        }
+        // search in the body for the task listing
+        childNodes = body.getChildNodes();
+        boolean needSection = false;
+        for (int i=0; i<childNodes.getLength(); i++) {
+            Node n = childNodes.item(i);
+            // After the H3-section we'll get the task listing
+            if (needSection) {
+                if (n.getNodeName().equalsIgnoreCase("a")) {
+                    Topic t = new Topic(n);
+                    toc.append("<").append(t.toString()).append("/>").append(BR);
+                }
+            }
+            if (n.getNodeName().equalsIgnoreCase("h3")) {
+                needSection = true;
+            }
+        }
+    }
+
+
+
+
+    /**
+     * Writes a StringBuffer to file.
+     * @param sb   The StringBuffer to write
+     * @param file The file to write into
+     * @throws IOException if writing throws an IOException
+     */
+    private void write(StringBuffer sb, File file) throws IOException {
+        FileWriter out = new FileWriter(file);
+        out.write(sb.toString());
+        out.close();
+    }
+
+
+
+    public void setDir(File dir) {
+        this.dir = dir;
+    }
+
+    public void setManualDir(File manualDir) {
+        this.manualDir = manualDir;
+    }
+
+
+
+
+    /**
+     * This class encapsulates the information of a <tt><a></tt> tag from a 
+     * toc-listing from the Ant manual.
+     */
+    public class Topic {
+        /** <topic>s label attribute gets the value from &lt;a>s text content. */
+        String label;
+        /** Internal value coming from &lt;a>s target attribute. */
+        String target;
+        /** <topic>s href attribute gets the value from &lt;a>s href attribute. */
+        String href;
+        
+        /**
+         * Constructor analyzes a DOMNode and creates a Topic object.
+         * @param n the DOMNode
+         */
+        public Topic(Node n) {
+            Node item = n.getAttributes().getNamedItem("href");
+            href   = (item!=null) ? item.getTextContent() : "";
+            item = n.getAttributes().getNamedItem("target");
+            target = (item!=null) ? item.getTextContent() : "";
+            label  = n.getTextContent().trim();
+        }
+        /**
+         * Checks the data against the three ignore-lists.
+         * @return <i>true</i> if one (or more) of the lists matches
+         */
+        public boolean isIgnorable() {
+            return ignoreLinks.contains(href)
+                || ignoreTargets.contains(target)
+                || ignoreText.contains(label);
+        }
+        /**
+         * You have to create nested <topic> elements if the link-target
+         * would open the linked page in the navigation frame. This method
+         * does the check.
+         * @return <i>true</i> if nestd <topic> elements could come.
+         */
+        public boolean hasNestedTopics() {
+            return "navFrame".equals(target);
+        }
+        @Override
+        public String toString() {
+            StringBuffer rv = new StringBuffer("topic");
+            if (label.length()>0) rv.append(" label=\"").append(label).append("\"");
+            if (href.length()>0 && !hasNestedTopics())  rv.append(" href=\"").append(href).append("\"");
+            return rv.toString().replaceAll("&", "&amp;");
+        }
+    }
+
 }

Added: ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/antlib.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/antlib.xml?view=auto&rev=513231
==============================================================================
--- ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/antlib.xml (added)
+++ ant/sandbox/antlibs/manual4eclipse/src/main/org/apache/ant/manual4eclipse/antlib.xml Thu Mar  1 01:06:12 2007
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+<antlib xmlns:current="ant:current">
+    <taskdef name="m4e" classname="org.apache.ant.manual4eclipse.Manual4EclipseTask"/>
+    <macrodef name="buildPlugin">
+        <attribute name="manualDir"/>
+        <attribute name="buildDir"/>
+        <attribute name="pluginDir" default="@{buildDir}/manual4eclipse"/>
+        <attribute name="pluginPackage" default="org.apache.ant.manual"/>
+        <attribute name="antVersion"/>
+        <sequential>
+            <tstamp>
+                <format property="timestamp" pattern="yyyyMMdd"/>
+            </tstamp>
+
+            <mkdir dir="@{pluginDir}"/>
+            
+            <!-- Generate Eclipse PlugIn files -->
+            <current:m4e dir="@{pluginDir}" manualDir="@{manualDir}"/>
+
+            <!-- Have to modify the cover.html because it refers to an image outside the manual dir. -->
+            <copy todir="@{pluginDir}" file="@{manualDir}/../images/ant_logo_large.gif"/>
+            <copy todir="@{pluginDir}" file="@{manualDir}/cover.html">
+                <filterchain>
+                    <replaceregex pattern="..\/images\/ant_logo_large.gif" replace="ant_logo_large.gif"/>
+                </filterchain>
+            </copy>
+
+            <!-- Jar the stuff -->
+            <jar destfile="@{buildDir}/@{pluginPackage}_@{antVersion}.v${timestamp}.jar" duplicate="preserve">
+                <fileset dir="@{pluginDir}"/>
+                <fileset dir="@{manualDir}"/>
+                <manifest>
+                    <!-- Who is building this jar? -->
+                    <attribute name="Built-By" value="${user.name}"/>
+                    <!-- Information about the program itself -->
+                    <attribute name="Implementation-Vendor"  value="Apache Software Foundation"/>
+                    <attribute name="Implementation-Title"   value="Ant Manual"/>
+                    <attribute name="Implementation-Version" value="@{antVersion}"/>
+                    <!-- Eclipse-PlugIn Information -->
+                    <attribute name="Bundle-Name"            value="Ant Manual"/>
+                    <attribute name="Bundle-Vendor"          value="ant.apache.org"/>
+                    <attribute name="Bundle-ManifestVersion" value="2"/>
+                    <attribute name="Bundle-Localization"    value="plugin"/>
+                    <attribute name="Bundle-SymbolicName"    value="@{pluginPackage}; singleton:=true"/>
+                    <attribute name="Bundle-Version"         value="@{antVersion}.v${timestamp}"/>
+                    <attribute name="Eclipse-LazyStart"      value="true"/>
+                </manifest>
+            </jar>
+        </sequential>
+    </macrodef>
+</antlib>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org