Skip to content
Snippets Groups Projects
Commit 25e92b67 authored by Damon Kohler's avatar Damon Kohler
Browse files

Refactoring the Python code in rosjava_bootstrap.

New tests are passing, but rosjava does not build due to a missing dependency on rosjava_bootstrap.
parent 7bf3f28a
Branches
Tags
No related merge requests found
Showing
with 937 additions and 16 deletions
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/rosjava_bootstrap/src/main/python</path>
</pydev_pathproperty>
</pydev_project>
......@@ -9,13 +9,13 @@ all: obtain-dependencies ant-properties eclipse-project eclipse-classpath msg-de
PACKAGE_NAME=$(shell basename $(PWD))
obtain-dependencies:
rosrun rosjava_bootstrap generate_properties.py --dependencies $(PACKAGE_NAME) > dependencies.xml
rosrun rosjava_bootstrap generate_dependencies_xml.py $(PACKAGE_NAME) > dependencies.xml
ant-properties:
rosrun rosjava_bootstrap generate_properties.py $(PACKAGE_NAME) > ros.properties
rosrun rosjava_bootstrap generate_ros_properties.py $(PACKAGE_NAME) > ros.properties
eclipse-classpath:
if [ ! -f .classpath ] ; then rosrun rosjava_bootstrap generate_properties.py --eclipse $(PACKAGE_NAME) > .classpath ; touch .classpath-generated; fi
if [ ! -f .classpath ] ; then rosrun rosjava_bootstrap generate_eclipse_project.py $(PACKAGE_NAME) > .classpath ; touch .classpath-generated; fi
eclipse-project:
if [ ! -f .project ] ; then sed s/PROJECT_NAME/$(PACKAGE_NAME)/ `rospack find rosjava_bootstrap`/eclipse/eclipse-project-template > .project ; touch .project-generated; fi
......
......@@ -47,7 +47,9 @@
<target name="gen-msg" depends="check-gen-msg-skip" unless="gen-msg.skip">
<mkdir dir="${gen-msg}" />
<exec executable="${ros.bootstrap.scripts.dir}/java_msgs.py">
<exec executable="rosrun">
<arg value="rosjava_bootstrap" />
<arg value="java_msgs.py" />
<arg value="-o ${gen-msg}" />
<arg value="${ros.package}" />
</exec>
......@@ -59,7 +61,9 @@
<target name="gen-srv" depends="check-gen-srv-skip" unless="gen-srv.skip">
<mkdir dir="${gen-srv}" />
<exec executable="${ros.bootstrap.scripts.dir}/java_srvs.py">
<exec executable="rosrun">
<arg value="rosjava_bootstrap" />
<arg value="java_srvs.py" />
<arg value="-o ${gen-srv}" />
<arg value="${ros.package}" />
</exec>
......
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2011, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import roslib
import which
class AndroidError(Exception):
pass
def is_android_library(package):
m = roslib.manifest.load_manifest(package)
return 'rosjava-android-lib' in [x.tag for x in m.exports]
def is_android_app(package):
m = roslib.manifest.load_manifest(package)
return 'rosjava-android-app' in [x.tag for x in m.exports]
def is_android_package(package):
return is_android_app(package) or is_android_library(package)
def get_android_library_paths(package):
m = roslib.manifest.load_manifest(package)
return [x.attrs.get('path', '.') for x in m.exports if x.tag == 'rosjava-android-lib']
def get_android_sdk_dir():
"""
@return: location of Android SDK
@raise UserError: if android is not installed
"""
location = which.which('android')
if not location:
raise AndroidError('The android tool is not in your command path. '
'Install the Android SDK and add the tools directory to your path.')
# SDK dir is two levels up in the path.
return os.path.dirname(os.path.dirname(location))
#!/usr/bin/python
# Copyright (C) 2011 Google Inc.
#
# 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.
__author__ = 'damonkohler@google.com (Damon Kohler)'
import os
import unittest
import roslib
class BaseTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
package_directory = roslib.packages.get_pkg_dir('rosjava_bootstrap')
resources_directory = os.path.join(
package_directory, 'src', 'main', 'resources')
os.environ['ROS_PACKAGE_PATH'] = (
resources_directory + os.path.pathsep + os.environ['ROS_PACKAGE_PATH'])
BaseTestCase._resources_directory = resources_directory
def get_resources_directory(self):
return BaseTestCase._resources_directory
\ No newline at end of file
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2011, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
from generate_msg_depends import msg_jar_file_path, is_msg_pkg, is_srv_pkg
import maven
def _resolve_path_elements(path_elements):
# TODO: Potentially recognize keys like ROS_HOME
return [os.path.abspath(package) for package in path_elements]
def _get_specified_classpath(rospack, package, include_package, scope):
"""
@param include_package: include library entries of self on path
@param scope: 'compile', 'runtime', 'test', or 'all'. These classpath
types are generated based on the scope of an export. Exports have a
default scope of 'compile', which means they are part of all types of
classpaths. For an exact mapping, see SCOPE_MAP. The behavior of these
scopes/classpath_types matches the Maven definition:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
Only gets the parts of the classpath which are not loaded by Maven.
Returns list of dependencies.
"""
path_elements = []
def export_operator(pkg, pkg_dir, e):
# If is a Maven artifact, create the entire name. Otherwise location
# has all.
if 'location' in e.attrs:
location = e.attrs['location']
if 'groupId' in e.attrs:
fullname = maven.get_full_maven_name(e)
path_elements.append(os.path.join(pkg_dir, location, fullname))
else:
path_elements.append(os.path.join(pkg_dir, location))
def package_operator(pkg):
if is_msg_pkg(pkg) or is_srv_pkg(pkg):
path_elements.append(msg_jar_file_path(pkg))
maven.walk_export_path(rospack, package, export_operator, package_operator, include_package, scope)
return _resolve_path_elements(path_elements)
def get_classpath(rospack, package, maven_depmap, include_package=False, scope='all'):
"""
@param include_package: include library entries of self on path
@param maven_depmap: A map of lists for maven dependencies by scope.
@param classpath_type: (optional, default 'all'). 'compile',
'runtime', 'test', or 'all'. These classpath types are generated
based on the scope of an export. Exports have a default scope of
'compile', which means they are part of all types of classpaths.
For an exact mapping, see SCOPE_MAP. The behavior of these
scopes/classpath_types matches the Maven definition:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
Only gets the parts of the classpath which are not loaded by Maven.
Returns list of dependencies.
"""
paths = _get_specified_classpath(rospack, package, include_package, scope)
paths.extend(maven_depmap[scope])
return os.pathsep.join(paths)
#!/usr/bin/python
# Copyright (C) 2011 Google Inc.
#
# 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.
__author__ = 'damonkohler@google.com (Damon Kohler)'
import os
import sys
import maven
def usage():
print "generate_dependencies_xml.py <package-name>"
sys.exit(os.EX_USAGE)
def main(argv):
if len(argv) != 2:
usage()
package = argv[1]
maven.generate_ant_maven_dependencies(package)
if __name__ == '__main__':
main(sys.argv)
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2011, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import android
import classpath
import maven
import roslib
# XML tag for the rosjava manifest tag for path elements.
TAG_ROSJAVA_PATHELEMENT = 'rosjava-pathelement'
# XML tag for the rosjava manifest tag for source elements.
TAG_ROSJAVA_SRC = 'rosjava-src'
def usage():
print "generate_eclipse_project.py <package-name>"
sys.exit(os.EX_USAGE)
def _get_source_paths(rospack, package):
"""
@return: list of source paths. Source paths will be returned in the
relative specification used in the ros manifest.xml file.
@rtype: [str]
"""
rospack.load_manifests([package])
m = rospack.manifests[package]
return [x.attrs['location'] for x in m.exports if x.tag == TAG_ROSJAVA_SRC]
def generate_classpath_file(rospack, package, maven_depmap, stream=sys.stdout):
print >>stream, '<?xml version="1.0" encoding="UTF-8"?>\n<classpath>'
# TODO(damonkohler): Move Eclipse .project file generation into this
# script as well so that we can alter it for use with Android.
if android.is_android_package(package):
print >>stream, ('\t<classpathentry kind="con" '
'path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>')
for p in filter(None, _get_source_paths(rospack, package)):
print >>stream, '\t<classpathentry kind="src" path="%s"/>' % (p)
print >>stream, '\t<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>'
print >>stream, '\t<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>'
for p in filter(None, classpath.get_classpath(
rospack, package, maven_depmap, include_package=True, scope='all').split(':')):
print >>stream, '\t<classpathentry kind="lib" path="%s"/>' % (p)
print >>stream, '\t<classpathentry kind="output" path="build"/>\n</classpath>'
def main(argv):
if len(argv) != 2:
usage()
package = argv[1]
rospack = roslib.packages.ROSPackages()
maven_depmap = maven.get_maven_dependencies(package, 'dependencies.xml')
generate_classpath_file(rospack, package, maven_depmap)
if __name__ == '__main__':
try:
main(sys.argv)
except roslib.packages.InvalidROSPkgException as e:
sys.stderr.write('ERROR: '+str(e)+'\n')
sys.exit(1)
......@@ -33,17 +33,16 @@
import os
import sys
import shutil
import subprocess
import roslib.rosenv
import roslib.packages
import roslib.stacks
import roslib
def usage():
print "generate_msg_depends.py <package-name>"
sys.exit(os.EX_USAGE)
BOOTSTRAP_PKG = 'rosjava_bootstrap'
_ros_home = roslib.rosenv.get_ros_home()
......@@ -187,8 +186,6 @@ def _generate_msgs(rospack, package, up_to_date):
classpath = classpath.replace(':', '\:')
artifact_built = msg_jar_file_path(package)
print "Hi there %s" % artifact_built
# Map for all properties
properties = {'ros.package': package,
'ros.artifact.built': artifact_built,
......
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2011, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import classpath
import maven
import roslib
def usage():
print 'generate_properties.py <package-name>'
sys.exit(os.EX_USAGE)
_stack_of_cache = {}
_stack_version_cache = {}
def get_package_version(package, stack_of_cache=None, stack_version_cache=None):
if stack_of_cache is None:
stack_of_cache = _stack_of_cache
if stack_version_cache is None:
stack_version_cache = _stack_version_cache
stack_of_cache[package] = stack = stack_of_cache.get(package) or roslib.stacks.stack_of(package)
stack_version_cache[stack] = version = (
stack_version_cache.get(stack) or
roslib.stacks.get_stack_version(stack)) #@UndefinedVariable
return version
def generate_properties(package, maven_depmap):
rospack = roslib.packages.ROSPackages()
depends = rospack.depends([package])[package]
properties = {'ros.home': roslib.rosenv.get_ros_home()}
# Add directory properties for every package we depend on.
for package in depends:
package_directory = roslib.packages.get_pkg_dir(package)
properties['ros.pkg.%s.dir' % (package)] = package_directory
if hasattr(roslib.stacks, 'get_stack_version'):
properties['ros.pkg.%s.version' % (package)] = get_package_version(package)
built_artifact = maven.get_package_build_artifact(rospack, package)
if built_artifact:
properties['ros.artifact.built'] = built_artifact
properties['ros.classpath'] = classpath.get_classpath(
rospack, package, maven_depmap, scope='all')
properties['ros.compile.classpath'] = classpath.get_classpath(
rospack, package, maven_depmap, scope='compile')
properties['ros.runtime.classpath'] = classpath.get_classpath(
rospack, package, maven_depmap, scope='runtime')
properties['ros.test.classpath'] = classpath.get_classpath(
rospack, package, maven_depmap, scope='test')
# Re-encode for ant <fileset includes="${ros.jarfileset}">. uses comma separator instead.
for prop in ['ros', 'ros.compile', 'ros.runtime', 'ros.test']:
properties[prop + '.jarfileset'] = properties[prop + '.classpath'].replace(':', ',')
properties['ros.test_results'] = os.path.join(roslib.rosenv.get_test_results_dir(), package)
return properties
def print_sorted_properties(properties, stream=sys.stdout):
for key in sorted(properties):
print >>stream, '%s=%s' % (key, properties[key])
def main(argv):
if len(argv) != 2:
usage()
package = argv[1]
maven_depmap = maven.get_maven_dependencies(package, 'dependencies.xml')
properties = generate_properties(package, maven_depmap)
print_sorted_properties(properties)
if __name__ == '__main__':
try:
main(sys.argv)
except roslib.packages.InvalidROSPkgException as e:
print >>sys.stderr, 'ERROR: %s' % str(e)
sys.exit(1)
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2011, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import subprocess
import sys
import tempfile
import roslib
# See http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
SCOPE_MAP = {
'compile': ['compile', 'runtime', 'test', 'all'],
'runtime': ['runtime', 'test', 'all'],
'test': ['test', 'all'],
}
DEFAULT_SCOPE = 'compile'
DEPENDENCY_FILE_PROPERTY = 'dependency.file'
DEPENDENCY_GENERATION_TARGET = 'get-dependencies'
# XML tag for the rosjava manifest tag for path elements.
TAG_ROSJAVA_PATHELEMENT = 'rosjava-pathelement'
BOOTSTRAP_PKG = 'rosjava_bootstrap'
BOOTSTRAP_PKG_DIR = roslib.packages.get_pkg_dir(BOOTSTRAP_PKG)
BOOTSTRAP_SCRIPTS_DIR = os.path.join(BOOTSTRAP_PKG_DIR, 'scripts')
def walk_export_path(rospack, package, export_operator, package_operator, include_package=False, scope='all'):
"""
Walk the entire set of dependencies for a package. Run the supplied
lambda expressions on each export and each package.
Export lambdas for a given package are all run before the package lambda.
"""
depends = rospack.depends([package])[package]
if include_package:
depends.append(package)
for pkg in depends:
m = rospack.manifests[pkg]
pkg_dir = roslib.packages.get_pkg_dir(pkg)
for e in [x for x in m.exports if x.tag == TAG_ROSJAVA_PATHELEMENT]:
# Don't include this package's built resources.
if include_package and pkg == package and e.attrs.get('built', False):
continue
entry_scope = e.attrs.get('scope', DEFAULT_SCOPE)
if scope in SCOPE_MAP[entry_scope]:
export_operator(pkg, pkg_dir, e)
if package_operator:
package_operator(pkg)
def get_package_build_artifact(rospack, package):
"""
Get what a given package builds.
Returns None if didn't generate a Java artifact.
"""
rospack.load_manifests([package])
manifest = rospack.manifests[package]
for e in [x for x in manifest.exports if x.tag == TAG_ROSJAVA_PATHELEMENT]:
if e.attrs.get('built', False):
if 'groupId' in e.attrs:
full_filename = get_full_maven_name(e)
# NOTE(damonkohler): If the rosjava-pathelement refers to
# something that is built, then it must have a location
# defined.
location = e.attrs['location']
# TODO(keith): Should always place in Maven repository.
return os.path.join(location, full_filename)
return e.attrs['location']
def get_full_maven_name(e):
"""
Creates an entire Maven filename from an XML element containing
groupId, artifactId, and version.
"""
return '%s-%s.jar' % (e.attrs['artifactId'], e.attrs['version'])
def get_maven_dependencies(package, dependency_filename):
"""
Run the dependency ant file and get all dependencies. Returns as a
dictionary of lists keyed by scope.
"""
full_dependency_filename = os.path.join(roslib.packages.get_pkg_dir(package),
dependency_filename)
# Get a temp file but doesn't need to stay open
fd, name = tempfile.mkstemp()
command = ['ant', '-f', full_dependency_filename,
'-logger', 'org.apache.tools.ant.NoBannerLogger',
'-D%s=%s'%(DEPENDENCY_FILE_PROPERTY, name),
DEPENDENCY_GENERATION_TARGET]
fnull = open(os.devnull)
subprocess.check_call(command, stdout=fnull, stderr=fnull)
fnull.close()
f = os.fdopen(fd, "r")
dependencies = f.read()
f.close()
os.remove(name)
depmap = {}
for line in dependencies.split():
pair = line.split('::::')
if pair[0] not in depmap:
depmap[pair[0]] = []
depmap[pair[0]].append(pair[1])
for scope in ['compile', 'runtime', 'test']:
depmap[scope] = depmap.get(scope, list())
depmap['all'] = depmap['test']
return depmap
def write_maven_dependencies_group(f, rospack, package, scope):
"""Write out a maven <dependencies> element in the file for the given scope"""
f.write(' <artifact:dependencies filesetId="dependency.fileset.%s">' %
scope)
f.write('<artifact:remoteRepository id="org.ros.release" url="http://robotbrains.hideho.org/nexus/content/groups/ros-public" />\n')
def export_operator(pkg, pkg_dir, e):
# TODO(khughes): Nuke location once in Maven repository
if 'groupId' in e.attrs and not 'location' in e.attrs:
f.write("""
<artifact:dependency groupId="%s" artifactId="%s" version="%s" />
"""%(
e.attrs['groupId'], e.attrs['artifactId'],
e.attrs['version']
))
walk_export_path(rospack, package,
export_operator, None,
True, scope)
f.write(" </artifact:dependencies>\n")
def generate_ant_maven_dependencies(package):
"""
Generate an Ant file which will get all dependencies needed via a Maven
repository and provide both a classpath for ant builds and a file of
dependencies to be consumed by this script.
ant -f file -Ddependency.file=fname get-dependencies
will create a file fname with 1 line per dependency. This file is appended
to so should be empty every time.
The fileset id dependency.fileset is available for such things as classpaths
for a build.
"""
rospack = roslib.packages.ROSPackages()
sys.stdout.write("""<?xml version="1.0"?>
<project name="dependencies" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant"
xmlns:ac="antlib:net.sf.antcontrib"
>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<path id="maven-ant-tasks.classpath" path="%s/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
<typedef resource="net/sf/antcontrib/antlib.xml"
uri="antlib:net.sf.antcontrib"
classpath="%s/ant-contrib-1.0b3.jar"/>
"""% (BOOTSTRAP_SCRIPTS_DIR, BOOTSTRAP_SCRIPTS_DIR))
sys.stdout.write(""" <artifact:dependencies filesetId="dependency.osgi">
<artifact:remoteRepository id="org.ros.release" url="http://robotbrains.hideho.org/nexus/content/groups/ros-public" />
<artifact:dependency groupId="biz.aQute" artifactId="bnd" version="0.0.384" />
</artifact:dependencies>
<path id="classpath.osgi">
<fileset refid="dependency.osgi" />
</path>
<taskdef resource="aQute/bnd/ant/taskdef.properties" classpathref="classpath.osgi" />
""")
write_maven_dependencies_group(sys.stdout, rospack, package, 'compile')
write_maven_dependencies_group(sys.stdout, rospack, package, 'test')
write_maven_dependencies_group(sys.stdout, rospack, package, 'runtime')
sys.stdout.write("""
<target name="%s">
<ac:for param="file">
<path>
<fileset refid="dependency.fileset.compile"/>
</path>
<sequential>
<echo file="${%s}" append="true">compile::::@{file}
</echo>
</sequential>
</ac:for>
<ac:for param="file">
<path>
<fileset refid="dependency.fileset.runtime"/>
</path>
<sequential>
<echo file="${%s}" append="true">runtime::::@{file}
</echo>
</sequential>
</ac:for>
<ac:for param="file">
<path>
<fileset refid="dependency.fileset.test"/>
</path>
<sequential>
<echo file="${%s}" append="true">test::::@{file}
</echo>
</sequential>
</ac:for>
</target>
</project>
"""%(DEPENDENCY_GENERATION_TARGET,
DEPENDENCY_FILE_PROPERTY, DEPENDENCY_FILE_PROPERTY,
DEPENDENCY_FILE_PROPERTY))
#!/usr/bin/python
# Copyright (C) 2011 Google Inc.
#
# 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.
__author__ = 'damonkohler@google.com (Damon Kohler)'
import os
import base_test_case
import classpath
import roslib
SAMPLE_PACKAGE = 'sample_package'
class TestClasspath(base_test_case.BaseTestCase):
def test_get_specified_classpath(self):
rospack = roslib.packages.ROSPackages()
path = classpath._get_specified_classpath(rospack, SAMPLE_PACKAGE, False, 'all')
self.assertEqual(2, len(path))
basenames = [os.path.basename(x) for x in path]
self.assertTrue('com.domain.sample_dependency.with_location-0.0.0.jar' in basenames)
self.assertTrue('com.domain.sample_dependency.built_with_location-0.0.0.jar' in basenames)
path = classpath._get_specified_classpath(rospack, SAMPLE_PACKAGE, True, 'all')
self.assertEqual(3, len(path))
basenames = [os.path.basename(x) for x in path]
self.assertTrue('com.domain.sample_dependency.with_location-0.0.0.jar' in basenames)
self.assertTrue('com.domain.sample_dependency.built_with_location-0.0.0.jar' in basenames)
self.assertTrue('com.domain.sample.with_location-0.0.0.jar' in basenames)
def test_get_classpath(self):
rospack = roslib.packages.ROSPackages()
path = classpath.get_classpath(rospack, SAMPLE_PACKAGE, {'all': []})
jars = [os.path.basename(x) for x in path.split(':')]
self.assertEquals([
'com.domain.sample_dependency.with_location-0.0.0.jar',
'com.domain.sample_dependency.built_with_location-0.0.0.jar'], jars)
\ No newline at end of file
#!/usr/bin/python
# Copyright (C) 2011 Google Inc.
#
# 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.
__author__ = 'damonkohler@google.com (Damon Kohler)'
import base_test_case
import generate_eclipse_project
import roslib
import StringIO
SAMPLE_PACKAGE = 'sample_package'
class TestGenerateEclipseProject(base_test_case.BaseTestCase):
def test_get_source_paths(self):
rospack = roslib.packages.ROSPackages()
paths = generate_eclipse_project._get_source_paths(rospack, SAMPLE_PACKAGE)
self.assertEqual(['src/main/java'], paths)
def test_generate_classpath_file(self):
rospack = roslib.packages.ROSPackages()
stream = StringIO.StringIO()
generate_eclipse_project.generate_classpath_file(
rospack, SAMPLE_PACKAGE, {'all': []}, stream)
# TODO(damonkohler): Actually test the content of the generated classpath file.
self.assertTrue(stream.getvalue())
\ No newline at end of file
#!/usr/bin/python
# Copyright (C) 2011 Google Inc.
#
# 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.
__author__ = 'damonkohler@google.com (Damon Kohler)'
import os
import base_test_case
import generate_ros_properties
import StringIO
SAMPLE_PACKAGE = 'sample_package'
class TestGenerateRosProperties(base_test_case.BaseTestCase):
def test_get_package_version(self):
self.assertEqual(42, generate_ros_properties.get_package_version(
'package', {'package': 'stack'}, {'stack': 42}))
def test_print_sorted_properties(self):
stream = StringIO.StringIO()
generate_ros_properties.print_sorted_properties({'foo': 3, 'bar': 1, 'baz': 2}, stream)
self.assertEqual('bar=1\nbaz=2\nfoo=3\n', stream.getvalue())
def test_generate_properties(self):
properties = generate_ros_properties.generate_properties(
SAMPLE_PACKAGE, {'all': [], 'compile': [], 'runtime': [], 'test': []})
self.assertEqual('target/com.domain.sample_dependency.built_with_location-0.0.0.jar',
properties['ros.artifact.built'])
expected = os.path.join(self.get_resources_directory(), 'sample_stack',
'sample_package_dependency')
self.assertEqual(expected, properties['ros.pkg.sample_package_dependency.dir'])
\ No newline at end of file
#!/usr/bin/python
# Copyright (C) 2011 Google Inc.
#
# 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.
__author__ = 'damonkohler@google.com (Damon Kohler)'
import base_test_case
import maven
import roslib
SAMPLE_PACKAGE = 'sample_package'
SAMPLE_PACKAGE_DEPENDENCY = 'sample_package_dependency'
class TestMaven(base_test_case.BaseTestCase):
def test_walk_export_path(self):
rospack = roslib.packages.ROSPackages()
def export_operator(package, package_directory, export):
pass
def package_operator(package):
pass
maven.walk_export_path(rospack, SAMPLE_PACKAGE, export_operator, package_operator)
def test_get_package_build_artifact(self):
rospack = roslib.packages.ROSPackages()
artifact = maven.get_package_build_artifact(rospack, SAMPLE_PACKAGE)
self.assertEqual('target/com.domain.sample.built_with_location-0.0.0.jar', artifact)
artifact = maven.get_package_build_artifact(rospack, SAMPLE_PACKAGE_DEPENDENCY)
self.assertEqual('target/com.domain.sample_dependency.built_with_location-0.0.0.jar', artifact)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment