コード例 #1
0
 /**
  * Return a directive suitable for publication as an external description.
  *
  * @param module the enclosing module
  * @return the resource directive
  */
 ResourceDirective exportResource(final DefaultModule module) {
   if (null == m_directive) {
     final String error = "Cannot export from the root module.";
     throw new UnsupportedOperationException(error);
   }
   String name = getName();
   String version = getVersion();
   String basedir = null;
   InfoDirective info = m_directive.getInfoDirective();
   TypeDirective[] types = m_directive.getTypeDirectives();
   TypeDirective[] exportedTypes = createExportedTypes(types);
   DependencyDirective[] dependencies = createDeps(module);
   Properties properties = getExportProperties();
   return ResourceDirective.createResourceDirective(
       name,
       version,
       Classifier.EXTERNAL,
       basedir,
       info,
       exportedTypes,
       dependencies,
       properties,
       null,
       true);
 }
コード例 #2
0
  /**
   * Creation of a new default resource.
   *
   * @param library the reference library
   * @param module the parent module
   * @param directive the resource directive
   */
  DefaultResource(
      final DefaultLibrary library, final DefaultModule module, final ResourceDirective directive) {
    super(module, directive);
    if (null == directive) {
      throw new NullPointerException("directive");
    }

    m_library = library;
    m_directive = directive;
    m_parent = module;

    if (module.isRoot()) {
      m_path = directive.getName();
    } else {
      m_path = module.getResourcePath() + "/" + directive.getName();
    }

    // setup produced types

    TypeDirective[] types = directive.getTypeDirectives();
    m_types = new Type[types.length];
    m_typeNames = new String[types.length];
    for (int i = 0; i < types.length; i++) {
      TypeDirective type = types[i];
      m_types[i] = new DefaultType(this, type);
      m_typeNames[i] = type.getID();
    }

    // setup the resource basedir

    File anchor = getAnchor();
    String filename = m_directive.getBasedir();
    if (null != filename) {
      String spec = resolve(filename);
      File file = new File(spec);
      if (file.isAbsolute()) {
        m_basedir = getCanonicalFile(file);
      } else {
        File basedir = new File(anchor, spec);
        m_basedir = getCanonicalFile(basedir);
        setProperty("basedir", m_basedir.toString());
      }
    } else {
      if (!m_directive.getClassifier().equals(Classifier.LOCAL)) {
        m_basedir = null;
      } else {
        final String error = "Missing base directory declaration in resource [" + m_path + "].";
        throw new ValidationException(error);
      }
    }

    // setup the default properties

    setProperty("project.name", getName());
    if (null != m_parent) {
      setProperty("project.group", m_parent.getResourcePath());
    } else {
      setProperty("project.group", "");
    }
    String version = getVersion();
    if (null != version) {
      setProperty("project.version", version);
    }

    // setup filters

    FilterDirective[] filters = directive.getFilterDirectives();
    for (int i = 0; i < filters.length; i++) {
      FilterDirective filter = filters[i];
      String token = filter.getToken();
      m_filters.put(token, filter);
    }
  }