Exemplo n.º 1
0
  private void generateResourcesFile(final File resfile) {

    final Framework framework = projectResourceMgr.getFramework();
    final NodeEntryImpl node = framework.createFrameworkNode();
    node.setFrameworkProject(getName());
    final NodesFileGenerator generator;
    if (resfile.getName().endsWith(".xml")) {
      generator = new ResourceXMLGenerator(resfile);
    } else if (resfile.getName().endsWith(".yaml")) {
      generator = new NodesYamlGenerator(resfile);
    } else {
      getLogger()
          .error(
              "Unable to generate resources file. Unrecognized extension for dest file: "
                  + resfile.getAbsolutePath());
      return;
    }
    generator.addNode(node);
    try {
      generator.generate();
    } catch (IOException e) {
      getLogger().error("Unable to generate resources file: " + e.getMessage(), e);
    } catch (NodesGeneratorException e) {
      getLogger().error("Unable to generate resources file: " + e.getMessage(), e);
    }

    getLogger().debug("generated resources file: " + resfile.getAbsolutePath());
  }
Exemplo n.º 2
0
  /**
   * Update the resources file given an input Nodes set
   *
   * @param source the source nodes
   * @throws UpdateUtils.UpdateException if an error occurs while trying to update the resources
   *     file or generate nodes
   */
  public void updateNodesResourceFile(final Nodes source) throws UpdateUtils.UpdateException {

    final Nodes.Format format;
    final String nodesResourceFilePath = getNodesResourceFilePath();
    if (nodesResourceFilePath.endsWith(".xml")) {
      format = Nodes.Format.resourcexml;
    } else if (nodesResourceFilePath.endsWith(".yaml")) {
      format = Nodes.Format.resourceyaml;
    } else {
      throw new UpdateUtils.UpdateException(
          "Unable to determine file format for file: " + nodesResourceFilePath);
    }
    File resfile = null;
    try {
      resfile = File.createTempFile("resource-temp", ".nodes");
      resfile.deleteOnExit();
    } catch (IOException e) {
      throw new UpdateUtils.UpdateException("Unable to create temp file: " + e.getMessage(), e);
    }
    // serialize nodes and replace the nodes resource file
    final NodesFileGenerator generator;
    if (Nodes.Format.resourcexml == format) {
      generator = new ResourceXMLGenerator(resfile);
    } else if (Nodes.Format.resourceyaml == format) {
      generator = new NodesYamlGenerator(resfile);
    } else {
      getLogger()
          .error(
              "Unable to generate resources file. Unrecognized extension for dest file: "
                  + resfile.getAbsolutePath());
      return;
    }
    generator.addNodes(source.listNodes());
    try {
      generator.generate();
    } catch (IOException e) {
      throw new UpdateUtils.UpdateException(
          "Unable to generate resources file: " + e.getMessage(), e);
    } catch (NodesGeneratorException e) {
      throw new UpdateUtils.UpdateException(
          "Unable to generate resources file: " + e.getMessage(), e);
    }

    updateNodesResourceFile(resfile);
    resfile.delete();
    getLogger().debug("generated resources file: " + resfile.getAbsolutePath());
  }