This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "UNNAMED PROJECT".

The branch, jh-symbols has been updated
       via  b852c25eb2f2d985a071d844b7bba66d3134b812 (commit)
      from  13798bcffea6a8fd35018b7e4d17995615da261b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b852c25eb2f2d985a071d844b7bba66d3134b812
Author: Niels Thykier <ni...@thykier.net>
Date:   Sat Jul 16 17:49:46 2011 +0200

    Use dpkg (where needed) to determine needed version

-----------------------------------------------------------------------

Summary of changes:
 src/org/debian/dpkg/internal/PollDpkg.java         |   11 ++++
 .../javahelper/symbols/cmd/DependencyProgram.java  |   52 ++++++++++++++++----
 2 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/src/org/debian/dpkg/internal/PollDpkg.java 
b/src/org/debian/dpkg/internal/PollDpkg.java
index fbcb765..a286be7 100644
--- a/src/org/debian/dpkg/internal/PollDpkg.java
+++ b/src/org/debian/dpkg/internal/PollDpkg.java
@@ -47,6 +47,17 @@ final public class PollDpkg {
                return res;
        }
 
+       public static int compareVersion(String v1, String op, String v2) 
throws IOException, InterruptedException{
+               ProcessBuilder b = new ProcessBuilder(new String[]{
+                               "dpkg",
+                               "--compare-versions",
+                               v1,
+                               op,
+                               v2
+               });
+               Process p = b.start();
+               return p.waitFor();
+       }
 
 
        public static final void main(String ... args) throws Exception{
diff --git a/src/org/debian/javahelper/symbols/cmd/DependencyProgram.java 
b/src/org/debian/javahelper/symbols/cmd/DependencyProgram.java
index afd2a35..6ba44a1 100644
--- a/src/org/debian/javahelper/symbols/cmd/DependencyProgram.java
+++ b/src/org/debian/javahelper/symbols/cmd/DependencyProgram.java
@@ -3,6 +3,7 @@ package org.debian.javahelper.symbols.cmd;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.debian.dpkg.internal.PollDpkg;
 import org.debian.javahelper.symbols.Factory;
 import org.debian.javahelper.symbols.IClassSymbol;
 import org.debian.javahelper.symbols.ILibrarySymbolData;
@@ -10,6 +11,8 @@ import org.debian.javahelper.symbols.ISymbol;
 
 public class DependencyProgram implements IProgram {
 
+       private static boolean doutput = true;
+
        public int exec(String[] args) throws IllegalProgramArgumentsException, 
Exception {
                Factory fac = Factory.newInstance();
                ILibrarySymbolData usagedata = fac.createSymbolData();
@@ -27,7 +30,7 @@ public class DependencyProgram implements IProgram {
                                Map<String, Boolean> syms = new HashMap<String, 
Boolean>();
                                neededCl.put(cs.getClassName(), syms);
                                for(ISymbol c : cs.getSymbols()){
-                                       System.out.println("N: needs-symbol " + 
c.getFullSymbolName());
+                                       debug("N: needs-symbol " + 
c.getFullSymbolName());
                                        syms.put(c.getName(), Boolean.TRUE);
                                }
                        } else {
@@ -36,6 +39,7 @@ public class DependencyProgram implements IProgram {
                }
                for( ; i < args.length ; i++){
                        ILibrarySymbolData prov = fac.createSymbolData();
+                       Map<String, Boolean> vMap = new HashMap<String, 
Boolean>(); // version result cache
                        String neededVer = null;
                        prov.read(args[i]);
                        for(ISymbol s : prov.getSymbols()){
@@ -49,20 +53,23 @@ public class DependencyProgram implements IProgram {
                                        cs = s.asClassSymbol();
                                        for(ISymbol c : cs.getSymbols()){
                                                if(nm.remove(c.getName()) != 
null){
-                                                       System.out.println("N: 
found-class-symbol: " + c.getFullSymbolName());
-                                                       neededVer = 
highest(neededVer, s.getVersion());
+                                                       debug("N: 
found-class-symbol: " + c.getFullSymbolName());
+                                                       neededVer = 
highest(vMap, neededVer, c.getVersion());
+                                                       if(nm.size() < 1) {
+                                                               break;
+                                                       }
                                                }
                                        }
                                        if(nm.size() < 1) {
-                                               neededVer = highest(neededVer, 
cs.getVersion());
+                                               neededVer = highest(vMap, 
neededVer, cs.getVersion());
                                                neededCl.remove(clname);
-                                               System.out.println("N: 
satisfied-class: " + clname);
+                                               debug("N: satisfied-class: " + 
clname);
                                        }
                                } else {
                                        String fn = s.getFullSymbolName();
                                        if(neededSyms.remove(fn) != null){
-                                               System.out.println("N: 
found-symbol: " + fn);
-                                               neededVer = highest(neededVer, 
s.getVersion());
+                                               debug("N: found-symbol: " + fn);
+                                               neededVer = highest(vMap, 
neededVer, s.getVersion());
                                        }
                                }
                        }
@@ -89,14 +96,39 @@ public class DependencyProgram implements IProgram {
                return 0;
        }
 
-       // FIXME XXX TODO - prototype
-       private static String highest(String v1, String v2){
+       /**
+        * Returns the highest version
+        * 
+        * @param v Map to cache old (inferior) versions to avoid querying dpkg.
+        *   If v2 appears in this map, is assumed to be inferior to v1.
+        *   If dpkg is queried, the inferior version it put into v.
+        * @param v1 The first version / the previously highest version
+        * @param v2 The second version / the unknown version
+        * @return v1 or v2
+        * @throws Exception
+        */
+       private static String highest(Map<String, Boolean> v, String v1, String 
v2) throws Exception {
                if(v1 == null) {
                        return v2;
                }
                if(v1.equals(v2)) {
                        return v1;
                }
-               return v1;
+               if(v.containsKey(v2)) {
+                       return v1;
+               }
+               if(PollDpkg.compareVersion(v1, "ge", v2) == 0){
+                       v.put(v2, Boolean.TRUE);
+                       return v1;
+               } else {
+                       v.put(v1, Boolean.TRUE);
+               }
+               return v2;
+       }
+
+       private static void debug(String msg){
+               if(doutput) {
+                       System.out.println(msg);
+               }
        }
 }


hooks/post-receive
-- 
UNNAMED PROJECT

_______________________________________________
pkg-java-commits mailing list
pkg-java-comm...@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

Reply via email to