]> source.dussan.org Git - archiva.git/commitdiff
Migrating scheduler to java.nio
authorMartin Stockhammer <martin_s@apache.org>
Sun, 10 Sep 2017 15:47:17 +0000 (17:47 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sun, 10 Sep 2017 15:47:17 +0000 (17:47 +0200)
15 files changed:
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTaskTest.java
archiva-modules/archiva-scheduler/archiva-scheduler-repository-api/src/main/java/org/apache/archiva/scheduler/repository/model/RepositoryTask.java
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/AbstractArchivaRepositoryScanningTaskExecutorTest.java
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorPhase2Test.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java

index 56fdf79944fbd410c8e5519952b7dbf859043d24..434f864e69182613406f7488a834f5eb29f94d9c 100644 (file)
@@ -148,7 +148,7 @@ public class NexusIndexerConsumer
         Path artifactFile = managedRepository.resolve(path);
 
         ArtifactIndexingTask task =
-            new ArtifactIndexingTask( repository, artifactFile.toFile(), ArtifactIndexingTask.Action.ADD, getIndexingContext() );
+            new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, getIndexingContext() );
         try
         {
             log.debug( "Queueing indexing task '{}' to add or update the artifact in the index.", task );
@@ -174,7 +174,7 @@ public class NexusIndexerConsumer
 
             // specify in indexing task that this is not a repo scan request!
             ArtifactIndexingTask task =
-                new ArtifactIndexingTask( repository, artifactFile.toFile(), ArtifactIndexingTask.Action.ADD,
+                new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD,
                                           getIndexingContext(), false );
             // only update index we don't need to scan the full repo here
             task.setOnlyUpdate( true );
index 7d6ea28eacbe7cdb668f578c8c628e966405030f..2b76279a033ef7056af0faa2e17180a2e8e4fb7f 100644 (file)
@@ -68,7 +68,7 @@ public class NexusIndexerConsumerTest
             switch ( task.getAction() )
             {
                 case ADD:
-                    indexed.add( task.getResourceFile().toPath() );
+                    indexed.add( task.getResourceFile() );
                     break;
                 case DELETE:
                     indexed.remove( task.getResourceFile() );
index e4e60fe73145a4e0df3110f7bf5311452436e3a2..f04fe192e9ba7f87da600f7b377ced3cbc0c73ee 100644 (file)
@@ -807,7 +807,7 @@ public class DefaultRepositoryProxyConnectors
     {
         RepositoryTask task = new RepositoryTask();
         task.setRepositoryId( repositoryId );
-        task.setResourceFile( localFile.toFile() );
+        task.setResourceFile( localFile );
         task.setUpdateRelatedArtifacts( true );
         task.setScanAll( true );
 
index 69ec1ec44e07b070a447a351c6f2e9a24241ddc3..666715f03291ccee826740b1ae42842ffc9b603d 100644 (file)
@@ -43,8 +43,8 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
-import java.io.File;
 import java.io.IOException;
+import java.nio.file.Path;
 
 /**
  * ArchivaIndexingTaskExecutor Executes all indexing tasks. Adding, updating and removing artifacts from the index are
@@ -115,7 +115,7 @@ public class ArchivaIndexingTaskExecutor
                     log.debug( "Creating indexing context on resource: {}", //
                                ( indexingTask.getResourceFile() == null
                                    ? "none"
-                                   : indexingTask.getResourceFile().getPath() ) );
+                                   : indexingTask.getResourceFile() ) );
                     context = managedRepositoryAdmin.createIndexContext( repository );
                 }
                 catch ( RepositoryAdminException e )
@@ -132,20 +132,20 @@ public class ArchivaIndexingTaskExecutor
 
             try
             {
-                File artifactFile = indexingTask.getResourceFile();
+                Path artifactFile = indexingTask.getResourceFile();
                 if ( artifactFile == null )
                 {
                     log.debug( "no artifact pass in indexing task so skip it" );
                 }
                 else
                 {
-                    ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
+                    ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile.toFile() );
 
                     if ( ac != null )
                     {
                         // MRM-1779 pom must be indexed too
                         // TODO make that configurable?
-                        if ( artifactFile.getPath().endsWith( ".pom" ) )
+                        if ( artifactFile.getFileName().toString().endsWith( ".pom" ) )
                         {
                             ac.getArtifactInfo().setFileExtension( "pom" );
                             ac.getArtifactInfo().setPackaging( "pom" );
@@ -205,7 +205,7 @@ public class ArchivaIndexingTaskExecutor
                 if ( !indexingTask.isExecuteOnEntireRepo() )
                 {
                     log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile() != null
-                        ? indexingTask.getResourceFile().getPath()
+                        ? indexingTask.getResourceFile()
                         : " none " );
                     finishIndexingTask( indexingTask, repository, context );
                 }
index 2da5ab77970d5de750efd8b35ee5e4430ad184a1..59f9d37c29c8bb1a22061a2d0d05d2c5268a0ea6 100644 (file)
@@ -23,7 +23,8 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.redback.components.taskqueue.Task;
 import org.apache.maven.index.context.IndexingContext;
 
-import java.io.File;
+import java.nio.file.Path;
+
 
 public class ArtifactIndexingTask
     implements Task
@@ -37,7 +38,7 @@ public class ArtifactIndexingTask
 
     private final ManagedRepository repository;
 
-    private final File resourceFile;
+    private final Path resourceFile;
 
     private final Action action;
 
@@ -50,7 +51,7 @@ public class ArtifactIndexingTask
      */
     private boolean onlyUpdate = false;
 
-    public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
+    public ArtifactIndexingTask( ManagedRepository repository, Path resourceFile, Action action,
                                  IndexingContext context )
     {
         this.repository = repository;
@@ -59,14 +60,14 @@ public class ArtifactIndexingTask
         this.context = context;
     }
 
-    public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
+    public ArtifactIndexingTask( ManagedRepository repository, Path resourceFile, Action action,
                                  IndexingContext context, boolean executeOnEntireRepo )
     {
         this( repository, resourceFile, action, context );
         this.executeOnEntireRepo = executeOnEntireRepo;
     }
 
-    public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
+    public ArtifactIndexingTask( ManagedRepository repository, Path resourceFile, Action action,
                                  IndexingContext context, boolean executeOnEntireRepo, boolean onlyUpdate )
     {
         this( repository, resourceFile, action, context, executeOnEntireRepo );
@@ -95,7 +96,7 @@ public class ArtifactIndexingTask
         return 0;
     }
 
-    public File getResourceFile()
+    public Path getResourceFile()
     {
         return resourceFile;
     }
index 62e95a530c46a2c8c9be29a6b4ae353d3b97f3b2..96acdfb448cbcc2e7bf3b5b3cb587f805420929a 100644 (file)
@@ -23,7 +23,6 @@ import org.apache.archiva.admin.model.beans.RemoteRepository;
 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
 import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.proxy.common.WagonFactoryRequest;
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.time.StopWatch;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.updater.IndexUpdateRequest;
@@ -45,12 +44,13 @@ import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 import java.util.Map;
 
@@ -106,7 +106,7 @@ public class DownloadRemoteIndexTask
             }
             this.runningRemoteDownloadIds.add( this.remoteRepository.getId() );
         }
-        File tempIndexDirectory = null;
+        Path tempIndexDirectory = null;
         StopWatch stopWatch = new StopWatch();
         stopWatch.start();
         try
@@ -115,15 +115,15 @@ public class DownloadRemoteIndexTask
             IndexingContext indexingContext = remoteRepositoryAdmin.createIndexContext( this.remoteRepository );
 
             // create a temp directory to download files
-            tempIndexDirectory = new File( indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex" );
-            File indexCacheDirectory = new File( indexingContext.getIndexDirectoryFile().getParent(), ".indexCache" );
-            indexCacheDirectory.mkdirs();
-            if ( tempIndexDirectory.exists() )
+            tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex" );
+            Path indexCacheDirectory = Paths.get( indexingContext.getIndexDirectoryFile().getParent(), ".indexCache" );
+            Files.createDirectories( indexCacheDirectory );
+            if ( Files.exists(tempIndexDirectory) )
             {
-                FileUtils.deleteDirectory( tempIndexDirectory );
+                org.apache.archiva.common.utils.FileUtils.deleteDirectory( tempIndexDirectory );
             }
-            tempIndexDirectory.mkdirs();
-            tempIndexDirectory.deleteOnExit();
+            Files.createDirectories( tempIndexDirectory );
+            tempIndexDirectory.toFile().deleteOnExit();
             String baseIndexUrl = indexingContext.getIndexUpdateUrl();
 
             String wagonProtocol = new URL( this.remoteRepository.getUrl() ).getProtocol();
@@ -167,17 +167,17 @@ public class DownloadRemoteIndexTask
             wagon.connect( new Repository( this.remoteRepository.getId(), baseIndexUrl ), authenticationInfo,
                            proxyInfo );
 
-            File indexDirectory = indexingContext.getIndexDirectoryFile();
-            if ( !indexDirectory.exists() )
+            Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
+            if ( !Files.exists(indexDirectory) )
             {
-                indexDirectory.mkdirs();
+                Files.createDirectories( indexDirectory );
             }
 
             ResourceFetcher resourceFetcher =
                 new WagonResourceFetcher( log, tempIndexDirectory, wagon, remoteRepository );
             IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher );
             request.setForceFullUpdate( this.fullDownload );
-            request.setLocalIndexCacheDir( indexCacheDirectory );
+            request.setLocalIndexCacheDir( indexCacheDirectory.toFile() );
 
             this.indexUpdater.fetchAndUpdateIndex( request );
             stopWatch.stop();
@@ -204,11 +204,11 @@ public class DownloadRemoteIndexTask
         log.info( "end download remote index for remote repository {}", this.remoteRepository.getId() );
     }
 
