Example #1
0
    // Invoke the pattern matching method on each file.
    // 今回はFileに対する走査だけなのでpreVisitDirectory等はoverride不要
    @Override
    public FileVisitResult visitFile(Path path, BasicFileAttributes bfa) throws IOException {
      Path name = path.getFileName();
      logger.fine("[" + name.toString() + "]がマッチするかチェック中...");
      if (name != null && matcher.matches(name)) {
        logger.fine("Found [" + path.toString() + "]");
        ScannedResult sr = findOrCreateScannedResult(path);

        // scanmodeによる挙動変更
        if (scanmode.equals(Constants.SCANTYPE_ALL)) {
          resultList.add(sr);
        } else if (scanmode.equals(Constants.SCANTYPE_IGNORED)
            && sr.getIgnored().equals(Constants.SCAN_IGNORED)) {
          resultList.add(sr);
        } else if (scanmode.equals(Constants.SCANTYPE_NOT_IGNORED)
            && sr.getIgnored().equals(Constants.SCAN_NOT_IGNORED)) {
          resultList.add(sr);
        } else {
          logger.fine(
              "ScanType["
                  + scanmode
                  + "]:ScannedResult("
                  + sr.getProductionPath()
                  + ")はIgnored=["
                  + sr.getIgnored()
                  + "]の為結果リストに含まれません.");
        }
      }
      return FileVisitResult.CONTINUE;
    }
Example #2
0
 private void find(Path path) {
   Path name = path.getFileName();
   if (name != null && matcher.matches(name)) {
     File fullFile = new File(currentDir, name.toString());
     fileList.add(fullFile);
   }
 }
Example #3
0
 protected boolean isMatchesFile(Path file) {
   boolean matches = true;
   if (fileMatcher != null) {
     Path rel = root.relativize(file);
     matches = fileMatcher.matches(rel);
   }
   return matches;
 }
Example #4
0
  @Override
  public File getFile(String id, String path) throws RootManagerException {
    RootManagerBean root = Mimas.getConfig().getRootConfig().getRoot(id);
    if (root == null) {
      throw new RootNotFoundException(id);
    }

    File f = new File(root.getFile(), path);
    try {
      String canonicalPath = f.getCanonicalPath();
      if (!canonicalPath.startsWith(root.getFile().getCanonicalPath())) {
        throw new RootManagerException(
            "File is not part of root \""
                + root.getFile().getCanonicalPath()
                + "\" ("
                + canonicalPath
                + ")");
      }
    } catch (IOException e) {
      throw new RootManagerException(e);
    }

    for (String mask : root.getExcludes()) {
      PathMatcher pathMatcher =
          FileSystems.getDefault().getPathMatcher(root.getSyntax() + ":" + mask);
      if (pathMatcher.matches(f.toPath())) {
        throw new RootExcludedException(f, mask);
      }
    }

    boolean isIncluded = false;
    for (String mask : root.getIncludes()) {
      PathMatcher pathMatcher =
          FileSystems.getDefault().getPathMatcher(root.getSyntax() + ":" + mask);
      if (pathMatcher.matches(root.getFile().toPath().relativize(f.toPath()))) {
        isIncluded = true;
        break;
      }
    }
    if (!isIncluded) {
      throw new RootExcludedException(f);
    }

    return f;
  }
 @Override
 public boolean matches(Path path) {
   for (PathMatcher matcher : matchers) {
     if (matcher.matches(path)) {
       return true;
     }
   }
   return false;
 }
 @Override
 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
   if (matcher.matches(file)) {
     channelFile = file;
     return FileVisitResult.TERMINATE;
   } else {
     return FileVisitResult.CONTINUE;
   }
 }
Example #7
0
  /**
   * Globbing is specifying DirectoryStream result with something like simplified regular
   * expressions.
   */
  @Test
  public void testDirectoryStreamGlobbing() throws IOException {
    Path rootDir = createDemonstrationDirectoryStructure();
    DirectoryStream<Path> dirStream = Files.newDirectoryStream(rootDir, "*.txt");
    List<Path> paths = iterableToList(dirStream);
    // closing is required
    dirStream.close();
    assertEquals(2, paths.size());
    assertTrue(paths.contains(rootDir.resolve("firstFile.txt")));
    assertTrue(paths.contains(rootDir.resolve("secondFile.txt")));

    // only dir
    dirStream = Files.newDirectoryStream(rootDir, "*Dir");
    paths = iterableToList(dirStream);
    dirStream.close();
    assertEquals(1, paths.size());
    assertTrue(paths.contains(rootDir.resolve("childDir")));

    // PathMatcher is used in loop
    PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*File*");
    dirStream = Files.newDirectoryStream(rootDir);
    int matchedFilenane = 0;
    int matchedPath = 0;
    for (Path p : dirStream) {
      if (matcher.matches(p.getFileName())) {
        matchedFilenane++;
      }

      if (matcher.matches(p)) {
        matchedPath++;
      }
    }
    dirStream.close();
    assertEquals(2, matchedFilenane);
    // don't work with whole path just with filename
    assertEquals(0, matchedPath);

    // path matcher with unrecognized prefix
    try {
      FileSystems.getDefault().getPathMatcher("gldob:*.txt");
      fail("UnsupportedOperationException expected!");
    } catch (UnsupportedOperationException e) {
    }
  }
 public boolean isFileExcluded(Path path) {
   if (this.ignoreFilesRules != null) {
     for (PathMatcher rule : this.ignoreFilesRules) {
       if (rule.matches(path)) {
         return true;
       }
     }
   }
   return false;
 }
 private void find(Path file) {
   Path name = file.getFileName();
   if (name != null) {
     for (PathMatcher matcher : matchers) {
       if (matcher.matches(name)) {
         resultList.add(file.toFile().getPath());
         return;
       }
     }
   }
 }
Example #10
0
  /**
   * Lists objects from AmazonS3 in chronological order [lexicographical order if 2 files have same
   * timestamp] which are later than or equal to the timestamp of the previous offset object
   *
   * @param s3Client
   * @param s3ConfigBean
   * @param pathMatcher glob patterns to match file name against
   * @param s3Offset current offset which provides the timestamp of the previous object
   * @param fetchSize number of objects to fetch in one go
   * @return
   * @throws AmazonClientException
   */
  static List<S3ObjectSummary> listObjectsChronologically(
      AmazonS3Client s3Client,
      S3ConfigBean s3ConfigBean,
      PathMatcher pathMatcher,
      AmazonS3Source.S3Offset s3Offset,
      int fetchSize)
      throws AmazonClientException {

    // Algorithm:
    // - Full scan all objects that match the file name pattern and which are later than the file in
    // the offset
    // - Select the oldest "fetchSize" number of files and return them.
    TreeSet<S3ObjectSummary> treeSet =
        new TreeSet<>(
            new Comparator<S3ObjectSummary>() {
              @Override
              public int compare(S3ObjectSummary o1, S3ObjectSummary o2) {
                int result = o1.getLastModified().compareTo(o2.getLastModified());
                if (result != 0) {
                  // same modified time. Use name to sort
                  return result;
                }
                return o1.getKey().compareTo(o2.getKey());
              }
            });

    S3Objects s3ObjectSummaries =
        S3Objects.withPrefix(s3Client, s3ConfigBean.s3Config.bucket, s3ConfigBean.s3Config.folder)
            .withBatchSize(BATCH_SIZE);
    for (S3ObjectSummary s : s3ObjectSummaries) {
      String fileName =
          s.getKey().substring(s3ConfigBean.s3Config.folder.length(), s.getKey().length());
      if (!fileName.isEmpty()) {
        // fileName can be empty.
        // If the user manually creates a folder "myFolder/mySubFolder" in bucket "myBucket" and
        // uploads "myObject",
        // then the first objects returned here are:
        // myFolder/mySubFolder
        // myFolder/mySubFolder/myObject
        //
        // All is good when pipeline is run but preview returns with no data. So we should ignore
        // the empty file as it
        // has no data
        if (pathMatcher.matches(Paths.get(fileName)) && isEligible(s, s3Offset)) {
          treeSet.add(s);
        }
        if (treeSet.size() > fetchSize) {
          treeSet.pollLast();
        }
      }
    }

    return new ArrayList<>(treeSet);
  }
