use of org.apache.archiva.common.filelock.DefaultFileLockManager in project archiva by apache.
the class MavenRepositoryMapperTest method reverseUpdate.
@Test
void reverseUpdate() throws IOException, URISyntaxException, UnsupportedURIException {
MavenRepositoryMapper mapper = new MavenRepositoryMapper();
MavenManagedRepository result = new MavenManagedRepository();
Path tmpDir = Files.createTempDirectory("mapper-test");
FilesystemStorage fsStorage = new FilesystemStorage(tmpDir, new DefaultFileLockManager());
EditableManagedRepository repository = new BasicManagedRepository(Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage);
repository.setDescription(Locale.getDefault(), "This is repo 02");
repository.setBlocksRedeployment(false);
repository.setLocation(new URI("test-path"));
repository.setScanned(true);
repository.setLayout("maven2");
repository.setSchedulingDefinition("* 3,5,10 * * *");
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class);
icf.setIndexPath(new URI(".indexer"));
icf.setPackedIndexPath(new URI(".index"));
icf.setSkipPackedIndexCreation(false);
ArtifactCleanupFeature acf = repository.getFeature(ArtifactCleanupFeature.class);
acf.setDeleteReleasedSnapshots(false);
acf.setRetentionPeriod(Period.ofDays(5));
acf.setRetentionCount(17);
StagingRepositoryFeature srf = repository.getFeature(StagingRepositoryFeature.class);
srf.setStageRepoNeeded(false);
mapper.reverseUpdate(repository, result);
assertEquals("repo02", result.getId());
assertEquals("Repo 02", result.getName());
assertEquals("This is repo 02", result.getDescription());
assertFalse(result.isBlocksRedeployments());
assertEquals("test-path", result.getLocation());
assertTrue(result.isScanned());
assertEquals("maven2", result.getLayout());
assertEquals("* 3,5,10 * * *", result.getSchedulingDefinition());
assertEquals(".indexer", result.getIndexPath());
assertEquals(".index", result.getPackedIndexPath());
assertFalse(result.isSkipPackedIndexCreation());
assertFalse(result.isDeleteSnapshotsOfRelease());
assertEquals(Period.ofDays(5), result.getRetentionPeriod());
assertEquals(17, result.getRetentionCount());
assertFalse(result.hasStagingRepository());
}
use of org.apache.archiva.common.filelock.DefaultFileLockManager in project archiva by apache.
the class ArtifactContentEntriesTests method readArtifactContentEntriesRootSlash.
@Test
public void readArtifactContentEntriesRootSlash() 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), "/", "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.common.filelock.DefaultFileLockManager in project archiva by apache.
the class RepositoryGroupHandlerTest method createRepository.
protected EditableRepositoryGroup createRepository(String id, String name, Path location) throws IOException {
FileLockManager lockManager = new DefaultFileLockManager();
FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager);
BasicRepositoryGroup repo = new BasicRepositoryGroup(id, name, storage);
repo.setLocation(location.toAbsolutePath().toUri());
return repo;
}
use of org.apache.archiva.common.filelock.DefaultFileLockManager 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.common.filelock.DefaultFileLockManager in project archiva by apache.
the class MavenRepositoryGroup method newLocalInstance.
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);
}
Aggregations