summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis Windatt2013-08-20 17:40:35 (EDT)
committerCurtis Windatt2013-08-20 17:40:35 (EDT)
commit5c9fb3716b760a6585d0ae57e3c3a6cea91754fe (patch)
tree4684d26713379794b0c9caa49e7eff218a4e9554
parentddbdc5aecddc3fbc2810a3e1dbd2d7506948ee16 (diff)
downloadeclipse.pde.ui-5c9fb3716b760a6585d0ae57e3c3a6cea91754fe.zip
eclipse.pde.ui-5c9fb3716b760a6585d0ae57e3c3a6cea91754fe.tar.gz
eclipse.pde.ui-5c9fb3716b760a6585d0ae57e3c3a6cea91754fe.tar.bz2
Bug 415008 - All extension point docs which include a file using the
schema: protocol are broken Change-Id: Iecd524372ced6b2fa8a456016d19fb3e32267847
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java2
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/SchemaErrorReporter.java5
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties1
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/IncludedSchemaDescriptor.java96
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/Schema.java21
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaDescriptor.java25
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaInclude.java29
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaRegistry.java4
-rw-r--r--ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java160
9 files changed, 253 insertions, 90 deletions
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
index 5b37cbb..043f453 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
@@ -272,6 +272,8 @@ public class PDECoreMessages extends NLS {
public static String ClasspathHelper_BadFileLocation;
+ public static String ConvertSchemaToHTML_InvalidAdditionalSearchPath;
+
public static String ExportWizard_badDirectory;
public static String FeatureExportJob_taskName;
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/SchemaErrorReporter.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/SchemaErrorReporter.java
index 049b4b0..670e46d 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/SchemaErrorReporter.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/SchemaErrorReporter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 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
@@ -84,6 +84,7 @@ public class SchemaErrorReporter extends XMLErrorReporter {
fSchema = desc.getSchema(false);
}
+ @Override
public void validateContent(IProgressMonitor monitor) {
List<String> elements = new ArrayList<String>();
Element element = getDocumentRoot();
@@ -278,7 +279,7 @@ public class SchemaErrorReporter extends XMLErrorReporter {
if (includedSchema == null)
continue;
URL includedSchemaUrl = includedSchema.getURL();
- URL computedUrl = IncludedSchemaDescriptor.computeURL(fSchema.getSchemaDescriptor(), schemaLocation);
+ URL computedUrl = IncludedSchemaDescriptor.computeURL(fSchema.getSchemaDescriptor(), schemaLocation, null);
if (includedSchemaUrl != null && computedUrl != null && includedSchemaUrl.equals(computedUrl)) {
if (!includedSchema.isValid())
report(NLS.bind(PDECoreMessages.Builders_Schema_includeNotValid, schemaLocation), getLine(element), CompilerFlags.ERROR, PDEMarkerFactory.CAT_OTHER);
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
index 4f91105..54ddeb1 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
@@ -213,6 +213,7 @@ FeatureExportOperation_runningPackagerScript=Running packager script
FeatureExportOperation_workspaceBuildErrorsFoundDuringExport=Export completed successfully, but build problems were detected in the following required projects: {0}
BaseExportTask_pdeExport=PDE Export
ClasspathHelper_BadFileLocation=Could not determine absolute location of file: {0}
+ConvertSchemaToHTML_InvalidAdditionalSearchPath=Invalid path found in additional search paths: {0}
XMLErrorReporter_ExternalEntityResolution=External entity resolution is not supported by PDE.
XMLTextChangeListener_editNames_removeNode=Remove "{0}" node
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/IncludedSchemaDescriptor.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/IncludedSchemaDescriptor.java
index e607a29..f8fc3a0 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/IncludedSchemaDescriptor.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/IncludedSchemaDescriptor.java
@@ -11,12 +11,13 @@
package org.eclipse.pde.internal.core.schema;
import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
+import java.net.*;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.core.runtime.*;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
+import org.eclipse.pde.internal.core.ant.ConvertSchemaToHTML;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
@@ -33,12 +34,12 @@ public class IncludedSchemaDescriptor implements ISchemaDescriptor {
fLastModified = file.lastModified();
}
- public static URL computeURL(ISchemaDescriptor parentDesc, String schemaLocation) throws MalformedURLException {
+ public static URL computeURL(ISchemaDescriptor parentDesc, String schemaLocation, List<IPath> additionalSearchLocations) throws MalformedURLException {
URL parentURL = parentDesc == null ? null : parentDesc.getSchemaURL();
if (schemaLocation.startsWith("schema://")) { //$NON-NLS-1$
// extract plug-in ID
IPath path = new Path(schemaLocation.substring(9));
- return getPluginRelativePath(path.segment(0), path.removeFirstSegments(1), parentURL);
+ return getPluginRelativePath(path.segment(0), path.removeFirstSegments(1), parentURL, additionalSearchLocations);
}
if (parentURL == null)
@@ -50,26 +51,83 @@ public class IncludedSchemaDescriptor implements ISchemaDescriptor {
return new URL(parentURL.getProtocol(), parentURL.getHost(), path.toString());
}
- private static URL getPluginRelativePath(String pluginID, IPath path, URL parentURL) {
+ /**
+ * Creates a URL describing the location of a included schema. First looks up
+ * the plug-in in the schema registry, then tries additional source locations,
+ * then looks for a co-located plug-in, then looks in the additional search
+ * path locations.
+ *
+ * @param pluginID ID of the plug-in owning the schema
+ * @param path the path to the schema inside the plug-in
+ * @param parentURL url of the parent schema file
+ * @param additionalSearchPath list of additional locations to search, only used with the {@link ConvertSchemaToHTML} ant task
+ * @return a url location of the included schema or <code>null</code>
+ */
+ private static URL getPluginRelativePath(String pluginID, IPath path, URL parentURL, List<IPath> additionalSearchPath) {
+ // Start by looking in the schema registry
URL url = SchemaRegistry.getSchemaURL(pluginID, path.toString());
+
+ // Next search source locations
if (url == null) {
IPluginModelBase model = PluginRegistry.findModel(pluginID);
if (model != null)
url = SchemaRegistry.getSchemaFromSourceExtension(model.getPluginBase(), path);
}
- try {
- if (url == null && parentURL != null) {
- String parentFile = parentURL.getFile();
- if (parentFile == null)
- return null;
- int lastSep = parentFile.lastIndexOf(File.separatorChar);
- parentFile = parentFile.substring(0, lastSep + 1);
- // assuming schemas are located in: pluginId/schema/schemaFile.exsd
- File file = new File(parentFile + "../../" + pluginID + "/" + path.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- if (file.exists() && file.isFile())
- url = file.toURL();
+
+ File parentFile = null;
+ if (url == null && parentURL != null) {
+ try {
+ parentFile = URIUtil.toFile(URIUtil.toURI(parentURL));
+ } catch (URISyntaxException e) {
+ }
+ }
+
+ // If we are running the ant task, see if another project co-located with the parent contains the schema file
+ // The project folder must have the plug-in ID as its file name
+ if (url == null && parentFile != null) {
+ try {
+ // assuming schemas are located in: pluginId/schema/schemaFile.exsd (need to go up to parent of plug-in directory)
+ File pluginFile = new File(parentFile + "/../../../" + pluginID); //$NON-NLS-1$
+ if (pluginFile.isDirectory()) {
+ File schemaFile = new File(pluginFile, path.toOSString());
+ if (schemaFile.exists()) {
+ url = schemaFile.toURL();
+ }
+ // This is how we would extract the schema from a jar, but in practice this will never be the case
+ // because when a bundle is built, the schema files are moved to the source bundle, not the bundle we are checking
+// } else if (CoreUtility.jarContainsResource(pluginFile, path.toPortableString(), false)) {
+// url = new URL("jar:file:" + pluginFile.getAbsolutePath() + "!/" + path); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } catch (MalformedURLException e) {
+ }
+ }
+
+ // If we are running the ant task, additional search locations may be provided
+ // The project folder must have the plug-in ID as its file name
+ if (url == null && additionalSearchPath != null) {
+ for (Iterator<IPath> iterator = additionalSearchPath.iterator(); iterator.hasNext();) {
+ IPath currentSearch = iterator.next();
+ File pluginFile = null;
+ if (currentSearch.isAbsolute()) {
+ // Append plug-in id directly to absolute paths
+ pluginFile = new File(currentSearch.toFile(), pluginID);
+ } else if (parentFile != null) {
+ // Append relative path to parent file location
+ File file = new File(parentFile, currentSearch.toOSString());
+ pluginFile = new File(file, pluginID);
+ }
+
+ if (pluginFile != null && pluginFile.isDirectory()) {
+ try {
+ File schemaFile = new File(pluginFile, path.toOSString());
+ if (schemaFile.exists()) {
+ url = schemaFile.toURL();
+ break;
+ }
+ } catch (MalformedURLException e) {
+ }
+ }
}
- } catch (MalformedURLException e) {
}
return url;
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/Schema.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/Schema.java
index 3c189a8..e35539a 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/Schema.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/Schema.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -14,8 +14,7 @@ package org.eclipse.pde.internal.core.schema;
import java.io.*;
import java.net.*;
import java.util.*;
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.*;
import org.eclipse.pde.core.*;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
@@ -63,6 +62,8 @@ public class Schema extends PlatformObject implements ISchema {
private boolean fAbbreviated;
+ private List<IPath> fSearchPath;
+
public Schema(String pluginId, String pointId, String name, boolean abbreviated) {
fPluginID = pluginId;
fPointID = pointId;
@@ -752,7 +753,7 @@ public class Schema extends PlatformObject implements ISchema {
private void processInclude(Node node) {
String location = getAttribute(node, "schemaLocation"); //$NON-NLS-1$
- SchemaInclude include = new SchemaInclude(this, location, fAbbreviated);
+ SchemaInclude include = new SchemaInclude(this, location, fAbbreviated, fSearchPath);
if (fIncludes == null)
fIncludes = new Vector<ISchemaInclude>();
fIncludes.add(include);
@@ -887,6 +888,18 @@ public class Schema extends PlatformObject implements ISchema {
fNotificationEnabled = newNotificationEnabled;
}
+ /**
+ * Sets a list of additional schema relative or absolute paths to search when
+ * trying to find an included schema. Must be set before {@link #load()} is
+ * called.
+ *
+ * @param searchPath the list of paths to search for included schema or <code>null</code> for no additional paths
+ */
+ public void setSearchPath(List<IPath> searchPath) {
+ fSearchPath = searchPath;
+ }
+
+ @Override
public String toString() {
return fName;
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaDescriptor.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaDescriptor.java
index 6f37d6f..8d3e7fd 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaDescriptor.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaDescriptor.java
@@ -11,9 +11,11 @@
package org.eclipse.pde.internal.core.schema;
import java.io.File;
-import java.net.*;
-import org.eclipse.core.filesystem.URIUtil;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
@@ -24,8 +26,21 @@ public class SchemaDescriptor implements ISchemaDescriptor {
private Schema fSchema;
private long fLastModified;
private boolean fEditable;
+ private List<IPath> fSearchPath;
public SchemaDescriptor(String extPointID, URL schemaURL) {
+ this(extPointID, schemaURL, null);
+ }
+
+ /**
+ * Creates a new schema descriptor for a schema at the given url. The searchPath will
+ * be used to lookup included schemas.
+ *
+ * @param extPointID the extension point the schema describes
+ * @param schemaURL the url location of the schema
+ * @param searchPath list of absolute or schema relative paths to search for included schemas, may be <code>null</code>
+ */
+ public SchemaDescriptor(String extPointID, URL schemaURL, List<IPath> searchPath) {
fPoint = extPointID;
fSchemaURL = schemaURL;
if (fSchemaURL != null) {
@@ -33,6 +48,7 @@ public class SchemaDescriptor implements ISchemaDescriptor {
if (file.exists())
fLastModified = file.lastModified();
}
+ fSearchPath = searchPath;
}
public SchemaDescriptor(IFile file, boolean editable) {
@@ -43,9 +59,7 @@ public class SchemaDescriptor implements ISchemaDescriptor {
public SchemaDescriptor(File file) {
try {
if (file.exists()) {
- // Encode the url in case the file path has special characters (Bug 403512)
- URI encodedURI = URIUtil.toURI(file.toString());
- fSchemaURL = encodedURI.toURL();
+ fSchemaURL = file.toURL();
fLastModified = file.lastModified();
}
} catch (MalformedURLException e) {
@@ -70,6 +84,7 @@ public class SchemaDescriptor implements ISchemaDescriptor {
fSchema = new EditableSchema(this, fSchemaURL, abbreviated);
else
fSchema = new Schema(this, fSchemaURL, abbreviated);
+ fSchema.setSearchPath(fSearchPath);
fSchema.load();
}
return fSchema;
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaInclude.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaInclude.java
index 30753ce..a2b0a13 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaInclude.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaInclude.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -13,13 +13,11 @@ package org.eclipse.pde.internal.core.schema;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
-
+import java.util.List;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.pde.internal.core.PDECore;
-import org.eclipse.pde.internal.core.ischema.ISchema;
-import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
-import org.eclipse.pde.internal.core.ischema.ISchemaInclude;
-import org.eclipse.pde.internal.core.ischema.ISchemaObject;
+import org.eclipse.pde.internal.core.ischema.*;
public class SchemaInclude extends SchemaObject implements ISchemaInclude {
@@ -31,10 +29,26 @@ public class SchemaInclude extends SchemaObject implements ISchemaInclude {
private boolean fAbbreviated;
+ private List<IPath> fSearchPath;
+
public SchemaInclude(ISchemaObject parent, String location, boolean abbreviated) {
+ this(parent, location, abbreviated, null);
+ }
+
+ /**
+ * Creates a new schema include describing an included schema at the given location. An optional
+ * search path may be provided to assist in finding the included schema.
+ *
+ * @param parent parent object, should be the schema containing this include
+ * @param location the string location from the schema xml
+ * @param abbreviated whether the schema is following the abbreviated syntax
+ * @param searchPath list of schema relative or absolute paths to look for the included schema, may be <code>null</code>
+ */
+ public SchemaInclude(ISchemaObject parent, String location, boolean abbreviated, List<IPath> searchPath) {
super(parent, location);
fLocation = location;
fAbbreviated = abbreviated;
+ fSearchPath = searchPath;
}
/**
@@ -76,7 +90,7 @@ public class SchemaInclude extends SchemaObject implements ISchemaInclude {
private ISchema createInternalSchema(ISchemaDescriptor desc, String location) {
try {
- URL schemaURL = IncludedSchemaDescriptor.computeURL(desc, location);
+ URL schemaURL = IncludedSchemaDescriptor.computeURL(desc, location, fSearchPath);
if (schemaURL == null)
return null;
Schema ischema = new Schema(null, schemaURL, fAbbreviated);
@@ -94,6 +108,7 @@ public class SchemaInclude extends SchemaObject implements ISchemaInclude {
}
}
+ @Override
public boolean equals(Object obj) {
if (obj instanceof ISchemaInclude) {
ISchemaInclude other = (ISchemaInclude) obj;
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaRegistry.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaRegistry.java
index 320fad1..956eb90 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaRegistry.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/schema/SchemaRegistry.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 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
@@ -52,7 +52,7 @@ public class SchemaRegistry {
public ISchema getIncludedSchema(ISchemaDescriptor parent, String schemaLocation) {
try {
- URL url = IncludedSchemaDescriptor.computeURL(parent, schemaLocation);
+ URL url = IncludedSchemaDescriptor.computeURL(parent, schemaLocation, null);
if (url == null)
return null;
diff --git a/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java b/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java
index 636592e..2636223 100644
--- a/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java
+++ b/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -13,10 +13,10 @@ package org.eclipse.pde.internal.core.ant;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
@@ -31,16 +31,29 @@ import org.eclipse.pde.internal.core.util.HeaderMap;
import org.eclipse.pde.internal.core.util.SAXParserWrapper;
import org.osgi.framework.Constants;
+/**
+ * Ant task that takes a plug-in and created HTML reference documents for all schema (.exsd) files.
+ *
+ */
public class ConvertSchemaToHTML extends Task {
private SchemaTransformer fTransformer = new SchemaTransformer();
private String manifest;
private String destination;
private URL cssURL;
+ private String additionalSearchPaths;
+ @Override
public void execute() throws BuildException {
- if (!validateDestination())
- return;
+ if (destination == null) {
+ throw new BuildException(NLS.bind(PDECoreMessages.Builders_Convert_missingAttribute, "destination")); //$NON-NLS-1$
+ }
+ if (manifest == null) {
+ throw new BuildException(NLS.bind(PDECoreMessages.Builders_Convert_missingAttribute, "manifest")); //$NON-NLS-1$
+ }
+ if (!new Path(destination).isValidPath(destination)) {
+ throw new BuildException(NLS.bind(PDECoreMessages.Builders_Convert_illegalValue, "destination")); //$NON-NLS-1$
+ }
IPluginModelBase model = readManifestFile();
if (model == null)
@@ -51,6 +64,8 @@ public class ConvertSchemaToHTML extends Task {
pluginID = getPluginID();
}
+ List<IPath> searchPaths = getSearchPaths();
+
IPluginExtensionPoint[] extPoints = model.getPluginBase().getExtensionPoints();
for (int i = 0; i < extPoints.length; i++) {
String schemaLocation = extPoints[i].getSchema();
@@ -65,9 +80,8 @@ public class ConvertSchemaToHTML extends Task {
File schemaFile = new File(model.getInstallLocation(), schemaLocation);
XMLDefaultHandler handler = new XMLDefaultHandler();
parser.parse(schemaFile, handler);
-
URL url = schemaFile.toURL();
- SchemaDescriptor desc = new SchemaDescriptor(extPoints[i].getFullId(), url);
+ SchemaDescriptor desc = new SchemaDescriptor(extPoints[i].getFullId(), url, searchPaths);
schema = (Schema) desc.getSchema(false);
File directory = new Path(destination).isAbsolute() ? new File(destination) : new File(getProject().getBaseDir(), destination);
@@ -84,8 +98,7 @@ public class ConvertSchemaToHTML extends Task {
out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), ICoreConstants.UTF_8), true);
fTransformer.transform(schema, out, cssURL, SchemaTransformer.BUILD);
} catch (Exception e) {
- if (e.getMessage() != null)
- System.out.println(e.getMessage());
+ throw new BuildException(e);
} finally {
if (out != null)
out.close();
@@ -95,38 +108,64 @@ public class ConvertSchemaToHTML extends Task {
}
}
- private String getPluginID() {
- File file = new Path(manifest).isAbsolute() ? new File(manifest) : new File(getProject().getBaseDir(), manifest);
- File OSGiFile = new File(file.getParentFile(), ICoreConstants.BUNDLE_FILENAME_DESCRIPTOR);
-
- if (OSGiFile.exists()) {
- try {
- Map<String, String> headers = ManifestElement.parseBundleManifest(new FileInputStream(OSGiFile), new HeaderMap<String, String>());
- 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)
- return elements[0].getValue();
- } catch (Exception e1) {
- System.out.print(e1.getMessage());
- }
- }
- return null;
- }
-
+ /**
+ * Required attribute describing the location of the plugin.xml file
+ * for the plug-in to create schema html docs for.
+ *
+ * @param manifest string file path to plugin.xml for the plug-in to convert
+ */
public void setManifest(String manifest) {
this.manifest = manifest;
}
+ /**
+ * Required attribute describing the location to output the HTML.
+ *
+ * @param destination string file path to output html to
+ */
public void setDestination(String destination) {
this.destination = destination;
}
+ /**
+ * Optional attribute providing a comma <code>','</code> delimited
+ * list of file paths to search for plug-ins that provide schema
+ * files included by the schema files being converted.
+ * <p>
+ * When a schema file includes another the html will include the
+ * element definitions from the included schema if it is available.
+ * If the schema does not exist in the same plug-in, the task will
+ * assume the schema url is of the form
+ * <code>schema://<pluginID>/<schemaPath>. It will extract the plug-in
+ * ID and look for a folder of that name in the same directory as the
+ * parent schema's host plug-in. If the plug-ins are not all in the same
+ * directory, this attribute can be used to locate them.
+ * </p><p>
+ * The paths can be absolute file paths or paths relative to the schema
+ * file. For example if converting a schema at <code>/WS/org.eclipse.test/schema/schemaA.exsd</code>
+ * which includes a schema: <code>schema://org.eclipse.included/schema/schemaB.exsd</code>
+ * you could provide the search paths: <code>c:\MySchemas\</code> to
+ * add an absolute path and <code>..\..\..\..\MyRepos\</code> to check
+ * a directory higher than where the plug-in is.
+ * </p>
+ *
+ * @param additionalSearchPaths comma delimited list of search paths
+ */
+ public void setAdditionalSearchPaths(String additionalSearchPaths) {
+ this.additionalSearchPaths = additionalSearchPaths;
+ }
+
public URL getCSSURL() {
return cssURL;
}
+ /**
+ * Sets a url location to lookup a CSS file to use during
+ * the schema transformation. If not set, the task will search
+ * for a default CSS in the product plug-in.
+ *
+ * @param url string form of url pointing to a CSS file
+ */
public void setCSSURL(String url) {
try {
cssURL = new URL(url);
@@ -139,20 +178,53 @@ public class ConvertSchemaToHTML extends Task {
cssURL = url;
}
- private IPluginModelBase readManifestFile() {
- if (manifest == null) {
- System.out.println(NLS.bind(PDECoreMessages.Builders_Convert_missingAttribute, "manifest")); //$NON-NLS-1$
+ private String getPluginID() {
+ File file = new Path(manifest).isAbsolute() ? new File(manifest) : new File(getProject().getBaseDir(), manifest);
+ File OSGiFile = new File(file.getParentFile(), ICoreConstants.BUNDLE_FILENAME_DESCRIPTOR);
+
+ if (OSGiFile.exists()) {
+ try {
+ Map<String, String> headers = ManifestElement.parseBundleManifest(new FileInputStream(OSGiFile), new HeaderMap<String, String>());
+ 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)
+ return elements[0].getValue();
+ } catch (Exception e1) {
+ System.out.print(e1.getMessage());
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return user specified search paths or <code>null</code>
+ */
+ private List<IPath> getSearchPaths() {
+ if (this.additionalSearchPaths == null) {
return null;
}
+ String[] paths = this.additionalSearchPaths.split(","); //$NON-NLS-1$
+ List<IPath> result = new ArrayList<IPath>(paths.length);
+ for (int i = 0; i < paths.length; i++) {
+ Path path = new Path(paths[i]);
+ if (path.isValidPath(paths[i])) {
+ result.add(path);
+ } else {
+ System.out.println(NLS.bind(PDECoreMessages.ConvertSchemaToHTML_InvalidAdditionalSearchPath, paths[i]));
+ }
+ }
+ return result;
+ }
+ private IPluginModelBase readManifestFile() throws BuildException {
File file = new Path(manifest).isAbsolute() ? new File(manifest) : new File(getProject().getBaseDir(), manifest);
InputStream stream = null;
try {
stream = new BufferedInputStream(new FileInputStream(file));
} catch (Exception e) {
- if (e.getMessage() != null)
- System.out.println(e.getMessage());
- return null;
+ throw new BuildException(e);
}
ExternalPluginModelBase model = null;
@@ -162,9 +234,8 @@ public class ConvertSchemaToHTML extends Task {
else if (file.getName().toLowerCase(Locale.ENGLISH).equals(ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR))
model = new ExternalPluginModel();
else {
- System.out.println(NLS.bind(PDECoreMessages.Builders_Convert_illegalValue, "manifest")); //$NON-NLS-1$
stream.close();
- return null;
+ throw new BuildException(NLS.bind(PDECoreMessages.Builders_Convert_illegalValue, "manifest")); //$NON-NLS-1$
}
String parentPath = file.getParentFile().getAbsolutePath();
@@ -172,23 +243,10 @@ public class ConvertSchemaToHTML extends Task {
model.load(stream, false);
stream.close();
} catch (Exception e) {
- if (e.getMessage() != null)
- System.out.println(e.getMessage());
+ throw new BuildException(e);
}
return model;
}
- private boolean validateDestination() {
- boolean valid = true;
- if (destination == null) {
- System.out.println(NLS.bind(PDECoreMessages.Builders_Convert_missingAttribute, "destination")); //$NON-NLS-1$
- valid = false;
- } else if (!new Path(destination).isValidPath(destination)) {
- System.out.println(NLS.bind(PDECoreMessages.Builders_Convert_illegalValue, "destination")); //$NON-NLS-1$
- valid = false;
- }
- return valid;
- }
-
}