You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.internal.tools.build;
  14. import java.io.File;
  15. import java.util.Hashtable;
  16. /**
  17. * Registration and factory for modules
  18. * @see Module
  19. * @see Builder
  20. */
  21. public class Modules {
  22. private final Hashtable<String,Module> modules = new Hashtable<String,Module>();
  23. public final File baseDir;
  24. public final File jarDir;
  25. private final Messager handler;
  26. public Modules(File baseDir, File jarDir, Messager handler) {
  27. this.baseDir = baseDir;
  28. this.jarDir = jarDir;
  29. this.handler = handler;
  30. Util.iaxIfNotCanReadDir(baseDir, "baseDir");
  31. Util.iaxIfNotCanReadDir(jarDir, "jarDir");
  32. Util.iaxIfNull(handler, "handler");
  33. }
  34. /**
  35. * Get module associated with name.
  36. * @return fail if unable to find or create module {name}.
  37. */
  38. public Module getModule(String name) {
  39. if (null == name) {
  40. return null;
  41. }
  42. Module result = (Module) modules.get(name);
  43. if (null == result) {
  44. File moduleDir = new File(baseDir, name);
  45. if (!Util.canReadDir(moduleDir)) {
  46. handler.error("not a module: " + name);
  47. } else {
  48. result = new Module(moduleDir, jarDir, name, this, handler);
  49. if (result.valid) {
  50. modules.put(name, result);
  51. } else {
  52. handler.error("invalid module: " + result.toLongString());
  53. }
  54. }
  55. }
  56. return result;
  57. }
  58. }