From 0539499b6e3fb40c76461655d6a4bca68cf6c2ca Mon Sep 17 00:00:00 2001 From: Daan Ravesteijn Date: Tue, 21 Jul 2020 12:16:52 +0000 Subject: [PATCH 1/3] Dirty fix for missing child headers --- .../internal/message/GenerateInterfaces.java | 35 ++++++++++++++++++- .../internal/message/StringFileProvider.java | 4 +++ .../MessageDefinitionFileProvider.java | 9 +++++ .../definition/MessageDefinitionParser.java | 3 ++ .../MessageDefinitionSeperators.java | 5 +++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeperators.java diff --git a/message_generation/src/main/java/org/ros/internal/message/GenerateInterfaces.java b/message_generation/src/main/java/org/ros/internal/message/GenerateInterfaces.java index 00bff33d..5e8570c5 100644 --- a/message_generation/src/main/java/org/ros/internal/message/GenerateInterfaces.java +++ b/message_generation/src/main/java/org/ros/internal/message/GenerateInterfaces.java @@ -20,6 +20,8 @@ import com.google.common.collect.Sets; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.SystemUtils; +import org.omg.SendingContext.RunTime; import org.ros.exception.RosMessageRuntimeException; import org.ros.internal.message.definition.MessageDefinitionProviderChain; import org.ros.internal.message.definition.MessageDefinitionTupleParser; @@ -36,8 +38,10 @@ import org.ros.message.MessageFactory; import org.ros.message.MessageIdentifier; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.util.Collection; import java.util.List; import java.util.ListIterator; @@ -96,12 +100,41 @@ private void writeTopicInterfaces(File outputDirectory, Collection packa } } for (MessageIdentifier topicType : topicTypes) { - String definition = messageDefinitionProviderChain.get(topicType.getType()); + String definition = getDefinition(topicType); MessageDeclaration messageDeclaration = new MessageDeclaration(topicType, definition); writeInterface(messageDeclaration, outputDirectory, true); } } + private String getDefinition(MessageIdentifier topicType) { + String definition; + final File directory = topicDefinitionFileProvider.getDirectory(topicType.getPackage()); + final String cmd = "rosrun roslib gendeps --cat " + directory.getAbsolutePath() + File.separator + "msg" + + File.separator + topicType.getName() + ".msg"; + final StringBuilder sb = new StringBuilder(); + try { + final Process p = Runtime.getRuntime().exec(cmd); + final BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream())); + final BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream())); + String s; + while ((s = bri.readLine()) != null) { + sb.append(s); + sb.append("\n"); + } + p.waitFor(); + if (p.exitValue() != 0) { + throw new RuntimeException(bre.readLine()); + } + p.destroy(); + definition = sb.toString(); + } catch (Exception e) { + System.out.println("ERROR: Cannot generate child definitions for " + topicType.getType() + + ". Failed to run '" + cmd + "': " + e.getMessage()); + definition = messageDefinitionProviderChain.get(topicType.getType()); + } + return definition; + } + /** * @param packages * a list of packages containing the topic types to generate diff --git a/message_generation/src/main/java/org/ros/internal/message/StringFileProvider.java b/message_generation/src/main/java/org/ros/internal/message/StringFileProvider.java index 2f9ddfaf..4cdf524f 100644 --- a/message_generation/src/main/java/org/ros/internal/message/StringFileProvider.java +++ b/message_generation/src/main/java/org/ros/internal/message/StringFileProvider.java @@ -124,6 +124,10 @@ public String get(File file) { return strings.get(file); } + public Collection getDirectories() { + return directories; + } + public boolean has(File file) { return strings.containsKey(file); } diff --git a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionFileProvider.java b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionFileProvider.java index 4aa03891..829ffef0 100644 --- a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionFileProvider.java +++ b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionFileProvider.java @@ -92,6 +92,15 @@ public void addDirectory(File directory) { stringFileProvider.addDirectory(directory); } + public File getDirectory(String pkg) { + for (File dir : stringFileProvider.getDirectories()) { + if (dir.getName().equals(pkg)) { + return dir; + } + } + return null; + } + @Override public Collection getPackages() { return messageIdentifiers.keySet(); diff --git a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionParser.java b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionParser.java index e0bbe1e6..ce3e42a2 100644 --- a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionParser.java +++ b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionParser.java @@ -103,6 +103,9 @@ public void parse(String messageType, String messageDefinition) { if (line.startsWith("#")) { continue; } + if (line.equals(MessageDefinitionSeperators.defaultSeperator)) { + break; + } if (line.length() > 0) { parseField(messageType, line); } diff --git a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeperators.java b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeperators.java new file mode 100644 index 00000000..d08c768f --- /dev/null +++ b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeperators.java @@ -0,0 +1,5 @@ +package org.ros.internal.message.definition; + +public class MessageDefinitionSeperators { + public static final String defaultSeperator = "================================================================================"; +} From 11c8a47926795e7a97a2107c50cc6fb884103767 Mon Sep 17 00:00:00 2001 From: Daan Ravesteijn Date: Tue, 21 Jul 2020 12:25:14 +0000 Subject: [PATCH 2/3] Always destroy process --- .../java/org/ros/internal/message/GenerateInterfaces.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/message_generation/src/main/java/org/ros/internal/message/GenerateInterfaces.java b/message_generation/src/main/java/org/ros/internal/message/GenerateInterfaces.java index 5e8570c5..f02e454d 100644 --- a/message_generation/src/main/java/org/ros/internal/message/GenerateInterfaces.java +++ b/message_generation/src/main/java/org/ros/internal/message/GenerateInterfaces.java @@ -112,8 +112,9 @@ private String getDefinition(MessageIdentifier topicType) { final String cmd = "rosrun roslib gendeps --cat " + directory.getAbsolutePath() + File.separator + "msg" + File.separator + topicType.getName() + ".msg"; final StringBuilder sb = new StringBuilder(); + Process p = null; try { - final Process p = Runtime.getRuntime().exec(cmd); + p = Runtime.getRuntime().exec(cmd); final BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream())); final BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream())); String s; @@ -125,12 +126,15 @@ private String getDefinition(MessageIdentifier topicType) { if (p.exitValue() != 0) { throw new RuntimeException(bre.readLine()); } - p.destroy(); definition = sb.toString(); } catch (Exception e) { System.out.println("ERROR: Cannot generate child definitions for " + topicType.getType() + ". Failed to run '" + cmd + "': " + e.getMessage()); definition = messageDefinitionProviderChain.get(topicType.getType()); + } finally { + if (p != null) { + p.destroy(); + } } return definition; } From 0efee889abc74caf8446f64902f24f837f123efd Mon Sep 17 00:00:00 2001 From: Daan Ravesteijn Date: Tue, 21 Jul 2020 12:57:45 +0000 Subject: [PATCH 3/3] Correct spelling mistake --- .../internal/message/definition/MessageDefinitionParser.java | 2 +- ...nitionSeperators.java => MessageDefinitionSeparators.java} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename message_generation/src/main/java/org/ros/internal/message/definition/{MessageDefinitionSeperators.java => MessageDefinitionSeparators.java} (52%) diff --git a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionParser.java b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionParser.java index ce3e42a2..10bd8f28 100644 --- a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionParser.java +++ b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionParser.java @@ -103,7 +103,7 @@ public void parse(String messageType, String messageDefinition) { if (line.startsWith("#")) { continue; } - if (line.equals(MessageDefinitionSeperators.defaultSeperator)) { + if (line.equals(MessageDefinitionSeparators.defaultSeparator)) { break; } if (line.length() > 0) { diff --git a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeperators.java b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeparators.java similarity index 52% rename from message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeperators.java rename to message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeparators.java index d08c768f..12a6abe5 100644 --- a/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeperators.java +++ b/message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionSeparators.java @@ -1,5 +1,5 @@ package org.ros.internal.message.definition; -public class MessageDefinitionSeperators { - public static final String defaultSeperator = "================================================================================"; +public class MessageDefinitionSeparators { + public static final String defaultSeparator = "================================================================================"; }