Skip to content

Commit

Permalink
Merge pull request #70 from eMoflon/extension-point-for-uri-configura…
Browse files Browse the repository at this point in the history
…tion

Extension point for uri configuration
  • Loading branch information
anthonyanjorin authored Apr 9, 2018
2 parents aee3a69 + 9a2ec9b commit eb2e46b
Show file tree
Hide file tree
Showing 6 changed files with 331 additions and 174 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.moflon.core.utilities;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.moflon.core.utilities.LogUtils;

public class ExtensionsUtil {
private static final Logger logger = Logger.getLogger(ExtensionsUtil.class);

/**
* Collects all registered extensions with the given ID.
*
* @param extensionID
* the ID of the extension
* @param property
* the name of the property
* @param extensionType
* the extension type
* @return all extensions with the given ID as extensions of the given type
*/
public static <T> Collection<T> collectExtensions(final String extensionID, final String property,
final Class<T> extensionType) {
Collection<T> extensions = new ArrayList<T>();
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionID);
try {
for (IConfigurationElement e : config) {
logger.debug("Evaluating extension");
final Object o = e.createExecutableExtension(property);
if (extensionType.isInstance(o)) {
extensions.add(extensionType.cast(o));
}
}
} catch (CoreException ex) {
LogUtils.error(logger, ex);
}

return extensions;
}
}
11 changes: 8 additions & 3 deletions org.moflon.emf.codegen/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
templates/,\
src/
bin.excludes = templates/emf/
src/,\
plugin.xml,\
schema/,\
.project,\
.gitignore,\
.classpath,\
build.properties,\
templates/
6 changes: 6 additions & 0 deletions org.moflon.emf.codegen/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="URIPreferenceExtension" name="URIPreferenceExtension" schema="schema/URIPreferenceExtension.exsd"/>

</plugin>
102 changes: 102 additions & 0 deletions org.moflon.emf.codegen/schema/URIPreferenceExtension.exsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.moflon.emf.codegen" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.moflon.emf.codegen" id="URIPreferenceExtension" name="URIPreferenceExtension"/>
</appinfo>
<documentation>
This is a hook into the building process. Use this to register extensions that are invoked during the compilation process and can specify a preferred platform URI (either resource or plugin) to be used for creating EPackages and GenModels.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<choice>
<element ref="uri_preference_extension"/>
</choice>
<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="uri_preference_extension">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.moflon.emf.codegen.URIPreferenceExtension"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</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>


</schema>
Loading

0 comments on commit eb2e46b

Please sign in to comment.