Search in sources :

Example 11 with DefaultFileLockManager

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());
}
Also used : Path(java.nio.file.Path) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 12 with DefaultFileLockManager

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

Example 13 with DefaultFileLockManager

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;
}
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 14 with DefaultFileLockManager

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Date(java.util.Date) TimeZone(java.util.TimeZone) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) SimpleDateFormat(java.text.SimpleDateFormat)

Example 15 with DefaultFileLockManager

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

DefaultFileLockManager (org.apache.archiva.common.filelock.DefaultFileLockManager)42 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)41 Path (java.nio.file.Path)23 FileLockManager (org.apache.archiva.common.filelock.FileLockManager)14 FilesystemAsset (org.apache.archiva.repository.storage.fs.FilesystemAsset)12 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)7 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)7 BasicManagedRepository (org.apache.archiva.repository.base.managed.BasicManagedRepository)6 ArtifactContentEntry (org.apache.archiva.rest.api.model.ArtifactContentEntry)6 IOException (java.io.IOException)5 URI (java.net.URI)5 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 DavException (org.apache.jackrabbit.webdav.DavException)3 Before (org.junit.Before)3 Date (java.util.Date)2 MavenMetadataReader (org.apache.archiva.maven.metadata.MavenMetadataReader)2 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)2