Search in sources :

Example 1 with FilesystemAsset

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, 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 FilesystemAsset

use of org.apache.archiva.repository.storage.fs.FilesystemAsset 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 3 with FilesystemAsset

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

the class FilesystemAssetTest method getName.

@Test
public void getName() {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/" + assetPathFile.getFileName().toString(), assetPathFile);
    Assert.assertEquals(assetPathFile.getFileName().toString(), asset.getName());
}
Also used : FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Test(org.junit.Test)

Example 4 with FilesystemAsset

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

the class FilesystemAssetTest method getSize.

@Test
public void getSize() throws IOException {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/test1234", assetPathFile);
    Assert.assertEquals(0, asset.getSize());
    Files.write(assetPathFile, new String("abcdef").getBytes("ASCII"));
    Assert.assertTrue(asset.getSize() >= 6);
}
Also used : FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Test(org.junit.Test)

Example 5 with FilesystemAsset

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

the class FilesystemAssetTest method isContainer.

@Test
public void isContainer() {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/test1323", assetPathFile);
    Assert.assertFalse(asset.isContainer());
    FilesystemAsset asset2 = new FilesystemAsset(filesystemStorage, "/test1234", assetPathDir);
    Assert.assertTrue(asset2.isContainer());
}
Also used : FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Test(org.junit.Test)

Aggregations

FilesystemAsset (org.apache.archiva.repository.storage.fs.FilesystemAsset)26 Test (org.junit.Test)20 Path (java.nio.file.Path)13 DefaultFileLockManager (org.apache.archiva.common.filelock.DefaultFileLockManager)13 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)13 ArtifactContentEntry (org.apache.archiva.rest.api.model.ArtifactContentEntry)6 OutputStream (java.io.OutputStream)5 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 URI (java.net.URI)3 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)3 Instant (java.time.Instant)2 Before (org.junit.Before)2 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1 Configuration (org.apache.archiva.configuration.model.Configuration)1