Author: snjeza
Date: 2008-11-17 13:42:45 -0500 (Mon, 17 Nov 2008)
New Revision: 11852
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/schema/
trunk/examples/plugins/org.jboss.tools.project.examples/schema/projectExamplesXml.exsd
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/build.properties
trunk/examples/plugins/org.jboss.tools.project.examples/plugin.properties
trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java
Log:
JBIDE-2966 Add an extension point in order to enable adding a new xml file to the
project.examples plugin
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/build.properties
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/build.properties 2008-11-17
17:36:13 UTC (rev 11851)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/build.properties 2008-11-17
18:42:45 UTC (rev 11852)
@@ -10,4 +10,5 @@
about.ini,\
about.mappings,\
about.properties,\
- rhds_wiz.png
+ rhds_wiz.png,\
+ schema/
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/plugin.properties
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/plugin.properties 2008-11-17
17:36:13 UTC (rev 11851)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/plugin.properties 2008-11-17
18:42:45 UTC (rev 11852)
@@ -3,4 +3,5 @@
BundleName = Project Examples
JBoss_Tools_category = JBoss Tools
Project_Examples_wizard = Project Examples
-Project_Examples_command = Project Examples
\ No newline at end of file
+Project_Examples_command =Project Examples
+ProjectExamples=Project Examples file
\ No newline at end of file
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml 2008-11-17 17:36:13
UTC (rev 11851)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml 2008-11-17 18:42:45
UTC (rev 11852)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
+ <extension-point id="projectExamplesXml"
name="%ProjectExamples" schema="schema/projectExamplesXml.exsd"/>
<extension point="org.eclipse.ui.newWizards">
<category
@@ -40,4 +41,9 @@
</menuContribution>
</extension>
+ <extension
+ point="org.jboss.tools.project.examples.projectExamplesXml">
+
<
url>http://anonsvn.jboss.org/repos/jbosstools/workspace/examples/proje...
+ </extension>
+
</plugin>
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/schema/projectExamplesXml.exsd
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/schema/projectExamplesXml.exsd
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/schema/projectExamplesXml.exsd 2008-11-17
18:42:45 UTC (rev 11852)
@@ -0,0 +1,101 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.tools.project.examples"
xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.jboss.tools.project.examples"
id="projectExamplesXml" name="Project Examples file"/>
+ </appinfo>
+ <documentation>
+ Adds a new Project Examples xml file
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="url" minOccurs="1"
maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="url" type="string">
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 3.0.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ <extension
+
point="org.jboss.tools.project.examples.projectExamplesXml">
+ <url>file:/C:/test/projectExamples.xml</url>
+</extension>
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ JBoss, a division of Red Hat
+ </documentation>
+ </annotation>
+
+</schema>
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2008-11-17
17:36:13 UTC (rev 11851)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2008-11-17
18:42:45 UTC (rev 11852)
@@ -46,6 +46,7 @@
public static String NewProjectExamplesWizardPage_Show_the_Quick_Fix_dialog;
public static String NewProjectExamplesWizardPage_URL;
public static String ProjectExamplesActivator_Waiting;
+ public static String ProjectUtil_Invalid_URL;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2008-11-17
17:36:13 UTC (rev 11851)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2008-11-17
18:42:45 UTC (rev 11852)
@@ -106,6 +106,11 @@
.getLocalizedMessage(), e);
ProjectExamplesActivator.getDefault().getLog().log(status);
}
+
+ public static void log(String message) {
+ IStatus status = new Status(IStatus.WARNING, PLUGIN_ID,message);
+ ProjectExamplesActivator.getDefault().getLog().log(status);
+ }
public static BundleContext getBundleContext() {
return context;
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2008-11-17
17:36:13 UTC (rev 11851)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2008-11-17
18:42:45 UTC (rev 11852)
@@ -30,3 +30,4 @@
NewProjectExamplesWizardPage_Show_the_Quick_Fix_dialog=Show the Quick Fix dialog
NewProjectExamplesWizardPage_URL=URL:
ProjectExamplesActivator_Waiting=Waiting...
+ProjectUtil_Invalid_URL=Invalid URL\: {0}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2008-11-17
17:36:13 UTC (rev 11851)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2008-11-17
18:42:45 UTC (rev 11852)
@@ -25,14 +25,17 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.filetransfer.ECFExamplesTransport;
-import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -44,20 +47,67 @@
*/
public class ProjectUtil {
- private final static String PROJECT_EXAMPLES_XML =
"http://anonsvn.jboss.org/repos/jbosstools/workspace/examples/projectExamples.xml";
//$NON-NLS-1$
private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
-
+
+ private static final String PROJECT_EXAMPLES_XML_EXTENSION_ID =
"org.jboss.tools.project.examples.projectExamplesXml"; //$NON-NLS-1$
+ private static List<URL> URLs;
+
private ProjectUtil() {
+ }
+ private static List<URL> getURLs() {
+ if (URLs == null) {
+ URLs = new ArrayList<URL>();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint = registry
+ .getExtensionPoint(PROJECT_EXAMPLES_XML_EXTENSION_ID);
+ IExtension[] extensions = extensionPoint.getExtensions();
+ for (int i = 0; i < extensions.length; i++) {
+ IExtension extension = extensions[i];
+ IConfigurationElement[] configurationElements = extension
+ .getConfigurationElements();
+ for (int j = 0; j < configurationElements.length; j++) {
+ IConfigurationElement configurationElement = configurationElements[j];
+ String urlString = configurationElement.getValue();
+ URL url = getURL(urlString);
+ if (url != null) {
+ URLs.add(url);
+ }
+ }
+ }
+ URL url = getURL(getProjectExamplesXml());
+ if (url != null) {
+ URLs.add(url);
+ }
+ }
+ return URLs;
}
+ private static URL getURL(String urlString) {
+ if (urlString != null && urlString.trim().length() > 0) {
+ urlString = urlString.trim();
+ try {
+ URL url = new URL(urlString);
+ return url;
+ } catch (MalformedURLException e) {
+ ProjectExamplesActivator.log(e);
+ }
+ }
+ return null;
+ }
+
public static List<Category> getProjects() {
+ getURLs();
List<Category> list = new ArrayList<Category>();
Category other = Category.OTHER;
try {
- // TODO add a progress monitor
- File file =
getProjectExamplesFile(getProjectExamplesXml(),"projectExamples",
".xml",null); //$NON-NLS-1$ //$NON-NLS-2$
- if (file.exists() && file.isFile()) {
+ for (URL url : URLs) {
+ File file = getProjectExamplesFile(url,
+ "projectExamples", ".xml", null); //$NON-NLS-1$ //$NON-NLS-2$
+ if (file == null || !file.exists() || !file.isFile()) {
+ ProjectExamplesActivator.log(NLS.bind(Messages.ProjectUtil_Invalid_URL,url.toString()));
+ continue;
+ }
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
@@ -80,10 +130,10 @@
if (nodeName.equals("category")) { //$NON-NLS-1$
String value = getContent(child);
boolean found = false;
- for (Category cat:list) {
+ for (Category cat : list) {
if (cat.getName().equals(value)) {
- category=cat;
- found=true;
+ category = cat;
+ found = true;
break;
}
}
@@ -97,7 +147,8 @@
project.setName(getContent(child));
}
if (nodeName.equals("shortDescription")) { //$NON-NLS-1$
- project.setShortDescription(getContent(child));
+ project
+ .setShortDescription(getContent(child));
}
if (nodeName.equals("description")) { //$NON-NLS-1$
project.setDescription(getContent(child));
@@ -116,13 +167,17 @@
if (nodeName.equals("included-projects")) { //$NON-NLS-1$
String includedProjects = getContent(child);
if (includedProjects != null) {
- includedProjects = includedProjects.trim();
- StringTokenizer tokenizer = new
StringTokenizer(includedProjects,","); //$NON-NLS-1$
+ includedProjects = includedProjects
+ .trim();
+ StringTokenizer tokenizer = new StringTokenizer(
+ includedProjects, ","); //$NON-NLS-1$
List<String> projectList = new ArrayList<String>();
while (tokenizer.hasMoreTokens()) {
- projectList.add(tokenizer.nextToken());
+ projectList.add(tokenizer
+ .nextToken());
}
- project.setIncludedProjects(projectList);
+ project
+ .setIncludedProjects(projectList);
}
}
}
@@ -139,46 +194,44 @@
}
private static String getProjectExamplesXml() {
- String projectXML =
System.getProperty("org.jboss.tools.project.examples.xml"); //$NON-NLS-1$
+ String projectXML = System
+ .getProperty("org.jboss.tools.project.examples.xml"); //$NON-NLS-1$
if (projectXML != null && projectXML.length() > 0) {
return projectXML;
}
- return PROJECT_EXAMPLES_XML;
+ return null;
}
private static String getContent(Element child) {
String value = child.getTextContent();
if (value == null) {
- value=""; //$NON-NLS-1$
+ value = ""; //$NON-NLS-1$
}
return value.trim();
}
-
- public static File getProjectExamplesFile(String urlString,String prefix, String suffix,
IProgressMonitor monitor) {
- URL url;
- try {
- url = new URL(urlString);
- } catch (MalformedURLException e) {
- ProjectExamplesActivator.log(e);
- return null;
- }
+
+ public static File getProjectExamplesFile(URL url, String prefix,
+ String suffix, IProgressMonitor monitor) {
File file = null;
if (PROTOCOL_FILE.equals(url.getProtocol())) {
try {
- //assume all illegal characters have been properly encoded, so use URI class to
unencode
+ // assume all illegal characters have been properly encoded, so
+ // use URI class to unencode
file = new File(new URI(url.toExternalForm()));
} catch (Exception e) {
- //URL contains unencoded characters
+ // URL contains unencoded characters
file = new File(url.getFile());
}
if (!file.exists())
return null;
} else {
try {
- file = File.createTempFile(prefix,suffix);
+ file = File.createTempFile(prefix, suffix);
file.deleteOnExit();
- BufferedOutputStream destination = new BufferedOutputStream(new
FileOutputStream(file));
- IStatus result = getTransport().download(prefix,url.toExternalForm(), destination,
monitor);
+ BufferedOutputStream destination = new BufferedOutputStream(
+ new FileOutputStream(file));
+ IStatus result = getTransport().download(prefix,
+ url.toExternalForm(), destination, monitor);
if (!result.isOK()) {
ProjectExamplesActivator.getDefault().getLog().log(result);
return null;
@@ -193,7 +246,7 @@
}
return file;
}
-
+
private static ECFExamplesTransport getTransport() {
return ECFExamplesTransport.getInstance();
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2008-11-17
17:36:13 UTC (rev 11851)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2008-11-17
18:42:45 UTC (rev 11852)
@@ -17,6 +17,8 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
@@ -113,8 +115,15 @@
Object object = iterator.next();
if (object instanceof Project) {
Project project = (Project) object;
- String url = project.getUrl();
+ String urlString = project.getUrl();
String name = project.getName();
+ URL url = null;
+ try {
+ url = new URL(urlString);
+ } catch (MalformedURLException e) {
+ ProjectExamplesActivator.log(e);
+ continue;
+ }
final File file = ProjectUtil.getProjectExamplesFile(
url, name, ".zip", monitor); //$NON-NLS-1$
if (file == null) {