-    private void deleteDirectoryQuiet( File f )
+    private void deleteDirectoryQuiet( Path f )
     {
         try
         {
-            FileUtils.deleteDirectory( f );
+            org.apache.archiva.common.utils.FileUtils.deleteDirectory( f );
         }
         catch ( IOException e )
         {
@@ -280,13 +280,13 @@ public class DownloadRemoteIndexTask
 
         Logger log;
 
-        File tempIndexDirectory;
+        Path tempIndexDirectory;
 
         Wagon wagon;
 
         RemoteRepository remoteRepository;
 
-        private WagonResourceFetcher( Logger log, File tempIndexDirectory, Wagon wagon,
+        private WagonResourceFetcher( Logger log, Path tempIndexDirectory, Wagon wagon,
                                       RemoteRepository remoteRepository )
         {
             this.log = log;
@@ -316,11 +316,11 @@ public class DownloadRemoteIndexTask
             try
             {
                 log.info( "index update retrieve file, name:{}", name );
-                File file = new File( tempIndexDirectory, name );
-                Files.deleteIfExists( file.toPath() );
-                file.deleteOnExit();
-                wagon.get( addParameters( name, this.remoteRepository ), file );
-                return Files.newInputStream( file.toPath() );
+                Path file = tempIndexDirectory.resolve( name );
+                Files.deleteIfExists( file );
+                file.toFile().deleteOnExit();
+                wagon.get( addParameters( name, this.remoteRepository ), file.toFile() );
+                return Files.newInputStream( file );
             }
             catch ( AuthorizationException | TransferFailedException e )
             {
index 14bf7fc50812a7f5ae6f724d918fd9a47716fbd4..b0bbbb6509768e6285db4ba7bb52295586e1fef4 100644 (file)
@@ -32,13 +32,13 @@ import org.apache.maven.index.context.IndexCreator;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.expr.SourcedSearchExpression;
 import org.apache.maven.index.expr.StringSearchExpression;
+import org.apache.maven.index.updater.DefaultIndexUpdater;
+import org.apache.maven.index.updater.IndexUpdateRequest;
+import org.apache.maven.index.updater.IndexUpdater;
 import org.apache.maven.index_shaded.lucene.search.BooleanClause;
 import org.apache.maven.index_shaded.lucene.search.BooleanQuery;
 import org.apache.maven.index_shaded.lucene.search.IndexSearcher;
 import org.apache.maven.index_shaded.lucene.search.TopDocs;
-import org.apache.maven.index.updater.DefaultIndexUpdater;
-import org.apache.maven.index.updater.IndexUpdateRequest;
-import org.apache.maven.index.updater.IndexUpdater;
 import org.assertj.core.api.Assertions;
 import org.junit.After;
 import org.junit.Before;
@@ -47,8 +47,10 @@ import org.junit.runner.RunWith;
 import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
-import java.io.File;
-import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 import java.util.Set;
 
@@ -87,7 +89,7 @@ public class ArchivaIndexingTaskExecutorTest
         repositoryConfig = new ManagedRepository();
         repositoryConfig.setId( "test-repo" );
         repositoryConfig.setLocation(
-            new File( System.getProperty( "basedir" ), "target/test-classes/test-repo" ).getAbsolutePath() );
+            Paths.get( System.getProperty( "basedir" ), "target/test-classes/test-repo" ).toAbsolutePath().toString() );
         repositoryConfig.setLayout( "default" );
         repositoryConfig.setName( "Test Repository" );
         repositoryConfig.setScanned( true );
@@ -130,7 +132,7 @@ public class ArchivaIndexingTaskExecutorTest
     public void testAddArtifactToIndex()
         throws Exception
     {
-        File artifactFile = new File( repositoryConfig.getLocation(),
+        Path artifactFile = Paths.get( repositoryConfig.getLocation(),
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
 
         ArtifactIndexingTask task =
@@ -150,8 +152,8 @@ public class ArchivaIndexingTaskExecutorTest
         {
             IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(), //
                                                                   repositoryConfig.getId(), //
-                                                                  new File( repositoryConfig.getLocation() ), //
-                                                                  new File( repositoryConfig.getLocation(), ".indexer" )
+                                                                  Paths.get( repositoryConfig.getLocation() ).toFile(), //
+                                                                  Paths.get( repositoryConfig.getLocation(), ".indexer" ).toFile()
                                                                   //
                 , null, null, indexCreators );
             context.setSearchable( true );
@@ -160,8 +162,8 @@ public class ArchivaIndexingTaskExecutorTest
         FlatSearchRequest request = new FlatSearchRequest( q );
         FlatSearchResponse response = indexer.searchFlat( request );
 
-        assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
-        assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
+        assertTrue( Files.exists(Paths.get( repositoryConfig.getLocation(), ".indexer" )) );
+        assertFalse( Files.exists(Paths.get( repositoryConfig.getLocation(), ".index" )) );
         assertEquals( 1, response.getTotalHits() );
 
         Set<ArtifactInfo> results = response.getResults();
@@ -177,7 +179,7 @@ public class ArchivaIndexingTaskExecutorTest
     public void testUpdateArtifactInIndex()
         throws Exception
     {
-        File artifactFile = new File( repositoryConfig.getLocation(),
+        Path artifactFile = Paths.get( repositoryConfig.getLocation(),
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
 
         ArtifactIndexingTask task =
@@ -202,8 +204,8 @@ public class ArchivaIndexingTaskExecutorTest
         //searcher.close();
         ctx.releaseIndexSearcher( searcher );
 
-        assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
-        assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
+        assertTrue( Files.exists(Paths.get( repositoryConfig.getLocation(), ".indexer" )) );
+        assertFalse( Files.exists(Paths.get( repositoryConfig.getLocation(), ".index" )) );
 
         // should only return 1 hit!
         assertEquals( 1, topDocs.totalHits );
@@ -213,7 +215,7 @@ public class ArchivaIndexingTaskExecutorTest
     public void testRemoveArtifactFromIndex()
         throws Exception
     {
-        File artifactFile = new File( repositoryConfig.getLocation(),
+        Path artifactFile = Paths.get( repositoryConfig.getLocation(),
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
 
         ArtifactIndexingTask task =
@@ -235,8 +237,8 @@ public class ArchivaIndexingTaskExecutorTest
 
         FlatSearchResponse response = indexer.searchFlat( flatSearchRequest );
 
-        assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
-        assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
+        assertTrue( Files.exists(Paths.get( repositoryConfig.getLocation(), ".indexer" )) );
+        assertFalse( Files.exists(Paths.get( repositoryConfig.getLocation(), ".index" )) );
 
         // should return 1 hit
         assertEquals( 1, response.getTotalHitsCount() );
@@ -257,8 +259,8 @@ public class ArchivaIndexingTaskExecutorTest
                                        new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
                BooleanClause.Occur.SHOULD );
 
-        assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
-        assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
+        assertTrue( Files.exists(Paths.get( repositoryConfig.getLocation(), ".indexer" )) );
+        assertFalse( Files.exists(Paths.get( repositoryConfig.getLocation(), ".index" )) );
 
         flatSearchRequest = new FlatSearchRequest( q, getIndexingContext() );
 
@@ -274,22 +276,23 @@ public class ArchivaIndexingTaskExecutorTest
         throws Exception
     {
 
-        File indexerDirectory = new File( repositoryConfig.getLocation(), ".indexer" );
+        Path indexerDirectory =Paths.get( repositoryConfig.getLocation(), ".indexer" );
 
-        indexerDirectory.listFiles( new FilenameFilter()
-        {
-            @Override
-            public boolean accept( File file, String s )
+        Files.list(indexerDirectory).filter( path -> path.getFileName().toString().startsWith("nexus-maven-repository-index") )
+            .forEach( path ->
             {
-                if ( s.startsWith( "nexus-maven-repository-index" ) )
+                try
                 {
-                    new File( file, s ).delete();
+                    Files.delete( path );
                 }
-                return false;
-            }
-        } );
+                catch ( IOException e )
+                {
+                    e.printStackTrace( );
+                }
+            } );
+
 
-        File artifactFile = new File( repositoryConfig.getLocation(),
+        Path artifactFile = Paths.get( repositoryConfig.getLocation(),
                                       "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
 
         ArtifactIndexingTask task =
@@ -306,19 +309,19 @@ public class ArchivaIndexingTaskExecutorTest
 
         indexingExecutor.executeTask( task );
 
-        assertTrue( indexerDirectory.exists() );
+        assertTrue( Files.exists(indexerDirectory) );
 
         // test packed index file creation
         //no more zip
         //Assertions.assertThat(new File( indexerDirectory, "nexus-maven-repository-index.zip" )).exists();
-        Assertions.assertThat( new File( indexerDirectory, "nexus-maven-repository-index.properties" ) ).exists();
-        Assertions.assertThat( new File( indexerDirectory, "nexus-maven-repository-index.gz" ) ).exists();
+        Assertions.assertThat( Files.exists(indexerDirectory.resolve("nexus-maven-repository-index.properties" ) ));
+        Assertions.assertThat( Files.exists(indexerDirectory.resolve("nexus-maven-repository-index.gz" ) ));
 
         // unpack .zip index
-        File destDir = new File( repositoryConfig.getLocation(), ".indexer/tmp" );
+        Path destDir = Paths.get( repositoryConfig.getLocation(), ".indexer/tmp" );
         //unzipIndex( indexerDirectory.getPath(), destDir.getPath() );
 
-        DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher( indexerDirectory );
+        DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher( indexerDirectory.toFile() );
         IndexUpdateRequest updateRequest = new IndexUpdateRequest( getIndexingContext(), fetcher );
         //updateRequest.setLocalIndexCacheDir( indexerDirectory );
         indexUpdater.fetchAndUpdateIndex( updateRequest );
index b7e630e1e8fc2c7993abb761bb0c069e802ec893..c40fc622d73eed5ddf7a1b3588d6232061e69fdb 100644 (file)
@@ -45,8 +45,10 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
-import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.concurrent.TimeUnit;
 
@@ -83,17 +85,17 @@ public class DownloadRemoteIndexTaskTest
         server = new Server( );
         serverConnector = new ServerConnector( server, new HttpConnectionFactory());
         server.addConnector( serverConnector );
-        createContext( server, new File( "src/test/" ) );
+        createContext( server, Paths.get( "src/test/" ) );
         this.server.start();
         this.port = serverConnector.getLocalPort();
         log.info( "start server on port {}", this.port );
     }
 
-    protected void createContext( Server server, File repositoryDirectory )
+    protected void createContext( Server server, Path repositoryDirectory )
         throws IOException
     {
         ServletContextHandler context = new ServletContextHandler();
-        context.setResourceBase( repositoryDirectory.getAbsolutePath() );
+        context.setResourceBase( repositoryDirectory.toAbsolutePath().toString() );
         context.setContextPath( "/" );
         ServletHolder sh = new ServletHolder( DefaultServlet.class );
         context.addServlet( sh, "/" );
@@ -141,16 +143,16 @@ public class DownloadRemoteIndexTaskTest
     }
 
 
-    protected RemoteRepository getRemoteRepository()
+    protected RemoteRepository getRemoteRepository() throws IOException
     {
         RemoteRepository remoteRepository = new RemoteRepository();
-        File indexDirectory =
-            new File( FileUtils.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) );
-        indexDirectory.mkdirs();
-        indexDirectory.deleteOnExit();
+        Path indexDirectory =
+            Paths.get( FileUtils.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) );
+        Files.createDirectories( indexDirectory );
+        indexDirectory.toFile().deleteOnExit();
 
         remoteRepository.setName( "foo" );
-        remoteRepository.setIndexDirectory( indexDirectory.getAbsolutePath() );
+        remoteRepository.setIndexDirectory( indexDirectory.toAbsolutePath().toString() );
         remoteRepository.setDownloadRemoteIndex( true );
         remoteRepository.setId( "test-repo" );
         remoteRepository.setUrl( "http://localhost:" + port );
index c665a79a987538e698f306f8b3110ff5f14abbfc..b93fe5a759144dfb9279c0a6e91f2b489542539e 100644 (file)
@@ -2,7 +2,8 @@ package org.apache.archiva.scheduler.repository.model;
 
 import org.apache.archiva.redback.components.taskqueue.Task;
 
-import java.io.File;
+import java.nio.file.Path;
+
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -32,7 +33,7 @@ public class RepositoryTask
 {
     private String repositoryId;
 
-    private File resourceFile;
+    private Path resourceFile;
 
     private boolean updateRelatedArtifacts;
 
@@ -80,12 +81,12 @@ public class RepositoryTask
         return 0;
     }
 
-    public File getResourceFile()
+    public Path getResourceFile()
     {
         return resourceFile;
     }
 
-    public void setResourceFile( File resourceFile )
+    public void setResourceFile( Path resourceFile )
     {
         this.resourceFile = resourceFile;
     }
index 87aaceb3e7fc2fd89edbf1f0147f67ca97e81acd..1ac363cd92d0f0a4d5145e63ce25b8c82c2008e6 100644 (file)
@@ -113,7 +113,7 @@ public class ArchivaRepositoryScanningTaskExecutor
             if ( task.getResourceFile() != null )
             {
                 log.debug( "Executing task from queue with job name: {}", task );
-                consumers.executeConsumers( arepo, task.getResourceFile().toPath(), task.isUpdateRelatedArtifacts() );
+                consumers.executeConsumers( arepo, task.getResourceFile(), task.isUpdateRelatedArtifacts() );
             }
             else
             {
index de7bd459d521c654f37eec32b0a0f676939175b1..18902975d5707f7b7f72d031a3ea85747b81b584 100644 (file)
@@ -36,8 +36,17 @@ import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.FileVisitOption;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
 import java.util.Calendar;
+import java.util.Comparator;
+import java.util.stream.Stream;
 
 import static org.mockito.Mockito.mock;
 
@@ -70,7 +79,7 @@ public abstract class AbstractArchivaRepositoryScanningTaskExecutorTest
     @Named( value = "repositorySessionFactory#mock" )
     private MockRepositorySessionFactory factory;
 
-    protected File repoDir;
+    protected Path repoDir;
 
     protected static final String TEST_REPO_ID = "testRepo";
 
@@ -83,28 +92,40 @@ public abstract class AbstractArchivaRepositoryScanningTaskExecutorTest
     {
         super.setUp();
 
-        File sourceRepoDir = new File( "./src/test/repositories/default-repository" );
-        repoDir = new File( "./target/default-repository" );
+        Path sourceRepoDir = Paths.get( "src/test/repositories/default-repository" );
+        repoDir = Paths.get( "target/default-repository" );
 
-        FileUtils.deleteDirectory( repoDir );
-        assertFalse( "Default Test Repository should not exist.", repoDir.exists() );
+        org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoDir );
+        assertFalse( "Default Test Repository should not exist.", Files.exists(repoDir) );
 
-        repoDir.mkdir();
+        Files.createDirectories(repoDir);
 
-        FileUtils.copyDirectoryStructure( sourceRepoDir, repoDir );
+        FileUtils.copyDirectoryStructure( sourceRepoDir.toFile(), repoDir.toFile() );
         // set the timestamps to a time well in the past
         Calendar cal = Calendar.getInstance();
         cal.add( Calendar.YEAR, -1 );
-        FileUtils.getFiles( repoDir, "**", null ) //
-            .stream().forEach( file -> file.setLastModified( cal.getTimeInMillis() ) );
-
-        // TODO: test they are excluded instead
-        for ( String dir : FileUtils.getDirectoryNames( repoDir, "**/.svn", null, false ) )
-        {
-            FileUtils.deleteDirectory( new File( repoDir, dir ) );
+        try(Stream<Path> stream = Files.walk( repoDir,FileVisitOption.FOLLOW_LINKS)) {
+            stream.forEach( path ->
+            {
+                try
+                {
+                    Files.setLastModifiedTime( path, FileTime.fromMillis( cal.getTimeInMillis( ) ) );
+                }
+                catch ( IOException e )
+                {
+                    e.printStackTrace( );
+                }
+            } );
         }
+        PathMatcher m = FileSystems.getDefault().getPathMatcher( "glob:**/.svn" );
+        Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS).filter(Files::isDirectory)
+            .sorted( Comparator.reverseOrder( ))
+            .filter( path -> m.matches( path ) )
+            .forEach( path ->
+                org.apache.archiva.common.utils.FileUtils.deleteQuietly( path )
+            );
 
-        assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
+        assertTrue( "Default Test Repository should exist.", Files.exists(repoDir) && Files.isDirectory( repoDir) );
 
         assertNotNull( archivaConfig );
 
@@ -112,7 +133,7 @@ public abstract class AbstractArchivaRepositoryScanningTaskExecutorTest
         ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
         repositoryConfiguration.setId( TEST_REPO_ID );
         repositoryConfiguration.setName( "Test Repository" );
-        repositoryConfiguration.setLocation( repoDir.getAbsolutePath() );
+        repositoryConfiguration.setLocation( repoDir.toAbsolutePath().toString() );
         archivaConfig.getConfiguration().getManagedRepositories().clear();
         archivaConfig.getConfiguration().addManagedRepository( repositoryConfiguration );
 
@@ -126,9 +147,9 @@ public abstract class AbstractArchivaRepositoryScanningTaskExecutorTest
     public void tearDown()
         throws Exception
     {
-        FileUtils.deleteDirectory( repoDir );
+        org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoDir );
 
-        assertFalse( repoDir.exists() );
+        assertFalse( Files.exists(repoDir) );
 
         super.tearDown();
     }
index 885c9a6a8bc4dcf2f765bbe2cb1e4fa479007f94..835454370e73002520296d8df93285efb5111f3a 100644 (file)
@@ -28,7 +28,10 @@ import org.codehaus.plexus.util.FileUtils;
 import org.junit.Test;
 import org.springframework.test.context.ContextConfiguration;
 
-import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
@@ -72,20 +75,20 @@ public class ArchivaRepositoryScanningTaskExecutorPhase2Test
 //        assertEquals( 5, newStats.getTotalProjectCount() );
 //        assertEquals( 14159, newStats.getTotalArtifactFileSize() );
 
-        File newArtifactGroup = new File( repoDir, "org/apache/archiva" );
-        assertFalse( "newArtifactGroup should not exist.", newArtifactGroup.exists() );
+        Path newArtifactGroup = repoDir.resolve( "org/apache/archiva" );
+        assertFalse( "newArtifactGroup should not exist.", Files.exists(newArtifactGroup) );
 
-        FileUtils.copyDirectoryStructure( new File( "target/test-classes/test-repo/org/apache/archiva" ),
-                                          newArtifactGroup );
+        FileUtils.copyDirectoryStructure( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
+                                          newArtifactGroup.toFile() );
 
         // update last modified date
-        new File( newArtifactGroup, "archiva-index-methods-jar-test/1.0/pom.xml" ).setLastModified(
-            Calendar.getInstance().getTimeInMillis() + 1000 );
-        new File( newArtifactGroup,
-                  "archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ).setLastModified(
-            Calendar.getInstance().getTimeInMillis() + 1000 );
+        Files.setLastModifiedTime(newArtifactGroup.resolve( "archiva-index-methods-jar-test/1.0/pom.xml" ), FileTime.fromMillis(
+            Calendar.getInstance().getTimeInMillis() + 1000 ));
+        Files.setLastModifiedTime( newArtifactGroup.resolve(
+                  "archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ), FileTime.fromMillis(
+            Calendar.getInstance().getTimeInMillis() + 1000 ));
 
-        assertTrue( newArtifactGroup.exists() );
+        assertTrue( Files.exists(newArtifactGroup) );
 
         taskExecutor.executeTask( repoTask );
 
@@ -117,20 +120,20 @@ public class ArchivaRepositoryScanningTaskExecutorPhase2Test
 
         createAndSaveTestStats();
 
-        File newArtifactGroup = new File( repoDir, "org/apache/archiva" );
-        assertFalse( "newArtifactGroup should not exist.", newArtifactGroup.exists() );
+        Path newArtifactGroup = repoDir.resolve( "org/apache/archiva" );
+        assertFalse( "newArtifactGroup should not exist.", Files.exists(newArtifactGroup) );
 
-        FileUtils.copyDirectoryStructure( new File( "target/test-classes/test-repo/org/apache/archiva" ),
-                                          newArtifactGroup );
+        FileUtils.copyDirectoryStructure( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
+                                          newArtifactGroup.toFile() );
 
         // update last modified date, placing shortly after last scan
-        new File( newArtifactGroup, "archiva-index-methods-jar-test/1.0/pom.xml" ).setLastModified(
-            Calendar.getInstance().getTimeInMillis() + 1000 );
-        new File( newArtifactGroup,
-                  "archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ).setLastModified(
-            Calendar.getInstance().getTimeInMillis() + 1000 );
+        Files.setLastModifiedTime(newArtifactGroup.resolve("archiva-index-methods-jar-test/1.0/pom.xml" ), FileTime.fromMillis(
+            Calendar.getInstance().getTimeInMillis() + 1000 ));
+        Files.setLastModifiedTime( newArtifactGroup.resolve(
+                  "archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ), FileTime.fromMillis(
+            Calendar.getInstance().getTimeInMillis() + 1000 ));
 
-        assertTrue( newArtifactGroup.exists() );
+        assertTrue( Files.exists(newArtifactGroup) );
 
         // scan using the really long previous duration
         taskExecutor.executeTask( repoTask );
@@ -164,20 +167,20 @@ public class ArchivaRepositoryScanningTaskExecutorPhase2Test
 
         createAndSaveTestStats();
 
-        File newArtifactGroup = new File( repoDir, "org/apache/archiva" );
-        assertFalse( "newArtifactGroup should not exist.", newArtifactGroup.exists() );
+        Path newArtifactGroup = repoDir.resolve( "org/apache/archiva" );
+        assertFalse( "newArtifactGroup should not exist.", Files.exists(newArtifactGroup) );
 
-        FileUtils.copyDirectoryStructure( new File( "target/test-classes/test-repo/org/apache/archiva" ),
-                                          newArtifactGroup );
+        FileUtils.copyDirectoryStructure( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
+                                          newArtifactGroup.toFile() );
 
         // update last modified date, placing in middle of last scan
-        new File( newArtifactGroup, "archiva-index-methods-jar-test/1.0/pom.xml" ).setLastModified(
-            Calendar.getInstance().getTimeInMillis() - 50000 );
-        new File( newArtifactGroup,
-                  "archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ).setLastModified(
-            Calendar.getInstance().getTimeInMillis() - 50000 );
+        Files.setLastModifiedTime( newArtifactGroup.resolve("archiva-index-methods-jar-test/1.0/pom.xml" ), FileTime.fromMillis(
+            Calendar.getInstance().getTimeInMillis() - 50000 ));
+        Files.setLastModifiedTime( newArtifactGroup.resolve(
+                  "archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ), FileTime.fromMillis(
+                      Calendar.getInstance().getTimeInMillis() - 50000 ));
 
-        assertTrue( newArtifactGroup.exists() );
+        assertTrue( Files.exists(newArtifactGroup) );
 
         // scan using the really long previous duration
         taskExecutor.executeTask( repoTask );
index 0c57b3c5c39bb3f07229d8e15a929f9c61a49996..a336849d0b1d7ceebaff501fd7ea675df750a5e8 100644 (file)
@@ -503,7 +503,7 @@ public class DefaultRepositoriesService
     {
         RepositoryTask task = new RepositoryTask();
         task.setRepositoryId( repositoryId );
-        task.setResourceFile( localFile );
+        task.setResourceFile( localFile.toPath() );
         task.setUpdateRelatedArtifacts( true );
         //task.setScanAll( true );
 
index 5d27b97e06d2f2d73484a7b4e2ddbfef5df38867..e02d52a6d554f83d7d0dc4714e56c83c638e916d 100644 (file)
@@ -559,7 +559,7 @@ public class DefaultFileUploadService
     {
         RepositoryTask task = new RepositoryTask();
         task.setRepositoryId( repositoryId );
-        task.setResourceFile( localFile );
+        task.setResourceFile( localFile.toPath() );
         task.setUpdateRelatedArtifacts( true );
         task.setScanAll( false );
 
index 20bb2cb39cd38d7248dae57e2b98358a416a1133..481b60414d1d3651e0dfccd90768f931624fb4ea 100644 (file)
@@ -713,7 +713,7 @@ public class ArchivaDavResource
     {
         RepositoryTask task = new RepositoryTask();
         task.setRepositoryId( repository.getId() );
-        task.setResourceFile( localFile );
+        task.setResourceFile( localFile.toPath() );
         task.setUpdateRelatedArtifacts( false );
         task.setScanAll( false );