@@ -164,9 +164,9 @@ public class ArchivaCli | |||
} | |||
private void doScan( String path, String[] consumers ) | |||
throws ConsumerException, MalformedURLException | |||
throws ConsumerException, IOException | |||
{ | |||
BasicManagedRepository repo = new BasicManagedRepository( Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo", Paths.get(path).getParent()); | |||
BasicManagedRepository repo = BasicManagedRepository.newFilesystemInstance( Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo", Paths.get(path).getParent()); | |||
repo.setLocation( Paths.get(path).toUri() ); | |||
List<KnownRepositoryContentConsumer> knownConsumerList = new ArrayList<>(); |
@@ -42,6 +42,7 @@ import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.springframework.stereotype.Service; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.nio.file.Paths; | |||
import java.time.Duration; | |||
@@ -73,19 +74,32 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
@Override | |||
public EditableManagedRepository createManagedInstance( String id, String name ) | |||
{ | |||
return new BasicManagedRepository( id, name, Paths.get("target/repositories") ); | |||
try { | |||
return BasicManagedRepository.newFilesystemInstance(id, name, Paths.get("target/repositories")); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@Override | |||
public EditableRemoteRepository createRemoteInstance( String id, String name ) | |||
{ | |||
return new BasicRemoteRepository( id, name , Paths.get("target/remotes")); | |||
try { | |||
return BasicRemoteRepository.newFilesystemInstance(id, name, Paths.get("target/remotes")); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@Override | |||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") ); | |||
BasicManagedRepository managedRepository; | |||
try { | |||
managedRepository = BasicManagedRepository.newFilesystemInstance(configuration.getId(), configuration.getName(), Paths.get("target/repositories")); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateManagedInstance( managedRepository, configuration ); | |||
return managedRepository; | |||
} | |||
@@ -132,17 +146,25 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") ); | |||
updateManagedInstance( managedRepository, configuration ); | |||
return managedRepository; | |||
try { | |||
BasicManagedRepository managedRepository = BasicManagedRepository.newFilesystemInstance(id, configuration.getName(), Paths.get("target/repositories")); | |||
updateManagedInstance(managedRepository, configuration); | |||
return managedRepository; | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
} | |||
@Override | |||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); | |||
updateRemoteInstance( remoteRepository, configuration ); | |||
return remoteRepository; | |||
try { | |||
BasicRemoteRepository remoteRepository = BasicRemoteRepository.newFilesystemInstance(configuration.getId(), configuration.getName(), Paths.get("target/remotes")); | |||
updateRemoteInstance(remoteRepository, configuration); | |||
return remoteRepository; | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
} | |||
@Override |
@@ -82,7 +82,7 @@ public class SimpleArtifactConsumerTest | |||
Files.createDirectories( repoDir ); | |||
repoDir.toFile().deleteOnExit(); | |||
testRepository = new BasicManagedRepository("test-consumer-repository","Test-Consumer-Repository", Paths.get("target/repositories") ); | |||
testRepository = BasicManagedRepository.newFilesystemInstance("test-consumer-repository","Test-Consumer-Repository", Paths.get("target/repositories") ); | |||
testRepository.setLocation( repoDir.toAbsolutePath().toUri() ); | |||
repositoryRegistry.putRepository(testRepository); |
@@ -49,7 +49,7 @@ public class ArtifactMissingChecksumsConsumerTest | |||
super.setUp(); | |||
Path basePath = Paths.get("target/test-classes"); | |||
repoConfig = new BasicManagedRepository( "test-repo", "Test Repository", basePath); | |||
repoConfig = BasicManagedRepository.newFilesystemInstance( "test-repo", "Test Repository", basePath); | |||
repoConfig.setLayout( "default" ); | |||
repoConfig.setLocation(basePath.resolve("test-repo/" ).toUri() ); | |||
@@ -146,10 +146,9 @@ public abstract class AbstractRepositoryPurgeTest | |||
return path; | |||
} | |||
public org.apache.archiva.repository.ManagedRepository getRepoConfiguration( String repoId, String repoName ) throws URISyntaxException | |||
{ | |||
public org.apache.archiva.repository.ManagedRepository getRepoConfiguration( String repoId, String repoName ) throws URISyntaxException, IOException { | |||
Path basePath = Paths.get("target/test-" + getName()).toAbsolutePath(); | |||
config = new BasicManagedRepository( repoId, repoName, basePath); | |||
config = BasicManagedRepository.newFilesystemInstance( repoId, repoName, basePath); | |||
config.addActiveReleaseScheme( ReleaseScheme.RELEASE ); | |||
config.addActiveReleaseScheme( ReleaseScheme.SNAPSHOT ); | |||
ArtifactCleanupFeature atf = config.getFeature( ArtifactCleanupFeature.class ).get(); |
@@ -43,6 +43,7 @@ import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.springframework.stereotype.Service; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.nio.file.Paths; | |||
import java.time.Duration; | |||
@@ -74,13 +75,21 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
@Override | |||
public EditableManagedRepository createManagedInstance( String id, String name ) | |||
{ | |||
return new BasicManagedRepository( id, name, Paths.get("target/repositories") ); | |||
try { | |||
return BasicManagedRepository.newFilesystemInstance( id, name, Paths.get("target/repositories") ); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@Override | |||
public EditableRemoteRepository createRemoteInstance( String id, String name ) | |||
{ | |||
return new BasicRemoteRepository( id, name, Paths.get("target/remotes") ); | |||
try { | |||
return BasicRemoteRepository.newFilesystemInstance( id, name, Paths.get("target/remotes") ); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@Override | |||
@@ -93,7 +102,12 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
@Override | |||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") ); | |||
BasicManagedRepository managedRepository = null; | |||
try { | |||
managedRepository = BasicManagedRepository.newFilesystemInstance( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") ); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateManagedInstance( managedRepository, configuration ); | |||
return managedRepository; | |||
} | |||
@@ -140,7 +154,12 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") ); | |||
BasicManagedRepository managedRepository = null; | |||
try { | |||
managedRepository = BasicManagedRepository.newFilesystemInstance( id, configuration.getName( ), Paths.get("target/repositories") ); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateManagedInstance( managedRepository, configuration ); | |||
return managedRepository; | |||
} | |||
@@ -148,7 +167,12 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
@Override | |||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); | |||
BasicRemoteRepository remoteRepository = null; | |||
try { | |||
remoteRepository = BasicRemoteRepository.newFilesystemInstance( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateRemoteInstance( remoteRepository, configuration ); | |||
return remoteRepository; | |||
} |
@@ -116,7 +116,7 @@ public class NexusIndexerConsumerTest | |||
// initialize to set the file types to be processed | |||
nexusIndexerConsumer.initialize(); | |||
repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", Paths.get("target/test-classes") ); | |||
repositoryConfig = BasicManagedRepository.newFilesystemInstance( "test-repo", "Test Repository", Paths.get("target/test-classes") ); | |||
repositoryConfig.setLocation( new URI("target/test-classes/test-repo") ); | |||
repositoryConfig.setLayout( "default" ); | |||
repositoryConfig.setScanned( true ); |
@@ -42,7 +42,7 @@ import java.util.function.Function; | |||
* | |||
* This interface | |||
*/ | |||
public interface ManagedRepositoryContent extends RepositoryContent, RepositoryStorage | |||
public interface ManagedRepositoryContent extends RepositoryContent | |||
{ | |||
@@ -20,6 +20,7 @@ package org.apache.archiva.repository; | |||
*/ | |||
import org.apache.archiva.indexer.ArchivaIndexingContext; | |||
import org.apache.archiva.repository.content.RepositoryStorage; | |||
import org.apache.archiva.repository.features.RepositoryFeature; | |||
import java.net.URI; | |||
@@ -33,7 +34,7 @@ import java.util.Set; | |||
* | |||
* Created by Martin Stockhammer on 21.09.17. | |||
*/ | |||
public interface Repository extends RepositoryEventHandler { | |||
public interface Repository extends RepositoryEventHandler, RepositoryStorage { | |||
/** | |||
* Return the identifier of the repository. Repository identifier should be unique at least |
@@ -23,6 +23,7 @@ import org.apache.archiva.configuration.ManagedRepositoryConfiguration; | |||
import org.apache.archiva.configuration.RemoteRepositoryConfiguration; | |||
import org.apache.archiva.configuration.RepositoryGroupConfiguration; | |||
import java.io.IOException; | |||
import java.util.Set; | |||
/** | |||
@@ -57,7 +58,7 @@ public interface RepositoryProvider extends RepositoryEventListener | |||
* @param name the repository name | |||
* @return a new created managed repository instance | |||
*/ | |||
EditableManagedRepository createManagedInstance(String id, String name); | |||
EditableManagedRepository createManagedInstance(String id, String name) throws IOException; | |||
/** | |||
* Creates a editable remote repository instance. The provider must not check the uniqueness of the |
@@ -20,11 +20,17 @@ package org.apache.archiva.repository; | |||
*/ | |||
import org.apache.archiva.repository.content.RepositoryStorage; | |||
import org.apache.archiva.repository.content.StorageAsset; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.nio.file.Path; | |||
import java.util.Collections; | |||
import java.util.HashSet; | |||
import java.util.Locale; | |||
import java.util.Set; | |||
import java.util.function.Consumer; | |||
/** | |||
* Simple implementation of a managed repository. | |||
@@ -36,14 +42,18 @@ public abstract class AbstractManagedRepository extends AbstractRepository imple | |||
private Set<ReleaseScheme> activeReleaseSchemes = new HashSet<>( ); | |||
private Set<ReleaseScheme> uActiveReleaseSchemes = Collections.unmodifiableSet( activeReleaseSchemes ); | |||
public AbstractManagedRepository( RepositoryType type, String id, String name, Path basePath ) | |||
private RepositoryStorage storage; | |||
public AbstractManagedRepository(RepositoryType type, String id, String name, RepositoryStorage storage) | |||
{ | |||
super( type, id, name, basePath ); | |||
super( type, id, name, storage ); | |||
this.storage = storage; | |||
} | |||
public AbstractManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath ) | |||
public AbstractManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage ) | |||
{ | |||
super( primaryLocale, type, id, name, basePath ); | |||
super( primaryLocale, type, id, name, storage ); | |||
this.storage = storage; | |||
} | |||
@Override | |||
@@ -92,4 +102,6 @@ public abstract class AbstractManagedRepository extends AbstractRepository imple | |||
{ | |||
this.activeReleaseSchemes.clear(); | |||
} | |||
} |
@@ -20,6 +20,8 @@ package org.apache.archiva.repository; | |||
*/ | |||
import org.apache.archiva.repository.content.RepositoryStorage; | |||
import java.nio.file.Path; | |||
import java.time.Duration; | |||
import java.util.Collections; | |||
@@ -44,14 +46,14 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem | |||
private String proxyId; | |||
private RemoteRepositoryContent content; | |||
public AbstractRemoteRepository( RepositoryType type, String id, String name , Path repositoryBase) | |||
public AbstractRemoteRepository(RepositoryType type, String id, String name , RepositoryStorage storage) | |||
{ | |||
super( type, id, name, repositoryBase ); | |||
super( type, id, name, storage ); | |||
} | |||
public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase ) | |||
public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage ) | |||
{ | |||
super( primaryLocale, type, id, name, repositoryBase ); | |||
super( primaryLocale, type, id, name, storage ); | |||
} | |||
@Override | |||
@@ -145,7 +147,7 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem | |||
*/ | |||
@Override | |||
public Path getLocalPath() { | |||
return repositoryBase.resolve(getId()); | |||
return getStorage().getAsset("").getFilePath(); | |||
} | |||
@Override |
@@ -25,6 +25,8 @@ import com.cronutils.model.definition.CronDefinitionBuilder; | |||
import com.cronutils.parser.CronParser; | |||
import org.apache.archiva.common.utils.PathUtil; | |||
import org.apache.archiva.indexer.ArchivaIndexingContext; | |||
import org.apache.archiva.repository.content.RepositoryStorage; | |||
import org.apache.archiva.repository.content.StorageAsset; | |||
import org.apache.archiva.repository.features.RepositoryFeature; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.apache.commons.lang.StringUtils; | |||
@@ -32,6 +34,7 @@ import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.net.URI; | |||
import java.nio.file.Path; | |||
import java.util.ArrayList; | |||
@@ -42,6 +45,7 @@ import java.util.List; | |||
import java.util.Locale; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import java.util.function.Consumer; | |||
/** | |||
* Implementation of a repository with the necessary fields for a bare repository. | |||
@@ -73,22 +77,22 @@ public abstract class AbstractRepository implements EditableRepository, Reposito | |||
Map<Class<? extends RepositoryFeature<?>>, RepositoryFeature<?>> featureMap = new HashMap<>( ); | |||
protected Path repositoryBase; | |||
private ArchivaIndexingContext indexingContext; | |||
private RepositoryStorage storage; | |||
public AbstractRepository(RepositoryType type, String id, String name, Path repositoryBase) { | |||
public AbstractRepository(RepositoryType type, String id, String name, RepositoryStorage repositoryStorage) { | |||
this.id = id; | |||
this.names.put( primaryLocale, name); | |||
this.type = type; | |||
this.repositoryBase=repositoryBase; | |||
this.storage = repositoryStorage; | |||
} | |||
public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase) { | |||
public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage repositoryStorage) { | |||
setPrimaryLocale( primaryLocale ); | |||
this.id = id; | |||
this.names.put( primaryLocale, name); | |||
this.type = type; | |||
this.repositoryBase=repositoryBase; | |||
this.storage = repositoryStorage; | |||
} | |||
protected void setPrimaryLocale(Locale locale) { | |||
@@ -139,17 +143,18 @@ public abstract class AbstractRepository implements EditableRepository, Reposito | |||
@Override | |||
public Path getLocalPath() { | |||
Path localPath; | |||
if (StringUtils.isEmpty(getLocation().getScheme()) || "file".equals(getLocation().getScheme()) ) { | |||
localPath = PathUtil.getPathFromUri(getLocation()); | |||
if (localPath.isAbsolute()) { | |||
return localPath; | |||
} else { | |||
return repositoryBase.resolve(localPath); | |||
} | |||
} else { | |||
return repositoryBase.resolve(getId()); | |||
} | |||
return storage.getAsset("").getFilePath(); | |||
// Path localPath; | |||
// if (StringUtils.isEmpty(getLocation().getScheme()) || "file".equals(getLocation().getScheme()) ) { | |||
// localPath = PathUtil.getPathFromUri(getLocation()); | |||
// if (localPath.isAbsolute()) { | |||
// return localPath; | |||
// } else { | |||
// return repositoryBase.resolve(localPath); | |||
// } | |||
// } else { | |||
// return repositoryBase.resolve(getId()); | |||
// } | |||
} | |||
@Override | |||
@@ -324,8 +329,47 @@ public abstract class AbstractRepository implements EditableRepository, Reposito | |||
this.listeners.clear(); | |||
} | |||
protected Path getRepositoryBase() { | |||
return repositoryBase; | |||
@Override | |||
public StorageAsset getAsset(String path ) | |||
{ | |||
return storage.getAsset(path); | |||
} | |||
@Override | |||
public StorageAsset addAsset( String path, boolean container ) | |||
{ | |||
return storage.addAsset(path, container); | |||
} | |||
@Override | |||
public void removeAsset( StorageAsset asset ) throws IOException | |||
{ | |||
storage.removeAsset(asset); | |||
} | |||
@Override | |||
public StorageAsset moveAsset( StorageAsset origin, String destination ) throws IOException | |||
{ | |||
return storage.moveAsset(origin, destination); | |||
} | |||
@Override | |||
public StorageAsset copyAsset( StorageAsset origin, String destination ) throws IOException | |||
{ | |||
return storage.copyAsset(origin, destination); | |||
} | |||
@Override | |||
public void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ) throws IOException | |||
{ | |||
storage.consumeData(asset, consumerFunction, readLock); | |||
} | |||
protected void setStorage(RepositoryStorage storage) { | |||
this.storage = storage; | |||
} | |||
protected RepositoryStorage getStorage() { | |||
return storage; | |||
} | |||
} |
@@ -44,16 +44,14 @@ public class AbstractRepositoryGroup extends AbstractRepository implements Edita | |||
private final ReadWriteLock rwl = new ReentrantReadWriteLock(); | |||
private RepositoryStorage storage; | |||
private RepositoryCapabilities capabilities; | |||
public AbstractRepositoryGroup(RepositoryType type, String id, String name, Path repositoryBase) { | |||
super(type, id, name, repositoryBase); | |||
public AbstractRepositoryGroup(RepositoryType type, String id, String name, RepositoryStorage storage) { | |||
super(type, id, name, storage); | |||
} | |||
public AbstractRepositoryGroup(Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase) { | |||
super(primaryLocale, type, id, name, repositoryBase); | |||
public AbstractRepositoryGroup(Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage) { | |||
super(primaryLocale, type, id, name, storage); | |||
} | |||
@Override | |||
@@ -173,40 +171,6 @@ public class AbstractRepositoryGroup extends AbstractRepository implements Edita | |||
return mergedIndexTTL; | |||
} | |||
@Override | |||
public StorageAsset getAsset(String path) { | |||
return storage.getAsset(path); | |||
} | |||
@Override | |||
public void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException { | |||
storage.consumeData(asset, consumerFunction, readLock); | |||
} | |||
@Override | |||
public StorageAsset addAsset(String path, boolean container) { | |||
return storage.addAsset(path, container); | |||
} | |||
@Override | |||
public void removeAsset(StorageAsset asset) throws IOException { | |||
storage.removeAsset(asset); | |||
} | |||
@Override | |||
public StorageAsset moveAsset(StorageAsset origin, String destination) throws IOException { | |||
return storage.moveAsset(origin, destination); | |||
} | |||
@Override | |||
public StorageAsset copyAsset(StorageAsset origin, String destination) throws IOException { | |||
return storage.copyAsset(origin, destination); | |||
} | |||
protected void setStorage(RepositoryStorage storage) { | |||
this.storage = storage; | |||
} | |||
protected void setCapabilities(RepositoryCapabilities capabilities) { | |||
this.capabilities = capabilities; | |||
} |
@@ -19,14 +19,22 @@ package org.apache.archiva.repository; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.common.filelock.DefaultFileLockManager; | |||
import org.apache.archiva.common.filelock.FileLockManager; | |||
import org.apache.archiva.repository.content.FilesystemStorage; | |||
import org.apache.archiva.repository.content.RepositoryStorage; | |||
import org.apache.archiva.repository.content.StorageAsset; | |||
import org.apache.archiva.repository.features.ArtifactCleanupFeature; | |||
import org.apache.archiva.repository.features.IndexCreationFeature; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.nio.file.Path; | |||
import java.util.Locale; | |||
import java.util.function.Consumer; | |||
/** | |||
* | |||
@@ -41,7 +49,6 @@ public class BasicManagedRepository extends AbstractManagedRepository | |||
ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( ); | |||
StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( ); | |||
static final StandardCapabilities CAPABILITIES = new StandardCapabilities( new ReleaseScheme[] { | |||
ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT | |||
}, new String[] {"default"}, new String[0], new String[] { | |||
@@ -49,15 +56,15 @@ public class BasicManagedRepository extends AbstractManagedRepository | |||
StagingRepositoryFeature.class.toString() | |||
}, true, true, true, true, true ); | |||
public BasicManagedRepository( String id, String name, Path basePath ) | |||
public BasicManagedRepository( String id, String name, RepositoryStorage repositoryStorage ) | |||
{ | |||
super( RepositoryType.MAVEN, id, name, basePath ); | |||
super( RepositoryType.MAVEN, id, name, repositoryStorage ); | |||
initFeatures(); | |||
} | |||
public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath ) | |||
public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage repositoryStorage ) | |||
{ | |||
super( primaryLocale, type, id, name, basePath ); | |||
super( primaryLocale, type, id, name, repositoryStorage); | |||
initFeatures(); | |||
} | |||
@@ -85,4 +92,11 @@ public class BasicManagedRepository extends AbstractManagedRepository | |||
public RepositoryRequestInfo getRequestInfo() { | |||
return null; | |||
} | |||
public static BasicManagedRepository newFilesystemInstance(String id, String name, Path basePath) throws IOException { | |||
FileLockManager lockManager = new DefaultFileLockManager(); | |||
FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); | |||
return new BasicManagedRepository(id, name, storage); | |||
} | |||
} |
@@ -19,11 +19,16 @@ package org.apache.archiva.repository; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.common.filelock.DefaultFileLockManager; | |||
import org.apache.archiva.common.filelock.FileLockManager; | |||
import org.apache.archiva.repository.content.FilesystemStorage; | |||
import org.apache.archiva.repository.content.RepositoryStorage; | |||
import org.apache.archiva.repository.features.IndexCreationFeature; | |||
import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.IOException; | |||
import java.nio.file.Path; | |||
import java.util.Locale; | |||
@@ -49,15 +54,15 @@ public class BasicRemoteRepository extends AbstractRemoteRepository | |||
IndexCreationFeature.class.toString() | |||
}, true, true, true, true, true ); | |||
public BasicRemoteRepository( String id, String name, Path basePath ) | |||
public BasicRemoteRepository( String id, String name, RepositoryStorage storage) | |||
{ | |||
super( RepositoryType.MAVEN, id, name, basePath); | |||
super( RepositoryType.MAVEN, id, name, storage); | |||
initFeatures(); | |||
} | |||
public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath ) | |||
public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage ) | |||
{ | |||
super( primaryLocale, type, id, name, basePath ); | |||
super( primaryLocale, type, id, name, storage ); | |||
initFeatures(); | |||
} | |||
@@ -79,4 +84,9 @@ public class BasicRemoteRepository extends AbstractRemoteRepository | |||
} | |||
public static BasicRemoteRepository newFilesystemInstance(String id, String name, Path basePath) throws IOException { | |||
FileLockManager lockManager = new DefaultFileLockManager(); | |||
FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); | |||
return new BasicRemoteRepository(id, name, storage); | |||
} | |||
} |
@@ -180,4 +180,8 @@ public class FilesystemStorage implements RepositoryStorage { | |||
return newAsset; | |||
} | |||
public FileLockManager getFileLockManager() { | |||
return fileLockManager; | |||
} | |||
} |
@@ -192,14 +192,14 @@ public class RepositoryRegistryTest | |||
@Test | |||
public void putManagedRepository( ) throws Exception | |||
{ | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( "test001", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); | |||
BasicManagedRepository managedRepository = BasicManagedRepository.newFilesystemInstance( "test001", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); | |||
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); | |||
repositoryRegistry.putRepository(managedRepository); | |||
assertNotNull(managedRepository.getContent()); | |||
assertEquals(6, repositoryRegistry.getRepositories().size()); | |||
managedRepository = new BasicManagedRepository( "central", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); | |||
managedRepository = BasicManagedRepository.newFilesystemInstance( "central", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); | |||
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); | |||
ManagedRepository updatedRepo = null; | |||
try { | |||
@@ -208,7 +208,7 @@ public class RepositoryRegistryTest | |||
} catch (RepositoryException e) { | |||
// OK | |||
} | |||
managedRepository = new BasicManagedRepository( "internal", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); | |||
managedRepository = BasicManagedRepository.newFilesystemInstance( "internal", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); | |||
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); | |||
updatedRepo = repositoryRegistry.putRepository( managedRepository ); | |||
@@ -283,7 +283,7 @@ public class RepositoryRegistryTest | |||
@Test | |||
public void putRemoteRepository( ) throws Exception | |||
{ | |||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( "test001", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); | |||
BasicRemoteRepository remoteRepository = BasicRemoteRepository.newFilesystemInstance( "test001", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); | |||
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); | |||
RemoteRepository newRepo = repositoryRegistry.putRepository(remoteRepository); | |||
@@ -291,7 +291,7 @@ public class RepositoryRegistryTest | |||
assertNotNull(remoteRepository.getContent()); | |||
assertEquals(6, repositoryRegistry.getRepositories().size()); | |||
remoteRepository = new BasicRemoteRepository( "internal", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); | |||
remoteRepository = BasicRemoteRepository.newFilesystemInstance( "internal", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); | |||
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); | |||
RemoteRepository updatedRepo = null; | |||
try | |||
@@ -302,7 +302,7 @@ public class RepositoryRegistryTest | |||
// OK | |||
} | |||
remoteRepository = new BasicRemoteRepository( "central", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); | |||
remoteRepository = BasicRemoteRepository.newFilesystemInstance( "central", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); | |||
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); | |||
updatedRepo = repositoryRegistry.putRepository( remoteRepository ); | |||
@@ -171,33 +171,4 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent | |||
return null; | |||
} | |||
@Override | |||
public StorageAsset getAsset(String path) { | |||
return null; | |||
} | |||
@Override | |||
public void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException { | |||
} | |||
@Override | |||
public StorageAsset addAsset(String path, boolean container) { | |||
return null; | |||
} | |||
@Override | |||
public void removeAsset(StorageAsset asset) throws IOException { | |||
} | |||
@Override | |||
public StorageAsset moveAsset(StorageAsset origin, String destination) throws IOException { | |||
return null; | |||
} | |||
@Override | |||
public StorageAsset copyAsset(StorageAsset origin, String destination) throws IOException { | |||
return null; | |||
} | |||
} |
@@ -29,6 +29,7 @@ import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.springframework.stereotype.Service; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.nio.file.Paths; | |||
import java.time.Duration; | |||
@@ -58,15 +59,18 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
} | |||
@Override | |||
public EditableManagedRepository createManagedInstance( String id, String name ) | |||
{ | |||
return new BasicManagedRepository( id, name, Paths.get("target/repositories") ); | |||
public EditableManagedRepository createManagedInstance( String id, String name ) throws IOException { | |||
return BasicManagedRepository.newFilesystemInstance( id, name, Paths.get("target/repositories") ); | |||
} | |||
@Override | |||
public EditableRemoteRepository createRemoteInstance( String id, String name ) | |||
{ | |||
return new BasicRemoteRepository( id, name , Paths.get("target/remotes")); | |||
try { | |||
return BasicRemoteRepository.newFilesystemInstance( id, name , Paths.get("target/remotes")); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@Override | |||
@@ -75,9 +79,13 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
} | |||
@Override | |||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") ); | |||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { | |||
BasicManagedRepository managedRepository = null; | |||
try { | |||
managedRepository = BasicManagedRepository.newFilesystemInstance( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") ); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateManagedInstance( managedRepository, configuration ); | |||
return managedRepository; | |||
} | |||
@@ -121,10 +129,14 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
@Override | |||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { | |||
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) , Paths.get("target/repositories")); | |||
BasicManagedRepository managedRepository = null; | |||
try { | |||
managedRepository = BasicManagedRepository.newFilesystemInstance( id, configuration.getName( ) , Paths.get("target/repositories")); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateManagedInstance( managedRepository, configuration ); | |||
managedRepository.getFeature(StagingRepositoryFeature.class).get().setStageRepoNeeded(false); | |||
return managedRepository; | |||
@@ -133,7 +145,12 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
@Override | |||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); | |||
BasicRemoteRepository remoteRepository = null; | |||
try { | |||
remoteRepository = BasicRemoteRepository.newFilesystemInstance( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateRemoteInstance( remoteRepository, configuration ); | |||
return remoteRepository; | |||
} |
@@ -35,13 +35,7 @@ import javax.inject.Inject; | |||
import java.io.IOException; | |||
import java.nio.file.FileVisitOption; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import java.util.ArrayList; | |||
import java.util.EnumSet; | |||
import java.util.LinkedHashSet; | |||
import java.util.List; | |||
import java.util.Set; | |||
import java.util.*; | |||
/** | |||
* DefaultRepositoryScanner | |||
@@ -97,7 +91,7 @@ public class DefaultRepositoryScanner | |||
throw new IllegalArgumentException( "Unable to operate on a null repository." ); | |||
} | |||
StorageAsset repositoryBase = repository.getContent().getAsset(""); | |||
StorageAsset repositoryBase = repository.getAsset(""); | |||
//MRM-1342 Repository statistics report doesn't appear to be working correctly | |||
//create the repo if not existing to have an empty stats |
@@ -76,16 +76,14 @@ public class RepositoryContentConsumersTest | |||
@Inject | |||
ApplicationContext applicationContext; | |||
protected ManagedRepository createRepository( String id, String name, Path location ) | |||
{ | |||
BasicManagedRepository repo = new BasicManagedRepository( id, name , location.getParent() ); | |||
protected ManagedRepository createRepository( String id, String name, Path location ) throws IOException { | |||
BasicManagedRepository repo = BasicManagedRepository.newFilesystemInstance( id, name , location.getParent() ); | |||
repo.setLocation( location.toAbsolutePath().toUri() ); | |||
return repo; | |||
} | |||
protected RemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException | |||
{ | |||
BasicRemoteRepository repo = new BasicRemoteRepository(id, name, Paths.get("remotes")); | |||
protected RemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException, IOException { | |||
BasicRemoteRepository repo = BasicRemoteRepository.newFilesystemInstance(id, name, Paths.get("remotes")); | |||
repo.setLocation( new URI( url ) ); | |||
return repo; | |||
} |
@@ -67,17 +67,16 @@ public class RepositoryScannerTest | |||
ApplicationContext applicationContext; | |||
protected EditableManagedRepository createRepository( String id, String name, Path location ) throws IOException { | |||
BasicManagedRepository repo = new BasicManagedRepository(id, name, location.getParent()); | |||
repo.setLocation( location.toAbsolutePath().toUri()); | |||
FileLockManager lockManager = new DefaultFileLockManager(); | |||
FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager); | |||
repo.setContent(new ManagedRepositoryContentMock(repo, storage)); | |||
BasicManagedRepository repo = new BasicManagedRepository(id, name, storage); | |||
repo.setLocation( location.toAbsolutePath().toUri()); | |||
repo.setContent(new ManagedRepositoryContentMock(repo)); | |||
return repo; | |||
} | |||
protected EditableRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException | |||
{ | |||
BasicRemoteRepository repo = new BasicRemoteRepository(id, name, Paths.get("remotes")); | |||
protected EditableRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException, IOException { | |||
BasicRemoteRepository repo = BasicRemoteRepository.newFilesystemInstance(id, name, Paths.get("remotes")); | |||
repo.setLocation( new URI( url ) ); | |||
return repo; | |||
} |
@@ -27,20 +27,14 @@ import org.apache.archiva.model.ArtifactReference; | |||
import org.apache.archiva.model.ProjectReference; | |||
import org.apache.archiva.model.VersionedReference; | |||
import org.apache.archiva.repository.*; | |||
import org.apache.archiva.repository.content.FilesystemAsset; | |||
import org.apache.archiva.repository.content.FilesystemStorage; | |||
import org.apache.archiva.repository.content.StorageAsset; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.springframework.stereotype.Service; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import java.util.function.Consumer; | |||
import java.util.regex.Matcher; | |||
import java.util.regex.Pattern; | |||
@@ -55,11 +49,9 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent | |||
private ManagedRepository repository; | |||
private FilesystemStorage storage; | |||
public ManagedRepositoryContentMock(ManagedRepository repo, FilesystemStorage storage) { | |||
public ManagedRepositoryContentMock(ManagedRepository repo) { | |||
this.repository = repo; | |||
this.storage = storage; | |||
} | |||
@Override | |||
@@ -391,33 +383,4 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent | |||
return null; | |||
} | |||
@Override | |||
public StorageAsset getAsset(String path) { | |||
return storage.getAsset(path); | |||
} | |||
@Override | |||
public void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException { | |||
storage.consumeData(asset, consumerFunction, readLock); | |||
} | |||
@Override | |||
public StorageAsset addAsset(String path, boolean container) { | |||
return storage.addAsset(path, container); | |||
} | |||
@Override | |||
public void removeAsset(StorageAsset asset) throws IOException { | |||
storage.removeAsset(asset); | |||
} | |||
@Override | |||
public StorageAsset moveAsset(StorageAsset origin, String destination) throws IOException { | |||
return storage.moveAsset(origin, destination); | |||
} | |||
@Override | |||
public StorageAsset copyAsset(StorageAsset origin, String destination) throws IOException { | |||
return storage.copyAsset(origin, destination); | |||
} | |||
} |
@@ -99,7 +99,7 @@ public class DefaultLegacyRepositoryConverter | |||
{ | |||
String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory ); | |||
BasicManagedRepository legacyRepository = new BasicManagedRepository( "legacy", "Legacy Repository", repositoryDirectory.getParent()); | |||
BasicManagedRepository legacyRepository = BasicManagedRepository.newFilesystemInstance( "legacy", "Legacy Repository", repositoryDirectory.getParent()); | |||
legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() ); | |||
legacyRepository.setLayout( "legacy" ); | |||
DefaultFileLockManager lockManager = new DefaultFileLockManager(); |
@@ -183,8 +183,8 @@ public class MavenIndexManagerTest { | |||
private ArchivaIndexingContext createTestContext() throws URISyntaxException, IndexCreationFailedException, IOException { | |||
indexPath = Paths.get("target/repositories/test-repo/.index-test"); | |||
FileUtils.deleteDirectory(indexPath); | |||
repository = new MavenManagedRepository("test-repo", "Test Repo", Paths.get("target/repositories")); | |||
repository.setLocation(new URI("test-repo")); | |||
repository = MavenManagedRepository.newLocalInstance("test-repo", "Test Repo", Paths.get("target/repositories")); | |||
// repository.setLocation(new URI("test-repo")); | |||
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get(); | |||
icf.setIndexPath(new URI(".index-test")); | |||
ctx = mavenIndexManager.createContext(repository); | |||
@@ -194,7 +194,7 @@ public class MavenIndexManagerTest { | |||
private ArchivaIndexingContext createTestContextForRemote() throws URISyntaxException, IndexCreationFailedException, IOException { | |||
indexPath = Paths.get("target/repositories/test-repo/.index-test"); | |||
Path repoPath = Paths.get("target/repositories").toAbsolutePath(); | |||
repositoryRemote = new MavenRemoteRepository("test-repo", "Test Repo", repoPath); | |||
repositoryRemote = MavenRemoteRepository.newLocalInstance("test-repo", "Test Repo", repoPath); | |||
repositoryRemote.setLocation(repoPath.resolve("test-repo").toUri()); | |||
RemoteIndexFeature icf = repositoryRemote.getFeature(RemoteIndexFeature.class).get(); | |||
icf.setIndexUri(new URI(".index-test")); |
@@ -319,7 +319,7 @@ public abstract class AbstractProxyTestCase | |||
protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout ) | |||
throws Exception | |||
{ | |||
ManagedRepository repo = new BasicManagedRepository(id, name, Paths.get(path)); | |||
ManagedRepository repo = BasicManagedRepository.newFilesystemInstance(id, name, Paths.get(path)); | |||
repositoryRegistry.putRepository(repo); | |||
return repositoryRegistry.getManagedRepository(id).getContent(); | |||
} |
@@ -94,7 +94,7 @@ public class HttpProxyTransferTest | |||
protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout ) | |||
throws Exception | |||
{ | |||
ManagedRepository repo = new BasicManagedRepository(id, name, Paths.get(path)); | |||
ManagedRepository repo = BasicManagedRepository.newFilesystemInstance(id, name, Paths.get(path)); | |||
repositoryRegistry.putRepository(repo); | |||
return repositoryRegistry.getManagedRepository(id).getContent(); | |||
} |
@@ -389,33 +389,4 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent | |||
return null; | |||
} | |||
@Override | |||
public StorageAsset getAsset(String path) { | |||
return null; | |||
} | |||
@Override | |||
public void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException { | |||
} | |||
@Override | |||
public StorageAsset addAsset(String path, boolean container) { | |||
return null; | |||
} | |||
@Override | |||
public void removeAsset(StorageAsset asset) throws IOException { | |||
} | |||
@Override | |||
public StorageAsset moveAsset(StorageAsset origin, String destination) throws IOException { | |||
return null; | |||
} | |||
@Override | |||
public StorageAsset copyAsset(StorageAsset origin, String destination) throws IOException { | |||
return null; | |||
} | |||
} |
@@ -43,6 +43,7 @@ import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
import org.apache.archiva.repository.features.StagingRepositoryFeature; | |||
import org.springframework.stereotype.Service; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.nio.file.Paths; | |||
import java.time.Duration; | |||
@@ -72,15 +73,18 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
} | |||
@Override | |||
public EditableManagedRepository createManagedInstance( String id, String name ) | |||
{ | |||
return new BasicManagedRepository( id, name , Paths.get("target/repositories")); | |||
public EditableManagedRepository createManagedInstance( String id, String name ) throws IOException { | |||
return BasicManagedRepository.newFilesystemInstance( id, name , Paths.get("target/repositories")); | |||
} | |||
@Override | |||
public EditableRemoteRepository createRemoteInstance( String id, String name ) | |||
{ | |||
return new BasicRemoteRepository( id, name, Paths.get("target/remotes") ); | |||
try { | |||
return BasicRemoteRepository.newFilesystemInstance( id, name, Paths.get("target/remotes") ); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@Override | |||
@@ -92,7 +96,12 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
@Override | |||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) , Paths.get("target/repositories")); | |||
BasicManagedRepository managedRepository = null; | |||
try { | |||
managedRepository = BasicManagedRepository.newFilesystemInstance( configuration.getId( ), configuration.getName( ) , Paths.get("target/repositories")); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateManagedInstance( managedRepository, configuration ); | |||
return managedRepository; | |||
} | |||
@@ -139,7 +148,12 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; | |||
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") ); | |||
BasicManagedRepository managedRepository = null; | |||
try { | |||
managedRepository = BasicManagedRepository.newFilesystemInstance( id, configuration.getName( ), Paths.get("target/repositories") ); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateManagedInstance( managedRepository, configuration ); | |||
return managedRepository; | |||
} | |||
@@ -147,7 +161,12 @@ public class RepositoryProviderMock implements RepositoryProvider | |||
@Override | |||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException | |||
{ | |||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); | |||
BasicRemoteRepository remoteRepository = null; | |||
try { | |||
remoteRepository = BasicRemoteRepository.newFilesystemInstance( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); | |||
} catch (IOException e) { | |||
throw new RepositoryException(e); | |||
} | |||
updateRemoteInstance( remoteRepository, configuration ); | |||
return remoteRepository; | |||
} |
@@ -67,8 +67,6 @@ public class ManagedDefaultRepositoryContent | |||
implements ManagedRepositoryContent | |||
{ | |||
private FilesystemStorage storage; | |||
private FileTypes filetypes; | |||
public void setFileTypes(FileTypes fileTypes) { | |||
@@ -421,13 +419,6 @@ public class ManagedDefaultRepositoryContent | |||
if (repository instanceof EditableManagedRepository) { | |||
((EditableManagedRepository) repository).setContent(this); | |||
} | |||
final Path repositoryDir = getRepoDir(); | |||
try { | |||
storage = new FilesystemStorage(repositoryDir, this.lockManager); | |||
} catch (IOException e) { | |||
log.error("Could not initialize the filesystem storage to repository {}: {}", repositoryDir, e.getMessage(), e); | |||
throw new RuntimeException("Fatal error. Could not initialize the filesystem storage for "+repositoryDir+": "+e.getMessage()); | |||
} | |||
} | |||
} | |||
@@ -545,42 +536,4 @@ public class ManagedDefaultRepositoryContent | |||
} | |||
@Override | |||
public void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ) throws IOException | |||
{ | |||
storage.consumeData(asset, consumerFunction, readLock); | |||
} | |||
@Override | |||
public StorageAsset getAsset( String path ) | |||
{ | |||
return storage.getAsset(path); | |||
} | |||
@Override | |||
public StorageAsset addAsset( String path, boolean container ) | |||
{ | |||
return storage.addAsset(path, container); | |||
} | |||
@Override | |||
public void removeAsset( StorageAsset asset ) throws IOException | |||
{ | |||
storage.removeAsset(asset); | |||
} | |||
@Override | |||
public StorageAsset moveAsset( StorageAsset origin, String destination ) throws IOException | |||
{ | |||
return storage.moveAsset(origin, destination); | |||
} | |||
@Override | |||
public StorageAsset copyAsset( StorageAsset origin, String destination ) throws IOException | |||
{ | |||
return storage.copyAsset(origin, destination); | |||
} | |||
} |
@@ -19,8 +19,12 @@ package org.apache.archiva.repository.maven2; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.common.filelock.DefaultFileLockManager; | |||
import org.apache.archiva.common.filelock.FileLockManager; | |||
import org.apache.archiva.common.utils.PathUtil; | |||
import org.apache.archiva.repository.*; | |||
import org.apache.archiva.repository.content.FilesystemStorage; | |||
import org.apache.archiva.repository.content.RepositoryStorage; | |||
import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo; | |||
import org.apache.archiva.repository.features.ArtifactCleanupFeature; | |||
import org.apache.archiva.repository.features.IndexCreationFeature; | |||
@@ -65,17 +69,18 @@ public class MavenManagedRepository extends AbstractManagedRepository | |||
false | |||
); | |||
public MavenManagedRepository( String id, String name, Path basePath ) | |||
public MavenManagedRepository(String id, String name, FilesystemStorage storage) | |||
{ | |||
super( RepositoryType.MAVEN, id, name, basePath); | |||
super( RepositoryType.MAVEN, id, name, storage); | |||
this.indexCreationFeature = new IndexCreationFeature(this, this); | |||
setLocation(basePath.resolve(id).toUri()); | |||
setLocation(storage.getAsset("").getFilePath().toUri()); | |||
} | |||
public MavenManagedRepository( Locale primaryLocale, String id, String name, Path basePath ) | |||
public MavenManagedRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage ) | |||
{ | |||
super( primaryLocale, RepositoryType.MAVEN, id, name, basePath ); | |||
setLocation(basePath.resolve(id).toUri()); | |||
super( primaryLocale, RepositoryType.MAVEN, id, name, storage ); | |||
setLocation(storage.getAsset("").getFilePath().toUri()); | |||
} | |||
@Override | |||
@@ -121,22 +126,44 @@ public class MavenManagedRepository extends AbstractManagedRepository | |||
@Override | |||
public void setLocation( URI location ) | |||
{ | |||
super.setLocation( location ); | |||
URI previousLocation = super.getLocation(); | |||
Path previousLoc = PathUtil.getPathFromUri(previousLocation); | |||
Path newLoc = PathUtil.getPathFromUri( location ); | |||
if (!Files.exists( newLoc )) { | |||
try | |||
{ | |||
Files.createDirectories( newLoc ); | |||
if (!newLoc.toAbsolutePath().equals(previousLoc.toAbsolutePath())) { | |||
super.setLocation(location); | |||
if (!Files.exists(newLoc)) { | |||
try { | |||
Files.createDirectories(newLoc); | |||
} catch (IOException e) { | |||
log.error("Could not create directory {}", location, e); | |||
} | |||
} | |||
catch ( IOException e ) | |||
{ | |||
log.error("Could not create directory {}",location, e); | |||
FilesystemStorage previous = (FilesystemStorage) getStorage(); | |||
try { | |||
FilesystemStorage fs = new FilesystemStorage(newLoc, previous.getFileLockManager()); | |||
setStorage(fs); | |||
} catch (IOException e) { | |||
log.error("Could not create new filesystem storage at {}", newLoc); | |||
try { | |||
Path tmpDir = Files.createTempDirectory("tmp-repo-"+getId()); | |||
FilesystemStorage fs = new FilesystemStorage(tmpDir, previous.getFileLockManager()); | |||
setStorage(fs); | |||
} catch (IOException ex) { | |||
throw new RuntimeException("Could not setup storage for repository "+getId()); | |||
} | |||
} | |||
} | |||
} | |||
@Override | |||
public RepositoryRequestInfo getRequestInfo() { | |||
return new MavenRepositoryRequestInfo(this); | |||
} | |||
public static MavenManagedRepository newLocalInstance(String id, String name, Path basePath) throws IOException { | |||
FileLockManager lockManager = new DefaultFileLockManager(); | |||
FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); | |||
return new MavenManagedRepository(id, name, storage); | |||
} | |||
} |
@@ -1,5 +1,7 @@ | |||
package org.apache.archiva.repository.maven2; | |||
import org.apache.archiva.common.filelock.DefaultFileLockManager; | |||
import org.apache.archiva.common.filelock.FileLockManager; | |||
import org.apache.archiva.repository.AbstractRemoteRepository; | |||
import org.apache.archiva.repository.ReleaseScheme; | |||
import org.apache.archiva.repository.RemoteRepository; | |||
@@ -7,12 +9,14 @@ import org.apache.archiva.repository.RepositoryCapabilities; | |||
import org.apache.archiva.repository.RepositoryType; | |||
import org.apache.archiva.repository.StandardCapabilities; | |||
import org.apache.archiva.repository.UnsupportedFeatureException; | |||
import org.apache.archiva.repository.content.FilesystemStorage; | |||
import org.apache.archiva.repository.features.IndexCreationFeature; | |||
import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
import org.apache.archiva.repository.features.RepositoryFeature; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.IOException; | |||
import java.nio.file.Path; | |||
import java.util.Locale; | |||
@@ -59,16 +63,16 @@ public class MavenRemoteRepository extends AbstractRemoteRepository | |||
false | |||
); | |||
public MavenRemoteRepository( String id, String name, Path basePath ) | |||
public MavenRemoteRepository(String id, String name, FilesystemStorage storage) | |||
{ | |||
super( RepositoryType.MAVEN, id, name, basePath ); | |||
super( RepositoryType.MAVEN, id, name, storage ); | |||
this.indexCreationFeature = new IndexCreationFeature(this, this); | |||
} | |||
public MavenRemoteRepository( Locale primaryLocale, String id, String name, Path basePath ) | |||
public MavenRemoteRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage ) | |||
{ | |||
super( primaryLocale, RepositoryType.MAVEN, id, name, basePath ); | |||
super( primaryLocale, RepositoryType.MAVEN, id, name, storage ); | |||
this.indexCreationFeature = new IndexCreationFeature(this, this); | |||
} | |||
@@ -111,4 +115,10 @@ public class MavenRemoteRepository extends AbstractRemoteRepository | |||
public String toString() { | |||
return super.toString()+", remoteIndexFeature="+remoteIndexFeature.toString()+", indexCreationFeature="+indexCreationFeature.toString(); | |||
} | |||
public static MavenRemoteRepository newLocalInstance(String id, String name, Path basePath) throws IOException { | |||
FileLockManager lockManager = new DefaultFileLockManager(); | |||
FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); | |||
return new MavenRemoteRepository(id, name, storage); | |||
} | |||
} |
@@ -19,6 +19,7 @@ package org.apache.archiva.repository.maven2; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.common.filelock.DefaultFileLockManager; | |||
import org.apache.archiva.common.filelock.FileLockManager; | |||
import org.apache.archiva.repository.*; | |||
import org.apache.archiva.repository.content.FilesystemStorage; | |||
@@ -47,41 +48,32 @@ public class MavenRepositoryGroup extends AbstractRepositoryGroup implements Edi | |||
private final Logger log = LoggerFactory.getLogger(MavenRepositoryGroup.class); | |||
private FileLockManager lockManager; | |||
private FilesystemStorage fsStorage; | |||
private IndexCreationFeature indexCreationFeature; | |||
public MavenRepositoryGroup(String id, String name, Path repositoryBase, FileLockManager lockManager) { | |||
super(RepositoryType.MAVEN, id, name, repositoryBase); | |||
this.lockManager = lockManager; | |||
public MavenRepositoryGroup(String id, String name, FilesystemStorage storage) { | |||
super(RepositoryType.MAVEN, id, name, storage); | |||
init(); | |||
} | |||
public MavenRepositoryGroup(Locale primaryLocale, String id, String name, Path repositoryBase, FileLockManager lockManager) { | |||
super(primaryLocale, RepositoryType.MAVEN, id, name, repositoryBase); | |||
this.lockManager = lockManager; | |||
public MavenRepositoryGroup(Locale primaryLocale, String id, String name, FilesystemStorage storage) { | |||
super(primaryLocale, RepositoryType.MAVEN, id, name, storage); | |||
init(); | |||
} | |||
private Path getRepositoryPath() { | |||
return getRepositoryBase().resolve(getId()); | |||
return getStorage().getAsset("").getFilePath(); | |||
} | |||
private void init() { | |||
setCapabilities(CAPABILITIES); | |||
try { | |||
Path repoPath = getRepositoryPath(); | |||
if (!Files.exists(repoPath)) { | |||
Files.createDirectories(repoPath); | |||
} | |||
fsStorage = new FilesystemStorage(getRepositoryPath(), lockManager); | |||
} catch (IOException e) { | |||
log.error("IOException while initializing repository group with path {}",getRepositoryBase()); | |||
throw new RuntimeException("Fatal error while accessing repository path "+ getRepositoryBase(), e); | |||
} | |||
setStorage(fsStorage); | |||
this.indexCreationFeature = new IndexCreationFeature(this, this); | |||
addFeature( this.indexCreationFeature ); | |||
} | |||
public static MavenRepositoryGroup newLocalInstance(String id, String name, Path basePath) throws IOException { | |||
FileLockManager lockManager = new DefaultFileLockManager(); | |||
FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); | |||
return new MavenRepositoryGroup(id, name, storage); | |||
} | |||
} |
@@ -23,6 +23,7 @@ import org.apache.archiva.common.filelock.FileLockManager; | |||
import org.apache.archiva.configuration.*; | |||
import org.apache.archiva.repository.*; | |||
import org.apache.archiva.repository.content.FilesystemAsset; | |||
import org.apache.archiva.repository.content.FilesystemStorage; | |||
import org.apache.archiva.repository.features.ArtifactCleanupFeature; | |||
import org.apache.archiva.repository.features.IndexCreationFeature; | |||
import org.apache.archiva.repository.features.RemoteIndexFeature; | |||
@@ -76,18 +77,51 @@ public class MavenRepositoryProvider implements RepositoryProvider { | |||
} | |||
@Override | |||
public EditableManagedRepository createManagedInstance(String id, String name) { | |||
return new MavenManagedRepository(id, name, archivaConfiguration.getRepositoryBaseDir()); | |||
public MavenManagedRepository createManagedInstance(String id, String name) { | |||
return createManagedInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir()); | |||
} | |||
public MavenManagedRepository createManagedInstance(String id, String name, Path baseDir) { | |||
FilesystemStorage storage = null; | |||
try { | |||
storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager); | |||
} catch (IOException e) { | |||
log.error("Could not initialize fileystem for repository {}", id); | |||
throw new RuntimeException(e); | |||
} | |||
return new MavenManagedRepository(id, name, storage); | |||
} | |||
@Override | |||
public EditableRemoteRepository createRemoteInstance(String id, String name) { | |||
return new MavenRemoteRepository(id, name, archivaConfiguration.getRemoteRepositoryBaseDir()); | |||
public MavenRemoteRepository createRemoteInstance(String id, String name) { | |||
return createRemoteInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir()); | |||
} | |||
public MavenRemoteRepository createRemoteInstance(String id, String name, Path baseDir) { | |||
FilesystemStorage storage = null; | |||
try { | |||
storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager); | |||
} catch (IOException e) { | |||
log.error("Could not initialize fileystem for repository {}", id); | |||
throw new RuntimeException(e); | |||
} | |||
return new MavenRemoteRepository(id, name, storage); | |||
} | |||
@Override | |||
public EditableRepositoryGroup createRepositoryGroup(String id, String name) { | |||
return new MavenRepositoryGroup(id, name, archivaConfiguration.getRepositoryBaseDir(), fileLockManager); | |||
return createRepositoryGroup(id, name, archivaConfiguration.getRepositoryBaseDir()); | |||
} | |||
public MavenRepositoryGroup createRepositoryGroup(String id, String name, Path baseDir) { | |||
FilesystemStorage storage = null; | |||
try { | |||
storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager); | |||
} catch (IOException e) { | |||
log.error("Could not initialize fileystem for repository {}", id); | |||
throw new RuntimeException(e); | |||
} | |||
return new MavenRepositoryGroup(id, name, storage); | |||
} | |||
private URI getURIFromString(String uriStr) throws RepositoryException { | |||
@@ -121,7 +155,7 @@ public class MavenRepositoryProvider implements RepositoryProvider { | |||
@Override | |||
public ManagedRepository createManagedInstance(ManagedRepositoryConfiguration cfg) throws RepositoryException { | |||
MavenManagedRepository repo = new MavenManagedRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRepositoryBaseDir()); | |||
MavenManagedRepository repo = createManagedInstance(cfg.getId(), cfg.getName(), Paths.get(cfg.getLocation()).getParent()); | |||
updateManagedInstance(repo, cfg); | |||
return repo; | |||
} | |||
@@ -181,7 +215,7 @@ public class MavenRepositoryProvider implements RepositoryProvider { | |||
@Override | |||
public RemoteRepository createRemoteInstance(RemoteRepositoryConfiguration cfg) throws RepositoryException { | |||
MavenRemoteRepository repo = new MavenRemoteRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir()); | |||
MavenRemoteRepository repo = createRemoteInstance(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir()); | |||
updateRemoteInstance(repo, cfg); | |||
return repo; | |||
} | |||
@@ -249,8 +283,8 @@ public class MavenRepositoryProvider implements RepositoryProvider { | |||
@Override | |||
public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException { | |||
Path repositoryGroupBase = getArchivaConfiguration().getRepositoryGroupBaseDir(); | |||
MavenRepositoryGroup newGrp = new MavenRepositoryGroup(configuration.getId(), configuration.getName(), | |||
repositoryGroupBase, fileLockManager); | |||
MavenRepositoryGroup newGrp = createRepositoryGroup(configuration.getId(), configuration.getName(), | |||
repositoryGroupBase); | |||
updateRepositoryGroupInstance(newGrp, configuration); | |||
return newGrp; | |||
} |
@@ -29,6 +29,7 @@ import org.springframework.context.ApplicationContext; | |||
import org.springframework.test.context.ContextConfiguration; | |||
import javax.inject.Inject; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import java.nio.file.Path; | |||
@@ -49,16 +50,14 @@ public abstract class AbstractRepositoryLayerTestCase | |||
@Inject | |||
protected ApplicationContext applicationContext; | |||
protected MavenManagedRepository createRepository( String id, String name, Path location ) | |||
{ | |||
MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent().toAbsolutePath()); | |||
protected MavenManagedRepository createRepository( String id, String name, Path location ) throws IOException { | |||
MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, location.getParent().toAbsolutePath()); | |||
repo.setLocation( location.toAbsolutePath().toUri() ); | |||
return repo; | |||
} | |||
protected MavenRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException | |||
{ | |||
MavenRemoteRepository repo = new MavenRemoteRepository(id, name, Paths.get("target/remotes")); | |||
protected MavenRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException, IOException { | |||
MavenRemoteRepository repo = MavenRemoteRepository.newLocalInstance(id, name, Paths.get("target/remotes")); | |||
repo.setLocation( new URI( url ) ); | |||
return repo; | |||
} | |||
@@ -67,7 +66,7 @@ public abstract class AbstractRepositoryLayerTestCase | |||
String layout ) | |||
throws Exception | |||
{ | |||
MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent() ); | |||
MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, location.getParent() ); | |||
repo.setLocation( location.toAbsolutePath().toUri() ); | |||
repo.setLayout( layout ); | |||
@@ -81,7 +80,7 @@ public abstract class AbstractRepositoryLayerTestCase | |||
protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout ) | |||
throws Exception | |||
{ | |||
MavenRemoteRepository repo = new MavenRemoteRepository(id, name, Paths.get("target/remotes")); | |||
MavenRemoteRepository repo = MavenRemoteRepository.newLocalInstance(id, name, Paths.get("target/remotes")); | |||
repo.setLocation( new URI( url ) ); | |||
repo.setLayout( layout ); | |||
@@ -40,6 +40,7 @@ import org.springframework.test.context.ContextConfiguration; | |||
import javax.inject.Inject; | |||
import javax.inject.Named; | |||
import java.io.IOException; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import java.util.List; | |||
@@ -74,9 +75,8 @@ public class MavenRepositoryRequestInfoTest | |||
private MavenRepositoryRequestInfo repoRequest; | |||
protected MavenManagedRepository createRepository( String id, String name, Path location ) | |||
{ | |||
MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent().toAbsolutePath()); | |||
protected MavenManagedRepository createRepository( String id, String name, Path location ) throws IOException { | |||
MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, location.getParent().toAbsolutePath()); | |||
repo.setLocation( location.toAbsolutePath().toUri() ); | |||
return repo; | |||
} | |||
@@ -549,7 +549,7 @@ public class MavenRepositoryRequestInfoTest | |||
String layout ) | |||
throws Exception | |||
{ | |||
MavenManagedRepository repo = new MavenManagedRepository( id, name, archivaConfiguration.getRepositoryBaseDir()); | |||
MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, archivaConfiguration.getRepositoryBaseDir()); | |||
repo.setLocation( location.toAbsolutePath().toUri() ); | |||
repo.setLayout( layout ); | |||
@@ -36,6 +36,7 @@ import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import java.nio.file.Files; | |||
@@ -217,7 +218,7 @@ public class MavenRepositoryProviderTest | |||
@Test | |||
public void getManagedConfiguration() throws Exception { | |||
MavenManagedRepository repo = new MavenManagedRepository( "test01", "My Test repo", Paths.get("target/repositories") ); | |||
MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( "test01", "My Test repo", Paths.get("target/repositories") ); | |||
repo.setLocation( new URI("file:///this.is/a/test") ); | |||
repo.setScanned( true ); | |||
@@ -262,7 +263,7 @@ public class MavenRepositoryProviderTest | |||
@Test | |||
public void getRemoteConfiguration() throws Exception { | |||
MavenRemoteRepository repo = new MavenRemoteRepository( "test01", "My Test repo", Paths.get("target/remotes") ); | |||
MavenRemoteRepository repo = MavenRemoteRepository.newLocalInstance( "test01", "My Test repo", Paths.get("target/remotes") ); | |||
repo.setLocation( new URI("https://this.is/a/test") ); | |||
repo.setScanned( true ); | |||
@@ -296,12 +297,10 @@ public class MavenRepositoryProviderTest | |||
} | |||
@Test | |||
public void getRepositoryGroupConfiguration() throws RepositoryException, URISyntaxException | |||
{ | |||
MavenRepositoryGroup repositoryGroup = new MavenRepositoryGroup("group1","group1",Paths.get("target/groups"), | |||
new DefaultFileLockManager()); | |||
MavenManagedRepository repo1 = new MavenManagedRepository( "test01", "My Test repo", Paths.get("target/repositories") ); | |||
MavenManagedRepository repo2 = new MavenManagedRepository( "test02", "My Test repo", Paths.get("target/repositories") ); | |||
public void getRepositoryGroupConfiguration() throws RepositoryException, URISyntaxException, IOException { | |||
MavenRepositoryGroup repositoryGroup = MavenRepositoryGroup.newLocalInstance("group1","group1",Paths.get("target/groups")); | |||
MavenManagedRepository repo1 = MavenManagedRepository.newLocalInstance( "test01", "My Test repo", Paths.get("target/repositories") ); | |||
MavenManagedRepository repo2 = MavenManagedRepository.newLocalInstance( "test02", "My Test repo", Paths.get("target/repositories") ); | |||
repositoryGroup.setDescription(repositoryGroup.getPrimaryLocale(), "Repository group"); |
@@ -29,6 +29,7 @@ import org.springframework.test.context.ContextConfiguration; | |||
import javax.inject.Inject; | |||
import javax.inject.Named; | |||
import java.io.IOException; | |||
import java.nio.file.Paths; | |||
/** | |||
@@ -43,21 +44,20 @@ public class Maven2RepositoryStorageTest | |||
RepositoryStorage repositoryStorage; | |||
@Test | |||
public void testGetLogicalPath() | |||
{ | |||
public void testGetLogicalPath() throws IOException { | |||
String href = "/repository/internal/org/apache/maven/someartifact.jar"; | |||
Assert.assertEquals( "/org/apache/maven/someartifact.jar", | |||
repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01", Paths.get("target/repositories")) ) ); | |||
repositoryStorage.getFilePath( href, MavenManagedRepository.newLocalInstance( "repo01", "repo01", Paths.get("target/repositories")) ) ); | |||
href = "repository/internal/org/apache/maven/someartifact.jar"; | |||
Assert.assertEquals( "/org/apache/maven/someartifact.jar", | |||
repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01", Paths.get("target/repositories") ) ) ); | |||
repositoryStorage.getFilePath( href, MavenManagedRepository.newLocalInstance( "repo01", "repo01", Paths.get("target/repositories") ) ) ); | |||
href = "repository/internal/org/apache/maven/"; | |||
Assert.assertEquals( "/org/apache/maven/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01", Paths.get("target/repositories")) ) ); | |||
Assert.assertEquals( "/org/apache/maven/", repositoryStorage.getFilePath( href, MavenManagedRepository.newLocalInstance("repo01", "repo01", Paths.get("target/repositories")) ) ); | |||
href = "mypath"; | |||
Assert.assertEquals( "/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01", Paths.get("target/repositories")) ) ); | |||
Assert.assertEquals( "/", repositoryStorage.getFilePath( href, MavenManagedRepository.newLocalInstance("repo01", "repo01", Paths.get("target/repositories")) ) ); | |||
} | |||
@@ -89,7 +89,7 @@ public class ArchivaIndexingTaskExecutorTest | |||
super.setUp(); | |||
Path baseDir = Paths.get(System.getProperty("basedir"), "target/test-classes").toAbsolutePath(); | |||
BasicManagedRepository repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", baseDir); | |||
BasicManagedRepository repositoryConfig = BasicManagedRepository.newFilesystemInstance( "test-repo", "Test Repository", baseDir); | |||
Path repoLocation = baseDir.resolve("test-repo" ); | |||
repositoryConfig.setLocation(repoLocation.toUri() ); | |||
repositoryConfig.setLayout( "default" ); |
@@ -574,12 +574,12 @@ public class ArchivaDavResourceFactory | |||
path = path.substring( 1 ); | |||
} | |||
LogicalResource logicalResource = new LogicalResource( path ); | |||
StorageAsset repoAsset = managedRepositoryContent.getAsset( path ); | |||
StorageAsset repoAsset = managedRepository.getAsset( path ); | |||
// Path resourceFile = Paths.get( managedRepositoryContent.getRepoRoot(), path ); | |||
try | |||
{ | |||
resource = | |||
new ArchivaDavResource( repoAsset, path, managedRepositoryContent, | |||
new ArchivaDavResource( repoAsset, path, managedRepository, | |||
request.getRemoteAddr(), activePrincipal, request.getDavSession(), | |||
archivaLocator, this, mimeTypes, auditListeners, scheduler ); | |||
} | |||
@@ -612,10 +612,10 @@ public class ArchivaDavResourceFactory | |||
// Perform an adjustment of the resource to the managed | |||
// repository expected path. | |||
// String localResourcePath = managedRepository.getRequestInfo().toNativePath( logicalResource.getPath() ); | |||
resourceAsset = managedRepositoryContent.getAsset( logicalResource.getPath() ); | |||
resourceAsset = managedRepository.getAsset( logicalResource.getPath() ); | |||
resource = | |||
new ArchivaDavResource( resourceAsset, logicalResource.getPath(), | |||
managedRepositoryContent, | |||
managedRepository, | |||
request.getRemoteAddr(), activePrincipal, | |||
request.getDavSession(), archivaLocator, this, mimeTypes, | |||
auditListeners, scheduler ); | |||
@@ -740,11 +740,11 @@ public class ArchivaDavResourceFactory | |||
{ | |||
logicalResource = logicalResource.substring( 1 ); | |||
} | |||
StorageAsset resourceAsset = managedRepositoryContent.getAsset( logicalResource ); | |||
StorageAsset resourceAsset = repo.getAsset( logicalResource ); | |||
try | |||
{ | |||
resource = new ArchivaDavResource( resourceAsset, logicalResource, | |||
repo.getContent(), davSession, archivaLocator, | |||
repo, davSession, archivaLocator, | |||
this, mimeTypes, auditListeners, scheduler); | |||
} | |||
catch ( LayoutException e ) | |||
@@ -1108,7 +1108,7 @@ public class ArchivaDavResourceFactory | |||
"Invalid managed repository <" + repo.getId() + ">"); | |||
} | |||
// Path resourceFile = Paths.get( managedRepository.getRepoRoot(), logicalResource.getPath() ); | |||
StorageAsset resourceFile = managedRepository.getAsset(logicalResource.getPath()); | |||
StorageAsset resourceFile = repo.getAsset(logicalResource.getPath()); | |||
if ( resourceFile.exists() && managedRepository.getRepository().supportsFeature( IndexCreationFeature.class )) | |||
{ | |||
// in case of group displaying index directory doesn't have sense !! |
@@ -184,7 +184,7 @@ public class RepositoryServlet | |||
fillRepositoryMap(); | |||
for (ManagedRepository repo : repositoryMap.values()) { | |||
StorageAsset repoDir = repo.getContent().getAsset(""); | |||
StorageAsset repoDir = repo.getAsset(""); | |||
if (!repoDir.exists()) { | |||
try { |
@@ -97,7 +97,7 @@ public class DavResourceTest | |||
baseDir = Paths.get( "target/DavResourceTest" ); | |||
Files.createDirectories( baseDir ); | |||
Files.createDirectories( baseDir.resolve( "conf" ) ); | |||
repository = new MavenManagedRepository( "repo001", "repo001", baseDir); | |||
repository = MavenManagedRepository.newLocalInstance( "repo001", "repo001", baseDir); | |||
repositoryRegistry.putRepository( repository ); | |||
myResource = baseDir.resolve( "myresource.jar" ); | |||
@@ -127,7 +127,7 @@ public class DavResourceTest | |||
private DavResource getDavResource( String logicalPath, Path file ) throws LayoutException | |||
{ | |||
return new ArchivaDavResource( new FilesystemAsset( logicalPath, file.toAbsolutePath()) , logicalPath, repository.getContent(), session, resourceLocator, | |||
return new ArchivaDavResource( new FilesystemAsset( logicalPath, file.toAbsolutePath()) , logicalPath, repository, session, resourceLocator, | |||
resourceFactory, mimeTypes, Collections.<AuditListener> emptyList(), null); | |||
} | |||
@@ -349,7 +349,7 @@ public class DavResourceTest | |||
{ | |||
try | |||
{ | |||
return new ArchivaDavResource( new FilesystemAsset( "/" , baseDir.toAbsolutePath()), "/", repository.getContent(), session, resourceLocator, | |||
return new ArchivaDavResource( new FilesystemAsset( "/" , baseDir.toAbsolutePath()), "/", repository, session, resourceLocator, | |||
resourceFactory, mimeTypes, Collections.<AuditListener> emptyList(), | |||
null ); | |||
} |
@@ -95,7 +95,7 @@ public class DuplicateArtifactsConsumerTest | |||
assertNotNull( consumer ); | |||
config = new BasicManagedRepository(TEST_REPO, TEST_REPO, Paths.get("target")); | |||
config = BasicManagedRepository.newFilesystemInstance(TEST_REPO, TEST_REPO, Paths.get("target")); | |||
config.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toUri() ); | |||
metadataRepository = mock( MetadataRepository.class ); |