[gradle-debian-helper] 02/04: Factorized the implementation of the getMavenDependency* methods

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 b594f86a97edb58e90d3b6050bfc621ed12bd2e7
Author: Emmanuel Bourg <ebourg at apache.org>
Date:   Wed Nov 16 00:55:21 2016 +0100

    Factorized the implementation of the getMavenDependency* methods
---
 .../java/org/debian/gradle/tasks/MavenPom.java     | 35 ++++++----------------
 1 file changed, 9 insertions(+), 26 deletions(-)

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 3366908..386ec9b 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
@@ -40,48 +40,31 @@ public class MavenPom extends DefaultTask {
     /* Since the Groovy in Gradle scripts are dynamically typed and due to
        Gradle's own class loading mechanism, we couldn't cast the type of
        org.apache.maven.model.Dependency. So we have to use Reflections. */
-    private String getMavenDependencyScope(Object dependency) {
+    private String getMavenDependencyProperty(Object dependency, String property) {
         String result = null;
         try {
             result = ((String)dependency.getClass()
-                                        .getMethod("getScope")
+                                        .getMethod("get" + property.substring(0, 1).toUpperCase() + property.substring(1))
                                         .invoke(dependency));
         } finally {
             return (result == null) ? "" : result;
         }
     }
 
+    private String getMavenDependencyScope(Object dependency) {
+        return getMavenDependencyProperty(dependency, "scope");
+    }
+
     private String getMavenDependencyGroupId(Object dependency) {
-        String result = null;
-        try {
-            result = ((String)dependency.getClass()
-                                        .getMethod("getGroupId")
-                                        .invoke(dependency));
-        } finally {
-            return (result == null) ? "" : result;
-        }
+        return getMavenDependencyProperty(dependency, "groupId");
     }
 
     private String getMavenDependencyArtifactId(Object dependency) {
-        String result = null;
-        try {
-            result = ((String)dependency.getClass()
-                                        .getMethod("getArtifactId")
-                                        .invoke(dependency));
-        } finally {
-            return (result == null) ? "" : result;
-        }
+        return getMavenDependencyProperty(dependency, "artifactId");
     }
 
     private String getMavenDependencyVersion(Object dependency) {
-        String result = null;
-        try {
-            result = ((String)dependency.getClass()
-                                        .getMethod("getVersion")
-                                        .invoke(dependency));
-        } finally {
-            return (result == null) ? "" : result;
-        }
+        return getMavenDependencyProperty(dependency, "version");
     }
 
     private void sortPomDependencies(org.gradle.api.artifacts.maven.MavenPom pom) {

-- 
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