Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejan Gloszic2005-04-08 22:30:41 +0000
committerDejan Gloszic2005-04-08 22:30:41 +0000
commit00df13b4c066e115bc63b080a3f05b9d16390a0b (patch)
treedc4c63fd2a259b5916031dfe98928831a4d085de /org.eclipse.help.base
parent2490cc33a17d6a2e126e4a179945961ac89d4b48 (diff)
downloadeclipse.platform.ua-00df13b4c066e115bc63b080a3f05b9d16390a0b.tar.gz
eclipse.platform.ua-00df13b4c066e115bc63b080a3f05b9d16390a0b.tar.xz
eclipse.platform.ua-00df13b4c066e115bc63b080a3f05b9d16390a0b.zip
*** empty log message ***
Diffstat (limited to 'org.eclipse.help.base')
-rw-r--r--org.eclipse.help.base/.classpath15
-rw-r--r--org.eclipse.help.base/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.help.base/build.properties7
-rw-r--r--org.eclipse.help.base/plugin.xml15
-rw-r--r--org.eclipse.help.base/src_ant/org/eclipse/help/base/ant/BuildHelpIndex.java200
5 files changed, 235 insertions, 5 deletions
diff --git a/org.eclipse.help.base/.classpath b/org.eclipse.help.base/.classpath
index 065ac06e1..8c4f20fec 100644
--- a/org.eclipse.help.base/.classpath
+++ b/org.eclipse.help.base/.classpath
@@ -1,7 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="src" path="src">
+ <attributes>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <attributes>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
+ <attributes>
+ </attributes>
+ </classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.help.base/META-INF/MANIFEST.MF b/org.eclipse.help.base/META-INF/MANIFEST.MF
index 9aedb7e3b..a54594022 100644
--- a/org.eclipse.help.base/META-INF/MANIFEST.MF
+++ b/org.eclipse.help.base/META-INF/MANIFEST.MF
@@ -21,5 +21,6 @@ Export-Package: org.eclipse.help.browser,
Require-Bundle: org.apache.lucene,
org.eclipse.help;visibility:=reexport,
org.eclipse.help.appserver,
- org.eclipse.core.runtime
+ org.eclipse.core.runtime,
+ org.eclipse.ant.core
Eclipse-AutoStart: true
diff --git a/org.eclipse.help.base/build.properties b/org.eclipse.help.base/build.properties
index 009ef6aba..4cb02507e 100644
--- a/org.eclipse.help.base/build.properties
+++ b/org.eclipse.help.base/build.properties
@@ -17,5 +17,10 @@ bin.includes = doc/,\
plugin.properties,\
about.html,\
.options,\
- META-INF/
+ META-INF/,\
+ ant_asks/helpbase-ant.jar
+jars.compile.order = .,\
+ ant_asks/helpbase-ant.jar
+source.ant_asks/helpbase-ant.jar = src_ant/
+jars.extra.classpath = ../org.apache.ant/lib/ant.jar
diff --git a/org.eclipse.help.base/plugin.xml b/org.eclipse.help.base/plugin.xml
index 25793c4fd..425c2294e 100644
--- a/org.eclipse.help.base/plugin.xml
+++ b/org.eclipse.help.base/plugin.xml
@@ -139,5 +139,20 @@
point="org.eclipse.core.runtime.preferences">
<initializer class="org.eclipse.help.internal.base.HelpBasePreferenceInitializer"/>
</extension>
+
+ <extension
+ point="org.eclipse.ant.core.antTasks">
+ <antTask
+ library="ant_tasks/helpbase-ant.jar"
+ name="help.buildHelpIndex"
+ class="org.eclipse.help.base.ant.BuildHelpIndex">
+ </antTask>
+ </extension>
+ <extension
+ point="org.eclipse.ant.core.extraClasspathEntries">
+ <extraClasspathEntry
+ library="ant_tasks/helpbase-ant.jar">
+ </extraClasspathEntry>
+ </extension>
</plugin>
diff --git a/org.eclipse.help.base/src_ant/org/eclipse/help/base/ant/BuildHelpIndex.java b/org.eclipse.help.base/src_ant/org/eclipse/help/base/ant/BuildHelpIndex.java
new file mode 100644
index 000000000..f696c1bd2
--- /dev/null
+++ b/org.eclipse.help.base/src_ant/org/eclipse/help/base/ant/BuildHelpIndex.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.help.base.ant;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.eclipse.ant.core.AntCorePlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.PluginVersionIdentifier;
+import org.eclipse.osgi.util.ManifestElement;
+import org.osgi.framework.Constants;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+public class BuildHelpIndex extends Task {
+ private static final String POINT_TOC = "org.eclipse.help.toc";
+ private String manifest;
+ private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
+ .newInstance();
+ private DocumentBuilder parser;
+
+ class PluginIdentifier {
+ String id;
+ PluginVersionIdentifier version;
+ public PluginIdentifier(String id, String version) {
+ this.id = id;
+ this.version = new PluginVersionIdentifier(version);
+ }
+ }
+
+ public void execute() throws BuildException {
+ IProgressMonitor monitor =
+ (IProgressMonitor) getProject().getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
+
+ Document doc = readManifestFile();
+ if (doc == null)
+ return;
+
+ PluginIdentifier pluginID = getPluginID(doc);
+
+ Node[] extensions = getTocExtensions(doc);
+ for (int i = 0; i < extensions.length; i++) {
+ Node extensionNode = extensions[i];
+ String file = getAttribute(extensionNode, "file");
+ String primary = getAttribute(extensionNode, "primary");
+ String extradir = getAttribute(extensionNode, "extradir");
+ addTocFile(pluginID, file, primary, extradir);
+ }
+ doc = null; // discard the DOM
+ }
+
+ private void addTocFile(PluginIdentifier pluginID, String file, String primary, String extradir) {
+ System.out.println("Adding toc: file="+file+", primary="+primary+", extradir="+extradir);
+ }
+
+ private PluginIdentifier getPluginID(Document doc) {
+ Node root = doc.getDocumentElement();
+ String id = getAttribute(root, "id");
+ String version = getAttribute(root, "version");
+ if (id!=null && version!=null)
+ return new PluginIdentifier(id, version);
+ // check for the OSGi manifest
+ File file =
+ new Path(manifest).isAbsolute()
+ ? new File(manifest)
+ : new File(getProject().getBaseDir(), manifest);
+ File OSGiFile = new File(file.getParentFile(), "META-INF/MANIFEST.MF"); //$NON-NLS-1$
+
+ if (OSGiFile.exists()) {
+ try {
+ Manifest OSGiManifest = new Manifest(new FileInputStream(OSGiFile));
+ Dictionary headers = manifestToProperties(OSGiManifest.getMainAttributes());
+ String value = headers.get(Constants.BUNDLE_SYMBOLICNAME).toString();
+ if (value == null)
+ return null;
+ ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, value);
+ if (elements.length > 0)
+ id= elements[0].getValue();
+ value = headers.get(Constants.BUNDLE_VERSION).toString();
+ if (value == null)
+ return null;
+ elements = ManifestElement.parseHeader(Constants.BUNDLE_VERSION, value);
+ if (elements.length >0)
+ version = elements[0].getValue();
+ if (id!=null && version!=null)
+ return new PluginIdentifier(id, version);
+ } catch (Exception e1) {
+ System.out.print(e1.getMessage());
+ }
+ }
+ return null;
+ }
+
+ private String getAttribute(Node node, String name) {
+ NamedNodeMap atts = node.getAttributes();
+ if (atts!=null) {
+ Node att = atts.getNamedItem(name);
+ if (att!=null)
+ return att.getNodeValue();
+ }
+ return null;
+ }
+
+ public void setManifest(String manifest) {
+ this.manifest = manifest;
+ }
+
+ private Document readManifestFile() {
+ if (manifest == null) {
+ //System.out.println(
+ //NLS.bind(PDEMessages.Builders_Convert_missingAttribute, "manifest")); //$NON-NLS-1$ //$NON-NLS-2$
+ return null;
+ }
+
+ File file =
+ new Path(manifest).isAbsolute()
+ ? new File(manifest)
+ : new File(getProject().getBaseDir(), manifest);
+ InputStream stream = null;
+ Document d = null;
+ try {
+ stream = new FileInputStream(file);
+ InputStreamReader reader = new InputStreamReader(stream, "utf-8"); //$NON-NLS-1$
+
+ InputSource inputSource = new InputSource(reader);
+ inputSource.setSystemId(file.toString());
+
+ if (parser==null)
+ parser = documentBuilderFactory
+ .newDocumentBuilder();
+ d = parser.parse(inputSource);
+ stream.close();
+ } catch (Exception e) {
+ if (e.getMessage() != null)
+ System.out.println(e.getMessage());
+ return null;
+ }
+ finally {
+ if (stream!=null) {
+ try {
+ stream.close();
+ }
+ catch (IOException e) {
+ }
+ stream = null;
+ }
+ }
+ return d;
+ }
+
+ private Node [] getTocExtensions(Document doc) {
+ ArrayList list = new ArrayList();
+ Node root = doc.getDocumentElement();
+ NodeList children = doc.getElementsByTagName("extension");
+ for (int i=0; i<children.getLength(); i++) {
+ Node child = children.item(i);
+ String point = getAttribute(child, "point");
+ if (point.equals(POINT_TOC))
+ list.add(child);
+ }
+ return (Node[])list.toArray(new Node[list.size()]);
+ }
+
+ private Properties manifestToProperties(Attributes d) {
+ Iterator iter = d.keySet().iterator();
+ Properties result = new Properties();
+ while (iter.hasNext()) {
+ Attributes.Name key = (Attributes.Name) iter.next();
+ result.put(key.toString(), d.get(key));
+ }
+ return result;
+ }
+}

Back to the top