Skip to content

Commit

Permalink
Merge pull request #97 from eMoflon/rkluge-dev
Browse files Browse the repository at this point in the history
Results of Hacker Day 2018-08
  • Loading branch information
RolandKluge authored Aug 9, 2018
2 parents ff9f55d + 77ed5f9 commit 266b3ba
Show file tree
Hide file tree
Showing 65 changed files with 3,019 additions and 918 deletions.
2 changes: 1 addition & 1 deletion org.moflon.core.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.moflon.core.feature"
label="eMoflon Core Components Feature"
version="1.2.0.qualifier"
version="1.3.0.qualifier"
provider-name="eMoflon Developers"
plugin="org.moflon.core.branding">

Expand Down
2 changes: 1 addition & 1 deletion org.moflon.core.releng.updatesite/category.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature url="features/org.moflon.core.feature_1.2.0.qualifier.jar" id="org.moflon.core.feature" version="1.2.0.qualifier">
<feature url="features/org.moflon.core.feature_1.3.0.qualifier.jar" id="org.moflon.core.feature" version="1.3.0.qualifier">
<category name="org.moflon.core.category"/>
</feature>
<category-def name="org.moflon.core.category" label="eMoflon Core">
Expand Down
6 changes: 6 additions & 0 deletions org.moflon.core.releng.updatesite/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2018-08-09 eMoflon Core 1.3.0 released

Integrate support for XCore and improve visualization of metamodels

* See also https://github.com/eMoflon/emoflon-core/issues?utf8=✓&q=is%3Aissue closed%3A2018-04-10..2018-08-09

2018-04-10 eMoflon Core 1.2.0 released

Minor improvements:
Expand Down
6 changes: 3 additions & 3 deletions org.moflon.core.releng.updatesite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</head>

<body>
This is an Eclipse UpdateSite and is not meant to be viewed in a normal browser.</br>
To install eMoflon, enter this UpdateSite in the Eclipse Update Manager.</br>
If you do not know what that is then work through this <a href="http://www.vogella.de/articles/Eclipse/article.html">tutorial</a>.
This is an Eclipse update site and is not meant to be viewed in a normal browser.</br>
To install eMoflon, enter the URL of this update site in the Eclipse Update Manager.</br>
For further help, please consult the <a href="https://help.eclipse.org/oxygen/topic/org.eclipse.platform.doc.user/tasks/tasks-124.htm">Eclipe tutorial on installing new software</a>.
</body>
</html>
2 changes: 1 addition & 1 deletion org.moflon.core.releng.updatesite/site.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature url="features/org.moflon.core.feature_1.2.0.qualifier.jar" id="org.moflon.core.feature" version="1.2.0.qualifier">
<feature url="features/org.moflon.core.feature_1.3.0.qualifier.jar" id="org.moflon.core.feature" version="1.3.0.qualifier">
<category name="org.moflon.core.category"/>
</feature>
<category-def name="org.moflon.core.category" label="eMoflon Core">
Expand Down
7 changes: 7 additions & 0 deletions org.moflon.core.ui.packageregistration/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 3 additions & 0 deletions org.moflon.core.ui.packageregistration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.settings/
/bin
/target
28 changes: 28 additions & 0 deletions org.moflon.core.ui.packageregistration/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.moflon.core.ui.packageregistration</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
15 changes: 15 additions & 0 deletions org.moflon.core.ui.packageregistration/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.moflon.core.ui.packageregistration
Bundle-SymbolicName: org.moflon.core.ui.packageregistration;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.emf.ecore;bundle-version="2.11.0",
org.eclipse.core.resources,
org.eclipse.equinox.registry,
org.apache.log4j,
org.eclipse.jface,
org.eclipse.ui.workbench,
org.eclipse.emf.ecore.xmi,
org.moflon.core.ui
Bundle-Vendor: eMoflon Developers
5 changes: 5 additions & 0 deletions org.moflon.core.ui.packageregistration/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions org.moflon.core.ui.packageregistration/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="org.moflon.core.ui.packageregistration.RegisterMetamodelHandler"
id="org.moflon.ide.ui.commands.emf.RegisterMetamodelCommand"
name="Register the selected metamodel in the global EMF registry"/>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution allPopups="false" locationURI="popup:org.moflon.ide.ui.moflon?after=moflonGroupResources">
<command
commandId="org.moflon.ide.ui.commands.emf.RegisterMetamodelCommand"
label="Register metamodel globally"
style="push"
tooltip="Register the selected metamodel in the global EMF registry"
icon="icons/register.png">
<visibleWhen checkEnabled="false">
<iterate ifEmpty="false" operator="and">
<reference definitionId="org.moflon.ide.ui.definitions.isEcoreFile"/>
<or>
<reference definitionId="org.moflon.ide.ui.definitions.isInPackageExplorer"/>
<reference definitionId="org.moflon.ide.ui.definitions.isInProjectExplorer"/>
</or>
</iterate>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*******************************************************************************
* Copyright (c) 2008 The University of York.
* 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:
* Dimitrios Kolovos - initial API and implementation
******************************************************************************/
package org.moflon.core.ui.packageregistration;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

