geirm 01/08/19 19:44:22 Modified: jjar/src/java/org/apache/commons/jjar DependencyEngine.java Log: Two changes : 1) Fixed the problem where you couldn't re-traverse the dependency graph Now you can. 2) Added new method getDependencies( List ) which lets you get a complete non-duplicating set of dependencies for a given list of projects. Revision Changes Path 1.2 +131 -4 jakarta-commons-sandbox/jjar/src/java/org/apache/commons/jjar/DependencyEngine.java Index: DependencyEngine.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jjar/src/java/org/apache/commons/jjar/DependencyEngine.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DependencyEngine.java 2001/05/07 22:47:45 1.1 +++ DependencyEngine.java 2001/08/20 02:44:22 1.2 @@ -58,6 +58,7 @@ import java.util.List; import java.util.Iterator; import java.util.ArrayList; +import java.lang.Thread; /** * <p> @@ -76,8 +77,12 @@ * when that happens * </p> * + * <p> + * This thing isn't close to threadsafe :) + * </p> + * * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a> - * @version $Id: DependencyEngine.java,v 1.1 2001/05/07 22:47:45 geirm Exp $ + * @version $Id: DependencyEngine.java,v 1.2 2001/08/20 02:44:22 geirm Exp $ */ public class DependencyEngine { @@ -85,6 +90,13 @@ private ArrayList buildList = null; /** + * this is a real sucky solution to something I don't want to + * think about right now... we use this to ensure that + * the information in our graph is fresh + */ + private long currentTimestamp = -1; + + /** * CTOR */ public DependencyEngine() @@ -100,6 +112,26 @@ try { + /* + * if we are called in the same millisecond as our + * last trip through, sleep as the sucky 'fresh graph' + * solution depends on this, and this would be quite + * an interesting time-dependent thing to debug :) + */ + if (System.currentTimeMillis() == currentTimestamp) + { + Thread.sleep(1); + } + + /* + * set the current time so we can see if our graph node + * state is for this trip, or a previous trip. + */ + currentTimestamp = System.currentTimeMillis(); + + /* + * now, just do it + */ doIt( pkg ); } catch( Exception e ) @@ -109,9 +141,50 @@ if( buildList.size() > 0) buildList.remove( buildList.size() - 1 ); + return buildList; } + + /** + * Generates a dependency list for a set of packages. + * + * @param packages List of strings, each string is a package name + * @return list of dependencies, in order + */ + public List getDependencies( List packages ) + { + HashMap h = new HashMap(); + ArrayList l = new ArrayList(); + + /* + * for each package, get the dependency list + * and drop them into the list if it's not already + * in there + */ + + for( Iterator i = packages.iterator(); i.hasNext(); ) + { + String pkg = (String) i.next(); + + List deps = getDependencies( pkg ); + + for (Iterator ii = deps.iterator(); ii.hasNext(); ) + { + String dep = (String) ii.next(); + + if ( h.get( dep ) == null) + { + h.put(dep, dep); + l.add(dep); + } + } + } + + return l; + } + + /** * from previous use - generates a dependency list * spanning the entire tree. Returns a list @@ -190,6 +263,17 @@ } /* + * get the timestamp and compare. If not the same, reset + */ + + if ( project.getTimestamp() != currentTimestamp) + { + project.setStatus( Node.ZILCH ); + } + + project.setTimestamp( currentTimestamp ); + + /* * check status of this one */ @@ -232,6 +316,17 @@ buildList.add( dep ); continue; } + + /* + * get the timestamp and compare. If not the same, reset + */ + + if ( depnode.getTimestamp() != currentTimestamp) + { + depnode.setStatus( Node.ZILCH ); + } + + depnode.setTimestamp( currentTimestamp ); /* * now, look at the status of this dependency @@ -404,23 +499,44 @@ d.addProject("F", deps, "F" ); /* - * generate the list + * generate the list of all */ List l = d.generateCookielist(); /* * show us */ - Iterator i = l.iterator(); while(i.hasNext()) { String s = (String) i.next(); - //System.out.println("Building : " + s ); + System.out.println("Building : " + s ); } + /* + * now test the 'project set' dep gen, so + * give it two projects - you should get out + * the correctly ordered list so that all + * can be correctly built + */ + + System.out.println("Mix test :"); + + ArrayList foo = new ArrayList(); + foo.add("E"); + foo.add("D"); + List foofoo = d.getDependencies(foo); + + i = foofoo.iterator(); + + while(i.hasNext()) + { + String s = (String) i.next(); + + System.out.println("Building : " + s ); + } } catch( Exception e ) { @@ -439,6 +555,7 @@ private ArrayList deps = new ArrayList(); private String name = ""; private Object cookie = null; + private long timestamp = 0; public Node( String name, Object cookie) { @@ -469,6 +586,16 @@ public int getStatus() { return status; + } + + public long getTimestamp() + { + return timestamp; + } + + public void setTimestamp( long t) + { + timestamp = t; } }