private void addAllFilesFromDirectory(
      KnowledgeBuilder knowledgeBuilder,
      String directoryName,
      RulesBaseDirectory ruleBaseDirectory) {
    String baseDirectory = determineBaseDirectory(ruleBaseDirectory);
    File directory = fileFromBaseDirectory(directoryName, baseDirectory);

    if (!directory.exists()) {
      throw new TestFluxException(
          "Directory "
              + directory.getAbsolutePath()
              + " given by @"
              + RuleSource.class.getSimpleName()
              + " must exist (but does not).");
    }
    if (!directory.isDirectory()) {
      throw new TestFluxException(
          "Directory "
              + directory.getAbsolutePath()
              + " given by @"
              + RuleSource.class.getSimpleName()
              + " must denote a directory (but does not).");
    }

    Iterator<File> fileIterator = null;
    try {
      fileIterator = FileUtils.iterateFiles(directory, new String[] {"drl"}, false);
    } catch (Throwable t) {
      throw new TestFluxException("Caught " + t.getClass().getSimpleName() + ": " + t.getMessage());
    }

    for (File file : IterableAdapter.makeFrom(fileIterator)) {
      addIndividualFile(knowledgeBuilder, file);
    }
  }
 @Override
 public void initialize(UimaContext context) throws ResourceInitializationException {
   super.initialize(context);
   fileIterator = FileUtils.iterateFiles(new File(xmlDirectory), new String[] {"gz"}, true);
   try {
     reader = new PubMedParser();
   } catch (JAXBException e) {
     e.printStackTrace();
   }
 }
 @Override
 protected void setUp() throws Exception {
   // copy over the data we'll use for the migration test
   root = new File("./target/migration");
   File origin = new File("./src/test/resources/org/geowebcache/ms_removal");
   FileUtils.deleteDirectory(root);
   FileUtils.copyDirectory(origin, root);
   // force all files to a specific date for testing sake
   Iterator<File> it = FileUtils.iterateFiles(root, new String[] {"png8", "png", "jpeg"}, true);
   while (it.hasNext()) {
     File file = it.next();
     file.setLastModified(FIXED_DATE);
   }
 }
  public static void duplicateFilesInYamlFormat(
      String inputDirectoryStr, String outputDirectoryStr) {
    Path outputDirectory = Paths.get(outputDirectoryStr);
    Path inputDirectory = Paths.get(inputDirectoryStr);

    deleteAndRecreateOutputDirectory(outputDirectory);

    final Iterator<File> fileIterator =
        FileUtils.iterateFiles(inputDirectory.toFile(), new String[] {"json"}, true);
    while (fileIterator.hasNext()) {
      File next = fileIterator.next();
      System.out.println("Processing " + next);

      processFile(next, inputDirectory, outputDirectory);
    }
  }
Exemplo n.º 5
0
  public ClazzpathUnit addClazzpathUnit(final File pFile, final String pId) throws IOException {
    if (pFile.isFile()) {
      return addClazzpathUnit(new FileInputStream(pFile), pId);
    }
    if (pFile.isDirectory()) {
      final String prefix =
          FilenameUtils.separatorsToUnix(
              FilenameUtils.normalize(
                  new StringBuilder(pFile.getAbsolutePath())
                      .append(File.separatorChar)
                      .toString()));
      final boolean recursive = true;
      @SuppressWarnings("unchecked")
      final Iterator<File> files = FileUtils.iterateFiles(pFile, new String[] {"class"}, recursive);
      return addClazzpathUnit(
          new Iterable<Resource>() {

            public Iterator<Resource> iterator() {
              return new Iterator<Clazzpath.Resource>() {

                public boolean hasNext() {
                  return files.hasNext();
                }

                public Resource next() {
                  final File file = files.next();
                  return new Resource(file.getAbsolutePath().substring(prefix.length())) {

                    @Override
                    InputStream getInputStream() throws IOException {
                      return new FileInputStream(file);
                    }
                  };
                }

                public void remove() {
                  throw new UnsupportedOperationException();
                }
              };
            }
          },
          pId,
          true);
    }
    throw new IllegalArgumentException();
  }
 protected List<File> getFilesInDirectory(String directory) {
   List<File> files = new LinkedList<File>();
   Iterator<File> fileIterator =
       FileUtils.iterateFiles(new File(directory), new String[] {"txt"}, false);
   while (fileIterator.hasNext()) {
     File file = fileIterator.next();
     if (!file.getName().contains("scenario")
         && file.getName()
             .contains(
                 fileNameShouldContain)) // && !file.getName().contains(fileNameShouldNotContain))
                                         // //
     {
       files.add(file);
     }
   }
   if (files.isEmpty()) throw new RuntimeException("Es konnten keine Dateien eingelesen werden");
   else return files;
 }
Exemplo n.º 7
0
  /**
   * Generate java code of a parser from a lexer file.
   *
   * <p>If the {@code lexDefinition} is a directory, process all lexer files contained within.
   *
   * @param lexDefinition Lexer definiton file or directory to process.
   * @throws MojoFailureException if the file is not found.
   * @throws MojoExecutionException
   */
  @SuppressWarnings("unchecked")
  private void parseLexDefinition(File lexDefinition)
      throws MojoFailureException, MojoExecutionException {
    assert lexDefinition.isAbsolute() : lexDefinition;

    if (lexDefinition.isDirectory()) {
      // recursively process files contained within
      String[] extensions = {"jflex", "jlex", "lex", "flex"};
      getLog().debug("Processing lexer files found in " + lexDefinition);
      Iterator<File> fileIterator = FileUtils.iterateFiles(lexDefinition, extensions, true);
      while (fileIterator.hasNext()) {
        File lexFile = fileIterator.next();
        parseLexFile(lexFile);
      }
    } else {
      parseLexFile(lexDefinition);
    }
  }
