From c8b33462257129f8b43b65b317abd43b028f69fc Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Mon, 4 Sep 2017 23:18:30 +0200 Subject: [PATCH] Moving indexer to java.nio --- .../apt/userguide/virtual-repositories.apt | 2 +- .../archiva/common/utils/FileUtils.java | 17 +++++ .../src/main/mdo/configuration.mdo | 2 +- .../indexer/merger/DefaultIndexMerger.java | 19 ++--- .../DefaultMergedRemoteIndexesScheduler.java | 4 +- .../indexer/merger/IndexMergerRequest.java | 12 +-- .../indexer/merger/TemporaryGroupIndex.java | 10 +-- .../search/AbstractMavenRepositorySearch.java | 75 +++++++++++-------- .../search/MavenRepositorySearchOSGITest.java | 4 +- .../search/MavenRepositorySearchTest.java | 66 ++++++++-------- .../admin/model/beans/RepositoryGroup.java | 2 +- .../group/DefaultRepositoryGroupAdmin.java | 6 +- .../MockMergedRemoteIndexesScheduler.java | 3 +- .../group/RepositoryGroupAdminTest.java | 4 +- .../repository/metadata/MetadataTools.java | 2 +- .../MergedRemoteIndexesScheduler.java | 4 +- .../webdav/ArchivaDavResourceFactory.java | 8 +- .../TemporaryGroupIndexSessionCleaner.java | 2 +- 18 files changed, 136 insertions(+), 106 deletions(-) diff --git a/archiva-docs/src/site/apt/userguide/virtual-repositories.apt b/archiva-docs/src/site/apt/userguide/virtual-repositories.apt index 5c60e451f..70723d600 100644 --- a/archiva-docs/src/site/apt/userguide/virtual-repositories.apt +++ b/archiva-docs/src/site/apt/userguide/virtual-repositories.apt @@ -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 diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java index 46c459b10..48cfd8b82 100644 --- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java @@ -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); + } + } } diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index 494af1204..eac0aa2c9 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -860,7 +860,7 @@ 1.2.0+ String false - /.indexer + .indexer The path of the merged index. diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java index de9342c74..b4daa8bd8 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java @@ -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 ); } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java index 20fe232f5..f0fbcbd31 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java @@ -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 scheduledFutureMap = new ConcurrentHashMap<>(); @Override - public void schedule( RepositoryGroup repositoryGroup, File directory ) + public void schedule( RepositoryGroup repositoryGroup, Path directory ) { if ( StringUtils.isEmpty( repositoryGroup.getCronExpression() ) ) { diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java index 708268e1c..0b3803f48 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java @@ -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; diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java index 9ab06d647..d0b576b74 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java @@ -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; diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java index f9e2cf301..9874fc75d 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java @@ -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 filesToBeIndexed, boolean scan ) + protected void createIndex( String repository, List 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" ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java index e9c10474b..7257e4a92 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java @@ -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.emptyList(), true ); + createIndex( TEST_REPO_1, Collections.emptyList(), true ); List selectedRepos = Arrays.asList( TEST_REPO_1 ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java index 596851362..a9893111c 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java @@ -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 files = new ArrayList<>(); + List 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 files = new ArrayList<>(); - files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + List 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 files = new ArrayList<>(); + List 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 files = new ArrayList<>(); - files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2 + List 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 files = new ArrayList<>(); - files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2 + List 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 files = new ArrayList<>(); - files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), + List 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 ); diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java index db152c9a7..6c25e3a67 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java @@ -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. diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java index 0f8e54f3d..024c35217 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java @@ -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; } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java index 3720405ca..6e708c0d3 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java @@ -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 } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java index 9403ae19d..faaaa0cca 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java @@ -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 ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java index d04de274d..016f42a3d 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java @@ -499,7 +499,7 @@ public class MetadataTools { try(Stream 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 ) { diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/MergedRemoteIndexesScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/MergedRemoteIndexesScheduler.java index b799861c2..cd9520cba 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/MergedRemoteIndexesScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/MergedRemoteIndexesScheduler.java @@ -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 ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index ecf26209f..493856100 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -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 ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java index 8571821d6..a9ccb8db3 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java @@ -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 ); } } -- 2.39.5