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;
}
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 );
}
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);
}
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;
}
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);
}
Aggregations