Search in sources :

Example 6 with FilesystemStorage

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

the class MavenIndexManager method getIndexPath.

private StorageAsset getIndexPath(URI indexDirUri, RepositoryStorage repoStorage, String defaultDir) throws IOException {
    StorageAsset rootAsset = repoStorage.getRoot();
    RepositoryStorage storage = rootAsset.getStorage();
    Path indexDirectory;
    Path repositoryPath = rootAsset.getFilePath().toAbsolutePath();
    StorageAsset indexDir;
    if (!StringUtils.isEmpty(indexDirUri.toString())) {
        indexDirectory = PathUtil.getPathFromUri(indexDirUri);
        // not absolute so create it in repository directory
        if (indexDirectory.isAbsolute() && !indexDirectory.startsWith(repositoryPath)) {
            if (storage instanceof FilesystemStorage) {
                FilesystemStorage fsStorage = (FilesystemStorage) storage;
                FilesystemStorage indexStorage = new FilesystemStorage(indexDirectory.getParent(), fsStorage.getFileLockManager());
                indexDir = indexStorage.getAsset(indexDirectory.getFileName().toString());
            } else {
                throw new IOException("The given storage is not file based.");
            }
        } else if (indexDirectory.isAbsolute()) {
            indexDir = storage.getAsset(repositoryPath.relativize(indexDirectory).toString());
        } else {
            indexDir = storage.getAsset(indexDirectory.toString());
        }
    } else {
        indexDir = storage.getAsset(defaultDir);
    }
    if (!indexDir.exists()) {
        indexDir.create(AssetType.CONTAINER);
    }
    return indexDir;
}
Also used : Path(java.nio.file.Path) RepositoryStorage(org.apache.archiva.repository.storage.RepositoryStorage) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) IOException(java.io.IOException)

Example 7 with FilesystemStorage

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

the class MetadataTransferTest method assertMetadataEquals.

private void assertMetadataEquals(String expectedMetadataXml, Path actualFile) throws Exception {
    assertNotNull("Actual File should not be null.", actualFile);
    assertTrue("Actual file exists.", Files.exists(actualFile));
    StringWriter actualContents = new StringWriter();
    FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager());
    StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString());
    ArchivaRepositoryMetadata metadata = metadataTools.getMetadataReader(null).read(actualFileAsset);
    RepositoryMetadataWriter.write(metadata, actualContents);
    Diff detailedDiff = DiffBuilder.compare(expectedMetadataXml).withTest(actualContents.toString()).checkForSimilar().build();
    if (detailedDiff.hasDifferences()) {
        for (Difference diff : detailedDiff.getDifferences()) {
            System.out.println(diff);
        }
        assertEquals(expectedMetadataXml, actualContents);
    }
// assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
}
Also used : StringWriter(java.io.StringWriter) Diff(org.xmlunit.diff.Diff) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Difference(org.xmlunit.diff.Difference) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 8 with FilesystemStorage

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

the class MavenRemoteRepository method newLocalInstance.

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);
}
Also used : FileLockManager(org.apache.archiva.common.filelock.FileLockManager) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager)

Example 9 with FilesystemStorage

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

the class MavenRepositoryProvider method createRepositoryGroup.

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

Example 10 with FilesystemStorage

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

the class BasicRepositoryGroup method newFilesystemInstance.

/**
 * Creates a filesystem based repository instance. The path is built by basePath/repository-id
 *
 * @param id The repository id
 * @param name The name of the repository
 * @param repositoryPath The path to the repository
 * @return The repository instance
 * @throws IOException
 */
public static BasicRepositoryGroup newFilesystemInstance(String id, String name, Path repositoryPath) throws IOException {
    FileLockManager lockManager = new DefaultFileLockManager();
    FilesystemStorage storage = new FilesystemStorage(repositoryPath, lockManager);
    return new BasicRepositoryGroup(id, name, storage);
}
Also used : FileLockManager(org.apache.archiva.common.filelock.FileLockManager) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager)

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