Search in sources :

Example 6 with Progress

use of org.opengrok.indexer.util.Progress in project OpenGrok by OpenGrok.

the class FileHistoryCache method storeRenamed.

/**
 * handle renamed files (in parallel).
 * @param renamedFiles set of renamed file paths
 * @param repository repository
 * @param tillRevision end revision (can be null)
 */
public void storeRenamed(Set<String> renamedFiles, Repository repository, String tillRevision) throws HistoryException {
    final File root = env.getSourceRootFile();
    if (renamedFiles.isEmpty()) {
        return;
    }
    renamedFiles = renamedFiles.stream().filter(f -> new File(env.getSourceRootPath() + f).exists()).collect(Collectors.toSet());
    LOGGER.log(Level.FINE, "Storing history for {0} renamed files in repository ''{1}'' till {2}", new Object[] { renamedFiles.size(), repository, getRevisionString(tillRevision) });
    createDirectoriesForFiles(renamedFiles, repository, "renamed files for history " + getRevisionString(tillRevision));
    final Repository repositoryF = repository;
    final CountDownLatch latch = new CountDownLatch(renamedFiles.size());
    AtomicInteger renamedFileHistoryCount = new AtomicInteger();
    try (Progress progress = new Progress(LOGGER, String.format("history cache for renamed files of %s till %s", repository, getRevisionString(tillRevision)), renamedFiles.size())) {
        for (final String file : renamedFiles) {
            env.getIndexerParallelizer().getHistoryFileExecutor().submit(() -> {
                try {
                    doRenamedFileHistory(file, new File(env.getSourceRootPath() + file), repositoryF, root, tillRevision);
                    renamedFileHistoryCount.getAndIncrement();
                } catch (Exception ex) {
                    // We want to catch any exception since we are in thread.
                    LOGGER.log(Level.WARNING, "doFileHistory() got exception ", ex);
                } finally {
                    latch.countDown();
                    progress.increment();
                }
            });
        }
        // Wait for the executors to finish.
        try {
            // Wait for the executors to finish.
            latch.await();
        } catch (InterruptedException ex) {
            LOGGER.log(Level.SEVERE, "latch exception", ex);
        }
    }
    LOGGER.log(Level.FINE, "Stored history for {0} renamed files in repository ''{1}''", new Object[] { renamedFileHistoryCount.intValue(), repository });
}
Also used : Progress(org.opengrok.indexer.util.Progress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) NoSuchFileException(java.nio.file.NoSuchFileException) ForbiddenSymlinkException(org.opengrok.indexer.util.ForbiddenSymlinkException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)6 Progress (org.opengrok.indexer.util.Progress)6 File (java.io.File)5 List (java.util.List)5 Files (java.nio.file.Files)4 Paths (java.nio.file.Paths)4 Map (java.util.Map)4 Set (java.util.Set)4 Level (java.util.logging.Level)4 Logger (java.util.logging.Logger)4 Collectors (java.util.stream.Collectors)4 LoggerFactory (org.opengrok.indexer.logger.LoggerFactory)4 TandemPath (org.opengrok.indexer.util.TandemPath)4 DirectoryStream (java.nio.file.DirectoryStream)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 FileVisitResult (java.nio.file.FileVisitResult)3 Path (java.nio.file.Path)3 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)3 StandardCopyOption (java.nio.file.StandardCopyOption)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3