Пример #1
0
  /**
   * Constructor
   *
   * @param name Name of the project
   * @param basedir the base directory for the Depot
   */
  public FrameworkProject(
      final String name, final File basedir, final IFrameworkProjectMgr resourceMgr) {
    super(name, basedir, resourceMgr);
    projectResourceMgr = resourceMgr;
    resourcesBaseDir = new File(getBaseDir(), "resources");
    etcDir = new File(getBaseDir(), ETC_DIR_NAME);
    if (!etcDir.exists()) {
      if (!etcDir.mkdirs()) {
        throw new FrameworkResourceException(
            "error while creating project structure. "
                + "failed creating directory: "
                + etcDir.getAbsolutePath(),
            this);
      }
    }

    if (!(new File(getEtcDir(), PROP_FILENAME).exists())) {
      generateProjectPropertiesFile(false);
    }
    final Properties ownProps = new Properties();
    ownProps.setProperty("project.name", name);
    final File fwkDepotPropertyFile =
        new File(projectResourceMgr.getFramework().getConfigDir(), PROP_FILENAME);
    final Properties nodeWideDepotProps = PropertyLookup.fetchProperties(fwkDepotPropertyFile);
    nodeWideDepotProps.putAll(ownProps);
    propertyFile = new File(getEtcDir(), PROP_FILENAME);
    if (propertyFile.exists()) {
      lookup =
          PropertyLookup.create(
              propertyFile,
              nodeWideDepotProps,
              projectResourceMgr.getFramework().getPropertyLookup());
      getLogger().debug("loading existing project.properties: " + propertyFile.getAbsolutePath());

    } else {
      lookup =
          PropertyLookup.create(
              fwkDepotPropertyFile,
              ownProps,
              projectResourceMgr.getFramework().getPropertyLookup());
      getLogger()
          .debug("loading instance-level project.properties: " + propertyFile.getAbsolutePath());
    }
    lookup.expand();

    final String resfilepath = getNodesResourceFilePath();
    File resfile = new File(resfilepath);
    if (!resfile.isFile() && shouldUpdateNodesResourceFile()) {
      try {
        updateNodesResourceFile();
      } catch (UpdateUtils.UpdateException e) {
        getLogger().error("Unable to retrieve resources file: " + e.getMessage());
      }
    } else if (!resfile.isFile()) {
      generateResourcesFile(resfile);
    }
    initialize();
  }
Пример #2
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());
  }
Пример #3
0
 /**
  * Return specific nodes resources file path for the project, based on the
  * framework.nodes.file.name property
  *
  * @return
  */
 public String getNodesResourceFilePath() {
   if (hasProperty(PROJECT_RESOURCES_FILE_PROPERTY)) {
     return new File(getProperty(PROJECT_RESOURCES_FILE_PROPERTY)).getAbsolutePath();
   }
   final Framework framework = projectResourceMgr.getFramework();
   final String s;
   if (framework.hasProperty(Framework.NODES_RESOURCES_FILE_PROP)) {
     return new File(getEtcDir(), framework.getProperty(Framework.NODES_RESOURCES_FILE_PROP))
         .getAbsolutePath();
   } else {
     return new File(getEtcDir(), NODES_XML).getAbsolutePath();
   }
 }
Пример #4
0
 public static boolean exists(
     final String project, final IFrameworkProjectMgr projectResourceMgr) {
   return projectResourceMgr.existsFrameworkProject(project);
 }