[Nice-commit] Nice/src/bossa/modules Locator.java,1.3,1.4 DirectorySourceContent.java,1.2,1.3 Compil
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-07-02 19:31:14
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14796/src/bossa/modules Modified Files: Locator.java DirectorySourceContent.java CompiledContent.java Log Message: Abstracted the resource location in pathes in the nice.tools.locator package. Index: Locator.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Locator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Locator.java 7 Aug 2003 09:53:39 -0000 1.3 --- Locator.java 2 Jul 2004 19:31:03 -0000 1.4 *************** *** 30,35 **** Locator (Compilation compilation, String classpath) { ! sourceRoots = splitPath(compilation.sourcePath); ! packageRoots = splitPath(classpath); } --- 30,52 ---- Locator (Compilation compilation, String classpath) { ! sources = new nice.tools.locator.Locator ! (compilation.sourcePath, ! new gnu.mapping.Procedure1() { ! public Object apply1(Object o) { ! String message = (String) o; ! User.warning(message); ! return null; ! } ! }); ! ! packages = new nice.tools.locator.Locator ! (classpath, ! new gnu.mapping.Procedure1() { ! public Object apply1(Object o) { ! String message = (String) o; ! User.warning(message); ! return null; ! } ! }); } *************** *** 39,57 **** CompiledContent compiled = null; ! String filesystemName = pkg.getName().replace('.', File.separatorChar); ! ! for (int i = 0; source == null && i < sourceRoots.length; i++) ! // source files cannot be in Jar files ! if (sourceRoots[i] instanceof File) ! source = DirectorySourceContent.create ! (pkg, new File((File) sourceRoots[i], filesystemName)); - for (int i = 0; compiled == null && i < packageRoots.length; i++) - if (packageRoots[i] instanceof File) - compiled = DirectoryCompiledContent.create - (pkg, new File((File) packageRoots[i], filesystemName)); - else - compiled = JarCompiledContent.create(pkg, (JarFile) packageRoots[i]); - Content res = new Content(pkg, source, compiled); --- 56,70 ---- CompiledContent compiled = null; ! String name = pkg.getName().replace('.', '/'); ! ! java.net.URLConnection sroot = sources.get(name); ! java.net.URLConnection croot = packages.get(name + "/package.nicei"); ! ! if (sroot != null) ! source = DirectorySourceContent.create(pkg, sroot.getURL()); ! ! if (croot != null) ! compiled = CompiledContent.create(pkg, croot.getURL()); Content res = new Content(pkg, source, compiled); *************** *** 65,115 **** * Private ****************************************************************/ ! /** where to find source files. */ ! private final Object[] sourceRoots; /** where to find compiled packages. */ ! private final Object[] packageRoots; ! ! private static Object[] splitPath (String path) ! { ! LinkedList res = new LinkedList(); ! ! int start = 0; ! // skip starting separators ! while (start<path.length() && ! path.charAt(start) == File.pathSeparatorChar) ! start++; ! ! while(start<path.length()) ! { ! int end = path.indexOf(File.pathSeparatorChar, start); ! if (end == -1) ! end = path.length(); ! ! String pathComponent = path.substring(start, end); ! if (pathComponent.length() > 0) ! { ! File f = nice.tools.util.System.getFile(pathComponent).getAbsoluteFile(); ! // Ignore non-existing directories and archives ! if (f.exists()) ! { ! if (pathComponent.endsWith(".jar")) ! try{ ! res.add(new JarFile(f)); ! } ! catch(IOException e){} ! else if (f.isDirectory()) ! res.add(f); ! else ! User.warning("Path " + f + " is not valid"); ! } ! else ! User.warning("Path " + f + " does not exist"); ! } ! start = end + 1; ! } ! ! return res.toArray(new Object[res.size()]); ! } } --- 78,86 ---- * Private ****************************************************************/ ! /** where to find source files. */ ! private final nice.tools.locator.Locator sources; /** where to find compiled packages. */ ! private final nice.tools.locator.Locator packages; } Index: DirectorySourceContent.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/DirectorySourceContent.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DirectorySourceContent.java 24 Jun 2003 15:28:19 -0000 1.2 --- DirectorySourceContent.java 2 Jul 2004 19:31:03 -0000 1.3 *************** *** 20,24 **** /** A package located in a directory. ! @version $Date$ @author Daniel Bonniot --- 20,24 ---- /** A package located in a directory. ! @version $Date$ @author Daniel Bonniot *************** *** 39,42 **** --- 39,50 ---- } + static DirectorySourceContent create(Package pkg, java.net.URL url) + { + if (! url.getProtocol().equals("file")) + User.error("Cannot use " + url + " to get sources for package " + pkg); + + return create(pkg, new File(url.getFile())); + } + DirectorySourceContent(Package pkg, File directory) { *************** *** 45,49 **** this.sources = getSources(); ! lastModification = maxLastModification(sources); } --- 53,57 ---- this.sources = getSources(); ! lastModification = maxLastModification(sources); } Index: CompiledContent.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/CompiledContent.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CompiledContent.java 18 Apr 2002 11:11:35 -0000 1.3 --- CompiledContent.java 2 Jul 2004 19:31:03 -0000 1.4 *************** *** 61,63 **** --- 61,87 ---- /** return a longer string that identifies the type of package source too. */ abstract public String toString(); + + static CompiledContent create(Package pkg, java.net.URL url) + { + if (url.getProtocol().equals("file")) + { + File dir = new File(url.getFile()).getParentFile(); + return DirectoryCompiledContent.create(pkg, dir); + } + + if (url.getProtocol().equals("jar")) + { + String jar = url.getFile(); + jar = jar.substring(jar.indexOf(':') + 1, jar.indexOf('!')); + try { + return JarCompiledContent.create + (pkg, new java.util.jar.JarFile(jar)); + } + catch(IOException e) { + return null; + } + } + + return null; + } } |