Skip to content

Commit 5369ef6

Browse files
authored
Merge pull request #5 from esteve/checkstyle
Add tests, refactor common code, add Javadocs
2 parents 2c7a159 + ccec287 commit 5369ef6

35 files changed

+1389
-563
lines changed

rcljava/CMakeLists.txt

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@ find_package(ament_cmake_export_jars REQUIRED)
77
find_package(rcl REQUIRED)
88
find_package(rmw REQUIRED)
99
find_package(rmw_implementation_cmake REQUIRED)
10+
find_package(rcljava_common REQUIRED)
11+
find_package(JavaExtra MODULE)
1012

11-
if (ANDROID)
13+
if(ANDROID)
1214
find_host_package(Java COMPONENTS Development)
1315
else()
1416
find_package(Java COMPONENTS Development)
1517
find_package(JNI REQUIRED)
1618
endif()
1719

18-
include (UseJava)
20+
include(UseJava)
1921

2022
set(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.6" "-target" "1.6")
2123

2224
if(NOT WIN32)
2325
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
2426
endif()
2527

28+
include_directories(include)
29+
2630
macro(target)
2731
if(NOT "${target_suffix} " STREQUAL " ")
2832
get_rcl_information("${rmw_implementation}" "rcl${target_suffix}")
@@ -56,37 +60,31 @@ macro(target)
5660

5761
ament_target_dependencies(${_target_name}
5862
"rcl${target_suffix}"
63+
"rcljava_common"
5964
)
6065

6166
target_include_directories(${_target_name}
6267
PUBLIC
6368
${JNI_INCLUDE_DIRS}
6469
)
6570

66-
if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
67-
ament_export_libraries(${_target_name})
71+
ament_export_libraries(${_target_name})
6872

69-
install(TARGETS ${_msg_name}${_javaext_suffix}
70-
DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}/${_msg_package_dir2}"
71-
ARCHIVE DESTINATION lib
72-
LIBRARY DESTINATION lib
73-
)
74-
install(TARGETS ${_target_name}
75-
ARCHIVE DESTINATION lib
76-
LIBRARY DESTINATION lib
77-
)
78-
endif()
73+
install(TARGETS ${_target_name}
74+
ARCHIVE DESTINATION lib
75+
LIBRARY DESTINATION lib
76+
)
7977

8078
endforeach()
8179

8280
endmacro()
8381

8482
set(${PROJECT_NAME}_sources
83+
"src/main/java/org/ros2/rcljava/Consumer.java"
8584
"src/main/java/org/ros2/rcljava/Node.java"
86-
"src/main/java/org/ros2/rcljava/RCLJava.java"
8785
"src/main/java/org/ros2/rcljava/Publisher.java"
86+
"src/main/java/org/ros2/rcljava/RCLJava.java"
8887
"src/main/java/org/ros2/rcljava/Subscription.java"
89-
"src/main/java/org/ros2/rcljava/Consumer.java"
9088
)
9189

