geirm 01/08/14 20:54:01 Modified: jjar/src/java/org/apache/commons/jjar RepositoryXML.java Log: Added support for distributed repository - this allows the repository to have package repository information stored at remote places. Revision Changes Path 1.2 +139 -82 jakarta-commons-sandbox/jjar/src/java/org/apache/commons/jjar/RepositoryXML.java Index: RepositoryXML.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jjar/src/java/org/apache/commons/jjar/RepositoryXML.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RepositoryXML.java 2001/05/07 22:47:45 1.1 +++ RepositoryXML.java 2001/08/15 03:54:01 1.2 @@ -83,7 +83,7 @@ * be careful * * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a> - * @version $Id: RepositoryXML.java,v 1.1 2001/05/07 22:47:45 geirm Exp $ + * @version $Id: RepositoryXML.java,v 1.2 2001/08/15 03:54:01 geirm Exp $ */ public class RepositoryXML extends MinML2 implements Repository { @@ -92,7 +92,7 @@ int packageCount = 0; /** handles package dependency generation */ - private DependencyEngine de = new DependencyEngine(); + private static DependencyEngine de = new DependencyEngine(); /** root of our document tree */ private Node root = null; @@ -125,13 +125,18 @@ */ public void load( URL url ) { + load( url, packageMap ); + } + + public void load( URL url, Map pkgMap ) + { try { URLConnection conn = url.openConnection(); InputStream is = conn.getInputStream(); parse(new InputStreamReader(new BufferedInputStream( is))); - process(); + process( pkgMap ); } catch ( IOException e) { @@ -219,9 +224,18 @@ */ public String getFetchTarget( String pkg, String version ) { + + /* + * first see if we know about this package. + */ + if (!isPackage( pkg )) return null; + /* + * next, get the package info and see if we have this version + */ + Map hp = (HashMap) packageMap.get( pkg ); Iterator i =((ArrayList) hp.get( VERSION_ARRAY )).iterator(); @@ -235,7 +249,6 @@ if (version.equals( ver ) ) { String out = (String) vi.get(VERSION_JAR); - return out; } } @@ -308,7 +321,7 @@ * internal data structures for use later. This needs to be * called right after parsing, and before use. */ - private void process() + private void process( Map pkgMap ) { /* * need to build a package list. Get the package groups. @@ -316,6 +329,9 @@ List packagegroup = getDocNodeList( root, "packagegroup"); + if (packagegroup == null) + System.out.println("Packagegroup == null"); + //System.out.println("packagegroup has " + packagegroup.size() + "elements"); Iterator i = packagegroup.iterator(); @@ -336,12 +352,12 @@ while( ii.hasNext() ) { - processPackageNode( (Node) ii.next() ); + processPackageNode( (Node) ii.next(), pkgMap ); } } } - private void processPackageNode( Node pkg ) + private void processPackageNode( Node pkg, Map pkgMap ) { HashMap pkginfo = new HashMap(); @@ -352,108 +368,149 @@ pkginfo.put( PACKAGENAME, pkg.getAttribute("name") ); pkginfo.put( DEFAULTVERSION, pkg.getAttribute("default")); pkginfo.put( NODE, pkg ); - - /* - * now get the information node - */ - - Node info = getDocNode( pkg, "info/desc"); - - if( info != null) - pkginfo.put( DESCRIPTION, info.getValue()); - - info = getDocNode( pkg, "info/href"); - - if( info != null) - pkginfo.put( HREF, info.getValue()); - - /* - * process version info - */ - List versionlist = getDocNodeList( pkg, "versionset/version"); - ArrayList versionArray = new ArrayList(); + /* + * does this have a definition here or remote? + */ - Iterator v = versionlist.iterator(); + Node def = getDocNode( pkg, "definition"); - while( v.hasNext() ) + if (def != null) { - Node n = (Node) v.next(); - - HashMap vi = new HashMap(); - - vi.put( VERSION, n.getAttribute("version") ); - - Node nn = getDocNode( n, "note"); - vi.put( VERSION_INFO, nn.getValue() ); + /* + * now get the information node + */ - nn = getDocNode( n, "jar"); - vi.put( VERSION_JAR, nn.getValue() ); + Node info = getDocNode( def, "info/desc"); - /* the dependencies */ + if( info != null) + pkginfo.put( DESCRIPTION, info.getValue()); - ArrayList deplist = new ArrayList(); + info = getDocNode( def, "info/href"); - List deps = getDocNodeList( n, "dependencies/dep"); - - if (deps != null) + if( info != null) + pkginfo.put( HREF, info.getValue()); + + /* + * process version info + */ + + List versionlist = getDocNodeList( def, "versionset/version"); + ArrayList versionArray = new ArrayList(); + + Iterator v = versionlist.iterator(); + + while( v.hasNext() ) { - Iterator ii = deps.iterator(); + Node n = (Node) v.next(); + + HashMap vi = new HashMap(); + + vi.put( VERSION, n.getAttribute("version") ); + + Node nn = getDocNode( n, "note"); + vi.put( VERSION_INFO, nn.getValue() ); + + nn = getDocNode( n, "jar"); + vi.put( VERSION_JAR, nn.getValue() ); - while( ii.hasNext() ) + /* the dependencies */ + + ArrayList deplist = new ArrayList(); + + List deps = getDocNodeList( n, "dependencies/dep"); + + if (deps != null) { - HashMap h = new HashMap(); - Node ndep = (Node) ii.next(); + Iterator ii = deps.iterator(); - h.put( DEP_PACKAGE, ndep.getAttribute("package") ); - h.put( DEP_VERSION, ndep.getAttribute("version") ); + while( ii.hasNext() ) + { + HashMap h = new HashMap(); + Node ndep = (Node) ii.next(); + + h.put( DEP_PACKAGE, ndep.getAttribute("package") ); + h.put( DEP_VERSION, ndep.getAttribute("version") ); + + deplist.add( h ); + } - deplist.add( h ); + vi.put( VERSION_DEPS, deplist ); } - vi.put( VERSION_DEPS, deplist ); - } - - versionArray.add( vi ); + versionArray.add( vi ); - /* - * add the package:version to the dependency engine - */ + /* + * add the package:version to the dependency engine + */ + + String token = pkginfo.get( PACKAGENAME ) + ":" + (String) vi.get( VERSION ); + + // System.out.println("Adding " + token + " to dependency engine."); + + ArrayList depar = new ArrayList(); + + Iterator depiter = deplist.iterator(); + + while( depiter.hasNext() ) + { + HashMap h = (HashMap) depiter.next(); + + String deptoken = (String) h.get(DEP_PACKAGE) + ":" + (String) h.get(DEP_VERSION); + depar.add( deptoken ); + } - String token = pkginfo.get( PACKAGENAME ) + ":" + (String) vi.get( VERSION ); + try + { + de.addProject( token, depar, token ); + } + catch( Exception e ) + {} - // System.out.println("Adding " + token + " to dependency engine."); + } - ArrayList depar = new ArrayList(); + pkginfo.put( VERSION_ARRAY, versionArray ); - Iterator depiter = deplist.iterator(); + /* + * add the info to the packageMap + */ + + pkgMap.put( pkginfo.get( PACKAGENAME ), pkginfo ); - while( depiter.hasNext() ) + // dumpPackageInfo( pkginfo ); + } + else + { + /* + * is this a remote repository? + */ + + Node remote = getDocNode( pkg, "remotedefinition"); + + if (remote != null) { - HashMap h = (HashMap) depiter.next(); + System.out.println( "Note package '" + ( (String) pkginfo.get( PACKAGENAME ) ) + + "' defining repository is remote, coming from " + remote.getValue() ); + + /* + * now recursively get the info + */ - String deptoken = (String) h.get(DEP_PACKAGE) + ":" + (String) h.get(DEP_VERSION); - depar.add( deptoken ); + try + { + RepositoryXML rep = new RepositoryXML(); + rep.load( new URL( remote.getValue() ), pkgMap ); + } + catch( Exception ee ) + {} } - - try + else { - de.addProject( token, depar, token ); + System.out.println("Malformed repository : neither <definition> or <remotedefinition>"); } - catch( Exception e ) - {} - + + } - - pkginfo.put( VERSION_ARRAY, versionArray ); - - /* - * add the info to the packageMap - */ - - packageMap.put( pkginfo.get( PACKAGENAME ), pkginfo ); - - // dumpPackageInfo( pkginfo ); } /**