Search in sources :

Example 31 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class Maven2RepositoryStorage method isProjectVersion.

private boolean isProjectVersion(StorageAsset dir) {
    final String artifactId = dir.getParent().getName();
    final String projectVersion = dir.getName();
    // check if there is a POM artifact file to ensure it is a version directory
    Predicate<StorageAsset> filter;
    if (VersionUtil.isSnapshot(projectVersion)) {
        filter = new PomFilenameFilter(artifactId, projectVersion);
    } else {
        final String pomFile = artifactId + "-" + projectVersion + ".pom";
        filter = new PomFileFilter(pomFile);
    }
    if (dir.list().stream().filter(f -> !f.isContainer()).anyMatch(filter)) {
        return true;
    }
    // if a metadata file is present, check if this is the "version" directory, marking it as a project version
    ArchivaRepositoryMetadata metadata = readMetadata(dir);
    if (metadata != null && projectVersion.equals(metadata.getVersion())) {
        return true;
    }
    return false;
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Filter(org.apache.archiva.filter.Filter) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) DefaultModelBuilderFactory(org.apache.maven.model.building.DefaultModelBuilderFactory) RepositoryProblemFacet(org.apache.archiva.metadata.model.facets.RepositoryProblemFacet) StringUtils(org.apache.commons.lang3.StringUtils) ReleaseScheme(org.apache.archiva.repository.ReleaseScheme) MavenSystemManager(org.apache.archiva.maven.repository.MavenSystemManager) ModelBuilder(org.apache.maven.model.building.ModelBuilder) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Try(org.apache.archiva.common.Try) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ContentItem(org.apache.archiva.repository.content.ContentItem) Predicate(java.util.function.Predicate) ProxyRegistry(org.apache.archiva.proxy.ProxyRegistry) Collection(java.util.Collection) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) ProxyDownloadException(org.apache.archiva.policies.ProxyDownloadException) ProxyConnector(org.apache.archiva.proxy.model.ProxyConnector) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Set(java.util.Set) NetworkProxy(org.apache.archiva.proxy.model.NetworkProxy) Reader(java.io.Reader) WagonFactory(org.apache.archiva.maven.common.proxy.WagonFactory) Collectors(java.util.stream.Collectors) Scm(org.apache.maven.model.Scm) FileNotFoundException(java.io.FileNotFoundException) ZoneId(java.time.ZoneId) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Relocation(org.apache.maven.model.Relocation) Organization(org.apache.maven.model.Organization) List(java.util.List) DistributionManagement(org.apache.maven.model.DistributionManagement) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) PostConstruct(javax.annotation.PostConstruct) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) Model(org.apache.maven.model.Model) RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException) Artifact(org.apache.archiva.repository.content.Artifact) CiManagement(org.apache.maven.model.CiManagement) RepositoryPathTranslator(org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator) RelocationException(org.apache.archiva.metadata.repository.storage.RelocationException) Dependency(org.apache.maven.model.Dependency) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) RemoteRepository(org.apache.archiva.repository.RemoteRepository) Charset(java.nio.charset.Charset) Service(org.springframework.stereotype.Service) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) Named(javax.inject.Named) IssueManagement(org.apache.maven.model.IssueManagement) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) SnapshotVersion(org.apache.archiva.model.SnapshotVersion) Logger(org.slf4j.Logger) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) Channels(java.nio.channels.Channels) VersionUtil(org.apache.archiva.common.utils.VersionUtil) IOException(java.io.IOException) License(org.apache.maven.model.License) RepositoryType(org.apache.archiva.repository.RepositoryType) ApplicationContext(org.springframework.context.ApplicationContext) ChecksummedFile(org.apache.archiva.checksum.ChecksummedFile) ModelProblem(org.apache.maven.model.building.ModelProblem) RepositoryStorageMetadataInvalidException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) MailingList(org.apache.maven.model.MailingList) LayoutException(org.apache.archiva.repository.content.LayoutException) Collections(java.util.Collections) RepositoryStorage(org.apache.archiva.metadata.repository.storage.RepositoryStorage) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 32 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method testArtifactListWithArtifactSelectorWithClassifier.

@Test
public void testArtifactListWithArtifactSelectorWithClassifier() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("test").withVersion("1.0-SNAPSHOT").withArtifactId("test").withClassifier("javadoc").withArtifactVersion("1.0-20050611.112233-1").build();
    List<? extends Artifact> results = repoContent.getArtifacts(selector);
    assertNotNull(results);
    assertEquals(1, results.size());
    Artifact artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("test-1.0-20050611.112233-1-javadoc.jar")).findFirst().get();
    assertNotNull(artifact);
    assertEquals("javadoc", artifact.getClassifier());
    assertEquals("javadoc", artifact.getType());
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 33 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method checkArtifactListWithVersionSelector1.

