Skip to content

Commit

Permalink
Update the plugin.xml with an Xml parser when adding modelTypes & lan…
Browse files Browse the repository at this point in the history
…guages descriptions.

We used the Eclipse api to edit the plugin.xml but it seems buggy/mis-used.
The model created doesn't contains extension tags present in the plugin.xml.
As a work around an XML parser do the job instead of the Eclipse API.
  • Loading branch information
fcoulon committed Jan 5, 2016
1 parent 48f9040 commit 18a4fce
Showing 1 changed file with 44 additions and 55 deletions.
Expand Up @@ -19,6 +19,7 @@ import org.eclipse.xtext.documentation.IEObjectDocumentationProvider
import org.eclipse.xtext.naming.IQualifiedNameProvider
import com.google.common.collect.ListMultimap
import com.google.common.collect.ArrayListMultimap
import fr.inria.diverse.melange.utils.PluginXmlChanger

/**
* For each model type, create a new fr.inria.diverse.melange.modeltype
Expand Down Expand Up @@ -49,6 +50,10 @@ class ExtensionPointProcessor extends DispatchMelangeProcessor

if (project !== null && !preLinkingPhase) {
val pluginXml = PDEProject::getPluginXml(project)

val changer = new PluginXmlChanger
changer.load(pluginXml.location.toString)

val pluginModel = PDECore::getDefault.modelManager.findModel(project)
val fModel = new WorkspacePluginModel(pluginXml, false)
val pluginBase = fModel.pluginBase
Expand All @@ -70,93 +75,77 @@ class ExtensionPointProcessor extends DispatchMelangeProcessor
val languages = root.languages.filter[isComplete]

if (modelTypes.size > 0 && modeltypeExtensionPoint !== null) {
val newExtension = fModel.factory.createExtension => [
point = modeltypeExtensionPoint.id
]

changer.deleteExtensions(MODELTYPE_EXTENSION_POINT)
val extensionTag = changer.addExtension(MODELTYPE_EXTENSION_POINT)

modelTypes.forEach[mt |
try {
val fqn = mt.fullyQualifiedName.toString
val doc = documentationProvider.getDocumentation(mt)
val modeltypeElement = fModel.factory.createElement(newExtension) => [
name = "modeltype"
setAttribute("id", fqn)
setAttribute("uri", mt.uri)

if (doc !== null && !doc.empty)
setAttribute("description", doc)
]


val modelTypeTag = changer.addChild(extensionTag,"modeltype")
changer.addAttribute(modelTypeTag, "id", fqn)
changer.addAttribute(modelTypeTag, "uri", mt.uri)
if (doc !== null && !doc.empty){
changer.addAttribute(modelTypeTag, "description", doc)
}

// Register subtypings
mt.subtypingRelations.forEach[superMt |
modeltypeElement.add(fModel.factory.createElement(modeltypeElement) => [
name = "subtyping"
setAttribute("modeltypeId", superMt.superType.fullyQualifiedName.toString)
])
val subtypingTag = changer.addChild(modelTypeTag,"subtyping")
changer.addAttribute(subtypingTag, "modeltypeId", superMt.superType.fullyQualifiedName.toString)
]

newExtension.add(modeltypeElement)
if (!newExtension.isInTheModel) {
fModel.extensions.add(newExtension)
log.debug('''Registered new modeltype contribution <«fqn», «mt.uri»> in plugin.xml''')
}

log.debug('''Registered new modeltype contribution <«fqn», «mt.uri»> in plugin.xml''')
} catch (CoreException e) {
log.debug('''Failed to register new model type contribution''', e)
}
]
}

if (languages.size > 0 && languageExtensionPoint !== null) {
val newExtension = fModel.factory.createExtension => [
point = languageExtensionPoint.id
]

changer.deleteExtensions(LANGUAGE_EXTENSION_POINT)
val extensionTag = changer.addExtension(LANGUAGE_EXTENSION_POINT)

languages.forEach[l |
try {
val fqn = l.fullyQualifiedName.toString
val doc = documentationProvider.getDocumentation(l)
val languageElement = fModel.factory.createElement(newExtension) => [
name = "language"
setAttribute("id", fqn)
setAttribute("exactType", l.exactType.fullyQualifiedName.toString)
setAttribute("uri", l.syntax.pkgs.head.nsURI)

if (doc !== null && !doc.empty)
setAttribute("description", doc)

setAttribute("entryPoints",

val languageTag = changer.addChild(extensionTag,"language")
changer.addAttribute(languageTag, "id", fqn)
changer.addAttribute(languageTag, "exactType", l.exactType.fullyQualifiedName.toString)
changer.addAttribute(languageTag, "uri", l.syntax.pkgs.head.nsURI)
if (doc !== null && !doc.empty){
changer.addAttribute(languageTag, "description", doc)
}
changer.addAttribute(languageTag, "entryPoints",
l.entryPoints
.map[
val args = parameters.map[it.parameterType.type.qualifiedName].join(',')
declaringType.qualifiedName+"."+simpleName+"("+args+")"
]
.join(';')
.map[
val args = parameters.map[it.parameterType.type.qualifiedName].join(',')
declaringType.qualifiedName+"."+simpleName+"("+args+")"
]
.join(';')
)
setAttribute("aspects", l.serializedAspects)
]

changer.addAttribute(languageTag, "aspects", l.serializedAspects)

// Register adapters
l.implements.forEach[mt |
languageElement.add(fModel.factory.createElement(languageElement) => [
name = "adapter"
setAttribute("modeltypeId", mt.fullyQualifiedName.toString)
setAttribute("class", l.syntax.adapterNameFor(mt))
])
val adapterTag = changer.addChild(languageTag,"adapter")
changer.addAttribute(adapterTag, "modeltypeId", mt.fullyQualifiedName.toString)
changer.addAttribute(adapterTag, "class", l.syntax.adapterNameFor(mt))
]

newExtension.add(languageElement)
if (!newExtension.isInTheModel) {
fModel.extensions.add(newExtension)
log.debug('''Registered new language contribution <«fqn»> in plugin.xml''')
}
log.debug('''Registered new language contribution <«fqn»> in plugin.xml''')
} catch (CoreException e) {
log.debug('''Failed to register language contribution''', e)
}
]
}
}

fModel.save
changer.save(2)
}
}

Expand Down

0 comments on commit 18a4fce

Please sign in to comment.