Search in sources :

Example 26 with FilesystemStorage

use of org.apache.archiva.repository.storage.fs.FilesystemStorage in project archiva by apache.

the class MavenRepositoryProvider method createRemoteInstance.

public MavenRemoteRepository createRemoteInstance(String id, String name, Path baseDir) {
    FilesystemStorage storage;
    try {
        storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
    } catch (IOException e) {
        log.error("Could not initialize filesystem for repository {}: '{}'", id, e.getMessage());
        throw new RuntimeException(e);
    }
    MavenRemoteRepository repo = new MavenRemoteRepository(id, name, storage);
    registerEventHandler(repo);
    return repo;
}
Also used : FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) IOException(java.io.IOException)

Example 27 with FilesystemStorage

use of org.apache.archiva.repository.storage.fs.FilesystemStorage in project archiva by apache.

the class MavenRepositoryProvider method createManagedInstance.

public MavenManagedRepository createManagedInstance(String id, String name, Path baseDir) {
    FilesystemStorage storage;
    try {
        storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
    } catch (IOException e) {
        log.error("Could not initialize fileystem for repository {}", id);
        throw new RuntimeException(e);
    }
    MavenManagedRepository repo = new MavenManagedRepository(id, name, storage);
    registerEventHandler(repo);
    return repo;
}
Also used : FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) IOException(java.io.IOException)

Example 28 with FilesystemStorage

use of org.apache.archiva.repository.storage.fs.FilesystemStorage in project archiva by apache.

the class MavenRepositoryProvider method updateRepositoryGroupInstance.

@Override
public void updateRepositoryGroupInstance(EditableRepositoryGroup repositoryGroup, RepositoryGroupConfiguration configuration) throws RepositoryException {
    repositoryGroup.setName(repositoryGroup.getPrimaryLocale(), configuration.getName());
    repositoryGroup.setMergedIndexTTL(configuration.getMergedIndexTtl());
    repositoryGroup.setSchedulingDefinition(configuration.getCronExpression());
    if (repositoryGroup.supportsFeature(IndexCreationFeature.class)) {
        IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature(IndexCreationFeature.class);
        indexCreationFeature.setIndexPath(getURIFromString(configuration.getMergedIndexPath()));
        Path localPath = Paths.get(configuration.getMergedIndexPath());
        Path repoGroupPath = repositoryGroup.getRoot().getFilePath().toAbsolutePath();
        if (localPath.isAbsolute() && !localPath.startsWith(repoGroupPath)) {
            try {
                FilesystemStorage storage = new FilesystemStorage(localPath.getParent(), fileLockManager);
                indexCreationFeature.setLocalIndexPath(storage.getAsset(localPath.getFileName().toString()));
            } catch (IOException e) {
                throw new RepositoryException("Could not initialize storage for index path " + localPath);
            }
        } else if (localPath.isAbsolute()) {
            indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(repoGroupPath.relativize(localPath).toString()));
        } else {
            indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(localPath.toString()));
        }
    }
// References to other repositories are set filled by the registry
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException)

Example 29 with FilesystemStorage

use of org.apache.archiva.repository.storage.fs.FilesystemStorage in project archiva by apache.

the class ArchivaIndexManagerMock method getIndexPath.

private StorageAsset getIndexPath(Repository repo) throws IOException {
    IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class);
    Path repoDir = repo.getRoot().getFilePath();
    URI indexDir = icf.getIndexPath();
    String indexPath = indexDir.getPath();
    Path indexDirectory = null;
    FilesystemStorage fsStorage = (FilesystemStorage) repo.getRoot().getStorage();
    if (!StringUtils.isEmpty(indexDir.toString())) {
        indexDirectory = PathUtil.getPathFromUri(indexDir);
        // not absolute so create it in repository directory
        if (indexDirectory.isAbsolute()) {
            indexPath = indexDirectory.getFileName().toString();
            fsStorage = new FilesystemStorage(indexDirectory.getParent(), new DefaultFileLockManager());
        } else {
            indexDirectory = repoDir.resolve(indexDirectory);
        }
    } else {
        indexDirectory = repoDir.resolve(".index");
        indexPath = ".index";
    }
    if (!Files.exists(indexDirectory)) {
        Files.createDirectories(indexDirectory);
    }
    return new FilesystemAsset(fsStorage, indexPath, indexDirectory);
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) URI(java.net.URI)

Example 30 with FilesystemStorage

use of org.apache.archiva.repository.storage.fs.FilesystemStorage in project archiva by apache.

the class ArtifactContentEntriesTests method readArtifactContentEntriesRootPathNull.

@Test
public void readArtifactContentEntriesRootPathNull() throws Exception {
    FilesystemStorage filesystemStorage = new FilesystemStorage(Paths.get(getBasedir()), new DefaultFileLockManager());
    Path file = Paths.get(getBasedir(), "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar");
    List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries(new FilesystemAsset(filesystemStorage, file.toString(), file), null, "foo");
    log.info("artifactContentEntries: {}", artifactContentEntries);
    assertThat(artifactContentEntries).isNotNull().isNotEmpty().hasSize(2).contains(new ArtifactContentEntry("org", false, 0, "foo"), new ArtifactContentEntry("META-INF", false, 0, "foo"));
}
Also used : Path(java.nio.file.Path) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArtifactContentEntry(org.apache.archiva.rest.api.model.ArtifactContentEntry) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Test(org.junit.Test)

Aggregations

FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)48 DefaultFileLockManager (org.apache.archiva.common.filelock.DefaultFileLockManager)42 Path (java.nio.file.Path)26 FileLockManager (org.apache.archiva.common.filelock.FileLockManager)14 FilesystemAsset (org.apache.archiva.repository.storage.fs.FilesystemAsset)13 IOException (java.io.IOException)11 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)9 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)8 BasicManagedRepository (org.apache.archiva.repository.base.managed.BasicManagedRepository)6 ArtifactContentEntry (org.apache.archiva.rest.api.model.ArtifactContentEntry)6 Test (org.junit.Test)6 URI (java.net.URI)5 Before (org.junit.Before)4 ArrayList (java.util.ArrayList)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 Test (org.junit.jupiter.api.Test)3 Date (java.util.Date)2 MavenMetadataReader (org.apache.archiva.maven.metadata.MavenMetadataReader)2 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)2 UnauthorizedException (org.apache.archiva.redback.authorization.UnauthorizedException)2