private void checkArtifactListWithVersionSelector1(List<? extends Artifact> results) {
    assertNotNull(results);
    assertEquals(2, results.size());
    Artifact mainArtifact = results.stream().filter(a -> a.getFileName().equals("jdbc-2.0.jar")).findFirst().get();
    assertNotNull(mainArtifact);
    assertEquals(BaseArtifactTypes.MAIN, mainArtifact.getDataType());
    Artifact metaArtifact = results.stream().filter(a -> a.getFileName().equals("maven-metadata-repository.xml")).findFirst().get();
    assertNotNull(metaArtifact);
    assertEquals(MavenTypes.REPOSITORY_METADATA, metaArtifact.getDataType());
}
Also used : Artifact(org.apache.archiva.repository.content.Artifact)

Example 34 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method testGetRelatedArtifactsFromArtifact.

@Test
public void testGetRelatedArtifactsFromArtifact() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven.shared").withProjectId("maven-downloader").withVersion("1.1").withExtension("jar").withArtifactId("maven-downloader").build();
    Artifact artifact = repoContent.getArtifact(selector);
    assertNotNull(artifact);
    List<? extends Artifact> artifacts = repoContent.getArtifacts(artifact);
    assertNotNull(artifacts);
    assertEquals(2, artifacts.size());
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 35 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method testAddArtifact.

@Test
public void testAddArtifact() throws IOException, URISyntaxException, LayoutException {
    ManagedRepository repo = createManagedRepoWithContent("delete-repository");
    ManagedRepositoryContent myRepoContent = repo.getContent();
    BaseRepositoryContentLayout layout = myRepoContent.getLayout(BaseRepositoryContentLayout.class);
    Path repoRoot = repo.getRoot().getFilePath();
    Path tmpFile = Files.createTempFile("archiva-mvn-repotest", "jar");
    try (OutputStream outputStream = Files.newOutputStream(tmpFile)) {
        for (int i = 0; i < 255; i++) {
            outputStream.write("test.test.test\n".getBytes(Charset.forName("UTF-8")));
        }
    }
    Path file = repoRoot.resolve("org/apache/maven/samplejar/2.0/samplejar-2.0.jar");
    FileTime lmt = Files.getLastModifiedTime(file);
    ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("samplejar").withVersion("2.0").withArtifactId("samplejar").withArtifactVersion("2.0").withExtension("jar").build();
    Artifact artifact = layout.getArtifact(selector);
    layout.addArtifact(tmpFile, artifact);
    FileTime lmtAfter = Files.getLastModifiedTime(file);
    assertNotEquals(lmtAfter, lmt);
    Reader ln = Files.newBufferedReader(file, Charset.forName("UTF-8"));
    char[] content = new char[50];
    ln.read(content);
    assertTrue(new String(content).startsWith("test.test.test"));
    tmpFile = Files.createTempFile("archiva-mvn-repotest", "jar");
    try (OutputStream outputStream = Files.newOutputStream(tmpFile)) {
        for (int i = 0; i < 255; i++) {
            outputStream.write("test.test.test\n".getBytes(Charset.forName("UTF-8")));
        }
    }
    file = repoRoot.resolve("org/apache/maven/samplejar/2.0/samplejar-2.0.test");
    assertFalse(Files.exists(file));
    assertTrue(Files.exists(tmpFile));
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("samplejar").withVersion("2.0").withArtifactId("samplejar").withArtifactVersion("2.0").withExtension("test").build();
    artifact = layout.getArtifact(selector);
    layout.addArtifact(tmpFile, artifact);
    ln = Files.newBufferedReader(file, Charset.forName("UTF-8"));
    ln.read(content);
    assertTrue(new String(content).startsWith("test.test.test"));
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) MavenManagedRepository(org.apache.archiva.maven.repository.MavenManagedRepository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) OutputStream(java.io.OutputStream) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) Reader(java.io.Reader) FileTime(java.nio.file.attribute.FileTime) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Aggregations

Artifact (org.apache.archiva.repository.content.Artifact)78 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)63 Test (org.junit.Test)60 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)59 Path (java.nio.file.Path)54 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)26 ItemSelector (org.apache.archiva.repository.content.ItemSelector)21 LayoutException (org.apache.archiva.repository.content.LayoutException)21 ContentItem (org.apache.archiva.repository.content.ContentItem)19 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)15 IOException (java.io.IOException)13 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 Project (org.apache.archiva.repository.content.Project)13 MavenMetadataReader (org.apache.archiva.maven.metadata.MavenMetadataReader)12 Version (org.apache.archiva.repository.content.Version)12 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)12 Reader (java.io.Reader)11 List (java.util.List)11 Collectors (java.util.stream.Collectors)11 Inject (javax.inject.Inject)11