Ejemplo n.º 1
0
  /**
   * Set embedded cassandra up and spawn it in a new thread.
   *
   * @throws TTransportException
   * @throws IOException
   * @throws InterruptedException
   */
  public void start()
      throws TTransportException, IOException, InterruptedException, ConfigurationException {

    File dir = Files.createTempDir();
    String dirPath = dir.getAbsolutePath();
    System.out.println("Storing Cassandra files in " + dirPath);

    URL url = Resources.getResource("cassandra.yaml");
    String yaml = Resources.toString(url, Charsets.UTF_8);
    yaml = yaml.replaceAll("REPLACEDIR", dirPath);
    String yamlPath = dirPath + File.separatorChar + "cassandra.yaml";
    org.apache.commons.io.FileUtils.writeStringToFile(new File(yamlPath), yaml);

    // make a tmp dir and copy cassandra.yaml and log4j.properties to it
    copy("/log4j.properties", dir.getAbsolutePath());
    System.setProperty("cassandra.config", "file:" + dirPath + yamlFilePath);
    System.setProperty("log4j.configuration", "file:" + dirPath + "/log4j.properties");
    System.setProperty("cassandra-foreground", "true");

    cleanupAndLeaveDirs();

    try {
      executor.execute(new CassandraRunner());
    } catch (RejectedExecutionException e) {
      log.error("RejectError", e);
      return;
    }

    try {
      TimeUnit.SECONDS.sleep(WAIT_SECONDS);
    } catch (InterruptedException e) {
      log.error("InterrputedError", e);
      throw new AssertionError(e);
    }
  }
Ejemplo n.º 2
0
  public void importFromFile(String filePath) throws IOException {
    Map<String, Long> cache = new HashMap<String, Long>(COUNT);
    final File storeDir = new File(this.path);
    org.apache.commons.io.FileUtils.deleteDirectory(storeDir);
    BatchInserter batchInserter = new BatchInserterImpl(storeDir.getAbsolutePath());
    final BatchInserterIndexProvider indexProvider =
        new LuceneBatchInserterIndexProvider(batchInserter);
    final BatchInserterIndex index =
        indexProvider.nodeIndex("nodes", MapUtil.stringMap("type", "exact"));
    BufferedReader reader = new BufferedReader(new FileReader(filePath));
    String line = null;
    int nodes = 0;
    long time = System.currentTimeMillis();
    long batchTime = time;
    while ((line = reader.readLine()) != null) {
      final String[] nodeNames = line.split("\\|");
      final String name = nodeNames[0];
      final Map<String, Object> props = MapUtil.map("name", name);
      final long node = batchInserter.createNode(props);
      index.add(node, props);
      cache.put(name, node);
      nodes++;
      if ((nodes % REPORT_COUNT) == 0) {
        System.out.printf(
            "%d nodes created. Took %d %n", nodes, (System.currentTimeMillis() - batchTime));
        batchTime = System.currentTimeMillis();
      }
    }

    System.out.println("Creating nodes took " + (System.currentTimeMillis() - time) / 1000);
    index.flush();
    reader.close();
    reader = new BufferedReader(new FileReader(filePath));
    int rels = 0;
    time = System.currentTimeMillis();
    batchTime = time;
    String relationshipType = "KNOWS";
    while ((line = reader.readLine()) != null) {
      final String[] nodeNames = line.split("\\|");
      final String name = nodeNames[0];
      // final Long from = index.get("name", name).getSingle();
      Long from = cache.get(name);
      for (int j = 1; j < nodeNames.length; j++) {
        // final Long to = index.get("name", nodeNames[j]).getSingle();
        final Long to = cache.get(name);
        batchInserter.createRelationship(
            from, to, DynamicRelationshipType.withName(relationshipType), null);
      }
      rels++;
      if ((rels % REPORT_COUNT) == 0) {
        System.out.printf(
            "%d relationships created. Took %d %n", rels, (System.currentTimeMillis() - batchTime));
        batchTime = System.currentTimeMillis();
      }
    }
    System.out.println("Creating relationships took " + (System.currentTimeMillis() - time) / 1000);
    indexProvider.shutdown();
    batchInserter.shutdown();
  }
