Skip to content

Commit

Permalink
Merge pull request #55 from eMoflon/rkluge-dev
Browse files Browse the repository at this point in the history
Ensure compatibility with current emoflon-tool
  • Loading branch information
RolandKluge authored Mar 13, 2018
2 parents 21e0764 + 3ce6d82 commit 0a6f8fd
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 113 deletions.
2 changes: 1 addition & 1 deletion org.moflon.core.plugins/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.moflon.core.plugins;singleton:=true
Bundle-Name: Components for reading, creating, and updating Eclipse plugin projects
Bundle-Version: 3.0.0.qualifier
Bundle-Version: 3.1.0.qualifier
Bundle-Vendor: eMoflon Developers
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.moflon.core.plugins,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,98 @@
*
* Instances of this class store the metadata of one generic eMoflon project.
*/
public class PluginProperties {

public static final String TYPE_KEY = "type";

public static final String NAME_KEY = "name";

public static final String PLUGIN_ID_KEY = "pluginId";

public static final String WORKING_SET_KEY = "workingSet";

public static final String DEPENDENCIES_KEY = "dependencies";

public static final String NS_URI_KEY = "nsURI";

private Map<String, String> data = new HashMap<>();

public PluginProperties() {
this(new HashMap<String, String>());
}

private PluginProperties(final Map<String, String> data) {
this.data = new HashMap<>(data);
}

public boolean containsKey(final String key) {
return this.data.containsKey(key);
}

public String get(final String key) {
return this.data.get(key);
}

public void put(final String key, final String value) {
this.data.put(key, value);
}

public String getType() {
return get(PluginProperties.TYPE_KEY);
}

public String getNsUri() {
return this.get(NS_URI_KEY);
}

public String getProjectName() {
return this.get(NAME_KEY);
}

public Collection<String> getDependencies() {
if (!this.data.containsKey(DEPENDENCIES_KEY))
return null;

return this.get(DEPENDENCIES_KEY).isEmpty() ? Collections.<String>emptyList()
: Arrays.asList(this.get(DEPENDENCIES_KEY).split(","));
}

public Collection<URI> getDependenciesAsURIs() {
return getDependencies().stream()//
.filter(dep -> !dep.equals(ManifestFileUpdater.IGNORE_PLUGIN_ID)) //
.map(dep -> MoflonConventions.getDefaultResourceDependencyUri(dep)).collect(Collectors.toSet());
}

public void setDependencies(final List<String> dependencies) {
this.put(DEPENDENCIES_KEY, dependencies.stream().collect(Collectors.joining(",")));
}

@Override
public String toString() {
return "MetamodelProperties [data=" + data + "]";
}
public class PluginProperties
{
public static final String TYPE_KEY = "type";

public static final String NAME_KEY = "name";

public static final String PLUGIN_ID_KEY = "pluginId";

public static final String WORKING_SET_KEY = "workingSet";

public static final String DEPENDENCIES_KEY = "dependencies";

public static final String NS_URI_KEY = "nsURI";

/**
* Inside MANIFEST.MF, dependencies are separated using this token
*/
private static final String DEPENDENCIES_SEPARATOR = ",";

private Map<String, String> data = new HashMap<>();

public PluginProperties()
{
this(new HashMap<String, String>());
}

private PluginProperties(final Map<String, String> data)
{
this.data = new HashMap<>(data);
}

public boolean containsKey(final String key)
{
return this.data.containsKey(key);
}

public String get(final String key)
{
return this.data.get(key);
}

public void put(final String key, final String value)
{
this.data.put(key, value);
}

public String getType()
{
return get(PluginProperties.TYPE_KEY);
}

public String getNsUri()
{
return this.get(NS_URI_KEY);
}

public String getProjectName()
{
return this.get(NAME_KEY);
}

public Collection<String> getDependencies()
{
if (!this.data.containsKey(DEPENDENCIES_KEY))
return null;

final String dependenciesString = this.get(DEPENDENCIES_KEY);
return dependenciesString.isEmpty() ? Collections.<String> emptyList() : Arrays.asList(dependenciesString.split(DEPENDENCIES_SEPARATOR));
}

public Collection<URI> getDependenciesAsURIs()
{
return getDependencies().stream()//
.filter(dep -> !dep.equals(ManifestFileUpdater.IGNORE_PLUGIN_ID)) //
.map(dep -> MoflonConventions.getDefaultResourceDependencyUri(dep)).collect(Collectors.toSet());
}

public void setDependencies(final List<String> dependencies)
{
this.put(DEPENDENCIES_KEY, dependencies.stream().collect(Collectors.joining(DEPENDENCIES_SEPARATOR)));
}

@Deprecated // Since 2017-03-13
public void setDefaultValues()
{
// empty
}

@Override
public String toString()
{
return "MetamodelProperties [data=" + data + "]";
}

}
2 changes: 1 addition & 1 deletion org.moflon.core.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: eMoflon Core UI components
Bundle-SymbolicName: org.moflon.core.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Version: 1.1.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.ui.workbench;bundle-version="3.0.0",
org.eclipse.ui.console;bundle-version="3.0.0",
Expand Down
1 change: 1 addition & 0 deletions org.moflon.core.ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</parent>
<artifactId>org.moflon.core.ui</artifactId>
<packaging>eclipse-plugin</packaging>
<version>1.1.0-SNAPSHOT</version>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@

import org.apache.log4j.Logger;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PartInitException;
Expand Down Expand Up @@ -81,11 +86,23 @@ protected static List<IProject> getProjects(final Object element) {
return projects;
}

/**
* Tries to extract the edited file from the given {@link ExecutionEvent}
*
* @param event
* the event to analyze
* @return the file of the active editor or <code>null</code> if there is no active editor
*/
protected static IFile getEditedFile(final ExecutionEvent event) {
return (IFile) HandlerUtil.getActiveEditor(event).getEditorInput().getAdapter(IFile.class);
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor != null) {
return (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
}

return null;
}

public void openInEditor(final IFile targetFile) throws CoreException, PartInitException {
protected void openInEditor(final IFile targetFile) throws CoreException, PartInitException {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(IMarker.LINE_NUMBER, new Integer(1));
Expand All @@ -98,6 +115,38 @@ public void openInEditor(final IFile targetFile) throws CoreException, PartInitE
marker.delete();
}

/**
* Extracts the edited file from the selection of the given
* {@link ExecutionEvent}
*
* Currently, {@link StructuredSelection} and {@link ITextSelection} are
* supported selection types. For all other types, <code>null</code> is
* returned.
*
* @param event
* the event to analyze
* @return the file or <code>null</code>
* @throws ExecutionException
* if extracting the selection from the given event fails
*/
protected IFile extractSelectedFile(final ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);

if (selection instanceof StructuredSelection) {
final StructuredSelection structuredSelection = (StructuredSelection) selection;
final Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IFile) {
return (IFile) firstElement;
} else if (firstElement instanceof ICompilationUnit) {
return (IFile) ((ICompilationUnit) firstElement).getResource();
}
} else if (selection instanceof ITextSelection) {
return getEditedFile(event);
}

return null;
}

protected static Collection<IProject> getProjectsFromSelection(final IStructuredSelection selection) {
final List<IProject> projects = new ArrayList<>();
if (selection instanceof StructuredSelection) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.moflon.core.ui.handler;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

Expand All @@ -9,8 +10,10 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.moflon.core.ui.AbstractCommandHandler;

Expand All @@ -23,9 +26,7 @@
public class TouchResourceHandler extends AbstractCommandHandler {
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);

final Collection<IResource> resources = extractResouresFromSelection(selection);
final Collection<IResource> resources = extractResouresFromSelection(event);
final WorkspaceJob job = new TouchResourceJob(resources);
job.setUser(true);
job.setRule(new MultiRule(resources.toArray(new IResource[resources.size()])));
Expand All @@ -35,24 +36,29 @@ public Object execute(final ExecutionEvent event) throws ExecutionException {
}

/**
* Retrieves the list of {@link IResource}s that are selected in the given
* {@link IStructuredSelection}
* Retrieves the list of {@link IResource}s that are selected
*
* Currently, supported selection types are {@link IStructuredSelection} and {@link TextSelection}.
*
* @param selection
* the selection
* @param event
* the event
* @return the list of resources
* @throws ExecutionException if extracting the selection from the given event fails
*/
private Collection<IResource> extractResouresFromSelection(final IStructuredSelection selection) {
private Collection<IResource> extractResouresFromSelection(final ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
final Collection<IResource> resources = new ArrayList<>();
if (selection instanceof StructuredSelection) {
final StructuredSelection structuredSelection = (StructuredSelection) selection;
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
for (final Iterator<?> selectionIterator = structuredSelection.iterator(); selectionIterator.hasNext();) {
final Object element = selectionIterator.next();
if (element instanceof IResource) {
final IResource resource = (IResource) element;
resources.add(resource);
}
}
} else if (selection instanceof ITextSelection) {
return Arrays.asList(getEditedFile(event));
}
return resources;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,19 @@ public static String getDefaultPathToEcoreFileInProject(final String projectName
* the project
* @return the URI
*/
public static final URI getDefaultProjectRelativeEcoreFileURI(final IProject project) {
public static URI getDefaultProjectRelativeEcoreFileURI(final IProject project) {
return URI.createURI(getDefaultPathToEcoreFileInProject(project.getName()));
}

/**
* @deprecated Use {@link #getDefaultProjectRelativeEcoreFileURI(IProject)}
*/
@Deprecated // Since 2017-03-13
public static URI getDefaultURIToEcoreFileInPlugin(final String projectName) {
final IProject project = WorkspaceHelper.getProjectByName(projectName);
return getDefaultProjectRelativeEcoreFileURI(project);
}

/**
* Returns handle to the default location of the moflon.properties.xmi file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ protected void createResourcesForWorkspaceProjects(final IProgressMonitor monito
final SubMonitor subMon = SubMonitor.convert(monitor, "Loading workspace projects", workspaceProjects.length);
for (final IProject workspaceProject : workspaceProjects) {
if (isValidProject(workspaceProject)) {
final URI projectURI = eMoflonEMFUtil.lookupProjectURIAsPlatformResource(workspaceProject);
//TODO@aanjorin: The following statement does not work with emoflon-tool (TGG compilation fails)
// final URI projectURI = eMoflonEMFUtil.lookupProjectURIAsPlatformResource(workspaceProject);
final URI projectURI = eMoflonEMFUtil.lookupProjectURI(workspaceProject);
final URI metamodelURI = MoflonConventions.getDefaultProjectRelativeEcoreFileURI(workspaceProject)
.resolve(projectURI);
new PackageRemappingDependency(metamodelURI, false, false).getResource(this.resourceSet, false, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public MoflonGenModelBuilder(final ResourceSet resourceSet, final List<Resource>
this.moflonProperties = moflonProperties;

final IProject project = ecoreFile.getProject();
final URI projectURI = eMoflonEMFUtil.lookupProjectURIAsPlatformResource(project);
//TODO@aanjorin: The following statement does not work with emoflon-tool (TGG compilation fails)
// final URI projectURI = eMoflonEMFUtil.lookupProjectURIAsPlatformResource(project);
final URI projectURI = eMoflonEMFUtil.lookupProjectURI(project);
this.ecoreURI = MoflonConventions.getDefaultProjectRelativeEcoreFileURI(project).resolve(projectURI);
}

Expand Down
Loading

0 comments on commit 0a6f8fd

Please sign in to comment.