コード例 #1
0
ファイル: NodeFilter.java プロジェクト: rophy/rundeck
 public static INodeSet filterNodes(final NodesSelector selector, final INodeSet nodeSet) {
   final NodeSetImpl nodeSet1 = new NodeSetImpl();
   for (final INodeEntry iNodeEntry : nodeSet.getNodes()) {
     if (selector.acceptNode(iNodeEntry)) {
       nodeSet1.putNode(iNodeEntry);
     }
   }
   return nodeSet1;
 }
コード例 #2
0
  private void generateResourcesFile(final File resfile, final String format)
      throws ResourceModelSourceException {
    final NodeEntryImpl node = framework.createFrameworkNode();
    node.setFrameworkProject(configuration.project);
    final ResourceFormatGenerator generator;
    if (null != format) {
      try {
        generator = framework.getResourceFormatGeneratorService().getGeneratorForFormat(format);
      } catch (UnsupportedFormatException e) {
        throw new ResourceModelSourceException(e);
      }
    } else {
      try {
        generator =
            framework.getResourceFormatGeneratorService().getGeneratorForFileExtension(resfile);
      } catch (UnsupportedFormatException e) {
        throw new ResourceModelSourceException(e);
      }
    }
    if (configuration.includeServerNode) {
      NodeSetImpl nodes = new NodeSetImpl();
      nodes.putNode(node);

      if (!resfile.getParentFile().exists()) {
        if (!resfile.getParentFile().mkdirs()) {
          throw new ResourceModelSourceException(
              "Parent dir for resource file does not exists, and could not be created: " + resfile);
        }
      }

      try {
        final FileOutputStream stream = new FileOutputStream(resfile);
        try {
          generator.generateDocument(nodes, stream);
        } finally {
          stream.close();
        }
      } catch (IOException e) {
        throw new ResourceModelSourceException(e);
      } catch (ResourceFormatGeneratorException e) {
        throw new ResourceModelSourceException(e);
      }
    }
  }
コード例 #3
0
 /**
  * Returns a {@link INodeSet} object conatining the nodes config data.
  *
  * @param nodesFile the source file
  * @param format nodes format
  * @return an instance of {@link INodeSet}
  * @throws ResourceModelSourceException on error
  */
 public synchronized INodeSet getNodes(final File nodesFile, final String format)
     throws ResourceModelSourceException {
   final Long modtime = nodesFile.lastModified();
   if (0 == nodeSet.getNodes().size() || (modtime > lastModTime)) {
     nodeSet = new NodeSetImpl();
     loadNodes(nodesFile, format);
     lastModTime = modtime;
   }
   return nodeSet;
 }
コード例 #4
0
 private void loadNodes(final File nodesFile, final String format)
     throws ResourceModelSourceException {
   if (!nodesFile.isFile() && configuration.generateFileAutomatically) {
     generateResourcesFile(nodesFile, format);
   } else if (configuration.includeServerNode) {
     final NodeEntryImpl node = framework.createFrameworkNode();
     nodeSet.putNode(node);
   }
   if (nodesFile.isFile()) {
     final ResourceFormatParser parser = createParser(nodesFile, format);
     try {
       final INodeSet set = parser.parseDocument(nodesFile);
       if (null != set) {
         nodeSet.putNodes(set);
       }
     } catch (ResourceFormatParserException e) {
       throw new ResourceModelSourceException(e);
     }
   } else if (configuration.requireFileExists) {
     throw new ResourceModelSourceException("File does not exist: " + nodesFile);
   }
 }