Skip to content
This repository was archived by the owner on Jan 14, 2023. It is now read-only.

Commit 3ee1817

Browse files
committed
Adds more robust message package detection from PR #13
Upgrades Android plugin version as done in PR #13
1 parent b19a808 commit 3ee1817

File tree

3 files changed

+86
-90
lines changed

3 files changed

+86
-90
lines changed

gradle_plugins/src/main/groovy/org/ros/gradle_plugins/CatkinPlugin.groovy

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.gradle.api.*;
2323
* println d
2424
* }
2525
* // filtered list of *_msg dependencies.
26-
* pkg.messageDependencies().each { d ->
26+
* pkg.getMessageDependencies().each { d ->
2727
* println d
2828
* }
2929
* }
@@ -32,7 +32,7 @@ import org.gradle.api.*;
3232
* only generate the properties once and share them this way.
3333
*/
3434
class CatkinPlugin implements Plugin<Project> {
35-
def void apply(Project project) {
35+
def void apply(Project project) {
3636
project.extensions.create("catkin", CatkinPluginExtension)
3737

3838
def workspaces = System.getenv("ROS_PACKAGE_PATH")
@@ -48,7 +48,7 @@ class CatkinPlugin implements Plugin<Project> {
4848
if (!packageXml.exists()) {
4949
throw new StopActionException("Missing package.xml for project: ${project}")
5050
}
51-
project.catkin.pkg = new CatkinPackage(packageXml)
51+
project.catkin.pkg = new CatkinPackage(project, packageXml)
5252

5353
project.task("catkinPackageInfo") << {
5454
println "Catkin Workspaces: ${project.catkin.workspaces}"
@@ -64,26 +64,31 @@ class CatkinPluginExtension {
6464
}
6565

6666
class CatkinPackages {
67-
def Map<String, CatkinPackage> pkgs
68-
def List<String> workspaces
69-
def Project project
7067

71-
def CatkinPackages(Project project, List<String> workspaces) {
68+
Map<String, CatkinPackage> pkgs
69+
List<String> workspaces
70+
Project project
71+
72+
CatkinPackages(Project project, List<String> workspaces) {
7273
this.project = project
7374
this.workspaces = workspaces
7475
pkgs = [:]
7576
}
7677

77-
def generate() {
78+
void generate() {
7879
if (pkgs.size() == 0) {
7980
workspaces.each { workspace ->
80-
def manifestTree = project.fileTree(dir: workspace, include: "**/package.xml")
81+
def manifestTree = project.fileTree(dir: workspace,
82+
include: "**/package.xml")
8183
manifestTree.each {
82-
def pkg = new CatkinPackage(it)
84+
def pkg = new CatkinPackage(project, it)
8385
if (pkgs.containsKey(pkg.name)) {
86+
// TODO(damonkohler): This comparison probably doesn't work since
87+
// versions are strings.
8488
if (pkgs[pkg.name].version < pkg.version) {
85-
println("Replacing " + pkg.name + " version " + pkgs[pkg.name].version +
86-
" with version " + pkg.version + ".")
89+
println("Replacing " + pkg.name + " version " +
90+
pkgs[pkg.name].version + " with version " + pkg.version +
91+
".")
8792
pkgs[pkg.name] = pkg
8893
}
8994
} else {
@@ -96,44 +101,51 @@ class CatkinPackages {
96101
}
97102

98103
class CatkinPackage {
99-
def name
100-
def version
101-
def dependencies
102104

103-
def CatkinPackage(File packageXmlFilename) {
105+
Project project
106+
String name
107+
String version
108+
Set<String> dependencies
109+
110+
CatkinPackage(Project project, File packageXmlFilename) {
111+
this.project = project
104112
println "Loading " + packageXmlFilename
105113
def packageXml = new XmlParser().parse(packageXmlFilename)
106114
name = packageXml.name.text()
107115
version = packageXml.version.text()
108-
dependencies = packageXml.build_depend.collect({ it.text() })
116+
dependencies = packageXml.build_depend.collect{ it.text() }
109117
}
110118

111119
String toString() { "${name} ${version} ${dependencies}" }
112120

113-
/*
114-
* Find and annotate a list of package package dependencies.
115-
* Useful for message artifact generation).
116-
*
117-
* @return List<String> : dependencies (package name strings)
118-
*/
119-
Set<String> messageDependencies(Project project, Collection<String> dependencies) {
121+
Set<String> getTransitiveDependencies(Collection<String> dependencies) {
120122
Set<String> result = [];
121123
dependencies.each {
122124
if (project.catkin.tree.pkgs.containsKey(it)) {
123-
if (it.contains("_msgs") || it.contains("_srvs")) {
124-
result.add(it)
125-
}
126-
result.addAll(messageDependencies(project, project.catkin.tree.pkgs[it].dependencies))
125+
result.add(it)
126+
result.addAll(getTransitiveDependencies(
127+
project.catkin.tree.pkgs[it].dependencies))
127128
}
128129
}
129130
return result
130131
}
131132

133+
Set<String> getMessageDependencies() {
134+
getTransitiveDependencies(dependencies).findAll {
135+
project.catkin.tree.pkgs.containsKey(it) &&
136+
project.catkin.tree.pkgs[it].dependencies.contains("message_generation")
137+
} as Set
138+
}
139+
132140
void generateMessageArtifact(Project project) {
133141
project.version = version
134142
project.dependencies.add("compile", "org.ros.rosjava_bootstrap:message_generation:[0.2,0.3)")
135-
messageDependencies(project, dependencies).each {
136-
project.dependencies.add("compile", project.dependencies.project(path: ":${it}"))
143+
getMessageDependencies().each {
144+
if (project.getParent().getChildProjects().containsKey(it)) {
145+
project.dependencies.add("compile", project.dependencies.project(path: ":${it}"))
146+
} else {
147+
project.dependencies.add("compile", "org.ros.rosjava_messages:${it}:[0.0,)")
148+
}
137149
}
138150
def generatedSourcesDir = "${project.buildDir}/generated-src"
139151
def generateSourcesTask = project.tasks.create("generateSources", JavaExec)
@@ -155,8 +167,8 @@ class CatkinPackage {
155167
project.version = version
156168
project.group = "org.ros.rosjava_messages"
157169
project.dependencies.add("compile", "org.ros.rosjava_bootstrap:message_generation:[0.2,0.3)")
158-
messageDependencies(project, dependencies).each { d ->
159-
project.dependencies.add("compile", "org.ros.rosjava_messages:" + d + ":[0.1,)")
170+
getMessageDependencies().each {
171+
project.dependencies.add("compile", "org.ros.rosjava_messages:${it}:[0.1,)")
160172
}
161173
def generatedSourcesDir = "${project.buildDir}/generated-src"
162174
def generateSourcesTask = project.tasks.create("generateSources", JavaExec)

gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosAndroid.groovy

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,49 @@ import org.gradle.api.Project
44
import org.gradle.api.Plugin
55
import java.util.HashMap
66

7-
/*
8-
* Configures java for the ros-android build environment. Pretty elementary right now,
9-
* just applies the java plugin and defines the jdk compatibility level.
7+
/**
8+
* Configures ROS on Android build environment.
109
*/
1110
class RosAndroidPlugin implements Plugin<Project> {
12-
Project project
13-
14-
def void apply(Project project) {
15-
this.project = project
16-
if (!project.plugins.findPlugin('ros')) {
17-
project.apply(plugin: 'ros')
18-
}
19-
project.extensions.create("rosandroid", RosAndroidPluginExtension)
20-
project.rosandroid.buildToolsVersion = "18.1.1"
21-
/*********************************************************************
22-
* Find the android plugin
23-
*********************************************************************/
24-
project.buildscript {
25-
repositories {
26-
mavenCentral()
27-
}
28-
dependencies {
29-
classpath 'com.android.tools.build:gradle:0.6.1'
30-
}
31-
}
32-
/**********************************************************************
33-
* Publishing - not we're using old style here. Upgrade to maven-publish
34-
* once they have support:
35-
* https://github.com/rosjava/rosjava_bootstrap/issues/1
36-
**********************************************************************/
37-
project.uploadArchives {
38-
repositories.mavenDeployer {
39-
repository(url: 'file://' + project.ros.mavenDeploymentRepository)
40-
}
41-
}
42-
/**********************************************************************
43-
* Our maven repo 3rd parties are currently incompatible with android
44-
* junit especially could use a look at - find a compatible version!
45-
**********************************************************************/
46-
project.configurations.create('compile')
47-
def excludes = new HashMap<String, String>()
48-
excludes.put('group', 'junit')
49-
excludes.put('group', 'xml-apis')
50-
project.configurations['compile'].exclude(excludes)
51-
/**********************************************************************
52-
* Delay android plugin configuration because that will depend on
53-
* the subproject's late loading of android or android-library plugin.
54-
**********************************************************************/
55-
project.afterEvaluate {
56-
project.android {
57-
buildToolsVersion project.rosandroid.buildToolsVersion
58-
}
59-
}
60-
11+
12+
void apply(Project project) {
13+
project.apply plugin: "ros"
14+
project.extensions.create("rosandroid", RosAndroidPluginExtension)
15+
project.rosandroid.buildToolsVersion = "18.1.1"
16+
17+
//Find the android plugin
18+
project.buildscript {
19+
repositories {
20+
mavenCentral()
21+
}
22+
dependencies {
23+
classpath "com.android.tools.build:gradle:0.7.1"
24+
}
25+
}
26+
27+
// Note that we're using old style here. Upgrade to maven-publish once they
28+
// have support: https://github.com/rosjava/rosjava_bootstrap/issues/1
29+
project.uploadArchives {
30+
repositories.mavenDeployer {
31+
repository(url: uri(project.ros.mavenDeploymentRepository))
32+
}
33+
}
34+
35+
// Our Maven repo 2rd parties are currently incompatible with Android JUnit.
36+
project.configurations.create("compile")
37+
project.configurations.compile.exclude "group": "junit"
38+
project.configurations.compile.exclude "group": "xml-apis"
39+
40+
// Delay android plugin configuration because that will depend on the
41+
// subproject's late loading of android or android-library plugin.
42+
project.afterEvaluate {
43+
project.android {
44+
buildToolsVersion project.rosandroid.buildToolsVersion
45+
}
6146
}
47+
}
6248
}
6349

6450
class RosAndroidPluginExtension {
65-
String buildToolsVersion
51+
String buildToolsVersion
6652
}

gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosPlugin.groovy

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package org.ros.gradle_plugins;
33
import org.gradle.api.*;
44
import org.gradle.api.publish.maven.MavenPublication;
55

6-
/*
7-
* Provides information about the ros workspace.
6+
/**
7+
* Configures a Java project for use with ROS.
88
*
99
* - project.ros.mavenPath : location of local ros maven repositories (in your chained workspaces)
1010
* - project.ros.mavenDeploymentRepository : location of the ros maven repository you will publish to
@@ -16,10 +16,8 @@ import org.gradle.api.publish.maven.MavenPublication;
1616
* - configures the uploadArchives for artifact deployment to the local ros maven repo (devel/share/maven)
1717
*/
1818
class RosPlugin implements Plugin<Project> {
19-
Project project
2019

2120
def void apply(Project project) {
22-
this.project = project
2321
project.apply plugin: "eclipse"
2422
project.apply plugin: "java"
2523
project.apply plugin: "maven"
@@ -84,4 +82,4 @@ class RosPluginExtension {
8482
String mavenRepository
8583
String mavenDeploymentRepository
8684
List<String> mavenPath
87-
}
85+
}

0 commit comments

Comments
 (0)