]> source.dussan.org Git - archiva.git/commitdiff
Moving indexer to java.nio
authorMartin Stockhammer <martin_s@apache.org>
Mon, 4 Sep 2017 21:18:30 +0000 (23:18 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Mon, 4 Sep 2017 21:18:30 +0000 (23:18 +0200)
18 files changed:
archiva-docs/src/site/apt/userguide/virtual-repositories.apt
archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java
archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java
archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java
archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java
archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java
archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/MergedRemoteIndexesScheduler.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java

index 5c60e451f1d74eb8d4558f4af7f6a891ce3767e5..70723d60085660b3aa287cf72caeda594615ee63 100644 (file)
@@ -108,7 +108,7 @@ Virtual Repositories
   only those repositories which the user has an Obeserver role for). The first resource found for the requested artifact
   would be returned.
 
-  Prior to version 1.4-M2, Virtual repositories can return a Maven index in the path /.indexer path
+  Prior to version 1.4-M2, Virtual repositories can return a Maven index in the path .indexer path
 
 * Configuring Virtual Repositories
 
index 46c459b10c0e20ae7a47e662a36fc3b539eaa73c..48cfd8b82a1679977434e4ea4603b9aa6153d3a1 100644 (file)
@@ -144,4 +144,21 @@ public class FileUtils
 
         return basedir;
     }
+
+    /**
+     * This checks, if the given child is a absolute path. If this is the case
+     * the relative path is used.
+     *
+     * @param parent The parent directory
+     * @param child The child
+     * @return The path parent/child
+     */
+    public Path resolveNonAbsolute(Path parent, String child) {
+        Path childPath = Paths.get(child);
+        if (childPath.isAbsolute()) {
+            return parent.resolve(childPath.getNameCount()>0 ? childPath.subpath(0, childPath.getNameCount()) : Paths.get(""));
+        } else {
+            return parent.resolve(child);
+        }
+    }
 }
index 494af12045825f5cd23d11e91fcbdb1772fef9f0..eac0aa2c95149d8af4770b85d12283d3285bd893 100644 (file)
           <version>1.2.0+</version>
           <type>String</type>
           <required>false</required>
-          <defaultValue>/.indexer</defaultValue>
+          <defaultValue>.indexer</defaultValue>
           <description>The path of the merged index.</description>
         </field>
         <field>
index de9342c7486d1fe3bbad743d6f14df61be1e5e98..b4daa8bd82ff28940bc0d1bfa538afef3666d3ae 100644 (file)
@@ -18,7 +18,7 @@ package org.apache.archiva.indexer.merger;
  * under the License.
  */
 
-import org.apache.commons.io.FileUtils;
+import org.apache.archiva.common.utils.FileUtils;
 import org.apache.commons.lang.time.StopWatch;
 import org.apache.maven.index.NexusIndexer;
 import org.apache.maven.index.context.IndexCreator;
@@ -32,8 +32,9 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
-import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -85,15 +86,15 @@ public class DefaultIndexMerger
         stopWatch.reset();
         stopWatch.start();
 
-        File mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();
+        Path mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();
 
