Esempio n. 1
0
  public static WarConfig fromXml(Node webapp) throws IOException {
    String path;
    Element root;
    Selector selector;
    List<String> statics;

    try {
      root = webapp.join("WEB-INF/project.xml").readXml().getDocumentElement();
      selector = webapp.getWorld().getXml().getSelector();
      statics = new ArrayList<>();
      for (Element element : selector.elements(root, "application/static/path")) {
        path = element.getTextContent();
        path = path.trim();
        if (path.isEmpty() || path.startsWith("/")) {
          throw new IllegalStateException(path);
        }
        if (!path.endsWith("/")) {
          path = path + "/";
        }
        statics.add(path);
      }
      return new WarConfig(statics);
    } catch (SAXException e) {
      throw new IOException("cannot load project descriptor: " + e);
    }
  }
Esempio n. 2
0
  private Node methodWithParameters(String method) throws IOException {
    String methodName = method.substring(0, method.indexOf('['));
    Node screenshotDir = classDirectory().join(methodName);

    int offset = 1;
    String unsplittedParameters =
        method.substring(method.indexOf('[') + offset, method.indexOf(']'));
    String[] parameters = unsplittedParameters.split("\\|");
    for (String parameter : parameters) {
      screenshotDir = screenshotDir.join(parameter);
    }
    return screenshotDir.mkdirsOpt();
  }
Esempio n. 3
0
  // avoids node.list() call if there is exactly 1 include with a literal head
  private List<? extends Node> list(Node node, List<Object[]> includes) throws IOException {
    Node child;

    if (includes.size() == 1 && includes.get(0)[0] instanceof String) {
      child = node.join((String) includes.get(0)[0]);
      if (child.exists()) {
        return Collections.singletonList(child);
      } else {
        return Collections.emptyList();
      }
    } else {
      return node.list();
    }
  }
Esempio n. 4
0
 private Node classDirectory() throws IOException {
   return baseDirectory.join(testClass.getSimpleName()).mkdirsOpt();
 }