Skip to content

Commit e0808a7

Browse files
committed
Use ament_java_resources to store CLASSPATH templates
1 parent 284afec commit e0808a7

File tree

8 files changed

+57
-74
lines changed

8 files changed

+57
-74
lines changed

ament_build_type_gradle/ament_build_type_gradle/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from ament_build_type_gradle.templates import get_environment_hook_template_path
2424

25-
from ament_package.templates import configure_file
25+
from ament_package.templates import configure_string
2626
from ament_package.templates import get_package_level_template_names
2727

2828
from ament_tools.helper import extract_argument_group
@@ -121,20 +121,22 @@ def extend_context(self, options):
121121
return ce
122122

123123
def on_build(self, context):
124+
ext = '.sh' if not IS_WINDOWS else '.bat'
125+
classpath_filename = 'classpath' + ext
126+
124127
# expand environment hook for CLASSPATH
125-
ext = '.sh.in' if not IS_WINDOWS else '.bat.in'
126-
template_path = get_environment_hook_template_path('classpath' + ext)
128+
template = get_environment_hook_template_path()
127129

128130
# If using the Gradle Ament Plugin, JAR files are installed into
129131
# $AMENT_CURRENT_PREFIX/share/$PROJECT_NAME/java/$PROJECT_NAME.jar
130132
classpath = os.path.join('$AMENT_CURRENT_PREFIX', 'share', context.package_manifest.name,
131133
'java', context.package_manifest.name + ".jar")
132134

133-
content = configure_file(template_path, {'_AMENT_EXPORT_JARS_CLASSPATH': classpath, })
135+
content = configure_string(template, {'_AMENT_EXPORT_JARS_CLASSPATH': classpath, })
134136

135137
environment_hooks_path = os.path.join('share', context.package_manifest.name, 'environment')
136138
classpath_environment_hook = os.path.join(environment_hooks_path,
137-
os.path.basename(template_path)[:-3])
139+
os.path.basename(classpath_filename))
138140

139141
destination_path = os.path.join(context.build_space, classpath_environment_hook)
140142
destination_dir = os.path.dirname(destination_path)

ament_build_type_gradle/ament_build_type_gradle/templates.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
1517
from ament_index_python import get_resource
1618

19+
IS_WINDOWS = os.name == 'nt'
20+
1721

18-
def get_environment_hook_template_path(name):
19-
return get_resource('templates', 'ament_build_type_gradle_classpath')[0]
22+
def get_environment_hook_template_path():
23+
ext = 'sh' if not IS_WINDOWS else 'bat'
24+
return get_resource('templates', 'ament_build_type_gradle_classpath_' + ext)[0]

ament_build_type_gradle/package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
<buildtool_export_depend>ament_tools</buildtool_export_depend>
1212

13+
<build_depend>ament_java_resources</build_depend>
14+
<exec_depend>ament_java_resources</exec_depend>
15+
1316
<test_depend>ament_copyright</test_depend>
1417
<test_depend>ament_pep257</test_depend>
1518
<test_depend>ament_pep8</test_depend>

ament_build_type_gradle/setup.py

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,6 @@
22