Ejemplo n.º 3
0
  /**
   * Take a screenshoot, log an Running Error into test result file.
   *
   * @param e
   * @param dr
   * @param tcName
   * @throws Exception
   */
  public void logCaseFail(String e, WebDriver dr, String tcName) throws Exception {
    try {
      if (tcName.trim() == "") {
        tcName = oi.logRunningTC;
      }

      if (StringUtils.left(tcName, 4).equals("test")) {
        tcName = StringUtils.mid(tcName, 4, tcName.length());
      }

      // log fail

      System.out.println(init.logErrorPrefixMsg + "Test Case Name:" + tcName + " ERROR: " + e);
      String tmp = "" + ran.nextInt(100000);
      String picName = oi.reportFilePath + "pic-" + tmp + ".jpg";

      String tmpStepLog = "";
      tmpStepLog = ",At step " + init.currentStep + " of " + init.sumStep;

      if (e.contains("\n")) {
        oi.logList.add(
            tcName
                + ","
                + init.logErrorPrefixMsg
                + tmpStepLog
                + ","
                + " Photo: "
                + picName
                + ","
                + e.toString().substring(0, e.toString().indexOf("\n")));
      } else {
        oi.logList.add(
            tcName
                + ","
                + init.logErrorPrefixMsg
                + tmpStepLog
                + ","
                + " Photo: "
                + picName
                + ","
                + e);
      }

      // taking screenshot
      org.apache.commons.io.FileUtils.copyFile(
          ((TakesScreenshot) dr).getScreenshotAs(OutputType.FILE), new File(picName));
    } catch (Exception e1) {
      throw e1;
    }

    // oi.reportFilePath = oi.reportFilePath + "error-" + tmp + "-";
  }
Ejemplo n.º 4
0
 /**
  * Takes an input dir and returns the du on that local directory. Very basic implementation.
  *
  * @param dir The input dir to get the disk space of this local dir
  * @return The total disk space of the input local directory
  */
 public static long getDU(File dir) {
   long size = 0;
   if (!dir.exists()) return 0;
   if (!dir.isDirectory()) {
     return dir.length();
   } else {
     File[] allFiles = dir.listFiles();
     if (allFiles != null) {
       for (int i = 0; i < allFiles.length; i++) {
         boolean isSymLink;
         try {
           isSymLink = org.apache.commons.io.FileUtils.isSymlink(allFiles[i]);
         } catch (IOException ioe) {
           isSymLink = true;
         }
         if (!isSymLink) {
           size += getDU(allFiles[i]);
         }
       }
     }
     return size;
   }
 }