-        String tempRepoId = mergedIndexDirectory.getName();
+        String tempRepoId = mergedIndexDirectory.getFileName().toString();
 
         try
         {
-            File indexLocation = new File( mergedIndexDirectory, indexMergerRequest.getMergedIndexPath() );
+            Path indexLocation = mergedIndexDirectory.resolve( indexMergerRequest.getMergedIndexPath() );
             IndexingContext indexingContext =
-                indexer.addIndexingContext( tempRepoId, tempRepoId, mergedIndexDirectory, indexLocation, null, null,
+                indexer.addIndexingContext( tempRepoId, tempRepoId, mergedIndexDirectory.toFile(), indexLocation.toFile(), null, null,
                                             indexCreators );
 
             for ( String repoId : indexMergerRequest.getRepositoriesIds() )
@@ -111,7 +112,7 @@ public class DefaultIndexMerger
             {
                 IndexPackingRequest request = new IndexPackingRequest( indexingContext, //
                                                                        indexingContext.acquireIndexSearcher().getIndexReader(), //
-                                                                       indexLocation );
+                                                                       indexLocation.toFile() );
                 indexPacker.packIndex( request );
             }
 
@@ -151,8 +152,8 @@ public class DefaultIndexMerger
             {
                 indexer.removeIndexingContext( indexingContext, true );
             }
-            File directory = temporaryGroupIndex.getDirectory();
-            if ( directory != null && directory.exists() )
+            Path directory = temporaryGroupIndex.getDirectory();
+            if ( directory != null && Files.exists(directory) )
             {
                 FileUtils.deleteDirectory( directory );
             }
index 20fe232f593d980e16c34e56446919e20331a880..f0fbcbd31a29fef7a13b35fbdaf667e04be7d837 100644 (file)
@@ -30,7 +30,7 @@ import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.File;
+import java.nio.file.Path;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -57,7 +57,7 @@ public class DefaultMergedRemoteIndexesScheduler
     private Map<String, ScheduledFuture> scheduledFutureMap = new ConcurrentHashMap<>();
 
     @Override
-    public void schedule( RepositoryGroup repositoryGroup, File directory )
+    public void schedule( RepositoryGroup repositoryGroup, Path directory )
     {
         if ( StringUtils.isEmpty( repositoryGroup.getCronExpression() ) )
         {
index 708268e1c7f0243894e87ee2a86fc96a2984e662..0b3803f48d730b8ee67d1e03c8644d5d248f673e 100644 (file)
@@ -18,7 +18,7 @@ package org.apache.archiva.indexer.merger;
  * under the License.
  */
 
-import java.io.File;
+import java.nio.file.Path;
 import java.util.Collection;
 
 /**
@@ -41,11 +41,11 @@ public class IndexMergerRequest
      */
     private String groupId;
 
-    private String mergedIndexPath = "/.indexer";
+    private String mergedIndexPath = ".indexer";
 
     private int mergedIndexTtl;
 
-    private File mergedIndexDirectory;
+    private Path mergedIndexDirectory;
 
     private boolean temporary;
 
@@ -119,17 +119,17 @@ public class IndexMergerRequest
         this.mergedIndexTtl = mergedIndexTtl;
     }
 
-    public File getMergedIndexDirectory()
+    public Path getMergedIndexDirectory()
     {
         return mergedIndexDirectory;
     }
 
-    public void setMergedIndexDirectory( File mergedIndexDirectory )
+    public void setMergedIndexDirectory( Path mergedIndexDirectory )
     {
         this.mergedIndexDirectory = mergedIndexDirectory;
     }
 
-    public IndexMergerRequest mergedIndexDirectory( File mergedIndexDirectory )
+    public IndexMergerRequest mergedIndexDirectory( Path mergedIndexDirectory )
     {
         this.mergedIndexDirectory = mergedIndexDirectory;
         return this;
index 9ab06d6478c8f13eae5402ed9c46b855016086b4..d0b576b74ef30dfa1395b05d9dfcc404612203c1 100644 (file)
@@ -18,8 +18,8 @@ package org.apache.archiva.indexer.merger;
  * under the License.
  */
 
-import java.io.File;
 import java.io.Serializable;
+import java.nio.file.Path;
 import java.util.Date;
 
 /**
@@ -30,7 +30,7 @@ public class TemporaryGroupIndex
 {
     private long creationTime = new Date().getTime();
 
-    private File directory;
+    private Path directory;
 
     private String indexId;
 
@@ -38,7 +38,7 @@ public class TemporaryGroupIndex
 
     private int mergedIndexTtl;
 
-    public TemporaryGroupIndex(File directory, String indexId, String groupId, int mergedIndexTtl)
+    public TemporaryGroupIndex(Path directory, String indexId, String groupId, int mergedIndexTtl)
     {
         this.directory = directory;
         this.indexId = indexId;
@@ -57,12 +57,12 @@ public class TemporaryGroupIndex
         return this;
     }
 
-    public File getDirectory()
+    public Path getDirectory()
     {
         return directory;
     }
 
-    public TemporaryGroupIndex setDirectory( File directory )
+    public TemporaryGroupIndex setDirectory( Path directory )
     {
         this.directory = directory;
         return this;
index f9e2cf301a263dcd68d1f54a81fc6dba66ce9011..9874fc75df94795d59bec1e720a32ccb9c74d073 100644 (file)
@@ -23,11 +23,11 @@ import junit.framework.TestCase;
 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
 import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
+import org.apache.archiva.common.utils.FileUtils;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.configuration.Configuration;
 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.apache.maven.index.ArtifactContext;
 import org.apache.maven.index.ArtifactContextProducer;
@@ -48,6 +48,10 @@ 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.List;
 
 /**
@@ -98,11 +102,11 @@ public abstract class AbstractMavenRepositorySearch
     {
         super.setUp();
 
-        FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ) );
-        assertFalse( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ).exists() );
+        FileUtils.deleteDirectory( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ) );
+        assertFalse( Files.exists(Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" )) );
 
-        FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ) );
-        assertFalse( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ).exists() );
+        FileUtils.deleteDirectory( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ) );
+        assertFalse( Files.exists(Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" )) );
 
         archivaConfigControl = EasyMock.createControl();
 
@@ -136,11 +140,11 @@ public abstract class AbstractMavenRepositorySearch
             nexusIndexer.removeIndexingContext( indexingContext, true );
         }
 
-        FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 ) );
-        assertFalse( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 ).exists() );
+        FileUtils.deleteDirectory( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 ) );
+        assertFalse( Files.exists(Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 )) );
 
-        FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 ) );
-        assertFalse( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 ).exists() );
+        FileUtils.deleteDirectory( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 ) );
+        assertFalse( Files.exists(Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 )) );
 
         super.tearDown();
     }
@@ -150,10 +154,17 @@ public abstract class AbstractMavenRepositorySearch
         ManagedRepositoryConfiguration repositoryConfig = new ManagedRepositoryConfiguration();
         repositoryConfig.setId( repository );
         repositoryConfig.setLocation( org.apache.archiva.common.utils.FileUtils.getBasedir() + "/target/repos/" + repository );
-        File f = new File( repositoryConfig.getLocation() );
-        if ( !f.exists() )
+        Path f = Paths.get( repositoryConfig.getLocation() );
+        if ( !Files.exists(f) )
         {
-            f.mkdirs();
+            try
+            {
+                Files.createDirectories( f );
+            }
+            catch ( IOException e )
+            {
+                log.error("Could not create directories for {}", f);
+            }
         }
         repositoryConfig.setLayout( "default" );
         repositoryConfig.setName( repository );
@@ -164,7 +175,7 @@ public abstract class AbstractMavenRepositorySearch
         return repositoryConfig;
     }
 
-    protected void createIndex( String repository, List<File> filesToBeIndexed, boolean scan )
+    protected void createIndex( String repository, List<Path> filesToBeIndexed, boolean scan )
         throws Exception
     {
 
@@ -175,43 +186,43 @@ public abstract class AbstractMavenRepositorySearch
             nexusIndexer.removeIndexingContext( context, true );
         }
 
-        File indexerDirectory = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + repository + "/.indexer" );
+        Path indexerDirectory = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + repository + "/.indexer" );
 
-        if ( indexerDirectory.exists() )
+        if ( Files.exists(indexerDirectory) )
         {
             FileUtils.deleteDirectory( indexerDirectory );
         }
 
-        assertFalse( indexerDirectory.exists() );
+        assertFalse( Files.exists(indexerDirectory) );
 
-        File lockFile = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + repository + "/.indexer/write.lock" );
-        if ( lockFile.exists() )
+        Path lockFile = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + repository + "/.indexer/write.lock" );
+        if ( Files.exists(lockFile) )
         {
-            lockFile.delete();
+            Files.delete(lockFile);
         }
 
-        assertFalse( lockFile.exists() );
+        assertFalse( Files.exists(lockFile) );
 
-        File repo = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + repository );
-        assertTrue( repo.exists() );
-        File indexDirectory =
-            new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) );
-        indexDirectory.deleteOnExit();
+        Path repo = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + repository );
+        assertTrue( Files.exists(repo) );
+        Path indexDirectory =
+            Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) );
+        indexDirectory.toFile().deleteOnExit();
         FileUtils.deleteDirectory( indexDirectory );
 
-        context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory,
-                                                   repo.toURI().toURL().toExternalForm(),
-                                                   indexDirectory.toURI().toURL().toString(), indexCreators );
+        context = nexusIndexer.addIndexingContext( repository, repository, repo.toFile(), indexDirectory.toFile(),
+                                                   repo.toUri().toURL().toExternalForm(),
+                                                   indexDirectory.toUri().toURL().toString(), indexCreators );
 
         // minimize datas in memory
 //        context.getIndexWriter().setMaxBufferedDocs( -1 );
 //        context.getIndexWriter().setRAMBufferSizeMB( 1 );
-        for ( File artifactFile : filesToBeIndexed )
+        for ( Path artifactFile : filesToBeIndexed )
         {
-            assertTrue( "file not exists " + artifactFile.getPath(), artifactFile.exists() );
-            ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
+            assertTrue( "file not exists " + artifactFile, Files.exists(artifactFile) );
+            ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile.toFile() );
 
-            if ( artifactFile.getPath().endsWith( ".pom" ) )
+            if ( artifactFile.toString().endsWith( ".pom" ) )
             {
                 ac.getArtifactInfo().setFileExtension( "pom" );
                 ac.getArtifactInfo().setPackaging( "pom" );
index e9c10474b4653193d8c706d9d917f5e5d9fa0426..7257e4a925d291f3af14ea562df1d8fa626bf6cd 100644 (file)
@@ -22,7 +22,7 @@ package org.apache.archiva.indexer.search;
 import org.easymock.EasyMock;
 import org.junit.Test;
 
-import java.io.File;
+import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -39,7 +39,7 @@ public class MavenRepositorySearchOSGITest
         throws Exception
     {
 
-        createIndex( TEST_REPO_1, Collections.<File>emptyList(), true );
+        createIndex( TEST_REPO_1, Collections.<Path>emptyList(), true );
 
         List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
 
index 5968513628e900d8093725b68ca52cad323ec86c..a9893111c68949c636576717c23be27cafd0f350 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.test.context.ContextConfiguration;
 
-import java.io.File;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -47,13 +47,13 @@ public class MavenRepositorySearchTest
     private void createSimpleIndex( boolean scan )
         throws Exception
     {
-        List<File> files = new ArrayList<>();
+        List<Path> files = new ArrayList<>();
         files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test", TEST_REPO_1,
-                              "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ).toFile() );
+                              "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
         files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test", TEST_REPO_1,
-                              "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ).toFile() );
+                              "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ));
         files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test", TEST_REPO_1,
-                              "org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ).toFile() );
+                              "org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ));
 
         createIndex( TEST_REPO_1, files, scan );
     }
@@ -61,20 +61,20 @@ public class MavenRepositorySearchTest
     private void createIndexContainingMoreArtifacts( boolean scan )
         throws Exception
     {
-        List<File> files = new ArrayList<>();
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        List<Path> files = new ArrayList<>();
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(),
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(),
                              "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(),
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(),
                              "src/test/" + TEST_REPO_1 + "/com/classname-search/1.0/classname-search-1.0.jar" ) );
 
         createIndex( TEST_REPO_1, files, scan );
@@ -83,15 +83,15 @@ public class MavenRepositorySearchTest
     private void createIndexContainingMultipleArtifactsSameVersion( boolean scan )
         throws Exception
     {
-        List<File> files = new ArrayList<>();
+        List<Path> files = new ArrayList<>();
 
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
 
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom" ) );
 
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar" ) );
 
         createIndex( TEST_REPO_1, files, scan );
@@ -325,10 +325,10 @@ public class MavenRepositorySearchTest
     {
         createSimpleIndex( true );
 
-        List<File> files = new ArrayList<>();
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2
+        List<Path> files = new ArrayList<>();
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2
             + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2
             + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
         createIndex( TEST_REPO_2, files, false );
 
@@ -456,10 +456,10 @@ public class MavenRepositorySearchTest
     public void testAdvancedSearch()
         throws Exception
     {
-        List<File> files = new ArrayList<>();
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2
+        List<Path> files = new ArrayList<>();
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2
             + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2
             + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
         createIndex( TEST_REPO_2, files, false );
 
@@ -542,10 +542,10 @@ public class MavenRepositorySearchTest
     public void testAdvancedSearchArtifactIdHasNumericChar()
         throws Exception
     {
-        List<File> files = new ArrayList<>();
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(),
+        List<Path> files = new ArrayList<>();
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(),
                              "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
-        files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
+        files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1
             + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
         createIndex( TEST_REPO_1, files, true );
 
@@ -866,17 +866,17 @@ public class MavenRepositorySearchTest
         throws Exception
     {
 
-        File repo = new File( "target/repo-release" );
-        File indexDirectory = new File( repo, ".index" );
-        FileUtils.copyDirectoryStructure( new File( "src/test/repo-release" ), repo );
+        Path repo = Paths.get( "target/repo-release" );
+        Path indexDirectory = repo.resolve(".index" );
+        FileUtils.copyDirectoryStructure( Paths.get( "src/test/repo-release" ).toFile(), repo.toFile() );
 
-        IndexUpgrader.main( new String[]{ indexDirectory.getAbsolutePath() } );
+        IndexUpgrader.main( new String[]{ indexDirectory.toAbsolutePath().toString() } );
 
         createIndex( "repo-release", Collections.emptyList(), false );
 
-        nexusIndexer.addIndexingContext( REPO_RELEASE, REPO_RELEASE, repo, indexDirectory,
-                                         repo.toURI().toURL().toExternalForm(),
-                                         indexDirectory.toURI().toURL().toString(), indexCreators );
+        nexusIndexer.addIndexingContext( REPO_RELEASE, REPO_RELEASE, repo.toFile(), indexDirectory.toFile(),
+                                         repo.toUri().toURL().toExternalForm(),
+                                         indexDirectory.toUri().toURL().toString(), indexCreators );
 
         SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
         limits.setPageSize( 300 );
index db152c9a73bf747ca9e7ed7edc7e6e98a5c9682e..6c25e3a672c1bc0314e7f4eae1b3aaa7ced71092 100644 (file)
@@ -44,7 +44,7 @@ public class RepositoryGroup
     /**
      * The path of the merged index.
      */
-    private String mergedIndexPath = "/.indexer";
+    private String mergedIndexPath = ".indexer";
 
     /**
      * The TTL (time to live) of the repo group's merged index.
index 0f8e54f3d69b4cc7071693cd4fb54936806254c0..024c3521701488d498a2a80e71ba1f96bdb5f768 100644 (file)
@@ -82,7 +82,7 @@ public class DefaultRepositoryGroupAdmin
             for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() )
             {
                 mergedRemoteIndexesScheduler.schedule( repositoryGroup,
-                                                       getMergedIndexDirectory( repositoryGroup.getId() ) );
+                                                       getMergedIndexDirectory( repositoryGroup.getId() ).toPath() );
                 // create the directory for each group if not exists
                 File groupPath = new File( groupsDirectory, repositoryGroup.getId() );
                 if ( !groupPath.exists() )
@@ -156,7 +156,7 @@ public class DefaultRepositoryGroupAdmin
         configuration.addRepositoryGroup( repositoryGroupConfiguration );
         saveConfiguration( configuration );
         triggerAuditEvent( repositoryGroup.getId(), null, AuditEvent.ADD_REPO_GROUP, auditInformation );
-        mergedRemoteIndexesScheduler.schedule( repositoryGroup, getMergedIndexDirectory( repositoryGroup.getId() ) );
+        mergedRemoteIndexesScheduler.schedule( repositoryGroup, getMergedIndexDirectory( repositoryGroup.getId() ).toPath() );
         return Boolean.TRUE;
     }
 
@@ -212,7 +212,7 @@ public class DefaultRepositoryGroupAdmin
             triggerAuditEvent( repositoryGroup.getId(), null, AuditEvent.MODIFY_REPO_GROUP, auditInformation );
         }
         mergedRemoteIndexesScheduler.unschedule( repositoryGroup );
-        mergedRemoteIndexesScheduler.schedule( repositoryGroup, getMergedIndexDirectory( repositoryGroup.getId() ) );
+        mergedRemoteIndexesScheduler.schedule( repositoryGroup, getMergedIndexDirectory( repositoryGroup.getId() ).toPath() );
         return Boolean.TRUE;
     }
 
index 3720405cab19c7da0c49271dd2b16eabcf6a7839..6e708c0d3fa47291946d96cb939eaa5cf61021c7 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.archiva.scheduler.MergedRemoteIndexesScheduler;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.nio.file.Path;
 
 /**
  * @author Olivier Lamy
@@ -34,7 +35,7 @@ public class MockMergedRemoteIndexesScheduler
 {
 
     @Override
-    public void schedule( RepositoryGroup repositoryGroup, File directory )
+    public void schedule( RepositoryGroup repositoryGroup, Path directory )
     {
         // no op
     }
index 9403ae19d3043e70de95ce5066de18b2ce55d525..faaaa0cca3f0084ee0d4c35c3b180d2b36785d10 100644 (file)
@@ -70,7 +70,7 @@ public class RepositoryGroupAdminTest
 
             // verify if default values were saved
             assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
-            assertEquals("/.indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
+            assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
 
             repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
 
@@ -264,7 +264,7 @@ public class RepositoryGroupAdminTest
 
             // verify if default values were saved
             assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
-            assertEquals("/.indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
+            assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
 
             repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
             assertNotNull( repositoryGroup );
index d04de274dc8b1ac74ca9dec422fa0dd60514e5f4..016f42a3d876192484d9c5ae7a00b7ff5821c772 100644 (file)
@@ -499,7 +499,7 @@ public class MetadataTools
                 {
                     try(Stream<Path> substream = Files.list(p))
                     {
-                        return substream.anyMatch( f -> Files.isRegularFile( f ) && f.endsWith( ".pom" ));
+                        return substream.anyMatch( f -> Files.isRegularFile( f ) && f.toString().endsWith( ".pom" ));
                     }
                     catch ( IOException e )
                     {
index b799861c25c77a33cd97f20661ffc0b4c61ec716..cd9520cbaf9b88b6a57f2106b8503ac7f9119857 100644 (file)
@@ -21,7 +21,7 @@ package org.apache.archiva.scheduler;
 
 import org.apache.archiva.admin.model.beans.RepositoryGroup;
 
-import java.io.File;
+import java.nio.file.Path;
 
 /**
  * @author Olivier Lamy
@@ -35,7 +35,7 @@ public interface MergedRemoteIndexesScheduler
      * remote indexes
      * @param repositoryGroup
      */
-    void schedule( RepositoryGroup repositoryGroup, File directory );
+    void schedule( RepositoryGroup repositoryGroup, Path directory );
 
     void unschedule( RepositoryGroup repositoryGroup );
 
index ecf26209fbfc10408b7683d181578544212dd87c..4938561004d724aff096ea9ae7c530adba3fdc6c 100644 (file)
@@ -1326,7 +1326,7 @@ public class ArchivaDavResourceFactory
 
             TemporaryGroupIndex tmp = temporaryGroupIndexMap.get( repositoryGroupConfiguration.getId() );
 
-            if ( tmp != null && tmp.getDirectory() != null && tmp.getDirectory().exists() )
+            if ( tmp != null && tmp.getDirectory() != null && Files.exists(tmp.getDirectory()))
             {
                 if ( System.currentTimeMillis() - tmp.getCreationTime() > (
                     repositoryGroupConfiguration.getMergedIndexTtl() * 60 * 1000 ) )
@@ -1339,7 +1339,7 @@ public class ArchivaDavResourceFactory
                 {
                     log.debug( MarkerFactory.getMarker( "group.merged.index" ),
                                "merged index for group '{}' found in cache", repositoryGroupConfiguration.getId() );
-                    return tmp.getDirectory();
+                    return tmp.getDirectory().toFile();
                 }
             }
 
@@ -1375,7 +1375,7 @@ public class ArchivaDavResourceFactory
                 new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(),
                                         repositoryGroupConfiguration.getMergedIndexPath(),
                                         repositoryGroupConfiguration.getMergedIndexTtl() ).mergedIndexDirectory(
-                    tempRepoFile ).temporary( true );
+                    tempRepoFile.toPath() ).temporary( true );
 
             MergedRemoteIndexesTaskRequest taskRequest =
                 new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger );
