[gradle-debian-helper] 03/04: Fixed the optional dependencies in the generated poms
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Wed Nov 16 00:09:24 UTC 2016
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to branch master
in repository gradle-debian-helper.
commit 9d75e5302b9a371448ab82c360d9bb36002b038a
Author: Emmanuel Bourg <ebourg at apache.org>
Date: Wed Nov 16 01:00:21 2016 +0100
Fixed the optional dependencies in the generated poms
---
debian/changelog | 1 +
.../java/org/debian/gradle/tasks/MavenPom.java | 26 ++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index 9faf71d..03431ae 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,6 @@
gradle-debian-helper (1.4.4) UNRELEASED; urgency=medium
+ * Fixed the optional dependencies in the generated poms
* Added a log message when the pom file is generated
-- Emmanuel Bourg <ebourg at apache.org> Wed, 16 Nov 2016 00:50:03 +0100
diff --git a/gradle-helper-plugin/src/main/java/org/debian/gradle/tasks/MavenPom.java b/gradle-helper-plugin/src/main/java/org/debian/gradle/tasks/MavenPom.java
index 386ec9b..deef390 100644
--- a/gradle-helper-plugin/src/main/java/org/debian/gradle/tasks/MavenPom.java
+++ b/gradle-helper-plugin/src/main/java/org/debian/gradle/tasks/MavenPom.java
@@ -51,6 +51,16 @@ public class MavenPom extends DefaultTask {
}
}
+ private void setMavenDependencyProperty(Object dependency, String property, String value) {
+ try {
+ dependency.getClass()
+ .getMethod("set" + property.substring(0, 1).toUpperCase() + property.substring(1), String.class)
+ .invoke(dependency, value);
+ } catch (Exception e) {
+ throw new RuntimeException("Unable to set the property '" + property + "' to '" + value + "' on " + dependency);
+ }
+ }
+
private String getMavenDependencyScope(Object dependency) {
return getMavenDependencyProperty(dependency, "scope");
}
@@ -89,6 +99,21 @@ public class MavenPom extends DefaultTask {
);
}
+ /**
+ * Turns the dependencies with a scope set to 'optional' into dependencies
+ * with a 'compile' scope and the optional attribute set to true.
+ */
+ private void fixOptionalDependencies(org.gradle.api.artifacts.maven.MavenPom pom) {
+ for (Object dependency : pom.getDependencies()) {
+ if (dependency.getClass().getName().equals("org.apache.maven.model.Dependency")) {
+ if ("optional".equals(getMavenDependencyScope(dependency))) {
+ setMavenDependencyProperty(dependency, "optional", "true");
+ setMavenDependencyProperty(dependency, "scope", "compile");
+ }
+ }
+ }
+ }
+
@OutputDirectory
private File getDestinationPomDir() {
return new File(getProject().getBuildDir(), "debian");
@@ -119,6 +144,7 @@ public class MavenPom extends DefaultTask {
.getArchivesBaseName());
final org.gradle.api.artifacts.maven.MavenPom effectivePom =
pom.getEffectivePom();
+ fixOptionalDependencies(effectivePom);
sortPomDependencies(effectivePom);
getDestinationPomDir().mkdir();
log.info("\tGenerating pom file " + getDestinationPomFile());
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/gradle-debian-helper.git
More information about the pkg-java-commits
mailing list