Search in sources :

Example 1 with FilesystemStorage

use of org.apache.archiva.repository.storage.fs.FilesystemStorage 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, 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);
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) URI(java.net.URI)

Example 2 with FilesystemStorage

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

the class MavenContentHelperTest method getArtifactVersion.

@Test
void getArtifactVersion() throws IOException, URISyntaxException {
    MavenContentHelper mavenContentHelper = new MavenContentHelper();
    MavenMetadataReader reader = new MavenMetadataReader();
    mavenContentHelper.setMetadataReader(reader);
    Path testRepoPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource("repositories/metadata-repository").toURI());
    FilesystemStorage storage = new FilesystemStorage(testRepoPath, new DefaultFileLockManager());
    assertArtifactVersion(mavenContentHelper, "1.0-alpha-11-SNAPSHOT", storage.getAsset("org/apache/archiva/metadata/tests/snap_shots_1/1.0-alpha-11-SNAPSHOT"), "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-SNAPSHOT");
    assertArtifactVersion(mavenContentHelper, "1.0-alpha-11-20070316.175232-11", storage.getAsset("org/apache/archiva/metadata/tests/snap_shots_a/1.0-alpha-11-SNAPSHOT"), "", "1.0-alpha-11-SNAPSHOT");
    assertArtifactVersion(mavenContentHelper, "2.2-20070316.153953-10", storage.getAsset("org/apache/archiva/metadata/tests/snap_shots_b/2.2-SNAPSHOT"), "", "2.2-SNAPSHOT");
}
Also used : Path(java.nio.file.Path) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) Test(org.junit.jupiter.api.Test)

Example 3 with FilesystemStorage

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

the class MavenContentHelperTest method setUp.

@BeforeAll
static void setUp() throws IOException {
    tempDir = Files.createTempDirectory("archivamaventest");
    storage = new FilesystemStorage(tempDir, new DefaultFileLockManager());
}
Also used : FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with FilesystemStorage

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

the class FilesystemStorageTest method init.

@Before
public void init() throws IOException {
    baseDir = Files.createTempDirectory("FsStorageTest");
    DefaultFileLockManager fl = new DefaultFileLockManager();
    fsStorage = new FilesystemStorage(baseDir, fl);
    Files.createDirectories(baseDir.resolve("dir1"));
    Files.createDirectories(baseDir.resolve("dir2"));
    file1 = Files.createFile(baseDir.resolve("dir1/testfile1.dat"));
    dir1 = Files.createDirectories(baseDir.resolve("dir1/testdir"));
    file1Asset = new FilesystemAsset(fsStorage, "/dir1/testfile1.dat", file1);
    dir1Asset = new FilesystemAsset(fsStorage, "/dir1/testdir", dir1);
}
Also used : FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Before(org.junit.Before)

Example 5 with FilesystemStorage

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

the class ArchivaDavResourceFactory method buildMergedIndexDirectory.

protected StorageAsset buildMergedIndexDirectory(String activePrincipal, DavServletRequest request, RepositoryGroup repositoryGroup) throws DavException {
    try {
        final List<ManagedRepository> repositories = repositoryGroup.getRepositories();
        HttpSession session = request.getSession();
        @SuppressWarnings("unchecked") Map<String, TemporaryGroupIndex> temporaryGroupIndexMap = (Map<String, TemporaryGroupIndex>) session.getAttribute(TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY);
        if (temporaryGroupIndexMap == null) {
            temporaryGroupIndexMap = new HashMap<>();
        }
        final String id = repositoryGroup.getId();
        TemporaryGroupIndex tmp = temporaryGroupIndexMap.get(id);
        if (tmp != null && tmp.getDirectory() != null && tmp.getDirectory().exists()) {
            if (System.currentTimeMillis() - tmp.getCreationTime() > (repositoryGroup.getMergedIndexTTL() * 60 * 1000)) {
                log.debug(MarkerFactory.getMarker("group.merged.index"), "tmp group index '{}' is too old so delete it", id);
                indexMerger.cleanTemporaryGroupIndex(tmp);
            } else {
                log.debug(MarkerFactory.getMarker("group.merged.index"), "merged index for group '{}' found in cache", id);
                return tmp.getDirectory();
            }
        }
        Set<String> authzRepos = new HashSet<String>();
        String permission = WebdavMethodUtil.getMethodPermission(request.getMethod());
        for (ManagedRepository repository : repositories) {
            try {
                if (servletAuth.isAuthorized(activePrincipal, repository.getId(), permission)) {
                    authzRepos.add(repository.getId());
                    authzRepos.addAll(this.repositorySearch.getRemoteIndexingContextIds(repository.getId()));
                }
            } catch (UnauthorizedException e) {
                // TODO: review exception handling
                log.debug("Skipping repository '{}' for user '{}': {}", repository, activePrincipal, e.getMessage());
            }
        }
        log.info("generate temporary merged index for repository group '{}' for repositories '{}'", id, authzRepos);
        IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature(IndexCreationFeature.class);
        Path indexPath = indexCreationFeature.getLocalIndexPath().getFilePath();
        if (indexPath != null) {
            Path tempRepoFile = Files.createTempDirectory("temp");
            tempRepoFile.toFile().deleteOnExit();
            FilesystemStorage storage = new FilesystemStorage(tempRepoFile, new DefaultFileLockManager());
            StorageAsset tmpAsset = storage.getRoot();
            IndexMergerRequest indexMergerRequest = new IndexMergerRequest(authzRepos, true, id, indexPath.toString(), repositoryGroup.getMergedIndexTTL()).mergedIndexDirectory(tmpAsset).temporary(true);
            MergedRemoteIndexesTaskRequest taskRequest = new MergedRemoteIndexesTaskRequest(indexMergerRequest, indexMerger);
            MergedRemoteIndexesTask job = new MergedRemoteIndexesTask(taskRequest);
            ArchivaIndexingContext indexingContext = job.execute().getIndexingContext();
            StorageAsset mergedRepoDir = indexingContext.getPath();
            TemporaryGroupIndex temporaryGroupIndex = new TemporaryGroupIndex(mergedRepoDir, indexingContext.getId(), id, // 
            repositoryGroup.getMergedIndexTTL()).setCreationTime(new Date().getTime());
            temporaryGroupIndexMap.put(id, temporaryGroupIndex);
            session.setAttribute(TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY, temporaryGroupIndexMap);
            return mergedRepoDir;
        } else {
            log.error("Local index path for repository group {} does not exist.", repositoryGroup.getId());
            throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositorySearchException e) {
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    } catch (IndexMergerException e) {
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    } catch (IOException e) {
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    }
}
Also used : TemporaryGroupIndex(org.apache.archiva.indexer.merger.TemporaryGroupIndex) ManagedRepository(org.apache.archiva.repository.ManagedRepository) MergedRemoteIndexesTaskRequest(org.apache.archiva.indexer.merger.base.MergedRemoteIndexesTaskRequest) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) UnauthorizedException(org.apache.archiva.redback.authorization.UnauthorizedException) IndexMergerException(org.apache.archiva.indexer.merger.IndexMergerException) HashSet(java.util.HashSet) Path(java.nio.file.Path) MergedRemoteIndexesTask(org.apache.archiva.indexer.merger.base.MergedRemoteIndexesTask) DavException(org.apache.jackrabbit.webdav.DavException) HttpSession(javax.servlet.http.HttpSession) IndexMergerRequest(org.apache.archiva.indexer.merger.IndexMergerRequest) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) IOException(java.io.IOException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) Date(java.util.Date) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Map(java.util.Map) HashMap(java.util.HashMap)

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