Exemplo n.º 8
0
  public static List<File> getImportFiles() {
    File extDir = Environment.getRootDirectory();
    String state = Environment.getExternalStorageState();
    // TODO check thru all state possibilities
    if (!state.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
      return new ArrayList<File>();
    }

    ArrayList<File> fileList = new ArrayList<File>();
    @SuppressWarnings("unchecked")
    Iterator<File> iter = FileUtils.iterateFiles(extDir, new String[] {"csv"}, true);

    while (iter.hasNext()) {
      File file = iter.next();
      if (file.getName().startsWith("._")) {
        continue;
      }
      fileList.add(file);
      Log.d(LOG, "### disk Import File: " + file.getAbsolutePath());
    }

    Log.i(LOG, "### Import Files in list : " + fileList.size());
    return fileList;
  }
Exemplo n.º 9
0
 public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive) {
   return FileUtils.iterateFiles(directory, extensions, recursive);
 }
Exemplo n.º 10
0
 public static Iterator iterateFiles(
     File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {
   return FileUtils.iterateFiles(directory, fileFilter, dirFilter);
 }
  public void calculateAll() throws IOException {
    String directory = configuration.getConfigurationValueString(INPUT_DIRECTORY);
    if (StringUtils.isEmpty(directory)) {
      throw new IllegalArgumentException(
          "No input directory specified. Please configure the parameter 'baseDirectory'.");
    }
    // first, dump the current configuration into the directory

    String configurationAsString = configuration.getConfigurationAsString();
    if (StringUtils.isNotEmpty(configuration.getConfigurationValueString(OUTPUT_DIRECTORY))) {
      File outputFile =
          new File(
              configuration.getConfigurationValueString(OUTPUT_DIRECTORY)
                  + "configuration"
                  + "-"
                  + sdf.format(Calendar.getInstance().getTime()));
      outputStream = FileUtils.openOutputStream(outputFile, true);
      IOUtils.write(configurationAsString, outputStream);
      //            IOUtils.closeQuietly(outputStream);
    } else {
      System.out.println(configurationAsString);
    }

    // open the output file
    SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd-HH-mm-ss");

    String outputDirectory = configuration.getConfigurationValueString(OUTPUT_DIRECTORY);
    if (StringUtils.isNotEmpty(outputDirectory)) {
      File outputFile =
          new File(
              outputDirectory
                  + "AllInstancesLeiEtAl"
                  + sdf.format(Calendar.getInstance().getTime())
                  + ".csv");
      outputStream = FileUtils.openOutputStream(outputFile, true);
    }

    IOUtils.write("Inst.;V;m;Q;det;stoch;gesamt;ms\n", outputStream);

    // get all problems / files in the directory
    Iterator<File> files = FileUtils.iterateFiles(new File(directory), new String[] {"txt"}, false);
    while (files.hasNext()) {
      File file = files.next();
      if (!file.getName().contains("scenario")) // && !file.getName().contains("c"))
      {
        System.out.println("processing file " + file.getName());
        FileInputStream openInputStream = null;
        try {
          openInputStream = FileUtils.openInputStream(file);
          List<String> lines = IOUtils.readLines(openInputStream);
          VrpProblem problem = VrpUtils.createProblemFromStringList(lines);
          try {
            createLeiEtAlSolution(problem, file.getName());
          } catch (Exception e) {
            System.err.println(
                "An error occurred while calculating the solution with the Lei et al. heuristic.");
            e.printStackTrace();
          }
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          IOUtils.closeQuietly(openInputStream);
        }
      }
    }
  }
  protected void processClassesDirectory(final ClassesSelector selector)
      throws MojoFailureException {

    try {

      final File classesDirectory = selector.getClassesDirectory(this);

      if (isValidDirectory(classesDirectory)) {
        getLog().info("");
        getLog().info("input classes = " + classesDirectory);
      } else {
        throw new MojoFailureException("classes directory invalid");
      }

      /** collect all class files */
      @SuppressWarnings("unchecked")
      final Iterator<File> iter =
          FileUtils.iterateFiles(classesDirectory, EXTENSIONS, IS_RECURSIVE);

      final ClassLoader loader = getClassloader(selector);

      getLog().info("");
      getLog().info("output directory = " + outputDirectorySCR());

      while (iter.hasNext()) {

        /** discovered *.class file */
        final File file = iter.next();

        /** resolved class name */
        final String name = getClassName(classesDirectory, file);

        getLog().debug("\t class : " + name);

        /** make individual descriptor */
        final String text = getMaker().make(loader, name);

        /** non component returns null */
        final boolean isComponent = text != null;

        allclassesCounter++;

        if (isComponent) {

          final String outputFile = outputFileSCR(name);

          getLog().info("\t descriptor = " + outputFile);

          saveDescriptor(name, text);

          descriptorCounter++;

        } else {

          getLog().debug("\t class is not a component");
        }
      }

      getLog().info("");

      if (descriptorCounter == 0) {
        getLog().warn("did not find any active scr components");
      } else {
        getLog().info("active components count = " + descriptorCounter);
      }

    } catch (final MojoFailureException exception) {

      throw exception;

    } catch (final Throwable exception) {

      throw new MojoFailureException("execution failure", exception);
    }
  }