Skip to content

Commit b506988

Browse files
committed
library and app rosjava templates, rosjava app-catkin integration.
1 parent b216064 commit b506988

File tree

17 files changed

+252
-25
lines changed

17 files changed

+252
-25
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
3+
"""This script creates the skeleton of a rosjava library project"""
4+
5+
##############################################################################
6+
# Imports
7+
##############################################################################
8+
9+
from __future__ import print_function
10+
import sys
11+
12+
from rosjava_build_tools import create_rosjava_library_project
13+
import rosjava_build_tools.console as console
14+
15+
##############################################################################
16+
# Main
17+
##############################################################################
18+
19+
if __name__ == "__main__":
20+
try:
21+
sys.exit(create_rosjava_library_project())
22+
except Exception as e:
23+
console.logerror("%s : %s" % (str(e), type(e)))
24+
sys.exit(1)

scripts/catkin_create_rosjava_msg_project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
"""This script creates the skeleton of an android library package"""
3+
"""This script creates the skeleton of a rosjava message project"""
44

55
##############################################################################
66
# Imports

scripts/catkin_create_rosjava_pkg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
"""This script creates the skeleton of an rosjava repo"""
3+
"""This script creates the skeleton of a rosjava catkin package (typically an entire repo)"""
44

55
##############################################################################
66
# Imports

scripts/catkin_create_rosjava_project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
"""This script creates the skeleton of an android library package"""
3+
"""This script creates the skeleton of a rosjava application project"""
44

55
##############################################################################
66
# Imports

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
'scripts/catkin_create_android_library_project',
1212
'scripts/catkin_create_rosjava_pkg',
1313
'scripts/catkin_create_rosjava_project',
14+
'scripts/catkin_create_rosjava_library_project',
1415
'scripts/catkin_create_rosjava_msg_project',
1516
],
1617
package_data = {'rosjava_build_tools': [
1718
'templates/android_package/*',
1819
'templates/android_project/*',
20+
'templates/rosjava_library_project/*',
1921
'templates/rosjava_msg_project/*',
2022
'templates/rosjava_package/*',
2123
'templates/rosjava_project/*',

src/rosjava_build_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
import console
88
from create_package import init_android_package, init_rosjava_package
99
from create_android_project import create_android_project
10-
from create_rosjava_project import create_rosjava_project, create_rosjava_msg_project
10+
from create_rosjava_project import create_rosjava_project, create_rosjava_msg_project, create_rosjava_library_project
1111
from utils import which
1212
from release import scrape_for_release_message_packages

src/rosjava_build_tools/create_rosjava_project.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def instantiate_template(template, project_name, author):
4646
return template % locals()
4747

4848

49+
def instantiate_code_template(template, package_name, project_name, author):
50+
return template % locals()
51+
52+
4953
def create_gradle_package_files(args, template_directory):
5054
'''
5155
This is almost a direct copy from catkin_create_pkg.
@@ -68,6 +72,27 @@ def create_gradle_package_files(args, template_directory):
6872
raise
6973

7074

75+
def create_talker_listener_classes(project_name, template_directory, author):
76+
path = os.path.join(os.getcwd(), project_name.lower())
77+
package_name = os.path.basename(os.getcwd())
78+
java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name)
79+
utils.mkdir_p(java_package_path)
80+
try:
81+
for template_name in ['Talker.java', 'Listener.java']:
82+
filename = os.path.join(java_package_path, template_name)
83+
template = utils.read_template_file(template_directory, template_name)
84+
contents = instantiate_code_template(template, package_name, project_name, author)
85+
try:
86+
f = open(filename, 'w')
87+
f.write(contents)
88+
console.pretty_print(' File : ', console.cyan)
89+
console.pretty_println(template_name, console.yellow)
90+
finally:
91+
f.close()
92+
except Exception:
93+
raise
94+
95+
7196
def add_to_root_gradle_settings(name):
7297
'''
7398
Adds project name to the root level settings.gradle file.
@@ -126,9 +151,33 @@ def add_to_package_xml(name):
126151
package_xml.write(new_contents)
127152

128153

154+
def add_install_app_to_cmake_targets():
155+
'''
156+
Adds project name to build_depends in package.xml (should be same name as the ros msg package name).
157+
'''
158+
for rel_path in ['.', '..']:
159+
cmakelists_txt_path = os.path.join(os.getcwd(), rel_path, 'CMakeLists.txt')
160+
if os.path.isfile(cmakelists_txt_path):
161+
break
162+
else:
163+
cmakelists_txt_path = None
164+
if cmakelists_txt_path is None:
165+
console.pretty_println("\nCouldn't find the root level CMakeLists.txt - not adding to the superproject.")
166+
return
167+
with open(cmakelists_txt_path, 'r') as cmakelists_txt:
168+
console.pretty_print(' File : ', console.cyan)
169+
console.pretty_println('CMakeLists.txt (gradle task update)', console.yellow)
170+
old_text = 'catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository)'
171+
new_text = 'catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository installApp)'
172+
new_contents = cmakelists_txt.read().replace(old_text, new_text)
173+
with open(cmakelists_txt_path, 'w') as cmakelists_txt:
174+
cmakelists_txt.write(new_contents)
175+
176+
129177
def create_dummy_java_class(project_name):
130178
path = os.path.join(os.getcwd(), project_name.lower())
131-
java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', 'rosjava', project_name)
179+
package_name = os.path.basename(os.getcwd())
180+
java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name)
132181
utils.mkdir_p(java_package_path)
133182
filename = os.path.join(java_package_path, 'Dude.java')
134183
java_class = "package com.github.rosjava.%s.Dude;\n" % project_name
@@ -170,12 +219,23 @@ def create_rosjava_project_common(args, template_directory):
170219

171220
def create_rosjava_project():
172221
args = parse_arguments()
222+
project_name = args.name[0]
223+
author = args.author
173224
create_rosjava_project_common(args, 'rosjava_project')
174-
create_dummy_java_class(args.name[0])
225+
create_talker_listener_classes(project_name, 'rosjava_project', author)
226+
add_install_app_to_cmake_targets()
227+
228+
229+
def create_rosjava_library_project():
230+
args = parse_arguments()
231+
project_name = args.name[0]
232+
create_rosjava_project_common(args, 'rosjava_library_project')
233+
create_dummy_java_class(project_name)
175234

176235

177236
def create_rosjava_msg_project():
178237
args = parse_arguments()
238+
project_name = args.name[0]
179239
create_rosjava_project_common(args, 'rosjava_msg_project')
180240
add_catkin_generate_tree_command()
181-
add_to_package_xml(args.name[0])
241+
add_to_package_xml(project_name)

src/rosjava_build_tools/templates/android_package/build.gradle.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2013 %(author)s
2+
* Copyright (C) 2014 %(author)s
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of

src/rosjava_build_tools/templates/android_package/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2013 %(author)s
2+
* Copyright (C) 2014 %(author)s
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of

src/rosjava_build_tools/templates/android_project/build.gradle.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2013 %(author)s.
2+
* Copyright (C) 2014 %(author)s.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of

0 commit comments

Comments
 (0)