Skip to content

Commit

Permalink
Add ROS 2 code generator plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ipa-nhg committed Dec 14, 2023
1 parent 942840f commit 12ad711
Show file tree
Hide file tree
Showing 18 changed files with 1,332 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugins/de.fraunhofer.ipa.ros.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,11 @@ POSSIBILITY OF SUCH DAMAGE.
version="3.0.0.qualifier"
unpack="false"/>

<plugin
id="de.fraunhofer.ipa.roscode.generator"
download-size="0"
install-size="0"
version="3.0.0.qualifier"
unpack="false"/>

</feature>
8 changes: 8 additions & 0 deletions plugins/de.fraunhofer.ipa.roscode.generator/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-19"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
34 changes: 34 additions & 0 deletions plugins/de.fraunhofer.ipa.roscode.generator/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>de.fraunhofer.ipa.roscode.generator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<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.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=19
org.eclipse.jdt.core.compiler.compliance=19
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=19
24 changes: 24 additions & 0 deletions plugins/de.fraunhofer.ipa.roscode.generator/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: de.fraunhofer.ipa.roscode.generator;singleton:=true
Bundle-Version: 3.0.0.qualifier
Bundle-Vendor: %providerName
Export-Package: de.fraunhofer.ipa.roscode.generator
Bundle-RequiredExecutionEnvironment: JavaSE-19
Import-Package: javax.inject;version="1.0.0",
org.eclipse.ui.handlers,
org.eclipse.xtext.ui.resource
Bundle-ActivationPolicy: lazy
Bundle-Activator: de.fraunhofer.ipa.roscode.generator.Activator
Require-Bundle: org.eclipse.xtext.builder,
org.eclipse.xtext.ui,
de.fraunhofer.ipa.ros2.xtext;bundle-version="3.0.0",
de.fraunhofer.ipa.ros2.xtext.ide;bundle-version="3.0.0",
de.fraunhofer.ipa.ros2.xtext.ui;bundle-version="3.0.0",
de.fraunhofer.ipa.ros.xtext;bundle-version="3.0.0",
de.fraunhofer.ipa.ros.xtext.ide;bundle-version="3.0.0",
de.fraunhofer.ipa.ros.xtext.ui;bundle-version="3.0.0",
de.fraunhofer.ipa.ros;bundle-version="3.0.0",
de.fraunhofer.ipa.ros.edit;bundle-version="3.0.0",
de.fraunhofer.ipa.ros.editor;bundle-version="3.0.0"
17 changes: 17 additions & 0 deletions plugins/de.fraunhofer.ipa.roscode.generator/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source.. = src/,\
xtend-gen/
bin.includes = .,\
META-INF/,\
plugin.xml
bin.excludes = **/*.mwe2,\
**/*.xtend
additional.bundles = org.eclipse.xtext.xbase,\
org.eclipse.xtext.common.types,\
org.eclipse.xtext.xtext.generator,\
org.eclipse.emf.codegen.ecore,\
org.eclipse.emf.mwe.utils,\
org.eclipse.emf.mwe2.lib,\
org.objectweb.asm,\
org.apache.commons.logging,\
org.apache.log4j,\
com.ibm.icu
144 changes: 144 additions & 0 deletions plugins/de.fraunhofer.ipa.roscode.generator/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<!-- <extension
point="org.eclipse.ui.handlers">
<handler
class="de.fraunhofer.ipa.roscode.generator.RosCodeGeneratorExecutableExtensionFactory:de.fraunhofer.ipa.roscode.generator.GenerationHandler"
commandId="de.fraunhofer.ipa.roscode.generator.command">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="de.fraunhofer.ipa.roscode.generator.command"
name="Generate ROS code">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="de.fraunhofer.ipa.roscode.generator.command"
>
<visibleWhen
checkEnabled="false">
<and>
<with
variable="selection">
<count
value="1">
</count>
</with>
<iterate
ifEmpty="false">
<test
property="org.eclipse.core.resources.extension"
value="ros">
</test>
</iterate>
</and>
</visibleWhen>
</command>
</menuContribution>
</extension>-->


<!-- ROS2 cpp code generator for nodes -->