Ejemplo n.º 5
0
  @Override
  public boolean publish(ProblemQuery problems) throws IOException {
    boolean ok;
    boolean subsetGoog = true;

    final String intermediateDirPath = outputFolder.getPath();
    final File intermediateDir = new File(intermediateDirPath);
    File srcDir = new File(configuration.getTargetFile());
    srcDir = srcDir.getParentFile();

    final String projectName = FilenameUtils.getBaseName(configuration.getTargetFile());
    final String outputFileName = projectName + "." + JSSharedData.OUTPUT_EXTENSION;

    File releaseDir = new File(outputParentFolder, FLEXJS_RELEASE_DIR_NAME);
    final String releaseDirPath = releaseDir.getPath();

    if (!isMarmotinniRun) {
      if (releaseDir.exists()) org.apache.commons.io.FileUtils.deleteQuietly(releaseDir);

      releaseDir.mkdirs();
    }

    // If the closure-lib parameter is empty we'll try to find the resources
    // in the classpath, dump its content to the output directory and use this
    // as closure-lib parameter.
    final String closureLibDirPath;
    if (((JSGoogConfiguration) configuration).isClosureLibSet()) {
      closureLibDirPath = ((JSGoogConfiguration) configuration).getClosureLib();
    } else {
      // Check if the "goog/deps.js" is available in the classpath.
      URL resource = Thread.currentThread().getContextClassLoader().getResource("goog/deps.js");
      if (resource != null) {
        File closureLibDir = new File(intermediateDir.getParent(), "closure");

        // Only create and dump the content, if the directory does not exists.
        if (!closureLibDir.exists()) {
          if (!closureLibDir.mkdirs()) {
            throw new IOException(
                "Unable to create directory for closure-lib at " + closureLibDir.getAbsolutePath());
          }

          // Strip the url of the parts we don't need.
          // Unless we are not using some insanely complex setup
          // the resource will always be on the same machine.
          String resourceJarPath = resource.getFile();
          if (resourceJarPath.contains(":")) {
            resourceJarPath = resourceJarPath.substring(resourceJarPath.lastIndexOf(":") + 1);
          }
          if (resourceJarPath.contains("!")) {
            resourceJarPath = resourceJarPath.substring(0, resourceJarPath.indexOf("!"));
          }
          File resourceJar = new File(resourceJarPath);

          // Dump the closure lib from classpath.
          dumpJar(resourceJar, closureLibDir);
        }
        // The compiler automatically adds a "closure" to the lib dir path,
        // so we omit this here.
        closureLibDirPath = intermediateDir.getParentFile().getPath();
      }
      // Fallback to the default.
      else {
        closureLibDirPath = ((JSGoogConfiguration) configuration).getClosureLib();
      }
    }

    final String closureGoogSrcLibDirPath = closureLibDirPath + "/closure/goog/";
    final String closureGoogTgtLibDirPath = intermediateDirPath + "/library/closure/goog";
    final String depsSrcFilePath = intermediateDirPath + "/library/closure/goog/deps.js";
    final String depsTgtFilePath = intermediateDirPath + "/deps.js";
    final String projectIntermediateJSFilePath =
        intermediateDirPath + File.separator + outputFileName;
    final String projectReleaseJSFilePath = releaseDirPath + File.separator + outputFileName;

    appendExportSymbol(projectIntermediateJSFilePath, projectName);
    appendEncodedCSS(projectIntermediateJSFilePath, projectName);

    if (!subsetGoog) {
      // (erikdebruin) We need to leave the 'goog' files and dependencies well
      //               enough alone. We copy the entire library over so the
      //               'goog' dependencies will resolve without our help.
      FileUtils.copyDirectory(
          new File(closureGoogSrcLibDirPath), new File(closureGoogTgtLibDirPath));
    }

    VF2JSClosureCompilerWrapper compilerWrapper = new VF2JSClosureCompilerWrapper();

    VF2JSDepsWriter gdw =
        new VF2JSDepsWriter(intermediateDir, projectName, (JSGoogConfiguration) configuration);
    try {
      StringBuilder depsFileData = new StringBuilder();
      ok = gdw.generateDeps(problems, depsFileData);
      if (!subsetGoog) {
        writeFile(depsTgtFilePath, depsFileData.toString(), false);
      } else {
        String s = depsFileData.toString();
        int c = s.indexOf("'goog.");
        ArrayList<String> googreqs = new ArrayList<String>();
        while (c != -1) {
          int c2 = s.indexOf("'", c + 1);
          String googreq = s.substring(c, c2 + 1);
          googreqs.add(googreq);
          c = s.indexOf("'goog.", c2);
        }
        HashMap<String, DependencyRecord> defmap = new HashMap<String, DependencyRecord>();
        // read in goog's deps.js
        FileInputStream fis = new FileInputStream(closureGoogSrcLibDirPath + "/deps.js");
        Scanner scanner = new Scanner(fis, "UTF-8");
        String addDependency = "goog.addDependency('";
        int currentLine = 0;
        while (scanner.hasNextLine()) {
          String googline = scanner.nextLine();
          if (googline.indexOf(addDependency) == 0) {
            int c1 = googline.indexOf("'", addDependency.length() + 1);
            String googpath = googline.substring(addDependency.length(), c1);
            String googdefs = googline.substring(googline.indexOf("[") + 1, googline.indexOf("]"));
            String googdeps =
                googline.substring(googline.lastIndexOf("[") + 1, googline.lastIndexOf("]"));
            String[] thedefs = googdefs.split(",");
            DependencyRecord deprec = new DependencyRecord();
            deprec.path = googpath;
            deprec.deps = googdeps;
            deprec.line = googline;
            deprec.lineNumber = currentLine;
            for (String def : thedefs) {
              def = def.trim();
              defmap.put(def, deprec);
            }
          }
          currentLine++;
        }
        // (erikdebruin) Prevent 'Resource leak' warning on line 212:
        scanner.close();
        ArrayList<DependencyRecord> subsetdeps = new ArrayList<DependencyRecord>();
        HashMap<String, String> gotgoog = new HashMap<String, String>();
        for (String req : googreqs) {
          DependencyRecord deprec = defmap.get(req);
          // if we've already processed this file, skip
          if (!gotgoog.containsKey(deprec.path)) {
            gotgoog.put(deprec.path, null);
            subsetdeps.add(deprec);
            addDeps(subsetdeps, gotgoog, defmap, deprec.deps);
          }
        }
        // now we should have the subset of files we need in the order needed
        StringBuilder sb = new StringBuilder();
        sb.append("goog.addDependency('base.js', ['goog'], []);\n");
        File file = new File(closureGoogSrcLibDirPath + "/base.js");
        FileUtils.copyFileToDirectory(file, new File(closureGoogTgtLibDirPath));
        compilerWrapper.addJSSourceFile(file.getCanonicalPath());
        Collections.sort(subsetdeps, new DependencyLineComparator());
        for (DependencyRecord subsetdeprec : subsetdeps) {
          sb.append(subsetdeprec.line).append("\n");
        }
        writeFile(depsTgtFilePath, sb.toString() + depsFileData.toString(), false);
        // copy the required files
        for (String googfn : gotgoog.keySet()) {
          file = new File(closureGoogSrcLibDirPath + File.separator + googfn);
          String dir = closureGoogTgtLibDirPath;
          if (googfn.contains("/")) {
            dir += File.separator + googfn.substring(0, googfn.lastIndexOf("/"));
          }
          FileUtils.copyFileToDirectory(file, new File(dir));
          compilerWrapper.addJSSourceFile(file.getCanonicalPath());
        }
      }
    } catch (InterruptedException e) {
      e.printStackTrace();
      return false;
    }

    IOFileFilter pngSuffixFilter =
        FileFilterUtils.and(FileFileFilter.FILE, FileFilterUtils.suffixFileFilter(".png"));
    IOFileFilter gifSuffixFilter =
        FileFilterUtils.and(FileFileFilter.FILE, FileFilterUtils.suffixFileFilter(".gif"));
    IOFileFilter jpgSuffixFilter =
        FileFilterUtils.and(FileFileFilter.FILE, FileFilterUtils.suffixFileFilter(".jpg"));
    IOFileFilter assetFiles = FileFilterUtils.or(pngSuffixFilter, jpgSuffixFilter, gifSuffixFilter);

    FileUtils.copyDirectory(srcDir, intermediateDir, assetFiles);
    FileUtils.copyDirectory(srcDir, releaseDir, assetFiles);

    File srcDeps = new File(depsSrcFilePath);

    // ToDo (erikdebruin): yeah, right, hard coded the path, nice!
    File sdkDepsFile =
        new File("/Users/erik/Documents/ApacheFlex/git/flex-asjs/vf2js/frameworks/js/sdk-deps.js");
    if (sdkDepsFile.exists())
      FileUtils.copyFile(
          sdkDepsFile, new File(intermediateDirPath + File.separator + "sdk-deps.js"));

    writeHTML("intermediate", projectName, intermediateDirPath, gdw.additionalHTML);
    writeHTML("release", projectName, releaseDirPath, gdw.additionalHTML);
    writeCSS(projectName, intermediateDirPath);
    writeCSS(projectName, releaseDirPath);

    if (!subsetGoog) {
      // (erikdebruin) add 'goog' files
      Collection<File> files =
          org.apache.commons.io.FileUtils.listFiles(
              new File(closureGoogTgtLibDirPath),
              new RegexFileFilter("^.*(\\.js)"),
              DirectoryFileFilter.DIRECTORY);
      for (File file : files) {
        compilerWrapper.addJSSourceFile(file.getCanonicalPath());
      }
    }

    // (erikdebruin) add project files
    for (String filePath : gdw.filePathsInOrder) {
      compilerWrapper.addJSSourceFile(new File(filePath).getCanonicalPath());
    }

    compilerWrapper.setOptions(projectReleaseJSFilePath, useStrictPublishing);

    // (erikdebruin) Include the 'goog' deps to allow the compiler to resolve
    //               dependencies.
    compilerWrapper.addJSSourceFile(closureGoogSrcLibDirPath + File.separator + "deps.js");

    List<String> externs = ((JSGoogConfiguration) configuration).getExternalJSLib();
    for (String extern : externs) {
      compilerWrapper.addJSExternsFile(extern);
    }

    compilerWrapper.targetFilePath = projectReleaseJSFilePath;
    compilerWrapper.compile();

    appendSourceMapLocation(projectReleaseJSFilePath, projectName);

    if (!isMarmotinniRun) {
      String allDeps = "";
      if (!subsetGoog) allDeps += FileUtils.readFileToString(srcDeps);
      allDeps += FileUtils.readFileToString(new File(depsTgtFilePath));

      FileUtils.writeStringToFile(srcDeps, allDeps);

      org.apache.commons.io.FileUtils.deleteQuietly(new File(depsTgtFilePath));
    }

    if (ok)
      System.out.println(
          "The project '" + projectName + "' has been successfully compiled and optimized.");

    return true;
  }