import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.security.ServletAuthenticator;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavLocatorFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.util.LinkedHashMap;
-import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.stream.Collectors;
/**
* RepositoryServlet
RepositoryRegistry repositoryRegistry;
- private Map<String, ManagedRepository> repositoryMap;
-
private DavLocatorFactory locatorFactory;
private DavResourceFactory resourceFactory;
configuration.addListener(this);
repositoryRegistry = wac.getBean(RepositoryRegistry.class);
- repositoryMap = new LinkedHashMap<>();
-
- fillRepositoryMap();
-
- for (ManagedRepository repo : repositoryMap.values()) {
- StorageAsset repoDir = repo.getAsset("");
-
- if (!repoDir.exists()) {
- try {
- repoDir.create();
- } catch (IOException e) {
- log.info("Unable to create missing directory for {}", repo.getLocation());
- continue;
- }
- }
- }
-
resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class);
locatorFactory = new ArchivaDavLocatorFactory();
log.debug( "initServers done in {} ms", (end - start) );
}
- private void fillRepositoryMap() {
- final Map<String, ManagedRepository> repos = repositoryRegistry.getManagedRepositories().stream().collect(Collectors.toMap(r -> r.getId(), r -> r));
- rwLock.writeLock().lock();
- try {
- repositoryMap.clear();
- repositoryMap.putAll(repos);
- } finally {
- rwLock.writeLock().unlock();
- }
- }
-
@Override
public void configurationEvent( ConfigurationEvent event )
{
public ManagedRepository getRepository( String prefix )
throws RepositoryAdminException
{
- rwLock.readLock().lock();
- try {
- if (repositoryMap.isEmpty()) {
- rwLock.readLock().unlock();
- fillRepositoryMap();
- rwLock.readLock().lock();
- }
- return repositoryMap.get(prefix);
- } finally {
- rwLock.readLock().unlock();
- }
+ return repositoryRegistry.getManagedRepository( prefix );
}
ArchivaConfiguration getConfiguration()
configuration = null;
locatorFactory = null;
sessionProvider = null;
- repositoryMap.clear();
- repositoryMap = null;
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
}
} finally
{
- ctx.close( );
+ if (ctx!=null)
+ {
+ ctx.close( );
+ }
}
CacheManager.getInstance().clearAll();
if ( Files.exists(repoRootInternal) )
{
- org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoRootInternal );
+ org.apache.archiva.common.utils.FileUtils.deleteQuietly( repoRootInternal );
}
if ( Files.exists(repoRootLegacy) )
{
- org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoRootLegacy );
+ org.apache.archiva.common.utils.FileUtils.deleteQuietly( repoRootLegacy );
}
String appserverBase = System.getProperty( "appserver.base" );
if ( StringUtils.isNotEmpty( appserverBase ) )
{
- org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( appserverBase ) );
+ org.apache.archiva.common.utils.FileUtils.deleteQuietly( Paths.get( appserverBase ) );
}
}
Configuration c = archivaConfiguration.getConfiguration();
c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
saveConfiguration( archivaConfiguration );
+ repositoryRegistry.removeRepository( REPOID_INTERNAL );
org.apache.archiva.repository.ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL );
assertNull( repository );
public void testGetRepositoryInvalidPathPassthroughPresent()
throws Exception
{
- String path = REQUEST_PATH + ".index/filecontent/segments.gen";
+ String path = REQUEST_PATH + ".indexer/filecontent/segments.gen";
- populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
+ populateRepo( repoRootInternal, ".indexer/filecontent/segments.gen", "index file" );
WebRequest request = new GetMethodWebRequest( path );
WebResponse response = getServletUnitClient().getResponse( request );
public void testGetRepositoryInvalidPathPassthroughMissing()
throws Exception
{
- String path = REQUEST_PATH + ".index/filecontent/foo.bar";
+ String path = REQUEST_PATH + ".indexer/filecontent/foo.bar";
WebRequest request = new GetMethodWebRequest( path );
WebResponse response = getServletUnitClient().getResponse( request );