@@ -1386,7 +1386,7 @@ public class ArchivaDavResourceFactory
 
             File mergedRepoDir = indexingContext.getIndexDirectoryFile();
             TemporaryGroupIndex temporaryGroupIndex =
-                new TemporaryGroupIndex( mergedRepoDir, indexingContext.getId(), repositoryGroupConfiguration.getId(),
+                new TemporaryGroupIndex( mergedRepoDir.toPath(), indexingContext.getId(), repositoryGroupConfiguration.getId(),
                                          repositoryGroupConfiguration.getMergedIndexTtl() ) //
                     .setCreationTime( new Date().getTime() );
             temporaryGroupIndexMap.put( repositoryGroupConfiguration.getId(), temporaryGroupIndex );
index 8571821d609b6341e8f18d0fc86e441564e61417..a9ccb8db34afd4a8649fb1b2ed20d3cf3a6fab22 100644 (file)
@@ -75,7 +75,7 @@ public class TemporaryGroupIndexSessionCleaner
         for ( TemporaryGroupIndex temporaryGroupIndex : tempFilesPerKey.values() )
         {
             log.info( "cleanup temporaryGroupIndex {} directory {}", temporaryGroupIndex.getIndexId(),
-                      temporaryGroupIndex.getDirectory().getAbsolutePath() );
+                      temporaryGroupIndex.getDirectory().toAbsolutePath() );
             getIndexMerger( httpSessionEvent ).cleanTemporaryGroupIndex( temporaryGroupIndex );
         }
     }