Example #11
0
 // it compares the link if it is equal to .html then it will be added to the list.
 private void find(Path file) {
   Path name = file.getFileName();
   if (name != null && matcher.matches(name)) {
     numMatches++;
     int i = -1;
     String shortPath = file.toString();
     i = shortPath.indexOf("-lewis");
     shortPath = shortPath.substring(i + 7, shortPath.length());
     URI newLink = new File(file.toString()).toURI();
     //  System.out.println("Antes  :" +newLink.toString() );
     newLink = newLink.normalize();
     linksMatches.add(newLink.toString().substring(6));
   }
 }
Example #12
0
 @Override
 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
   if (pathMatcher.matches(file.getFileName())) {
     if (attrs.isSymbolicLink()) {
       System.out.format("Symbolic link: %s ", file);
     } else if (attrs.isRegularFile()) {
       System.out.format("Regular file: %s ", file);
     } else {
       System.out.format("Other: %s ", file);
     }
     System.out.println("(" + attrs.size() + "bytes)");
   }
   return FileVisitResult.CONTINUE;
 }
  public static List<Path> searchFiles(Path path, String globPattern) throws IOException {

    if (Files.isDirectory(path)) {
      Finder finder = new Finder(globPattern);
      Files.walkFileTree(path, finder);
      return finder.getPaths();
    } else {
      PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + globPattern);

      if (matcher.matches(path.getFileName())) {
        return Arrays.asList(path);
      } else {
        return Collections.emptyList();
      }
    }
  }
  private boolean isIgnored(String path) {
    for (Path entry : this.ignoredPaths) {
      if (Paths.get(path).startsWith(entry)) {
        return true;
      }
    }

    for (String pattern : this.ignorePatterns) {
      PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
      if (matcher.matches(Paths.get(path))) {
        return true;
      }
    }

    return false;
  }
  @Before
  public void reset() throws IOException, RestException {
    // skip test if it matches one of the blacklist globs
    for (PathMatcher blacklistedPathMatcher : blacklistPathMatchers) {
      // we need to replace a few characters otherwise the test section name can't be parsed as a
      // path on windows
      String testSection =
          testCandidate
              .getTestSection()
              .getName()
              .replace("*", "")
              .replace("\\", "/")
              .replaceAll("\\s+/", "/")
              .trim();
      String testPath = testCandidate.getSuitePath() + "/" + testSection;
      assumeFalse(
          "[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted",
          blacklistedPathMatcher.matches(Paths.get(testPath)));
    }
    // The client needs non static info to get initialized, therefore it can't be initialized in the
    // before class
    restTestExecutionContext.initClient(cluster().httpAddresses(), restClientSettings());
    restTestExecutionContext.clear();

    // skip test if the whole suite (yaml file) is disabled
    assumeFalse(
        buildSkipMessage(
            testCandidate.getSuitePath(), testCandidate.getSetupSection().getSkipSection()),
        testCandidate
            .getSetupSection()
            .getSkipSection()
            .skip(restTestExecutionContext.esVersion()));
    // skip test if test section is disabled
    assumeFalse(
        buildSkipMessage(
            testCandidate.getTestPath(), testCandidate.getTestSection().getSkipSection()),
        testCandidate.getTestSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
  }
 @Override
 public boolean accept(Path entry) throws IOException {
   return matcher.matches(entry);
 }
Example #17
0
 // Compares the glob pattern against
 // the file or directory name.
 void find(Path file) {
   Path name = file.getFileName();
   if (name != null && matcher.matches(name)) {
     fileList.add(file);
   }
 }
Example #18
0
  @Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (_pathMatcher.matches(file.getFileName())) storeFile(file.toFile());

    return super.visitFile(file, attrs);
  }
Example #19
0
 void find(Path file) {
   Path name = file.getFileName();
   if (name != null && pathMatcher.matches(name)) {
     System.out.println(name);
   }
 }