33
from setuptools import find_packages
44
from setuptools import setup
5-
from setuptools.command.install import install
6-
from setuptools.command.develop import develop
7-
8-
IS_WINDOWS = os.name == 'nt'
9-
10-
# Customize both the install (non-symlinked) and develop (symlinked) commands so that we can
11-
# install an entry in the ament index for the path to the CLASSPATH templates
12-
13-
14-
class ament_gradle_install(install):
15-
def run(self):
16-
super().run()
17-
install_dir = self.prefix
18-
install_index_dir = os.path.join(install_dir, 'share', 'ament_index',
19-
'resource_index', 'templates')
20-
install_index_path = os.path.join(install_index_dir,
21-
'ament_build_type_gradle_classpath')
22-
23-
install_lib_dir = self.get_finalized_command('install_lib').install_dir
24-
25-
template_dir = os.path.join(install_lib_dir, 'ament_build_type_gradle',
26-
'template', 'environment_hook')
27-
template_filename = 'classpath' + ('.sh.in'
28-
if not IS_WINDOWS else '.bat.in')
29-
template_path = os.path.join(template_dir, template_filename)
30-
31-
self.mkpath(install_index_dir)
32-
with open(install_index_path, 'w') as f:
33-
f.write(template_path)
34-
35-
36-
class ament_gradle_develop(develop):
37-
def run(self):
38-
super().run()
39-
build_dir = os.path.abspath(self.setup_path)
40-
src_dir = os.path.dirname(
41-
os.path.realpath(os.path.join(build_dir, 'setup.py')))
42-
install_dir = self.prefix
43-
44-
template_dir = os.path.join(src_dir, 'ament_build_type_gradle',
45-
'template', 'environment_hook')
46-
template_filename = 'classpath' + ('.sh.in'
47-
if not IS_WINDOWS else '.bat.in')
48-
template_path = os.path.join(template_dir, template_filename)
49-
50-
build_index_dir = os.path.join(build_dir, 'share', 'ament_index',
51-
'resource_index', 'templates')
52-
build_index_path = os.path.join(build_index_dir,
53-
'ament_build_type_gradle_classpath')
54-
self.mkpath(build_index_dir)
55-
with open(build_index_path, 'w') as f:
56-
f.write(template_path)
57-
58-
install_index_dir = os.path.join(install_dir, 'share', 'ament_index',
59-
'resource_index', 'templates')
60-
install_index_path = os.path.join(install_index_dir,
61-
'ament_build_type_gradle_classpath')
62-
self.mkpath(install_index_dir)
63-
64-
if os.path.exists(install_index_path):
65-
os.remove(install_index_path)
66-
if not os.path.exists(install_index_path):
67-
os.symlink(build_index_path, install_index_path)
685

696

707
setup(
@@ -93,7 +30,4 @@ def run(self):
9330
package_data={
9431
'ament_build_type_gradle': ['template/environment_hook/*.in']
9532
},
96-
cmdclass={
97-
'develop': ament_gradle_develop,
98-
'install': ament_gradle_install,
99-
}, )
33+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(ament_java_resources NONE)
4+
5+
find_package(ament_cmake REQUIRED)
6+
7+
ament_index_register_resource(
8+
"templates"
9+
CONTENT_FILE "classpath.sh.template"
10+
PACKAGE_NAME "ament_build_type_gradle_classpath_sh")
11+
12+
ament_index_register_resource(
13+
"templates"
14+
CONTENT_FILE "classpath.bat.template"
15+
PACKAGE_NAME "ament_build_type_gradle_classpath_bat")
16+
17+
ament_package()

ament_build_type_gradle/ament_build_type_gradle/template/environment_hook/classpath.bat.in renamed to ament_java_resources/classpath.bat.template

File renamed without changes.

ament_build_type_gradle/ament_build_type_gradle/template/environment_hook/classpath.sh.in renamed to ament_java_resources/classpath.sh.template

File renamed without changes.

ament_java_resources/package.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="2">
4+
<name>ament_java_resources</name>
5+
<version>0.0.0</version>
6+
<description>
7+
Register ament_java resources in the Ament index.
8+
</description>
9+
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
10+
<license>Apache License 2.0</license>
11+
12+
<buildtool_depend>ament_cmake</buildtool_depend>
13+
14+
<buildtool_export_depend>ament_cmake</buildtool_export_depend>
15+
16+
<test_depend>ament_lint_auto</test_depend>
17+
<test_depend>ament_lint_common</test_depend>
18+
19+
<export>
20+
<build_type>ament_cmake</build_type>
21+
</export>
22+
</package>

0 commit comments

Comments
 (0)