01: /**************************************************************************/
02: /* N I C E */
03: /* A high-level object-oriented research language */
04: /* (c) Daniel Bonniot 2001 */
05: /* */
06: /* This program is free software; you can redistribute it and/or modify */
07: /* it under the terms of the GNU General Public License as published by */
08: /* the Free Software Foundation; either version 2 of the License, or */
09: /* (at your option) any later version. */
10: /* */
11: /**************************************************************************/package bossa.modules;
12:
13: import java.io.*;
14: import java.util.LinkedList;
15: import java.net.URL;
16: import bossa.util.Debug;
17: import bossa.util.User;
18: import nice.tools.repository.VersionTracker;
19:
20: /**
21: Locates package definitions.
22:
23: @version $Date: 2004/08/07 14:57:33 $
24: @author Daniel Bonniot (Daniel.Bonniot@inria.fr)
25: */
26:
27: final class Locator {
28: Locator(Compilation compilation, String classpath, URL repository) {
29: gnu.mapping.Procedure1 warning = new gnu.mapping.Procedure1() {
30: public Object apply1(Object o) {
31: String message = (String) o;
32: User.warning(message);
33: return null;
34: }
35: };
36:
37: sources = new nice.tools.locator.Locator(
38: compilation.sourcePath, warning);
39: packages = new nice.tools.locator.Locator(classpath, warning);
40:
41: vt = nice.tools.repository.dispatch.versionTracker(new File(
42: "nice.versions").getAbsoluteFile());
43: remote = new nice.tools.locator.Locator(vt
44: .repository(repository));
45: }
46:
47: Content find(Package pkg) {
48: SourceContent source = null;
49: CompiledContent compiled = null;
50:
51: String name = pkg.getName().replace('.', '/');
52:
53: java.net.URLConnection sroot = sources.get(name);
54: java.net.URLConnection croot = packages.get(name
55: + "/package.nicei");
56:
57: if (sroot != null)
58: source = DirectorySourceContent.create(pkg, sroot.getURL());
59:
60: // If the package couldn't be found locally, try remotely.
61: if (source == null && croot == null)
62: croot = remote.get(name + "/package.nicei");
63:
64: if (croot != null)
65: compiled = CompiledContent.create(pkg, croot.getURL());
66:
67: Content res = new Content(pkg, source, compiled);
68:
69: if (Debug.modules)
70: Debug.println("Locating " + pkg.getName() + ":\n" + res);
71:
72: return res;
73: }
74:
75: void save() {
76: vt.save();
77: }
78:
79: /****************************************************************
80: * Private
81: ****************************************************************/
82:
83: /** where to find source files. */
84: private final nice.tools.locator.Locator sources;
85:
86: /** where to find compiled packages. */
87: private final nice.tools.locator.Locator packages;
88:
89: /** remote location where to find imported packages. */
90: private final nice.tools.locator.Locator remote;
91:
92: private VersionTracker vt;
93: }
|