<extension
point="org.eclipse.ui.handlers">
<handler
class="de.fraunhofer.ipa.roscode.generator.RosCodeGeneratorExecutableExtensionFactory:de.fraunhofer.ipa.roscode.generator.GenerationRos2CppHandler"
commandId="de.fraunhofer.ipa.ros2cppcode.generator.command">
</handler>
</extension>

<extension
point="org.eclipse.ui.commands">
<command
id="de.fraunhofer.ipa.ros2cppcode.generator.command"
name="Generate ROS 2 Cpp code">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="de.fraunhofer.ipa.ros2cppcode.generator.command"
>
<visibleWhen
checkEnabled="false">
<and>
<with
variable="selection">
<count
value="1">
</count>
</with>
<iterate
ifEmpty="false">
<test
property="org.eclipse.core.resources.extension"
value="ros2">
</test>
</iterate>
</and>
</visibleWhen>
</command>
</menuContribution>
</extension>


<!-- ROS2 python code generator for nodes -->
<extension
point="org.eclipse.ui.handlers">
<handler
class="de.fraunhofer.ipa.roscode.generator.RosCodeGeneratorExecutableExtensionFactory:de.fraunhofer.ipa.roscode.generator.GenerationRos2PythonHandler"
commandId="de.fraunhofer.ipa.ros2pythoncode.generator.command">
</handler>
</extension>

<extension
point="org.eclipse.ui.commands">
<command
id="de.fraunhofer.ipa.ros2pythoncode.generator.command"
name="Generate ROS 2 Python code">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="de.fraunhofer.ipa.ros2pythoncode.generator.command"
>
<visibleWhen
checkEnabled="false">
<and>
<with
variable="selection">
<count
value="1">
</count>
</with>
<iterate
ifEmpty="false">
<test
property="org.eclipse.core.resources.extension"
value="ros2">
</test>
</iterate>
</and>
</visibleWhen>
</command>
</menuContribution>
</extension>

</plugin>
31 changes: 31 additions & 0 deletions plugins/de.fraunhofer.ipa.roscode.generator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.fraunhofer.ipa.ros</groupId>
<artifactId>de.fraunhofer.ipa.ros.parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../de.fraunhofer.ipa.ros.parent/pom.xml</relativePath>
</parent>
<artifactId>de.fraunhofer.ipa.roscode.generator</artifactId>
<packaging>eclipse-plugin</packaging>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>xtend-gen-clean</id>
<phase>clean</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.fraunhofer.ipa.roscode.generator;

import de.fraunhofer.ipa.ros2.xtext.ui.internal.XtextActivator;

public class Activator extends XtextActivator {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package de.fraunhofer.ipa.roscode.generator;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
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.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2;
import org.eclipse.xtext.generator.GeneratorContext;
import org.eclipse.xtext.generator.IOutputConfigurationProvider;
import org.eclipse.xtext.generator.OutputConfiguration;
import org.eclipse.xtext.resource.IResourceDescriptions;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;

import com.google.inject.Inject;
import com.google.inject.Provider;

import de.fraunhofer.ipa.roscode.generator.RosCodeGenerator;;

public class GenerationHandler extends AbstractHandler implements IHandler {

@Inject
private Provider<EclipseResourceFileSystemAccess2> fileAccessProvider;

@Inject
IResourceDescriptions resourceDescriptions;

@Inject
IResourceSetProvider resourceSetProvider;

static Map<String, OutputConfiguration> getOutputConfigurationsAsMap(IOutputConfigurationProvider provider) {
Map<String, OutputConfiguration> outputs = new HashMap<String, OutputConfiguration>();
for(OutputConfiguration c: provider.getOutputConfigurations()) {
outputs.put(c.getName(), c);
}
return outputs;
}

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IFile) {
IFile file = (IFile) firstElement;
IProject project = file.getProject();

final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
fsa.setProject(project);
fsa.setOutputConfigurations(getOutputConfigurationsAsMap(new CustomOutputProvider()));
fsa.setMonitor(new NullProgressMonitor());

URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = resourceSetProvider.get(project);
Resource r = rs.getResource(uri, true);

RosCodeGenerator generator = new RosCodeGenerator();
generator.doGenerate(r, fsa, new GeneratorContext());

}
}
return null;
}

@Override
public boolean isEnabled() {
return true;
}
}
Loading

0 comments on commit 12ad711

Please sign in to comment.