use of org.apache.archiva.repository.storage.fs.FilesystemAsset in project archiva by apache.
the class Maven2RepositoryMerger method createFolderStructure.
private void createFolderStructure(String sourceRepoId, String targetRepoId, ArtifactMetadata artifactMetadata) throws IOException, RepositoryException {
Configuration config = configuration.getConfiguration();
ManagedRepositoryConfiguration targetRepoConfig = config.findManagedRepositoryById(targetRepoId);
ManagedRepositoryConfiguration sourceRepoConfig = config.findManagedRepositoryById(sourceRepoId);
Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
TimeZone timezone = TimeZone.getTimeZone("UTC");
DateFormat fmt = new SimpleDateFormat("yyyyMMdd.HHmmss");
fmt.setTimeZone(timezone);
String timestamp = fmt.format(lastUpdatedTimestamp);
String targetRepoPath = targetRepoConfig.getLocation();
String sourceRepoPath = sourceRepoConfig.getLocation();
String artifactPath = pathTranslator.toPath(artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getProjectVersion(), artifactMetadata.getId());
Path sourceArtifactFile = Paths.get(sourceRepoPath, artifactPath);
Path targetArtifactFile = Paths.get(targetRepoPath, artifactPath);
log.debug("artifactPath {}", artifactPath);
int lastIndex = artifactPath.lastIndexOf(RepositoryPathTranslator.PATH_SEPARATOR);
Path targetFile = Paths.get(targetRepoPath, artifactPath.substring(0, lastIndex));
if (!Files.exists(targetFile)) {
// create the folder structure when it does not exist
Files.createDirectories(targetFile);
}
// artifact copying
copyFile(sourceArtifactFile, targetArtifactFile);
// pom file copying
// TODO need to use path translator to get the pom file path
// String fileName = artifactMetadata.getProject() + "-" + artifactMetadata.getVersion() + ".pom";
//
// File sourcePomFile =
// pathTranslator.toFile( new File( sourceRepoPath ), artifactMetadata.getId(), artifactMetadata.getProject(),
// artifactMetadata.getVersion(), fileName );
//
// String relativePathToPomFile = sourcePomFile.getAbsolutePath().split( sourceRepoPath )[1];
// File targetPomFile = new File( targetRepoPath, relativePathToPomFile );
// pom file copying (file path is taken with out using path translator)
String index = artifactPath.substring(lastIndex + 1);
int last = index.lastIndexOf('.');
Path sourcePomFile = Paths.get(sourceRepoPath, artifactPath.substring(0, lastIndex) + "/" + artifactPath.substring(lastIndex + 1).substring(0, last) + ".pom");
Path targetPomFile = Paths.get(targetRepoPath, artifactPath.substring(0, lastIndex) + "/" + artifactPath.substring(lastIndex + 1).substring(0, last) + ".pom");
if (!Files.exists(targetPomFile) && Files.exists(sourcePomFile)) {
copyFile(sourcePomFile, targetPomFile);
}
// explicitly update only if metadata-updater consumer is not enabled!
if (!config.getRepositoryScanning().getKnownContentConsumers().contains("metadata-updater")) {
// updating version metadata files
FilesystemStorage fsStorage = new FilesystemStorage(Paths.get(sourceRepoPath), new DefaultFileLockManager());
StorageAsset versionMetaDataFileInSourceRepo = pathTranslator.toFile(new FilesystemAsset(fsStorage, "", Paths.get(sourceRepoPath)), artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getVersion(), METADATA_FILENAME);
if (versionMetaDataFileInSourceRepo.exists()) {
// Pattern quote for windows path
String relativePathToVersionMetadataFile = getRelativeAssetPath(versionMetaDataFileInSourceRepo);
Path versionMetaDataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToVersionMetadataFile);
if (!Files.exists(versionMetaDataFileInTargetRepo)) {
copyFile(versionMetaDataFileInSourceRepo.getFilePath(), versionMetaDataFileInTargetRepo);
} else {
updateVersionMetadata(versionMetaDataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp);
}
}
// updating project meta data file
StorageAsset projectDirectoryInSourceRepo = versionMetaDataFileInSourceRepo.getParent().getParent();
StorageAsset projectMetadataFileInSourceRepo = projectDirectoryInSourceRepo.resolve(METADATA_FILENAME);
if (projectMetadataFileInSourceRepo.exists()) {
String relativePathToProjectMetadataFile = getRelativeAssetPath(projectMetadataFileInSourceRepo);
Path projectMetadataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToProjectMetadataFile);
if (!Files.exists(projectMetadataFileInTargetRepo)) {
copyFile(projectMetadataFileInSourceRepo.getFilePath(), projectMetadataFileInTargetRepo);
} else {
updateProjectMetadata(projectMetadataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp, timestamp);
}
}
}
}
use of org.apache.archiva.repository.storage.fs.FilesystemAsset 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 filesystemStorage = (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();
filesystemStorage = 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(filesystemStorage, indexPath, indexDirectory);
}
use of org.apache.archiva.repository.storage.fs.FilesystemAsset 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);
}
use of org.apache.archiva.repository.storage.fs.FilesystemAsset 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"));
}
use of org.apache.archiva.repository.storage.fs.FilesystemAsset in project archiva by apache.
the class ArtifactContentEntriesTests method readArtifactContentEntriesSecondDepthOnlyOneDirectory.
@Test
public void readArtifactContentEntriesSecondDepthOnlyOneDirectory() 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), "org", "foo");
log.info("artifactContentEntries: {}", artifactContentEntries);
assertThat(artifactContentEntries).isNotNull().isNotEmpty().hasSize(1).contains(new ArtifactContentEntry("org/apache", false, 1, "foo"));
}
Aggregations