Skip to content
Snippets Groups Projects
Commit 4ccaa93f authored by Daniel Stonier's avatar Daniel Stonier
Browse files

scripts working for rosjava packages and projects.

parent b110ae0f
Branches
No related tags found
No related merge requests found
Showing
with 472 additions and 10 deletions
...@@ -20,7 +20,7 @@ import rosjava_build_tools.console as console ...@@ -20,7 +20,7 @@ import rosjava_build_tools.console as console
if __name__ == "__main__": if __name__ == "__main__":
try: try:
sys.exit(init_android_repo()) sys.exit(init_android_package())
except Exception as e: except Exception as e:
console.logerror("%s : %s" % (str(e), type(e))) console.logerror("%s : %s" % (str(e), type(e)))
sys.exit(1) sys.exit(1)
#!/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)
#!/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)
#!/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)
...@@ -9,6 +9,9 @@ d = generate_distutils_setup( ...@@ -9,6 +9,9 @@ d = generate_distutils_setup(
scripts=['scripts/catkin_create_android_pkg', scripts=['scripts/catkin_create_android_pkg',
'scripts/catkin_create_android_project', 'scripts/catkin_create_android_project',
'scripts/catkin_create_android_library_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': [ package_data = {'rosjava_build_tools': [
'templates/android_package/*', 'templates/android_package/*',
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
############################################################################## ##############################################################################
import console import console
from create_package import init_android_repo from create_package import init_android_package, init_rosjava_package
from create_project import create_android_project 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 utils import which
from release import scrape_for_release_message_packages from release import scrape_for_release_message_packages
...@@ -27,7 +27,7 @@ import console ...@@ -27,7 +27,7 @@ import console
def parse_arguments(): def parse_arguments():
argv = sys.argv[1:] argv = sys.argv[1:]
parser = argparse.ArgumentParser( 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('path', nargs='?', default=os.getcwd(), help='path to the repository you wish to create (must not exist beforehand).')
parser.add_argument('dependencies', parser.add_argument('dependencies',
nargs='*', nargs='*',
...@@ -78,8 +78,8 @@ def instantiate_template(template, repo_name, author): ...@@ -78,8 +78,8 @@ def instantiate_template(template, repo_name, author):
return template % locals() return template % locals()
def get_templates(): def get_templates(template_directory):
template_dir = os.path.join(os.path.dirname(__file__), 'templates', 'init_repo') template_dir = os.path.join(os.path.dirname(__file__), 'templates', template_directory)
templates = {} templates = {}
templates['CMakeLists.txt'] = read_template(os.path.join(template_dir, 'CMakeLists.txt.in')) 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')) templates['build.gradle'] = read_template(os.path.join(template_dir, 'build.gradle.in'))
...@@ -87,10 +87,10 @@ def get_templates(): ...@@ -87,10 +87,10 @@ def get_templates():
return templates return templates
def populate_repo(repo_path): def populate_repo(repo_path, package_type):
author = utils.author_name() author = utils.author_name()
repo_name = os.path.basename(repo_path) repo_name = os.path.basename(repo_path)
templates = get_templates() templates = get_templates(package_type)
for filename, template in templates.iteritems(): for filename, template in templates.iteritems():
contents = instantiate_template(template, repo_name, author) contents = instantiate_template(template, repo_name, author)
try: try:
...@@ -154,13 +154,21 @@ def create_catkin_package_files(package_name, package_path, args): ...@@ -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() args = parse_arguments()
try: try:
repo_path = utils.validate_path(args.path) repo_path = utils.validate_path(args.path)
repo_name = os.path.basename(os.path.normpath(repo_path)).lower() 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_catkin_package_files(repo_name, repo_path, args)
create_gradle_wrapper(repo_path) create_gradle_wrapper(repo_path)
except Exception: except Exception:
raise raise
def init_rosjava_package():
init_package('rosjava_package')
def init_android_package():
init_package('android_package')
#!/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])
...@@ -13,3 +13,14 @@ find_package(catkin REQUIRED rosjava_build_tools) ...@@ -13,3 +13,14 @@ find_package(catkin REQUIRED rosjava_build_tools)
# Set the gradle targets you want catkin's make to run by default # Set the gradle targets you want catkin's make to run by default
catkin_android_setup(assembleRelease uploadArchives) catkin_android_setup(assembleRelease uploadArchives)
catkin_package() 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})
/*
* 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")
}
##############################################################################
# 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})
/*
* 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'
/*
* 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.
*/
/*
* 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.+'
}
*/
...@@ -117,3 +117,19 @@ def validate_path(path): ...@@ -117,3 +117,19 @@ def validate_path(path):
if os.path.isfile(os.path.join(path, 'build.gradle')): if os.path.isfile(os.path.join(path, 'build.gradle')):
raise ValueError("Error: a gradle project already resides in this location [%s]" % absolute_path) raise ValueError("Error: a gradle project already resides in this location [%s]" % absolute_path)
return 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment