[SCM] UNNAMED PROJECT branch, jh-symbols, updated. 0.37-8-gc94a2bd

Niels Thykier nthykier at alioth.debian.org
Sat Jul 16 14:43:29 UTC 2011


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  c94a2bd76534fa0b718a762ce5196d98abb1bbd5 (commit)
       via  49dde5064b64d991fbeae0f4125d9c26b32d2824 (commit)
       via  0448c2b5417dbe401cf2a8db4e341837137f2698 (commit)
       via  5df7ff57bf0d547551af0c8b72d5950e75c49987 (commit)
       via  3d4f70184f999de6c3f9d7c2081d6af3158f7468 (commit)
       via  e811a2154dfcd85ce8c9ce93356dc4d9adf14712 (commit)
       via  c550f982f48c856a5b985e652eb963b0afcd41ca (commit)
       via  1557c4938ed019f03bf4c9d02d581f722be37916 (commit)
      from  33af870ae42bf1a5f0300e08ce93509782d45c21 (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 c94a2bd76534fa0b718a762ce5196d98abb1bbd5
Author: Niels Thykier <niels at thykier.net>
Date:   Sat Jul 16 16:38:57 2011 +0200

    Refactored jh-symbol main and added prototype depends calculator

commit 49dde5064b64d991fbeae0f4125d9c26b32d2824
Merge: 33af870 0448c2b
Author: Niels Thykier <niels at thykier.net>
Date:   Tue Jul 12 00:43:09 2011 +0200

    Merge branch 'master' into jh-symbols

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

Summary of changes:
 debian/changelog                                   |   22 +++
 debian/control                                     |    2 +-
 jh_build                                           |    4 +
 jh_classpath                                       |    3 +-
 jh_depends                                         |   14 ++-
 jh_exec                                            |    3 +-
 jh_installjavadoc                                  |    3 +-
 jh_installlibs                                     |    3 +-
 jh_lib.sh.in                                       |    2 +-
 jh_makepkg                                         |    1 +
 src/org/debian/javahelper/symbols/ISymbol.java     |    4 +
 src/org/debian/javahelper/symbols/Main.java        |  158 ++++++--------------
 .../javahelper/symbols/cmd/DependencyProgram.java  |  102 +++++++++++++
 .../debian/javahelper/symbols/cmd/DiffProgram.java |  102 +++++++++++++
 .../javahelper/symbols/cmd/GenerateProgram.java    |   41 +++++
 .../debian/javahelper/symbols/cmd/IProgram.java    |   30 ++++
 .../cmd/IllegalProgramArgumentsException.java      |   30 ++++
 .../javahelper/symbols/internal/ClassSymbol.java   |    6 +
 .../javahelper/symbols/internal/SimpleSymbol.java  |    5 +
 19 files changed, 411 insertions(+), 124 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 4e6e267..90445f5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,25 @@
+javatools (0.38) UNRELEASED; urgency=low
+
+  * Added missing empty line the in d/control generated by jh_makepkg
+
+ -- Niels Thykier <niels at thykier.net>  Mon, 11 Jul 2011 15:20:40 +0200
+
+javatools (0.37) unstable; urgency=low
+
+  [ Niels Thykier ]
+  * Do not assume that $pkg/usr/share/doc is present when jh_depends
+    runs.  (Closes: #632620)
+  * Applied changes from NMU.
+    - depend on gcj-jdk rather than gcj for java-propose-classpath.
+  * Added support for -s/--same-arch in jh_lib and related shell
+    scripts.  (Closes: #632619)
+
+  [ Matthew Johnson ]
+  * Default to -source 1.5 in jh_build unless specified in the extra
+    args (Closes: #591874)
+
+ -- Niels Thykier <niels at thykier.net>  Wed, 06 Jul 2011 14:53:12 +0200
+
 javatools (0.36) unstable; urgency=low
 
   * Made jh_manifest always follow symlinks - the fix for this in
diff --git a/debian/control b/debian/control
index c6f139e..0ebe6db 100644
--- a/debian/control
+++ b/debian/control
@@ -76,7 +76,7 @@ Description: Helper scripts for packaging Java programs
 
 Package: java-propose-classpath
 Architecture: all
-Depends: gcj, javahelper (= ${binary:Version}), fastjar, ${misc:Depends}
+Depends: gcj-jdk, javahelper (= ${binary:Version}), fastjar, ${misc:Depends}
 Description: Helper script to suggest a classpath for jar files
  java-propose-classpath analyzes a set of jar files and the installed
  jars on the system to suggest a correct classpath for use with
diff --git a/jh_build b/jh_build
index a024313..08da232 100755
--- a/jh_build
+++ b/jh_build
@@ -52,6 +52,10 @@ fi
 JH_JAVAC_OPTS="`getarg o javacopts`"
 JH_JAVADOC_OPTS="`getarg O javadoc-opts`"
 
+if ! grep -- -source <<< "$JH_JAVAC_OPTS" &>/dev/null; then
+	JH_JAVAC_OPTS="-source 1.5 $JH_JAVAC_OPTS"
+fi
+
 function dobuild()
 {
 
diff --git a/jh_classpath b/jh_classpath
index 6dad090..3112d2b 100755
--- a/jh_classpath
+++ b/jh_classpath
@@ -12,6 +12,7 @@ syntax()
    echo -e "\t-V --version: show the version"
    echo -e "\t-i --indep: act on all Arch: all packages"
    echo -e "\t-a --arch: act on all Arch-specific packages"
+   echo -e "\t-s --same-arch: alias of --arch for compatibility with debhelper"
    echo -e "\t-p<package> --package=<package>: package to act on (default=all)"  
    echo -e "\t-P<packagedir> --tmpdir=<package>: package directory (default=\$CWD/debian/package)"  
    echo -e "\t-c<classpath> --classpath=<classpath>: The classpath to set on the jar(s)"
@@ -20,7 +21,7 @@ syntax()
    exit 1
 }
 
-ARGS="i indep a arch p package P tmpdir v verbose n no-act c classpath" parseargs "$@"
+ARGS="i indep a arch s same-arch p package P tmpdir v verbose n no-act c classpath" parseargs "$@"
 
 dh_testdir
 
diff --git a/jh_depends b/jh_depends
index c191afe..93bf6b6 100755
--- a/jh_depends
+++ b/jh_depends
@@ -17,6 +17,7 @@ syntax()
    echo -e "\t-v --verbose: show more information while running"
    echo -e "\t-i --indep: work on all indep packages"
    echo -e "\t-a --arch: work on all arch-specific packages"
+   echo -e "\t-s --same-arch: alias of --arch for compatibility with debhelper"
    echo -e "\t-n --no-act: don't actually do anything, just print the results"
    echo -e "\t-j[<jvm>] --jvm[=<jvm>]: Options are: default, headless, gcj, open, sun, sun6. Can be a space-separated list."
    echo -e "\t-X<package> --exclude=<package>: don't add this package to depends"  
@@ -82,7 +83,7 @@ function home-to-jvm()
 	echo "$JVM"
 }
 
-ARGS="X exclude p package P tmpdir v verbose i indep a arch n no-act j jvm" parseargs "$@"
+ARGS="X exclude p package P tmpdir v verbose i indep a arch s same-arch n no-act j jvm" parseargs "$@"
 
 VERBOSE="`getarg v verbose`"
 
@@ -244,8 +245,15 @@ for p in $PACKAGES; do
       fi
    fi
    cd "$OLDDIR"
-   API=`find "$PACKAGEDIR/usr/share/doc" -type f -name 'package-list' -exec dirname {} \;`
-   DOC_REC=`/usr/share/javahelper/jh_scanjavadoc $API`
+   # Do not rely on the presence of /usr/share/doc, it might have been removed already and
+   # it is a policy voliation to do so. #632620
+   if [ -d "$PACKAGEDIR/usr/share/doc" ] ; then
+       API=`find "$PACKAGEDIR/usr/share/doc" -type f -name 'package-list' -exec dirname {} \;`
+       DOC_REC=`/usr/share/javahelper/jh_scanjavadoc $API`
+   else
+       API=''
+       DOC_REC=''
+   fi
 
    if [ -n "$VERBOSE" ]; then
       echo "Adding substvars:" "java:Depends=$JVMDEPS`echo $DEBDEPS | sed 's/\([a-zA-Z0-9_.+-]*\( *([^)]*)\)\{0,1\}\)/\1, /g;s/, *$//'`" \
diff --git a/jh_exec b/jh_exec
index c9df872..d031661 100755
--- a/jh_exec
+++ b/jh_exec
@@ -14,6 +14,7 @@ syntax()
    echo -e "\t-V --version: print the version"
    echo -e "\t-i --indep: run for all Arch: all packages"
    echo -e "\t-a --arch: run for all Arch-specific packages"
+   echo -e "\t-s --same-arch: alias of --arch for compatibility with debhelper"
    echo -e "\t-p<package> --package=<package>: package to act on (default=all)"  
    echo -e "\t-P<packagedir> --tmpdir=<package>: package directory (default=\$CWD/debian/package)"  
    echo -e "\t-v --verbose: show more information while running"
@@ -21,7 +22,7 @@ syntax()
    exit 1
 }
 
-ARGS="i indep a arch p package P tmpdir v verbose n no-act" parseargs "$@"
+ARGS="i indep a arch s same-arch p package P tmpdir v verbose n no-act" parseargs "$@"
 
 VERBOSE="`getarg v verbose`"
 dh_testdir
diff --git a/jh_installjavadoc b/jh_installjavadoc
index 5d8a283..52ebf6b 100755
--- a/jh_installjavadoc
+++ b/jh_installjavadoc
@@ -12,6 +12,7 @@ syntax()
    echo -e "\t-V --version: show the version"
    echo -e "\t-i --indep: act on all Arch: all packages"
    echo -e "\t-a --arch: act on all Arch-specific packages"
+   echo -e "\t-s --same-arch: alias of --arch for compatibility with debhelper"
    echo -e "\t-p<package> --package=<package>: package to act on (default=all)"  
    echo -e "\t-P<packagedir> --tmpdir=<package>: package directory (default=\$CWD/debian/package)"  
    echo -e "\t-v --verbose: show more information while running"
@@ -20,7 +21,7 @@ syntax()
    exit 1
 }
 
-ARGS="A author i indep a arch p package P tmpdir v verbose n no-act" parseargs "$@"
+ARGS="A author i indep a arch s same-arch p package P tmpdir v verbose n no-act" parseargs "$@"
 
 dh_testdir
 
diff --git a/jh_installlibs b/jh_installlibs
index f5e95af..0760145 100755
--- a/jh_installlibs
+++ b/jh_installlibs
@@ -12,6 +12,7 @@ syntax()
    echo -e "\t-V --version: show the version"
    echo -e "\t-i --indep: act on all Arch: all packages"
    echo -e "\t-a --arch: act on all Arch-specific packages"
+   echo -e "\t-s --same-arch: alias of --arch for compatibility with debhelper"
    echo -e "\t-p<package> --package=<package>: package to act on (default=all)"  
    echo -e "\t-P<packagedir> --tmpdir=<package>: package directory (default=\$CWD/debian/package)"  
    echo -e "\t-v --verbose: show more information while running"
@@ -22,7 +23,7 @@ syntax()
    exit 1
 }
 
-ARGS="i indep s arch p package P tmpdir v verbose n no-act no-mangle upstream-version version-strip" parseargs "$@"
+ARGS="i indep a arch s same-arch p package P tmpdir v verbose n no-act no-mangle upstream-version version-strip" parseargs "$@"
 
 dh_testdir
 
diff --git a/jh_lib.sh.in b/jh_lib.sh.in
index 79fd3a9..0cb90f6 100644
--- a/jh_lib.sh.in
+++ b/jh_lib.sh.in
@@ -86,7 +86,7 @@ findpackages()
       echo $opt_package
    elif [ -n "$opt_i" ] || [ -n "$opt_indep" ]; then
       egrep '^(Package|Architecture)' debian/control | grep -B1 'Architecture: all'|sed -n '/^Package:/s/^[^:]*: *//p'
-   elif [ -n "$opt_a" ] || [ -n "$opt_arch" ]; then
+   elif [ -n "$opt_a" ] || [ -n "$opt_arch" ] || [ -n "$opt_s" ] || [ -n "$opt_same_arch" ]; then
       egrep '^(Package|Architecture)' debian/control | grep -v 'Architecture: all' | grep -B1 Architecture|sed -n '/^Package:/s/^[^:]*: *//p'
    else
       sed -n '/^Package:/s/^[^:]*: *//p' debian/control
diff --git a/jh_makepkg b/jh_makepkg
index 3a80721..d84a1fe 100755
--- a/jh_makepkg
+++ b/jh_makepkg
@@ -300,6 +300,7 @@ END
 if [ "$TYPE" = "lib" ] ; then
     # add doc package template
     cat >> debian/control <<END
+
 Package: $BINPACKAGE-doc
 Architecture: all
 Depends: \${java:Depends}, \${misc:Depends}
diff --git a/src/org/debian/javahelper/symbols/ISymbol.java b/src/org/debian/javahelper/symbols/ISymbol.java
index e032709..05f5f0c 100644
--- a/src/org/debian/javahelper/symbols/ISymbol.java
+++ b/src/org/debian/javahelper/symbols/ISymbol.java
@@ -11,6 +11,10 @@ public interface ISymbol {
 	 */
 	public String getClassName();
 	/**
+	 * @return The full symbol name (usually {@link #getClassName()} "." {@link #getName()})
+	 */
+	public String getFullSymbolName();
+	/**
 	 * @return The version of the symbol
 	 */
 	public String getVersion();
diff --git a/src/org/debian/javahelper/symbols/Main.java b/src/org/debian/javahelper/symbols/Main.java
index 8d60889..e0ba8ce 100644
--- a/src/org/debian/javahelper/symbols/Main.java
+++ b/src/org/debian/javahelper/symbols/Main.java
@@ -1,134 +1,62 @@
 package org.debian.javahelper.symbols;
 
-import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
-import org.debian.javahelper.symbols.ISymbolDiff.SymbolDiffStatus;
+import org.debian.javahelper.symbols.cmd.DependencyProgram;
+import org.debian.javahelper.symbols.cmd.GenerateProgram;
+import org.debian.javahelper.symbols.cmd.IProgram;
+import org.debian.javahelper.symbols.cmd.IllegalProgramArgumentsException;
 
 public class Main {
 
+
+	private static final Map<String, IProgram> PROGRAMS = new HashMap<String, IProgram>();
+
 	/**
 	 * @param args
 	 * @throws Exception
 	 */
 	public static void main(String[] args) throws Exception {
-		Factory fac = Factory.newInstance();
-		ILibrarySymbolData symdata;
-		ILibrarySymbolData usagedata = null;
-		String out = null;
-		String usageOut = null;
-		if(args.length < 2 || args.length > 6){
-			throw new IllegalArgumentException("Usage: gen <library> <pkg> <version> [write-to] [usage-to] || read <symbol>");
-		}
-		if(args[0].equals("gen")) {
-			if(args.length < 3){
-				throw new IllegalArgumentException("Usage: gen <library> <pkg> <version> [write-to]");
-			}
-			if(args.length >= 5) {
-				out = args[4];
-				if(args.length == 6) {
-					usageOut = args[5];
-				}
-			}
-			ILibraryParser libpar = fac.createLibraryParser();
-			libpar.parseLibrary(new File(args[1]), args[2], args[3]);
-			symdata = libpar.getExportedSymbols();
-			usagedata = libpar.getUsedSymbols();
-		} else if(args[0].equals("read")){
-			symdata = fac.createSymbolData();
-			symdata.read(args[1]);
-		} else if(args[0].equals("")){
-			return;
-		} else if(args[0].equals("diff")){
-			IDifferenceMaker differ = fac.createDifferenceMaker();
-			ISymbolContainer oData;
-			ISymbolContainer nData;
-			ISymbolDiff diff;
-			if(args.length != 3) {
-				throw new IllegalArgumentException("Usage: diff <org lib/sym-file> <new lib/sym-file>");
-			}
-			if(args[1].toLowerCase().endsWith(".jar") || args[1].toLowerCase().endsWith(".zip")){
-				ILibraryParser libpar = fac.createLibraryParser();
-				libpar.parseLibrary(new File(args[1]), "<pkg>", "0.0");
-				oData = libpar.getExportedSymbols();
-			} else if(args[1].equals("") || args[1].equals("/dev/null")) {
-				oData = IDifferenceMaker.EMPTY_SYMBOL_CONTAINER;
-			} else {
-				ILibrarySymbolData d = fac.createSymbolData();
-				oData = d;
-				d.read(args[1]);
-			}
-			if(args[2].toLowerCase().endsWith(".jar") || args[2].toLowerCase().endsWith(".zip")){
-				ILibraryParser libpar = fac.createLibraryParser();
-				libpar.parseLibrary(new File(args[2]), "<pkg>", "0.0");
-				nData = libpar.getExportedSymbols();
-			} else if(args[2].equals("") || args[2].equals("/dev/null")) {
-				nData = IDifferenceMaker.EMPTY_SYMBOL_CONTAINER;
-			} else {
-				ILibrarySymbolData d = fac.createSymbolData();
-				nData = d;
-				d.read(args[2]);
-			}
-			diff = differ.diff(oData, nData);
-			printDiff(diff);
-			return;
+		IProgram prg;
+		if(args.length < 1){
+			System.err.println("Missing program argument");
+			System.exit(255);
+		}
+		prg = PROGRAMS.get(args[0]);
+		if(prg != null) {
+			int c;
+			try {
+				c = prg.exec(args);
+			} catch (IllegalProgramArgumentsException e){
+				c = e.getExitCode();
+				System.err.println(e.getLocalizedMessage());
+			} catch (Throwable e){
+				e.printStackTrace();
+				System.exit(255);
+				return; /* To avoid "c has not been initialized" error */
+			}
+			System.exit(c);
 		} else {
-			throw new IllegalArgumentException("Usage: gen <library> <pkg> <version> [write-to] || read <symbol>");
-		}
-		System.out.println("Library: " + symdata.getLibraryFilename());
-		for(ISymbol sym : symdata.getSymbols()){
-			System.out.println(" " + sym.getClassName() + " - " + sym.getVersion());
-		}
-		if(out != null) {
-			System.out.println("Writing to: " + out);
-			symdata.write(out);
-		}
-		if(usageOut != null && usagedata != null) {
-			System.out.println("Writing usage info to: " + usageOut);
-			usagedata.write(usageOut);
-		}
-	}
-
-	private static void printDiff(ISymbolDiff diff) {
-		printDiff(diff, "");
-	}
-
-	private static void printDiff(ISymbolDiff diff, String pre) {
-		SymbolDiffStatus stat = diff.getDiffStatus();
-		if(stat == SymbolDiffStatus.UNCHANGED){
-			return;
-		}
-		printDiffList(diff.getNewSymbols(), "+", pre);
-		printDiffList(diff.getMissingSymbols(), "-", pre);
-		printDiffList(diff.getModifiedSymbols(), " ", pre);
-	}
-
-	private static void printDiffList(List<ISymbolDiff> syms, String s, String pre){
-		for(ISymbolDiff diff : syms){
-			ISymbol sym = diff.getNewSymbol();
-			if(sym == null) {
-				throw new IllegalArgumentException();
-			}
-			if(sym.isClassSymbol()){
-				IClassSymbol cl = sym.asClassSymbol();
-				System.out.println(s + pre + sym.getClassName() + ": " + cl.getParentClassName() + " "+
-						SL2S(cl.getImplementedInterfaceNames()));
-				printDiff(diff, pre + "  ");
-			} else {
-				System.out.println(s + pre + sym.getName());
+			System.err.println("Unknown program: " + args[0]);
+			System.err.println("Try one of:");
+			List<String> names = new ArrayList<String>(PROGRAMS.keySet());
+			Collections.sort(names);
+			for(String s : names) {
+				System.err.println(" " + s);
 			}
+			System.exit(255);
 		}
 	}
 
-	private static final String SL2S(List<String> l){
-		int i = 0;
-		StringBuilder b = new StringBuilder();
-		for(String s : l){
-			if(i++ > 0) {
-				b.append(',');
-			}
-			b.append(s);
-		}
-		return b.toString();
+	static {
+		// FIXME: make this better than just "diff old.jsymbols new.jsymbols" - or maybe just remove this
+		//PROGRAMS.put("diff", new DiffProgram());
+		PROGRAMS.put("generate", new GenerateProgram());
+		PROGRAMS.put("gen", PROGRAMS.get("generate"));
+		PROGRAMS.put("depends", new DependencyProgram());
 	}
 }
diff --git a/src/org/debian/javahelper/symbols/cmd/DependencyProgram.java b/src/org/debian/javahelper/symbols/cmd/DependencyProgram.java
new file mode 100644
index 0000000..6139299
--- /dev/null
+++ b/src/org/debian/javahelper/symbols/cmd/DependencyProgram.java
@@ -0,0 +1,102 @@
+package org.debian.javahelper.symbols.cmd;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.debian.javahelper.symbols.Factory;
+import org.debian.javahelper.symbols.IClassSymbol;
+import org.debian.javahelper.symbols.ILibrarySymbolData;
+import org.debian.javahelper.symbols.ISymbol;
+
+public class DependencyProgram implements IProgram {
+
+	public int exec(String[] args) throws IllegalProgramArgumentsException, Exception {
+		Factory fac = Factory.newInstance();
+		ILibrarySymbolData usagedata = fac.createSymbolData();
+		Map<String, Boolean> neededSyms = new HashMap<String, Boolean>();
+		Map<String, Map<String, Boolean>> neededCl = new HashMap<String, Map<String,Boolean>>();
+		int i = 2;
+		if(args.length < 3){
+			throw new IllegalProgramArgumentsException("Usage: " + args[0] + " <usage> <provider1> [...]");
+		}
+		usagedata.read(args[1]);
+		for(ISymbol s : usagedata.getSymbols()) {
+			String fn = s.getFullSymbolName();
+			if(s.isClassSymbol()){
+				IClassSymbol cs = s.asClassSymbol();
+				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());
+					syms.put(c.getName(), Boolean.TRUE);
+				}
+			} else {
+				neededSyms.put(fn, Boolean.TRUE);
+			}
+		}
+		for( ; i < args.length ; i++){
+			ILibrarySymbolData prov = fac.createSymbolData();
+			String neededVer = null;
+			prov.read(args[i]);
+			for(ISymbol s : prov.getSymbols()){
+				if(s.isClassSymbol()){
+					String clname = s.getClassName();
+					Map<String, Boolean> nm = neededCl.get(clname);
+					IClassSymbol cs;
+					if(nm == null) {
+						continue;
+					}
+					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());
+						}
+					}
+					if(nm.size() < 1) {
+						neededVer = highest(neededVer, cs.getVersion());
+						neededCl.remove(clname);
+						System.out.println("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());
+						}
+				}
+			}
+			if(neededVer != null) {
+				//FIXME assuming only one providing package
+				System.out.println("Needs: " +  prov.getProvidingPackages().get(0) + " (>= " + neededVer + ")");
+			}
+		}
+		if(neededSyms.size() > 0) {
+			System.err.println("Missing information for " + neededSyms.size() + " non-class symbols");
+			for(String s : neededSyms.keySet()) {
+				System.err.println(" - " + s);
+			}
+		}
+		if(neededCl.size() > 0) {
+			System.err.println("Missing information for " + neededCl.size() + " class symbols");
+			for(String s : neededCl.keySet()) {
+				Map<String, ?> e = neededCl.get(s);
+				for(String j : e.keySet()) {
+					System.err.println(" - " + s + "." + j);
+				}
+			}
+		}
+		return 0;
+	}
+
+	// FIXME XXX TODO - prototype
+	private static String highest(String v1, String v2){
+		if(v1 == null) {
+			return v2;
+		}
+		if(v1.equals(v2)) {
+			return v1;
+		}
+		return v1;
+	}
+}
diff --git a/src/org/debian/javahelper/symbols/cmd/DiffProgram.java b/src/org/debian/javahelper/symbols/cmd/DiffProgram.java
new file mode 100644
index 0000000..99af026
--- /dev/null
+++ b/src/org/debian/javahelper/symbols/cmd/DiffProgram.java
@@ -0,0 +1,102 @@
+package org.debian.javahelper.symbols.cmd;
+
+import java.io.File;
+import java.util.List;
+
+import org.debian.javahelper.symbols.Factory;
+import org.debian.javahelper.symbols.IClassSymbol;
+import org.debian.javahelper.symbols.IDifferenceMaker;
+import org.debian.javahelper.symbols.ILibraryParser;
+import org.debian.javahelper.symbols.ILibrarySymbolData;
+import org.debian.javahelper.symbols.ISymbol;
+import org.debian.javahelper.symbols.ISymbolContainer;
+import org.debian.javahelper.symbols.ISymbolDiff;
+import org.debian.javahelper.symbols.ISymbolDiff.SymbolDiffStatus;
+
+
+public class DiffProgram implements IProgram {
+
+	public int exec(String[] args) throws Exception {
+		Factory fac = Factory.newInstance();
+		IDifferenceMaker differ = fac.createDifferenceMaker();
+		ISymbolContainer oData;
+		ISymbolContainer nData;
+		ISymbolDiff diff;
+		if(args.length != 3) {
+			throw new IllegalProgramArgumentsException("Usage: diff <org lib/sym-file> <new lib/sym-file>");
+		}
+		if(args[1].toLowerCase().endsWith(".jar") || args[1].toLowerCase().endsWith(".zip")){
+			ILibraryParser libpar = fac.createLibraryParser();
+			libpar.parseLibrary(new File(args[1]), "<pkg>", "0.0");
+			oData = libpar.getExportedSymbols();
+		} else if(args[1].equals("") || args[1].equals("/dev/null")) {
+			oData = IDifferenceMaker.EMPTY_SYMBOL_CONTAINER;
+		} else {
+			ILibrarySymbolData d = fac.createSymbolData();
+			oData = d;
+			d.read(args[1]);
+		}
+		if(args[2].toLowerCase().endsWith(".jar") || args[2].toLowerCase().endsWith(".zip")){
+			ILibraryParser libpar = fac.createLibraryParser();
+			libpar.parseLibrary(new File(args[2]), "<pkg>", "0.0");
+			nData = libpar.getExportedSymbols();
+		} else if(args[2].equals("") || args[2].equals("/dev/null")) {
+			nData = IDifferenceMaker.EMPTY_SYMBOL_CONTAINER;
+		} else {
+			ILibrarySymbolData d = fac.createSymbolData();
+			nData = d;
+			d.read(args[2]);
+		}
+		diff = differ.diff(oData, nData);
+		printDiff(diff);
+		return 0;
+	}
+
+	private static void printDiff(ISymbolDiff diff) {
+		printDiff(diff, "");
+	}
+
+	private static void printDiff(ISymbolDiff diff, String pre) {
+		SymbolDiffStatus stat = diff.getDiffStatus();
+		if(stat == SymbolDiffStatus.UNCHANGED){
+			return;
+		}
+		printDiffList(diff.getNewSymbols(), "+", pre);
+		printDiffList(diff.getMissingSymbols(), "-", pre);
+		printDiffList(diff.getModifiedSymbols(), " ", pre);
+	}
+
+	private static void printDiffList(List<ISymbolDiff> syms, String s, String pre){
+		for(ISymbolDiff diff : syms){
+			ISymbol nsym = diff.getNewSymbol();
+			ISymbol osym = diff.getOldSymbol();
+			if(nsym == null && osym == null) {
+				throw new IllegalArgumentException();
+			}
+			//FIXME: handle changed / removed
+			if(nsym != null) {
+				if(nsym.isClassSymbol()){
+					IClassSymbol cl = nsym.asClassSymbol();
+					System.out.println(s + pre + nsym.getClassName() + ": " + cl.getParentClassName() + " "+
+							SL2S(cl.getImplementedInterfaceNames()));
+					printDiff(diff, pre + "  ");
+				} else {
+					System.out.println(s + pre + nsym.getName());
+				}
+			}
+
+		}
+	}
+
+	private static final String SL2S(List<String> l){
+		int i = 0;
+		StringBuilder b = new StringBuilder();
+		for(String s : l){
+			if(i++ > 0) {
+				b.append(',');
+			}
+			b.append(s);
+		}
+		return b.toString();
+	}
+}
diff --git a/src/org/debian/javahelper/symbols/cmd/GenerateProgram.java b/src/org/debian/javahelper/symbols/cmd/GenerateProgram.java
new file mode 100644
index 0000000..68ac649
--- /dev/null
+++ b/src/org/debian/javahelper/symbols/cmd/GenerateProgram.java
@@ -0,0 +1,41 @@
+package org.debian.javahelper.symbols.cmd;
+
+import java.io.File;
+
+import org.debian.javahelper.symbols.Factory;
+import org.debian.javahelper.symbols.ILibraryParser;
+import org.debian.javahelper.symbols.ILibrarySymbolData;
+
+public class GenerateProgram implements IProgram {
+
+	public int exec(String[] args) throws IllegalProgramArgumentsException, Exception {
+		Factory fac = Factory.newInstance();
+		ILibrarySymbolData symdata;
+		ILibrarySymbolData usagedata = null;
+		String out = null;
+		String usageOut = null;
+		if(args.length < 3 || args.length > 6){
+			throw new IllegalProgramArgumentsException("Usage: gen <library> <pkg> <version> [write-to] [usage-to]");
+		}
+		if(args.length >= 5) {
+			out = args[4];
+			if(args.length == 6) {
+				usageOut = args[5];
+			}
+		}
+		ILibraryParser libpar = fac.createLibraryParser();
+		libpar.parseLibrary(new File(args[1]), args[2], args[3]);
+		symdata = libpar.getExportedSymbols();
+		usagedata = libpar.getUsedSymbols();
+		if(out != null) {
+			System.out.println("Writing to: " + out);
+			symdata.write(out);
+		}
+		if(usageOut != null && usagedata != null) {
+			System.out.println("Writing usage info to: " + usageOut);
+			usagedata.write(usageOut);
+		}
+		return 0;
+	}
+
+}
diff --git a/src/org/debian/javahelper/symbols/cmd/IProgram.java b/src/org/debian/javahelper/symbols/cmd/IProgram.java
new file mode 100644
index 0000000..9737e55
--- /dev/null
+++ b/src/org/debian/javahelper/symbols/cmd/IProgram.java
@@ -0,0 +1,30 @@
+package org.debian.javahelper.symbols.cmd;
+
+
+public interface IProgram {
+
+	/**
+	 * If returned from exec, the usage will be printed and the program will exit with
+	 * code 0.
+	 */
+	//public static final int HELP_AND_EXIT = 256;
+
+	/**
+	 * Called to run a specific program.
+	 * 
+	 * @param args Command-line args (C-style: args[0] refers to IProgram itself)
+	 * @return The exit code (0 <= code <= 255) or {@link #HELP_AND_EXIT}
+	 * @throws Exception If any
+	 */
+	public int exec(String[] args) throws IllegalProgramArgumentsException, Exception;
+
+	/**
+	 * Output usage info (help) - This is called if
+	 * 
+	 * @param ps The stream to print it to
+	 * @param cmd The way this program was referred to.
+	 * @param extended If true, the full ("--help"-like) info; else just a short usage info.
+	 */
+	//public void usage(PrintStream ps, String cmd, boolean extended);
+
+}
diff --git a/src/org/debian/javahelper/symbols/cmd/IllegalProgramArgumentsException.java b/src/org/debian/javahelper/symbols/cmd/IllegalProgramArgumentsException.java
new file mode 100644
index 0000000..2f14de6
--- /dev/null
+++ b/src/org/debian/javahelper/symbols/cmd/IllegalProgramArgumentsException.java
@@ -0,0 +1,30 @@
+package org.debian.javahelper.symbols.cmd;
+
+public class IllegalProgramArgumentsException extends Exception {
+
+	private static final long serialVersionUID = 8554836660382761475L;
+
+	private final int exitCode;
+
+	/**
+	 * 
+	 * @param msg The message to be printed
+	 */
+	public IllegalProgramArgumentsException(String msg) {
+		this(1, msg);
+	}
+
+	public IllegalProgramArgumentsException(int exitCode, String msg) {
+		super(msg);
+		if(exitCode < 1 || exitCode > 255) {
+			exitCode = 1;
+		}
+		this.exitCode = exitCode;
+	}
+
+	public int getExitCode() {
+		return exitCode;
+	}
+
+
+}
diff --git a/src/org/debian/javahelper/symbols/internal/ClassSymbol.java b/src/org/debian/javahelper/symbols/internal/ClassSymbol.java
index 513e448..bdcf22b 100644
--- a/src/org/debian/javahelper/symbols/internal/ClassSymbol.java
+++ b/src/org/debian/javahelper/symbols/internal/ClassSymbol.java
@@ -35,6 +35,12 @@ public class ClassSymbol extends SimpleSymbol implements IClassSymbol {
 		return this.getClassName();
 	}
 
+	@Override
+	public String getFullSymbolName() {
+		return clname;
+	}
+
+
 	public ISymbol getSymbol(String name) {
 		return symMap.get(name);
 	}
diff --git a/src/org/debian/javahelper/symbols/internal/SimpleSymbol.java b/src/org/debian/javahelper/symbols/internal/SimpleSymbol.java
index 110f269..ce2914a 100644
--- a/src/org/debian/javahelper/symbols/internal/SimpleSymbol.java
+++ b/src/org/debian/javahelper/symbols/internal/SimpleSymbol.java
@@ -40,4 +40,9 @@ public class SimpleSymbol implements ISymbol {
 		return IClassSymbol.class.cast(this);
 	}
 
+
+	public String getFullSymbolName() {
+		return clname + "." + name;
+	}
+
 }


hooks/post-receive
-- 
UNNAMED PROJECT



More information about the pkg-java-commits mailing list