mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 01:15:08 +00:00
Moving indexer to java.nio
This commit is contained in:
parent
b5eddeb67b
commit
c8b3346225
@ -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
|
||||
|
||||
|
@ -144,4 +144,21 @@ public static String getBasedir()
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -860,7 +860,7 @@
|
||||
<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>
|
||||
|
@ -18,7 +18,7 @@
|
||||
* 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.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 IndexingContext buildMergedIndex( IndexMergerRequest indexMergerRequest )
|
||||
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 IndexingContext buildMergedIndex( IndexMergerRequest indexMergerRequest )
|
||||
{
|
||||
IndexPackingRequest request = new IndexPackingRequest( indexingContext, //
|
||||
indexingContext.acquireIndexSearcher().getIndexReader(), //
|
||||
indexLocation );
|
||||
indexLocation.toFile() );
|
||||
indexPacker.packIndex( request );
|
||||
}
|
||||
|
||||
@ -151,8 +152,8 @@ public void cleanTemporaryGroupIndex( TemporaryGroupIndex temporaryGroupIndex )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
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() ) )
|
||||
{
|
||||
|
@ -18,7 +18,7 @@
|
||||
* 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 void setMergedIndexTtl( int mergedIndexTtl )
|
||||
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;
|
||||
|
@ -18,8 +18,8 @@
|
||||
* 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 TemporaryGroupIndex setCreationTime( long creationTime )
|
||||
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;
|
||||
|
@ -23,11 +23,11 @@
|
||||
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 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 void setUp()
|
||||
{
|
||||
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 void tearDown()
|
||||
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 @@ protected ManagedRepositoryConfiguration createRepositoryConfig( String reposito
|
||||
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 @@ protected ManagedRepositoryConfiguration createRepositoryConfig( String reposito
|
||||
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 @@ protected void createIndex( String repository, List<File> filesToBeIndexed, bool
|
||||
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" );
|
||||
|
@ -22,7 +22,7 @@
|
||||
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 void searchFelixWithSymbolicName()
|
||||
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 );
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
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 @@ private void createSimpleIndex( boolean scan )
|
||||
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 @@ private void createIndexContainingMoreArtifacts( boolean scan )
|
||||
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 void testArtifactFoundInMultipleRepositories()
|
||||
{
|
||||
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 void testSearchWithinSearchResults()
|
||||
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 void testAdvancedSearchWithPagination()
|
||||
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 void nolimitedResult()
|
||||
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 );
|
||||
|
@ -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.
|
||||
|
@ -82,7 +82,7 @@ public void initialize()
|
||||
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 Boolean addRepositoryGroup( RepositoryGroup repositoryGroup, AuditInforma
|
||||
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 @@ private Boolean updateRepositoryGroup( RepositoryGroup repositoryGroup, AuditInf
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
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
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public void addAndDeleteGroup()
|
||||
|
||||
// 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 void testAddAndUpdateGroupWithInvalidMergedIndexTtl() throws Exception {
|
||||
|
||||
// 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 );
|
||||
|
@ -499,7 +499,7 @@ private Set<String> findPossibleVersions( Set<String> versions, Path metadataPar
|
||||
{
|
||||
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 )
|
||||
{
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
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 );
|
||||
|
||||
|
@ -1326,7 +1326,7 @@ protected File buildMergedIndexDirectory( List<String> repositories, String acti
|
||||
|
||||
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 @@ protected File buildMergedIndexDirectory( List<String> repositories, String acti
|
||||
{
|
||||
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 @@ protected File buildMergedIndexDirectory( List<String> repositories, String acti
|
||||
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 @@ protected File buildMergedIndexDirectory( List<String> repositories, String acti
|
||||
|
||||
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 );
|
||||
|
@ -75,7 +75,7 @@ public void sessionDestroyed( HttpSessionEvent httpSessionEvent )
|
||||
for ( TemporaryGroupIndex temporaryGroupIndex : tempFilesPerKey.values() )
|
||||
{
|
||||
log.info( "cleanup temporaryGroupIndex {} directory {}", temporaryGroupIndex.getIndexId(),
|
||||
temporaryGroupIndex.getDirectory().getAbsolutePath() );
|
||||
temporaryGroupIndex.getDirectory().toAbsolutePath() );
|
||||
getIndexMerger( httpSessionEvent ).cleanTemporaryGroupIndex( temporaryGroupIndex );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user