diff --git a/scripts/catkin_create_android_pkg b/scripts/catkin_create_android_pkg index 5356e282627640a4763a28a5ddb7d0550b763de7..eb1604bbcf83a92abafa93b7e289e5747715814a 100755 --- a/scripts/catkin_create_android_pkg +++ b/scripts/catkin_create_android_pkg @@ -20,7 +20,7 @@ import rosjava_build_tools.console as console if __name__ == "__main__": try: - sys.exit(init_android_repo()) + sys.exit(init_android_package()) except Exception as e: console.logerror("%s : %s" % (str(e), type(e))) sys.exit(1) diff --git a/scripts/catkin_create_rosjava_msg_project b/scripts/catkin_create_rosjava_msg_project new file mode 100755 index 0000000000000000000000000000000000000000..afedb840c9ff6c0d9a1b6ef2ba31c20b9046ee43 --- /dev/null +++ b/scripts/catkin_create_rosjava_msg_project @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +"""This script creates the skeleton of an android library package""" + +############################################################################## +# Imports +############################################################################## + +from __future__ import print_function +import argparse +import os +import sys + +from rosjava_build_tools import create_rosjava_msg_project +import rosjava_build_tools.console as console + +############################################################################## +# Main +############################################################################## + +if __name__ == "__main__": + try: + sys.exit(create_rosjava_msg_project()) + except Exception as e: + console.logerror("%s : %s" % (str(e), type(e))) + sys.exit(1) diff --git a/scripts/catkin_create_rosjava_pkg b/scripts/catkin_create_rosjava_pkg new file mode 100755 index 0000000000000000000000000000000000000000..b21eb85e282c42682d2785177897b461bef858e9 --- /dev/null +++ b/scripts/catkin_create_rosjava_pkg @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +"""This script creates the skeleton of an rosjava repo""" + +############################################################################## +# Imports +############################################################################## + +from __future__ import print_function +import argparse +import os +import sys + +from rosjava_build_tools import init_rosjava_package +import rosjava_build_tools.console as console + +############################################################################## +# Main +############################################################################## + +if __name__ == "__main__": + try: + sys.exit(init_rosjava_package()) + except Exception as e: + console.logerror("%s : %s" % (str(e), type(e))) + sys.exit(1) diff --git a/scripts/catkin_create_rosjava_project b/scripts/catkin_create_rosjava_project new file mode 100755 index 0000000000000000000000000000000000000000..9a2a34660f9000acffd19325dc986adf94307ad6 --- /dev/null +++ b/scripts/catkin_create_rosjava_project @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +"""This script creates the skeleton of an android library package""" + +############################################################################## +# Imports +############################################################################## + +from __future__ import print_function +import argparse +import os +import sys + +from rosjava_build_tools import create_rosjava_project +import rosjava_build_tools.console as console + +############################################################################## +# Main +############################################################################## + +if __name__ == "__main__": + try: + sys.exit(create_rosjava_project()) + except Exception as e: + console.logerror("%s : %s" % (str(e), type(e))) + sys.exit(1) diff --git a/setup.py b/setup.py index f7c844c4ed43b0006c1c76ab5791bc450b619640..86a08f68bcf1cbc08996027ce409b23e6ff3a11f 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,9 @@ d = generate_distutils_setup( scripts=['scripts/catkin_create_android_pkg', 'scripts/catkin_create_android_project', 'scripts/catkin_create_android_library_project', + 'scripts/catkin_create_rosjava_pkg', + 'scripts/catkin_create_rosjava_project', + 'scripts/catkin_create_rosjava_msg_project', ], package_data = {'rosjava_build_tools': [ 'templates/android_package/*', diff --git a/src/rosjava_build_tools/__init__.py b/src/rosjava_build_tools/__init__.py index f13fffbad5a9dfa6ae5cdcdbf51afd4261544486..cabbaa26a6a79f2c9b0bf4caea8323459ed7aead 100644 --- a/src/rosjava_build_tools/__init__.py +++ b/src/rosjava_build_tools/__init__.py @@ -9,7 +9,8 @@ ############################################################################## import console -from create_package import init_android_repo -from create_project import create_android_project +from create_package import init_android_package, init_rosjava_package +from create_android_project import create_android_project +from create_rosjava_project import create_rosjava_project, create_rosjava_msg_project from utils import which from release import scrape_for_release_message_packages diff --git a/src/rosjava_build_tools/create_project.py b/src/rosjava_build_tools/create_android_project.py similarity index 100% rename from src/rosjava_build_tools/create_project.py rename to src/rosjava_build_tools/create_android_project.py diff --git a/src/rosjava_build_tools/create_package.py b/src/rosjava_build_tools/create_package.py index 1db93152da048b8ced737d52fc0bfec8f4cfde74..a93a34a29629813a3bd603e0bfe7f756d629ed16 100644 --- a/src/rosjava_build_tools/create_package.py +++ b/src/rosjava_build_tools/create_package.py @@ -27,7 +27,7 @@ import console def parse_arguments(): argv = sys.argv[1:] parser = argparse.ArgumentParser( - description='Creates a new android repository based on catkin and gradle. \n\nNote that the path you provide will become the maven group for your repo.\n') + description='Creates a new rosjava/android repository based on catkin and gradle. \n\nNote that the path you provide will become the maven group for your repo.\n') parser.add_argument('path', nargs='?', default=os.getcwd(), help='path to the repository you wish to create (must not exist beforehand).') parser.add_argument('dependencies', nargs='*', @@ -78,8 +78,8 @@ def instantiate_template(template, repo_name, author): return template % locals() -def get_templates(): - template_dir = os.path.join(os.path.dirname(__file__), 'templates', 'init_repo') +def get_templates(template_directory): + template_dir = os.path.join(os.path.dirname(__file__), 'templates', template_directory) templates = {} templates['CMakeLists.txt'] = read_template(os.path.join(template_dir, 'CMakeLists.txt.in')) templates['build.gradle'] = read_template(os.path.join(template_dir, 'build.gradle.in')) @@ -87,10 +87,10 @@ def get_templates(): return templates -def populate_repo(repo_path): +def populate_repo(repo_path, package_type): author = utils.author_name() repo_name = os.path.basename(repo_path) - templates = get_templates() + templates = get_templates(package_type) for filename, template in templates.iteritems(): contents = instantiate_template(template, repo_name, author) try: @@ -154,13 +154,21 @@ def create_catkin_package_files(package_name, package_path, args): ############################################################################## -def init_android_repo(): +def init_package(package_type): args = parse_arguments() try: repo_path = utils.validate_path(args.path) repo_name = os.path.basename(os.path.normpath(repo_path)).lower() - populate_repo(repo_path) + populate_repo(repo_path, package_type) create_catkin_package_files(repo_name, repo_path, args) create_gradle_wrapper(repo_path) except Exception: raise + + +def init_rosjava_package(): + init_package('rosjava_package') + + +def init_android_package(): + init_package('android_package') diff --git a/src/rosjava_build_tools/create_rosjava_project.py b/src/rosjava_build_tools/create_rosjava_project.py new file mode 100644 index 0000000000000000000000000000000000000000..0a0abd3d64acd07b4bc4d298f3643f5dca381f47 --- /dev/null +++ b/src/rosjava_build_tools/create_rosjava_project.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python +# +# License: Apache 2.0 +# https://raw.github.com/rosjava/rosjava_build_tools/license/LICENSE +# + +############################################################################## +# Imports +############################################################################## + +from __future__ import print_function + +import os +import sys +import argparse +import xml.etree.ElementTree as ElementTree + +# local imports +import utils +import console + +############################################################################## +# Methods +############################################################################## + + +def parse_arguments(): + argv = sys.argv[1:] + parser = argparse.ArgumentParser( + description='Creates a new rosjava package based on catkin and gradle. \n') + parser.add_argument('name', + nargs=1, + help='The name for the package') + parser.add_argument('-a', '--author', + action='store', + default=utils.author_name(), + help='A single author, may be used multiple times') + args = parser.parse_args(argv) + return args + + +############################################################################## +# Methods acting on classes +############################################################################## + + +# This inserts the labelled variables into the template wherever the corresponding +# %package, %brief, %description and %depends is found. +def instantiate_template(template, project_name, author): + return template % locals() + + +def create_gradle_package_files(args, template_directory): + ''' + This is almost a direct copy from catkin_create_pkg. + ''' + try: + project_name = args.name[0].lower() + package_path = os.path.abspath(os.path.join(os.getcwd(), project_name)) + for template_name in ['build.gradle']: # 'CMakeLists.txt']: + filename = os.path.join(package_path, template_name) + template = utils.read_template_file(template_directory, template_name) + contents = instantiate_template(template, project_name, args.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): + ''' + Adds project name to the root level settings.gradle file. + ''' + for rel_path in ['.', '..']: + settings_gradle_path = os.path.join(os.getcwd(), rel_path, 'settings.gradle') + if os.path.isfile(settings_gradle_path): + break + else: + settings_gradle_path = None + if settings_gradle_path is None: + console.pretty_println("\nCouldn't find the root level settings.gradle file - not adding to the superproject.") + return + with open(settings_gradle_path, 'a') as settings_gradle: + console.pretty_print(' File : ', console.cyan) + console.pretty_println('settings.gradle', console.yellow) + settings_gradle.write("include '%s'\n" % name) + + +def add_catkin_generate_tree_command(): + for rel_path in ['.', '..']: + build_gradle_path = os.path.join(os.getcwd(), rel_path, 'build.gradle') + if os.path.isfile(build_gradle_path): + break + else: + build_gradle_path = None + if build_gradle_path is None: + console.pretty_println("\nCouldn't find the root level build.gradle file - not adding to the superproject.") + return + with open(build_gradle_path, 'r') as build_gradle: + console.pretty_print(' File : ', console.cyan) + console.pretty_println('build.gradle (catkin_generate_tree update)', console.yellow) + new_contents = build_gradle.read().replace("apply plugin: 'catkin'", "apply plugin: 'catkin'\nproject.catkin.tree.generate()\n") + with open(build_gradle_path, 'w') as build_gradle: + build_gradle.write(new_contents) + + +def add_to_package_xml(name): + ''' + Adds project name to build_depends in package.xml (should be same name as the ros msg package name). + ''' + for rel_path in ['.', '..']: + package_xml_path = os.path.join(os.getcwd(), rel_path, 'package.xml') + if os.path.isfile(package_xml_path): + break + else: + package_xml_path = None + if package_xml_path is None: + console.pretty_println("\nCouldn't find the root level package.xml file - not adding to the superproject.") + return + with open(package_xml_path, 'r') as package_xml: + console.pretty_print(' File : ', console.cyan) + console.pretty_println('package.xml (dependency update)', console.yellow) + new_contents = package_xml.read().replace("</package>", "<build_depend>%s</build_depend>\n</package>" % name) + with open(package_xml_path, 'w') as package_xml: + package_xml.write(new_contents) + + +def create_dummy_java_class(project_name): + path = os.path.join(os.getcwd(), project_name.lower()) + java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', 'rosjava', project_name) + utils.mkdir_p(java_package_path) + filename = os.path.join(java_package_path, 'Dude.java') + java_class = "package com.github.rosjava.%s.Dude;\n" % project_name + java_class += "\n" + java_class += "public class Dude {\n" + java_class += "}\n" + console.pretty_print(' File : ', console.cyan) + console.pretty_println('Dude.class', console.yellow) + with open(filename, 'w') as dude_class: + dude_class.write(java_class) + + +def ros_package_name(): + for rel_path in ['.', '..']: + package_xml_path = os.path.join(os.getcwd(), rel_path, 'package.xml') + if os.path.isfile(package_xml_path): + break + else: + package_xml_path = None + if package_xml_path is None: + console.pretty_println("\nCouldn't find the root level package.xml file - not adding to the superproject.") + return + tree = ElementTree.parse(package_xml_path) + root = tree.getroot() + name = root.find('name').text + return name + + +def create_rosjava_project_common(args, template_directory): + project_name = args.name[0] + console.pretty_println("\nCreating rosjava project ", console.bold) + console.pretty_print(" Name : ", console.cyan) + console.pretty_println("%s" % project_name, console.yellow) + utils.mkdir_p(os.path.join(os.getcwd(), project_name.lower())) + # This is in the old form, let's shovel the shit around to the new form + create_gradle_package_files(args, template_directory) + add_to_root_gradle_settings(args.name[0]) + + +def create_rosjava_project(): + args = parse_arguments() + create_rosjava_project_common(args, 'rosjava_project') + create_dummy_java_class(args.name[0]) + + +def create_rosjava_msg_project(): + args = parse_arguments() + create_rosjava_project_common(args, 'rosjava_msg_project') + add_catkin_generate_tree_command() + add_to_package_xml(args.name[0]) diff --git a/src/rosjava_build_tools/templates/init_repo/CMakeLists.txt.in b/src/rosjava_build_tools/templates/android_package/CMakeLists.txt.in similarity index 50% rename from src/rosjava_build_tools/templates/init_repo/CMakeLists.txt.in rename to src/rosjava_build_tools/templates/android_package/CMakeLists.txt.in index b71f2fbe1f88ec7ec70cf788268373c027d8893c..46f3c06b34be0ff13066820851c4b13267832cd2 100644 --- a/src/rosjava_build_tools/templates/init_repo/CMakeLists.txt.in +++ b/src/rosjava_build_tools/templates/android_package/CMakeLists.txt.in @@ -13,3 +13,14 @@ find_package(catkin REQUIRED rosjava_build_tools) # Set the gradle targets you want catkin's make to run by default catkin_android_setup(assembleRelease uploadArchives) catkin_package() + + +############################################################################## +# Installation +############################################################################## + +# If you are deploying android libraries (.aar's) uncomment this and +# change this to match the maven group name you have specified in the +# allprojects closure the root build.gradle +#install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_MAVEN_DESTINATION}/com/github/rosjava/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_GLOBAL_MAVEN_DESTINATION}/com/github/rosjava/${PROJECT_NAME}) diff --git a/src/rosjava_build_tools/templates/init_repo/build.gradle.in b/src/rosjava_build_tools/templates/android_package/build.gradle.in similarity index 100% rename from src/rosjava_build_tools/templates/init_repo/build.gradle.in rename to src/rosjava_build_tools/templates/android_package/build.gradle.in diff --git a/src/rosjava_build_tools/templates/init_repo/settings.gradle b/src/rosjava_build_tools/templates/android_package/settings.gradle similarity index 100% rename from src/rosjava_build_tools/templates/init_repo/settings.gradle rename to src/rosjava_build_tools/templates/android_package/settings.gradle diff --git a/src/rosjava_build_tools/templates/rosjava_msg_project/build.gradle.in b/src/rosjava_build_tools/templates/rosjava_msg_project/build.gradle.in new file mode 100644 index 0000000000000000000000000000000000000000..87c9221894e770fb361b88f6ae0448e9f12d6920 --- /dev/null +++ b/src/rosjava_build_tools/templates/rosjava_msg_project/build.gradle.in @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2013 %(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. + */ + +try { + project.catkin.tree.pkgs['%(project_name)s'].generateMessageArtifact(project) +} catch (NullPointerException e) { + println("Couldn't find %(project_name)s on the ROS_PACKAGE_PATH") +} + diff --git a/src/rosjava_build_tools/templates/rosjava_package/CMakeLists.txt.in b/src/rosjava_build_tools/templates/rosjava_package/CMakeLists.txt.in new file mode 100644 index 0000000000000000000000000000000000000000..ab5fa4b8ce45e2c604255e3068cb037ef42f639b --- /dev/null +++ b/src/rosjava_build_tools/templates/rosjava_package/CMakeLists.txt.in @@ -0,0 +1,24 @@ +############################################################################## +# CMake +############################################################################## + +cmake_minimum_required(VERSION 2.8.3) +project(%(repo_name)s) + +############################################################################## +# Catkin +############################################################################## + +find_package(catkin REQUIRED rosjava_build_tools) +# Set the gradle targets you want catkin's make to run by default +catkin_android_setup(publishMavenJavaPublicationToMavenRepository) +catkin_package() + +############################################################################## +# Installation +############################################################################## + +# Change this to match the maven group name you have specified in the +# allprojects closure the root build.gradle +install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_MAVEN_DESTINATION}/com/github/rosjava/${PROJECT_NAME}/ + DESTINATION ${CATKIN_GLOBAL_MAVEN_DESTINATION}/com/github/rosjava/${PROJECT_NAME}) diff --git a/src/rosjava_build_tools/templates/rosjava_package/build.gradle.in b/src/rosjava_build_tools/templates/rosjava_package/build.gradle.in new file mode 100644 index 0000000000000000000000000000000000000000..d16e60d86a6dfaf3c0f6f7bc31cefd4025cd9372 --- /dev/null +++ b/src/rosjava_build_tools/templates/rosjava_package/build.gradle.in @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2013 %(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. + */ + +task wrapper(type: Wrapper) { + gradleVersion = '1.7' +} + +buildscript { + def rosMavenPath = "$System.env.ROS_MAVEN_PATH".split(':').collect { 'file://' + it } + repositories { + rosMavenPath.each { p -> + maven { + url p + } + } + mavenLocal() + maven { + url 'https://github.com/rosjava/rosjava_mvn_repo/raw/master' + } + } + dependencies { + classpath group: 'org.ros.rosjava_bootstrap', name: 'gradle_plugins', version: '0.1.+' + } +} + +apply plugin: 'catkin' + + +allprojects { + /* + A github url provides a good standard unique name for your project + Example below, but you may wish to switch to your own unique url. + */ + group 'com.github.rosjava.%(repo_name)s' + version = project.catkin.pkg.version +} + +subprojects { + /* + See https://github.com/rosjava/rosjava_bootstrap (look for gradle_plugins) + to see what is going on under the hood. + */ + apply plugin: 'ros-java' +} + +/* + Some useful tasks: + install: deploys jar's to MavenLocal() (i.e. ~/.m2/repository) + publishMavenJavaPublicationToMavenRepository : deploys jar's to devel/share/maven + installApp : assembles java apps in the _subproject_/build directories. +*/ +defaultTasks 'install' diff --git a/src/rosjava_build_tools/templates/rosjava_package/settings.gradle b/src/rosjava_build_tools/templates/rosjava_package/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..1b0606e29ed5989755d9cdca7da5b191569410b3 --- /dev/null +++ b/src/rosjava_build_tools/templates/rosjava_package/settings.gradle @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2013 %(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. + */ + diff --git a/src/rosjava_build_tools/templates/rosjava_project/build.gradle.in b/src/rosjava_build_tools/templates/rosjava_project/build.gradle.in new file mode 100644 index 0000000000000000000000000000000000000000..4949b4e8979b2cbab297c5e27d36b09e18d5a3c3 --- /dev/null +++ b/src/rosjava_build_tools/templates/rosjava_project/build.gradle.in @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2013 %(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. + */ + +/* + Examples of + 1) dependencies from another project in this gradle stack. + 2,3) dependency from a maven repository. + + It's a good idea to use + on the patch version dependency to + save continually updating these references, but avoid applying + the same principle to api breaking minor changes in the version. +*/ +/* +dependencies { + compile project(':local_android_library_dependency') + compile 'org.ros.android_core:android_gingerbread_mr1:0.1.+' + compile 'com.github.ros_java.android_extras:gingerbread:0.1.+' +} +*/ + diff --git a/src/rosjava_build_tools/utils.py b/src/rosjava_build_tools/utils.py index c7aaffb2d9dc0120ff24602db3328d4822cc202d..410621f1d03af535095c1f605b5e3045062363ec 100644 --- a/src/rosjava_build_tools/utils.py +++ b/src/rosjava_build_tools/utils.py @@ -117,3 +117,19 @@ def validate_path(path): if os.path.isfile(os.path.join(path, 'build.gradle')): raise ValueError("Error: a gradle project already resides in this location [%s]" % absolute_path) return absolute_path + +############################################################################## +# Borrowed from catkin_pkg.package_templates +############################################################################## + + +def read_template_file(template_directory, filename): + template_dir = os.path.join(os.path.dirname(__file__), 'templates', template_directory) + template = os.path.join(template_dir, '%s.in' % filename) + if not os.path.isfile(template): + raise IOError( + "Could not read template [%s]" % template + ) + with open(template, 'r') as fhand: + template_contents = fhand.read() + return template_contents