Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

Fix child headers #82

Open
wants to merge 3 commits into
base: kinetic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -96,12 +100,45 @@ private void writeTopicInterfaces(File outputDirectory, Collection<String> 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();
Process p = null;
try {
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());
}
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;
}

/**
* @param packages
* a list of packages containing the topic types to generate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public String get(File file) {
return strings.get(file);
}

public Collection<File> getDirectories() {
return directories;
}

public boolean has(File file) {
return strings.containsKey(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getPackages() {
return messageIdentifiers.keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public void parse(String messageType, String messageDefinition) {
if (line.startsWith("#")) {
continue;
}
if (line.equals(MessageDefinitionSeparators.defaultSeparator)) {
break;
}
if (line.length() > 0) {
parseField(messageType, line);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.ros.internal.message.definition;

public class MessageDefinitionSeparators {
public static final String defaultSeparator = "================================================================================";
}