Exemple #1
0
  private static void check(MimeType type, String str) throws Exception {
    References references;

    Node node = WORLD.getTemp().createTempFile();
    node.writeString(str);
    references = References.create(type, true, node);
    references.readBytes();
    node.deleteFile();

    System.gc();
    Thread.sleep(1000);

    System.out.println("Startup done");
    Thread.sleep(20000);
    System.out.println("computing ...");

    node = WORLD.getTemp().createTempFile();
    node.writeString(str);
    references = References.create(type, true, node);
    references.readBytes();
    node.deleteFile();

    System.out.println("busy wait to keep references");
    for (; ; ) ;
  }
Exemple #2
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);
    }
  }
Exemple #3
0
  protected void writeCssTo(Writer writer, Output output) throws IOException {
    Object[] results;
    Mapper mapper;
    Node node;

    if (output.getMuted()) {
      throw new IllegalArgumentException();
    }
    mapper = SSASS.newInstance();
    mapper.setErrorHandler(new ExceptionErrorHandler());
    for (int i = 0; i < nodes.size(); i++) {
      node = nodes.get(i);
      if (i > 0) {
        writer.write(LF);
      }
      if (!overallMinimize) {
        writer.write(type.comment(location(node)));
      }
      results = mapper.run(node);
      if (results == null) {
        throw new IOException(node.toString() + ": css/sass error");
      }
      output.setMuted(declarationsOnly.get(i));
      try {
        ((Stylesheet) results[0]).toCss(output);
      } catch (GenericException e) {
        throw new IOException(node.toString() + ": css generation failed: " + e.getMessage(), e);
      }
      if (output.getMuted() != declarationsOnly.get(i)) {
        throw new IllegalStateException();
      }
    }
  }
Exemple #4
0
 public void save(String json, String action, String method) {
   try {
     Node file = methodDirectory(method).join(filename(action, ".log"));
     file.writeString(json);
   } catch (IOException e) {
     throw new RuntimeException("ToDo: Handle this", e);
   }
 }
Exemple #5
0
 public void save(byte[] screenshot, String action, String method) {
   try {
     Node file = methodDirectory(method).join(filename(action, ".png"));
     file.writeBytes(screenshot);
   } catch (IOException e) {
     throw new RuntimeException("ToDo: Handle this", e);
   }
 }
Exemple #6
0
  /* @return -1 for unknown */
  public long getLastModified() throws GetLastModifiedException {
    long result;

    result = Long.MIN_VALUE;
    for (Node node : nodes) {
      if (node instanceof WebdavNode) {
        // skip getLastModified - it's not supported by Webservice Stub Servlet
      } else {
        result = Math.max(result, node.getLastModified());
      }
    }
    return result == Long.MIN_VALUE ? -1 : result;
  }
Exemple #7
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();
  }
Exemple #8
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();
    }
  }
Exemple #9
0
  private void doInvoke(
      int currentDepth,
      Node parent,
      boolean parentIsLink,
      List<Object[]> includes,
      List<Object[]> excludes,
      Action result)
      throws IOException {
    List<? extends Node> children;
    List<Object[]> remainingIncludes;
    List<Object[]> remainingExcludes;
    String name;
    boolean childIsLink;
    boolean in;
    boolean ex;

    if (currentDepth >= maxDepth) {
      return;
    }
    if (!followLinks && parentIsLink) {
      return;
    }
    try {
      children = list(parent, includes);
    } catch (IOException e) {
      result.enterFailed(parent, parentIsLink, e);
      return;
    }
    if (children == null) {
      // ignore file
    } else {
      result.enter(parent, parentIsLink);
      currentDepth++;
      for (Node child : children) {
        name = child.getName();
        childIsLink = child.isLink();
        remainingIncludes = new ArrayList<>();
        remainingExcludes = new ArrayList<>();
        in = doMatch(name, includes, remainingIncludes);
        ex = doMatch(name, excludes, remainingExcludes);
        if (in && !ex && currentDepth >= minDepth && matchPredicates(child, childIsLink)) {
          result.select(child, childIsLink);
        }
        if (remainingIncludes.size() > 0 && !excludesAll(remainingExcludes)) {
          doInvoke(currentDepth, child, childIsLink, remainingIncludes, remainingExcludes, result);
        }
      }
      result.leave(parent, parentIsLink);
    }
  }
Exemple #10
0
 private static String readString(Node node) throws IOException {
   try {
     return node.readString();
   } catch (CreateInputStreamException e) {
     if ((e.getCause() instanceof org.apache.http.NoHttpResponseException)
         && (node instanceof WebdavNode)) {
       try {
         return node.readString();
       } catch (IOException e2) {
         e.addSuppressed(e2);
         throw e;
       }
     }
     throw e;
   }
 }
Exemple #11
0
  // do not return full paths -- security!
  public static String location(Node node) {
    String name;
    int idx;

    if (node instanceof ZipNode) {
      name = ((ZipNode) node).getRoot().getZip().getName();
      idx = name.lastIndexOf('/');
      if (idx >= 0) {
        name = name.substring(idx + 1);
      }
      return "zip:" + name + "/" + node.getPath();
    } else if (node instanceof FileNode) {
      return "file:" + node.getRelative(node.getWorld().getWorking());
    } else if (node instanceof WebdavNode) {
      return "http:" + node.getName() + ((WebdavNode) node).getQuery();
    } else {
      return node.getName();
    }
  }
Exemple #12
0
 /**
  * Main methods of this class.
  *
  * @throws IOException as thrown by the specified FileTask
  */
 public void invoke(Node root, Action result) throws IOException {
   doInvoke(0, root, root.isLink(), new ArrayList<>(includes), new ArrayList<>(excludes), result);
 }
Exemple #13
0
 public boolean matches(Node node, boolean isLink) throws ExistsException {
   return node.isDirectory();
 }
Exemple #14
0
 private Node classDirectory() throws IOException {
   return baseDirectory.join(testClass.getSimpleName()).mkdirsOpt();
 }