9290
add_jar("${PROJECT_NAME}_jar"
@@ -97,21 +95,50 @@ add_jar("${PROJECT_NAME}_jar"
9795

9896
call_for_each_rmw_implementation(target)
9997

100-
if(AMENT_ENABLE_TESTING)
98+
set(_install_jar_dir "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}")
99+
get_property(_jar_file TARGET "${PROJECT_NAME}_jar" PROPERTY "JAR_FILE")
100+
101+
install_jar("${PROJECT_NAME}_jar" "share/${PROJECT_NAME}/java")
102+
ament_export_jars("share/${PROJECT_NAME}/java/${PROJECT_NAME}.jar")
103+
104+
if(BUILD_TESTING)
101105
find_package(ament_lint_auto REQUIRED)
102106
ament_lint_auto_find_test_dependencies()
103107

104-
ament_add_nose_test(rcljavatests test
105-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
108+
set(${PROJECT_NAME}_test_sources
109+
"src/test/java/org/ros2/rcljava/NodeTest.java"
110+
"src/test/java/org/ros2/rcljava/PublisherTest.java"
111+
"src/test/java/org/ros2/rcljava/RCLJavaTest.java"
112+
"src/test/java/org/ros2/rcljava/SubscriptionTest.java"
113+
)
114+
115+
set(${PROJECT_NAME}_testsuites
116+
"org.ros2.rcljava.NodeTest"
117+
"org.ros2.rcljava.PublisherTest"
118+
"org.ros2.rcljava.RCLJavaTest"
119+
"org.ros2.rcljava.SubscriptionTest"
106120
)
107-
endif()
108121

109-
if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
110-
set(_install_jar_dir "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}")
111-
get_property(_jar_file TARGET "${PROJECT_NAME}_jar" PROPERTY "JAR_FILE")
122+
set(_deps_library_paths "")
123+
foreach(_dep_lib ${std_msgs_LIBRARIES})
124+
get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY)
125+
list(APPEND _deps_library_paths ${_dep_dir})
126+
endforeach()
127+
list(APPEND _deps_library_paths ${CMAKE_CURRENT_BINARY_DIR})
128+
129+
foreach(testsuite ${${PROJECT_NAME}_testsuites})
130+
add_junit_tests("${PROJECT_NAME}_tests_${testsuite}"
131+
"${${PROJECT_NAME}_test_sources}"
132+
TESTS
133+
"${testsuite}"
134+
INCLUDE_JARS
135+
"${std_msgs_JARS}"
136+
"${_jar_file}"
137+
LIBRARY_PATHS
138+
"${_deps_library_paths}"
139+
)
140+
endforeach()
112141

113-
install_jar("${PROJECT_NAME}_jar" "share/${PROJECT_NAME}/java")
114-
ament_export_jars("share/${PROJECT_NAME}/java/${PROJECT_NAME}.jar")
115142
endif()
116143

117144
ament_package()

rcljava/src/main/cpp/org_ros2_rcljava_Node.h renamed to rcljava/include/org_ros2_rcljava_Node.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
// Copyright 2016 Esteve Fernandez <esteve@apache.org>
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
/* DO NOT EDIT THIS FILE - it is machine generated */
216
#include <jni.h>
317
/* Header for class org_ros2_rcljava_Node */
418

5-
#ifndef _Included_org_ros2_rcljava_Node
6-
#define _Included_org_ros2_rcljava_Node
19+
#ifndef ORG_ROS2_RCLJAVA_NODE_H_
20+
#define ORG_ROS2_RCLJAVA_NODE_H_
721
#ifdef __cplusplus
822
extern "C" {
923
#endif
@@ -26,4 +40,4 @@ JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_Node_nativeCreateSubscriptionHandl
2640
#ifdef __cplusplus
2741
}
2842
#endif
29-
#endif
43+
#endif // ORG_ROS2_RCLJAVA_NODE_H_
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2016 Esteve Fernandez <esteve@apache.org>
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/* DO NOT EDIT THIS FILE - it is machine generated */
16+
#include <jni.h>
17+
/* Header for class org_ros2_rcljava_Publisher */
18+
19+
#ifndef ORG_ROS2_RCLJAVA_PUBLISHER_H_
20+
#define ORG_ROS2_RCLJAVA_PUBLISHER_H_
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
/*
25+
* Class: org_ros2_rcljava_Publisher
26+
* Method: nativePublish
27+
* Signature: (JLjava/lang/Object;)
28+
*/
29+
JNIEXPORT void JNICALL Java_org_ros2_rcljava_Publisher_nativePublish
30+
(JNIEnv *, jclass, jlong, jobject);
31+
32+
/*
33+
* Class: org_ros2_rcljava_Node
34+
* Method: nativeDispose
35+
* Signature: (JJ)V
36+
*/
37+
JNIEXPORT void JNICALL Java_org_ros2_rcljava_Publisher_nativeDispose
38+
(JNIEnv *, jclass, jlong, jlong);
39+
40+
#ifdef __cplusplus
41+
}
42+
#endif
43+
#endif // ORG_ROS2_RCLJAVA_PUBLISHER_H_

rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.h renamed to rcljava/include/org_ros2_rcljava_RCLJava.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
// Copyright 2016 Esteve Fernandez <esteve@apache.org>
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
/* DO NOT EDIT THIS FILE - it is machine generated */
216
#include <jni.h>
317
/* Header for class org_ros2_rcljava_RCLJava */
418

5-
#ifndef _Included_org_ros2_rcljava_RCLJava
6-
#define _Included_org_ros2_rcljava_RCLJava
19+
#ifndef ORG_ROS2_RCLJAVA_RCLJAVA_H_
20+
#define ORG_ROS2_RCLJAVA_RCLJAVA_H_
721
#ifdef __cplusplus
822
extern "C" {
923
#endif
@@ -98,4 +112,4 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_RCLJava_nativeShutdown
98112
#ifdef __cplusplus
99113
}
100114
#endif
101-
#endif
115+
#endif // ORG_ROS2_RCLJAVA_RCLJAVA_H_

rcljava/package.xml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
<buildtool_depend>ament_cmake</buildtool_depend>
1010
<buildtool_depend>ament_cmake_export_jars</buildtool_depend>
11+
<buildtool_depend>rcljava_common</buildtool_depend>
12+
1113
<buildtool_export_depend>rosidl_cmake</buildtool_export_depend>
1214

1315
<exec_depend>rmw_implementation</exec_depend>
@@ -21,32 +23,9 @@
2123

2224
<exec_depend>rcl</exec_depend>
2325

24-
<!--
25-
<depend>rmw_implementation</depend>
26-
-->
27-
<!--
28-
<depend>rcl</depend>
29-
-->
30-
31-
<!--
32-
<depend>rosidl_cmake</depend>
33-
<depend>rosidl_parser</depend>
34-
35-
-->
36-
<!--
37-
<exec_depend>rosidl_default_runtime</exec_depend>
38-
39-
<depend>rmw_implementation</depend>
40-
-->
41-
42-
<!--
43-
<test_depend>ament_cmake_nose</test_depend>
4426
<test_depend>ament_lint_auto</test_depend>
4527
<test_depend>ament_lint_common</test_depend>
4628
<test_depend>std_msgs</test_depend>
47-
<test_depend>rosidl_generator_java</test_depend>
48-
<test_depend>rosidl_typesupport_opensplice_c</test_depend>
49-
-->
5029

5130
<export>
5231
<build_type>ament_cmake</build_type>

0 commit comments

Comments
 (0)