Search in sources :

Example 16 with FilesystemAsset

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

the class ArtifactContentEntriesTests method readArtifactContentEntriesDirectoryAndFiles.

@Test
public void readArtifactContentEntriesDirectoryAndFiles() 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/apache/commons/logging/", "foo");
    log.info("artifactContentEntries: {}", artifactContentEntries);
    assertThat(artifactContentEntries).isNotNull().isNotEmpty().hasSize(10).contains(new ArtifactContentEntry("org/apache/commons/logging/impl", false, 4, "foo"), new ArtifactContentEntry("org/apache/commons/logging/LogSource.class", true, 4, "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 17 with FilesystemAsset

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

the class ArtifactContentEntriesTests method readArtifactContentEntriesOnlyFiles.

@Test
public void readArtifactContentEntriesOnlyFiles() 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/apache/commons/logging/impl/", "foo");
    log.info("artifactContentEntries: {}", artifactContentEntries);
    assertThat(artifactContentEntries).isNotNull().isNotEmpty().hasSize(16).contains(new ArtifactContentEntry("org/apache/commons/logging/impl/AvalonLogger.class", true, 5, "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 18 with FilesystemAsset

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

the class ArtifactContentEntriesTests method readArtifactContentEntriesRootPathEmpty.

@Test
public void readArtifactContentEntriesRootPathEmpty() 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 19 with FilesystemAsset

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

the class FilesystemAssetTest method list.

@Test
public void list() throws IOException {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/test1234", assetPathFile);
    Assert.assertEquals(0, asset.list().size());
    FilesystemAsset asset2 = new FilesystemAsset(filesystemStorage, "/test1235", assetPathDir);
    Assert.assertEquals(1, asset2.list().size());
    Path f1 = Files.createTempFile(assetPathDir, "testfile", "dat");
    Path f2 = Files.createTempFile(assetPathDir, "testfile", "dat");
    Path d1 = Files.createTempDirectory(assetPathDir, "testdir");
    Assert.assertEquals(4, asset2.list().size());
    Assert.assertTrue(asset2.list().stream().anyMatch(p -> p.getName().equals(f1.getFileName().toString())));
    Assert.assertTrue(asset2.list().stream().anyMatch(p -> p.getName().equals(f2.getFileName().toString())));
    Assert.assertTrue(asset2.list().stream().anyMatch(p -> p.getName().equals(d1.getFileName().toString())));
    Files.deleteIfExists(f1);
    Files.deleteIfExists(f2);
    Files.deleteIfExists(d1);
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) Files(java.nio.file.Files) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) IOException(java.io.IOException) Instant(java.time.Instant) IOUtils(org.apache.commons.io.IOUtils) Paths(java.nio.file.Paths) After(org.junit.After) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assert(org.junit.Assert) Path(java.nio.file.Path) Before(org.junit.Before) InputStream(java.io.InputStream) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Test(org.junit.Test)

Example 20 with FilesystemAsset

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

the class FilesystemAssetTest method writeDataExceptionOnDir.

@Test
public void writeDataExceptionOnDir() throws IOException {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/test1234", assetPathDir);
    try {
        OutputStream os = asset.getWriteStream(true);
        Assert.assertTrue("Writing to a directory should throw a IOException", false);
    } catch (IOException e) {
    // Fine
    }
}
Also used : OutputStream(java.io.OutputStream) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) IOException(java.io.IOException) 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