/**
* This class allows to register and manage EMF metamodels
*
* @author Roland Kluge - Initial implementation
*
*/
public class EmfRegistryManager {
private static EmfRegistryManager instance = null;

private HashMap<String, List<EPackage>> managedMetamodels = new HashMap<>();

public static EmfRegistryManager getInstance() {
if (instance == null) {
instance = new EmfRegistryManager();
}
return instance;
}

public void registerMetamodel(String fileName) throws Exception {
List<EPackage> ePackages = register(URI.createPlatformResourceURI(fileName, true), EPackage.Registry.INSTANCE);
managedMetamodels.put(fileName, ePackages);
}

// The following methods are taken from org.eclipse.epsilon.emc.emf.EmfUtil

public static List<EPackage> register(URI uri, EPackage.Registry registry) throws Exception {
return register(uri, registry, true);
}

/**
* Register all the packages in the metamodel specified by the uri in the
* registry.
*
* @param uri
* The URI of the metamodel
* @param registry
* The registry in which the metamodel's packages are registered
* @param useUriForResource
* If True, the URI of the resource created for the metamodel would
* be overwritten with the URI of the last EPackage in the metamodel.
* @return A list of the EPackages registered.
* @throws Exception
* If there is an error accessing the resources.
*/
public static List<EPackage> register(URI uri, EPackage.Registry registry, boolean useUriForResource)
throws Exception {

List<EPackage> ePackages = new ArrayList<EPackage>();

initialiseResourceFactoryRegistry();

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE);

Resource metamodel = resourceSet.createResource(uri);
metamodel.load(Collections.EMPTY_MAP);

setDataTypesInstanceClasses(metamodel);

Iterator<EObject> it = metamodel.getAllContents();
while (it.hasNext()) {
Object next = it.next();
if (next instanceof EPackage) {
EPackage p = (EPackage) next;

adjustNsAndPrefix(metamodel, p, useUriForResource);
registry.put(p.getNsURI(), p);
ePackages.add(p);
}
}

return ePackages;

}

private static void initialiseResourceFactoryRegistry() {
final Map<String, Object> etfm = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap();

if (!etfm.containsKey("*")) {
etfm.put("*", new XMIResourceFactoryImpl());
}

}

private static void adjustNsAndPrefix(Resource metamodel, EPackage p, boolean useUriForResource) {
if (p.getNsURI() == null || p.getNsURI().trim().length() == 0) {
if (p.getESuperPackage() == null) {
p.setNsURI(p.getName());
} else {
p.setNsURI(p.getESuperPackage().getNsURI() + "/" + p.getName());
}
}

if (p.getNsPrefix() == null || p.getNsPrefix().trim().length() == 0) {
if (p.getESuperPackage() != null) {
if (p.getESuperPackage().getNsPrefix() != null) {
p.setNsPrefix(p.getESuperPackage().getNsPrefix() + "." + p.getName());
} else {
p.setNsPrefix(p.getName());
}
}
}

if (p.getNsPrefix() == null)
p.setNsPrefix(p.getName());
if (useUriForResource)
metamodel.setURI(URI.createURI(p.getNsURI()));
}

protected static void setDataTypesInstanceClasses(Resource metamodel) {
Iterator<EObject> it = metamodel.getAllContents();
while (it.hasNext()) {
EObject eObject = (EObject) it.next();
if (eObject instanceof EEnum) {
// ((EEnum) eObject).setInstanceClassName("java.lang.Integer");
} else if (eObject instanceof EDataType) {
EDataType eDataType = (EDataType) eObject;
String instanceClass = "";
if (eDataType.getName().equals("String")) {
instanceClass = "java.lang.String";
} else if (eDataType.getName().equals("Boolean")) {
instanceClass = "java.lang.Boolean";
} else if (eDataType.getName().equals("Integer")) {
instanceClass = "java.lang.Integer";
} else if (eDataType.getName().equals("Float")) {
instanceClass = "java.lang.Float";
} else if (eDataType.getName().equals("Double")) {
instanceClass = "java.lang.Double";
}
if (instanceClass.trim().length() > 0) {
eDataType.setInstanceClassName(instanceClass);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2008 The University of York.
* 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:
* Dimitrios Kolovos - initial API and implementation
******************************************************************************/
package org.moflon.core.ui.packageregistration;

import java.util.Iterator;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.moflon.core.ui.AbstractCommandHandler;

/**
* This class provides the front-end capabilities for registering an EMF model.
*
* @author Roland Kluge - Initial implementation
*
*/
public class RegisterMetamodelHandler extends AbstractCommandHandler {

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);

if (selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
final Iterator<?> it = structuredSelection.iterator();
while (it.hasNext()) {
final IFile file = (IFile) it.next();
registerMetamodelInFile(file);
}
}

return AbstractCommandHandler.DEFAULT_HANDLER_RESULT;
}

private void registerMetamodelInFile(final IFile file) {
final String fileName = file.getFullPath().toOSString();
try {
EmfRegistryManager.getInstance().registerMetamodel(fileName);
logger.info("Metamodel " + fileName + " registered successfully");
} catch (final Exception ex) {
logger.info("Metamodel " + fileName + " could not be registered", ex);
}
}

}
1 change: 1 addition & 0 deletions org.moflon.core.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Export-Package: org.moflon.core.ui,
Bundle-Activator: org.moflon.core.ui.MoflonCoreUiActivator
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: org.moflon.core.ui
Import-Package: org.eclipse.emf.edit.domain

Loading

0 comments on commit 266b3ba

Please sign in to comment.