Skip to content
Snippets Groups Projects
Commit b5069888 authored by Daniel Stonier's avatar Daniel Stonier
Browse files

library and app rosjava templates, rosjava app-catkin integration.

parent b2160644
No related branches found
No related tags found
No related merge requests found
Showing
with 252 additions and 25 deletions
#!/usr/bin/env python
"""This script creates the skeleton of a rosjava library project"""
##############################################################################
# Imports
##############################################################################
from __future__ import print_function
import sys
from rosjava_build_tools import create_rosjava_library_project
import rosjava_build_tools.console as console
##############################################################################
# Main
##############################################################################
if __name__ == "__main__":
try:
sys.exit(create_rosjava_library_project())
except Exception as e:
console.logerror("%s : %s" % (str(e), type(e)))
sys.exit(1)
#!/usr/bin/env python #!/usr/bin/env python
"""This script creates the skeleton of an android library package""" """This script creates the skeleton of a rosjava message project"""
############################################################################## ##############################################################################
# Imports # Imports
......
#!/usr/bin/env python #!/usr/bin/env python
"""This script creates the skeleton of an rosjava repo""" """This script creates the skeleton of a rosjava catkin package (typically an entire repo)"""
############################################################################## ##############################################################################
# Imports # Imports
......
#!/usr/bin/env python #!/usr/bin/env python
"""This script creates the skeleton of an android library package""" """This script creates the skeleton of a rosjava application project"""
############################################################################## ##############################################################################
# Imports # Imports
......
...@@ -11,11 +11,13 @@ d = generate_distutils_setup( ...@@ -11,11 +11,13 @@ d = generate_distutils_setup(
'scripts/catkin_create_android_library_project', 'scripts/catkin_create_android_library_project',
'scripts/catkin_create_rosjava_pkg', 'scripts/catkin_create_rosjava_pkg',
'scripts/catkin_create_rosjava_project', 'scripts/catkin_create_rosjava_project',
'scripts/catkin_create_rosjava_library_project',
'scripts/catkin_create_rosjava_msg_project', 'scripts/catkin_create_rosjava_msg_project',
], ],
package_data = {'rosjava_build_tools': [ package_data = {'rosjava_build_tools': [
'templates/android_package/*', 'templates/android_package/*',
'templates/android_project/*', 'templates/android_project/*',
'templates/rosjava_library_project/*',
'templates/rosjava_msg_project/*', 'templates/rosjava_msg_project/*',
'templates/rosjava_package/*', 'templates/rosjava_package/*',
'templates/rosjava_project/*', 'templates/rosjava_project/*',
......
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
import console import console
from create_package import init_android_package, init_rosjava_package from create_package import init_android_package, init_rosjava_package
from create_android_project import create_android_project from create_android_project import create_android_project
from create_rosjava_project import create_rosjava_project, create_rosjava_msg_project from create_rosjava_project import create_rosjava_project, create_rosjava_msg_project, create_rosjava_library_project
from utils import which from utils import which
from release import scrape_for_release_message_packages from release import scrape_for_release_message_packages
...@@ -46,6 +46,10 @@ def instantiate_template(template, project_name, author): ...@@ -46,6 +46,10 @@ def instantiate_template(template, project_name, author):
return template % locals() return template % locals()
def instantiate_code_template(template, package_name, project_name, author):
return template % locals()
def create_gradle_package_files(args, template_directory): def create_gradle_package_files(args, template_directory):
''' '''
This is almost a direct copy from catkin_create_pkg. This is almost a direct copy from catkin_create_pkg.
...@@ -68,6 +72,27 @@ def create_gradle_package_files(args, template_directory): ...@@ -68,6 +72,27 @@ def create_gradle_package_files(args, template_directory):
raise raise
def create_talker_listener_classes(project_name, template_directory, author):
path = os.path.join(os.getcwd(), project_name.lower())
package_name = os.path.basename(os.getcwd())
java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name)
utils.mkdir_p(java_package_path)
try:
for template_name in ['Talker.java', 'Listener.java']:
filename = os.path.join(java_package_path, template_name)
template = utils.read_template_file(template_directory, template_name)
contents = instantiate_code_template(template, package_name, project_name, author)
try:
f = open(filename, 'w')
f.write(contents)
console.pretty_print(' File : ', console.cyan)
console.pretty_println(template_name, console.yellow)
finally:
f.close()
except Exception:
raise
def add_to_root_gradle_settings(name): def add_to_root_gradle_settings(name):
''' '''
Adds project name to the root level settings.gradle file. Adds project name to the root level settings.gradle file.
...@@ -126,9 +151,33 @@ def add_to_package_xml(name): ...@@ -126,9 +151,33 @@ def add_to_package_xml(name):
package_xml.write(new_contents) package_xml.write(new_contents)
def add_install_app_to_cmake_targets():
'''
Adds project name to build_depends in package.xml (should be same name as the ros msg package name).
'''
for rel_path in ['.', '..']:
cmakelists_txt_path = os.path.join(os.getcwd(), rel_path, 'CMakeLists.txt')
if os.path.isfile(cmakelists_txt_path):
break
else:
cmakelists_txt_path = None
if cmakelists_txt_path is None:
console.pretty_println("\nCouldn't find the root level CMakeLists.txt - not adding to the superproject.")
return
with open(cmakelists_txt_path, 'r') as cmakelists_txt:
console.pretty_print(' File : ', console.cyan)
console.pretty_println('CMakeLists.txt (gradle task update)', console.yellow)
old_text = 'catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository)'
new_text = 'catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository installApp)'
new_contents = cmakelists_txt.read().replace(old_text, new_text)
with open(cmakelists_txt_path, 'w') as cmakelists_txt:
cmakelists_txt.write(new_contents)
def create_dummy_java_class(project_name): def create_dummy_java_class(project_name):
path = os.path.join(os.getcwd(), project_name.lower()) path = os.path.join(os.getcwd(), project_name.lower())
java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', 'rosjava', project_name) package_name = os.path.basename(os.getcwd())
java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name)
utils.mkdir_p(java_package_path) utils.mkdir_p(java_package_path)
filename = os.path.join(java_package_path, 'Dude.java') filename = os.path.join(java_package_path, 'Dude.java')
java_class = "package com.github.rosjava.%s.Dude;\n" % project_name java_class = "package com.github.rosjava.%s.Dude;\n" % project_name
...@@ -170,12 +219,23 @@ def create_rosjava_project_common(args, template_directory): ...@@ -170,12 +219,23 @@ def create_rosjava_project_common(args, template_directory):
def create_rosjava_project(): def create_rosjava_project():
args = parse_arguments() args = parse_arguments()
project_name = args.name[0]
author = args.author
create_rosjava_project_common(args, 'rosjava_project') create_rosjava_project_common(args, 'rosjava_project')
create_dummy_java_class(args.name[0]) create_talker_listener_classes(project_name, 'rosjava_project', author)
add_install_app_to_cmake_targets()
def create_rosjava_library_project():
args = parse_arguments()
project_name = args.name[0]
create_rosjava_project_common(args, 'rosjava_library_project')
create_dummy_java_class(project_name)
def create_rosjava_msg_project(): def create_rosjava_msg_project():
args = parse_arguments() args = parse_arguments()
project_name = args.name[0]
create_rosjava_project_common(args, 'rosjava_msg_project') create_rosjava_project_common(args, 'rosjava_msg_project')
add_catkin_generate_tree_command() add_catkin_generate_tree_command()
add_to_package_xml(args.name[0]) add_to_package_xml(project_name)
/* /*
* Copyright (C) 2013 %(author)s * Copyright (C) 2014 %(author)s
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
......
/* /*
* Copyright (C) 2013 %(author)s * Copyright (C) 2014 %(author)s
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
......
/* /*
* Copyright (C) 2013 %(author)s. * Copyright (C) 2014 %(author)s.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
......
/*
* Copyright (C) 2014 %(author)s.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
/*
Dependencies can be on external maven artifacts (such as rosjava_core
here) or on sibling subprojects. Fpr external maven artifact dependencies
it's convenient to use an open ranged dependency, but restrict it to
cover the patch version only to avoid breakages due to api changes
which usually occur on minor and major version numbers.
*/
dependencies {
/* Example of an external maven artifact dependency */
/* compile 'org.ros.rosjava_core:rosjava:[0.1,)' */
/* Example of a local subproject dependency */
/* compile project(':sibling_gradle_project') */
}
/* /*
* Copyright (C) 2013 %(author)s. * Copyright (C) 2014 %(author)s.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
......
...@@ -11,7 +11,7 @@ project(%(repo_name)s) ...@@ -11,7 +11,7 @@ project(%(repo_name)s)
find_package(catkin REQUIRED rosjava_build_tools) find_package(catkin REQUIRED rosjava_build_tools)
# Set the gradle targets you want catkin's make to run by default # Set the gradle targets you want catkin's make to run by default
catkin_android_setup(publishMavenJavaPublicationToMavenRepository) catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository)
catkin_package() catkin_package()
############################################################################## ##############################################################################
......
/* /*
* Copyright (C) 2013 %(author)s * Copyright (C) 2014 %(author)s
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
......
/*
* Copyright (C) 2014 %(author)s.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.github.%(package_name)s.%(project_name)s;
import org.apache.commons.logging.Log;
import org.ros.message.MessageListener;
import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber;
/**
* A simple {@link Subscriber} {@link NodeMain}.
*/
public class Listener extends AbstractNodeMain {
@Override
public GraphName getDefaultNodeName() {
return GraphName.of("rosjava/listener");
}
@Override
public void onStart(ConnectedNode connectedNode) {
final Log log = connectedNode.getLog();
Subscriber<std_msgs.String> subscriber = connectedNode.newSubscriber("chatter", std_msgs.String._TYPE);
subscriber.addMessageListener(new MessageListener<std_msgs.String>() {
@Override
public void onNewMessage(std_msgs.String message) {
log.info("I heard: \"" + message.getData() + "\"");
}
});
}
}
/*
* Copyright (C) 2014 %(author)s.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.github.%(package_name)s.%(project_name)s;
import org.ros.concurrent.CancellableLoop;
import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher;
/**
* A simple {@link Publisher} {@link NodeMain}.
*/
public class Talker extends AbstractNodeMain {
@Override
public GraphName getDefaultNodeName() {
return GraphName.of("rosjava/talker");
}
@Override
public void onStart(final ConnectedNode connectedNode) {
final Publisher<std_msgs.String> publisher =
connectedNode.newPublisher("chatter", std_msgs.String._TYPE);
// This CancellableLoop will be canceled automatically when the node shuts
// down.
connectedNode.executeCancellableLoop(new CancellableLoop() {
private int sequenceNumber;
@Override
protected void setup() {
sequenceNumber = 0;
}
@Override
protected void loop() throws InterruptedException {
std_msgs.String str = publisher.newMessage();
str.setData("Hello world! " + sequenceNumber);
publisher.publish(str);
sequenceNumber++;
Thread.sleep(1000);
}
});
}
}
/* /*
* Copyright (C) 2013 %(author)s. * Copyright (C) 2014 %(author)s.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
...@@ -14,20 +14,22 @@ ...@@ -14,20 +14,22 @@
* the License. * the License.
*/ */
/* /* This plugin is necessary for creating installApp tasks (i.e. executables) */
Examples of apply plugin: 'application'
1) dependencies from another project in this gradle stack. mainClassName = 'org.ros.RosRun'
2,3) open ranged dependencies from a maven repository.
It's a good idea to restrict the open ranged dependency to /*
the patch version to avoid breakages due to api changes Dependencies can be on external maven artifacts (such as rosjava_core
here) or on sibling subprojects. Fpr external maven artifact dependencies
it's convenient to use an open ranged dependency, but restrict it to
cover the patch version only to avoid breakages due to api changes
which usually occur on minor and major version numbers. which usually occur on minor and major version numbers.
*/ */
/*
dependencies { dependencies {
compile project(':local_android_library_dependency') /* An external maven artifact dependency */
compile 'org.ros.rosjava_core:rosjava:[0.1,)' compile 'org.ros.rosjava_core:rosjava:[0.1,)'
compile 'com.github.rosjava.rosjava_extras:hokuyo:[0.1,0.2)' /* Example of a local subproject dependency */
/* compile project(':sibling_gradle_project') */
} }
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment