Search in sources :

Example 11 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataTransferTest method assertRepoProjectMetadata.

/**
 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
 * list of expected versions within.
 *
 * @param proxiedRepoId
 * @param requestedResource
 * @param expectedProxyVersions
 */
private void assertRepoProjectMetadata(String proxiedRepoId, String requestedResource, String[] expectedProxyVersions) throws Exception {
    String proxiedFile = metadataTools.getRepositorySpecificName(proxiedRepoId, requestedResource);
    Path actualFile = managedDefaultDir.resolve(proxiedFile);
    assertTrue(Files.exists(actualFile));
    ProjectReference metadata = createProjectReference(requestedResource);
    // Build expected metadata XML
    StringWriter expectedMetadataXml = new StringWriter();
    ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
    m.setGroupId(metadata.getGroupId());
    m.setArtifactId(metadata.getArtifactId());
    if (expectedProxyVersions != null) {
        m.getAvailableVersions().addAll(Arrays.asList(expectedProxyVersions));
    }
    RepositoryMetadataWriter.write(m, expectedMetadataXml);
    // Compare the file to the actual contents.
    assertMetadataEquals(expectedMetadataXml.toString(), actualFile);
}
Also used : Path(java.nio.file.Path) ProjectReference(org.apache.archiva.model.ProjectReference) StringWriter(java.io.StringWriter) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 12 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataUpdaterConsumer method updateProjectMetadata.

private void updateProjectMetadata(ArtifactReference artifact, String path) {
    ProjectReference projectRef = new ProjectReference();
    projectRef.setGroupId(artifact.getGroupId());
    projectRef.setArtifactId(artifact.getArtifactId());
    try {
        String metadataPath = this.metadataTools.toPath(projectRef);
        Path projectMetadata = this.repositoryDir.resolve(metadataPath);
        if (Files.exists(projectMetadata) && (Files.getLastModifiedTime(projectMetadata).toMillis() >= this.scanStartTimestamp)) {
            // This metadata is up to date. skip it.
            log.debug("Skipping uptodate metadata: {}", this.metadataTools.toPath(projectRef));
            return;
        }
        metadataTools.updateMetadata(this.repository, metadataPath);
        log.debug("Updated metadata: {}", this.metadataTools.toPath(projectRef));
    } catch (RepositoryMetadataException e) {
        log.error("Unable to write project metadat for artifact [{}]:", path, e);
        triggerConsumerError(TYPE_METADATA_WRITE_FAILURE, "Unable to write project metadata for artifact [" + path + "]: " + e.getMessage());
    } catch (IOException e) {
        log.warn("Project metadata not written due to IO warning: ", e);
        triggerConsumerWarning(TYPE_METADATA_IO, "Project metadata not written due to IO warning: " + e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) ProjectReference(org.apache.archiva.model.ProjectReference) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) IOException(java.io.IOException)

Example 13 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataTransferTest method testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled.

@Test
public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled() throws Exception {
    // New project metadata that does not exist locally but exists on remote.
    String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
    setupTestableManagedRepository(requestedResource);
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true);
    assertResourceNotFound(requestedResource);
    assertNoRepoMetadata(ID_PROXIED1, requestedResource);
    Path expectedFile = managedDefaultDir.resolve(requestedResource);
    ProjectReference metadata = createProjectReference(requestedResource);
    Path downloadedFile = proxyHandler.fetchMetadataFromProxies(managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata)).getFile();
    assertNull("Should not have downloaded a file.", downloadedFile);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) ProjectReference(org.apache.archiva.model.ProjectReference) Test(org.junit.Test)

Example 14 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataTransferTest method assertRepoGroupMetadataContents.

private void assertRepoGroupMetadataContents(String proxiedRepoId, String requestedResource, String[] expectedPlugins) throws Exception {
    String proxiedFile = metadataTools.getRepositorySpecificName(proxiedRepoId, requestedResource);
    Path actualFile = managedDefaultDir.resolve(proxiedFile);
    assertTrue("Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile));
    ProjectReference actualMetadata = createGroupReference(requestedResource);
    assertGroupMetadata(actualFile, actualMetadata, expectedPlugins);
}
Also used : Path(java.nio.file.Path) ProjectReference(org.apache.archiva.model.ProjectReference)

Example 15 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataTools method toProjectReference.

public ProjectReference toProjectReference(String path) throws RepositoryMetadataException {
    if (!path.endsWith("/" + MAVEN_METADATA)) {
        throw new RepositoryMetadataException("Cannot convert to versioned reference, not a metadata file. ");
    }
    ProjectReference reference = new ProjectReference();
    String normalizedPath = StringUtils.replace(path, "\\", "/");
    String[] pathParts = StringUtils.split(normalizedPath, '/');
    // Assume last part of the path is the version.
    int artifactIdOffset = pathParts.length - 2;
    int groupIdEnd = artifactIdOffset - 1;
    reference.setArtifactId(pathParts[artifactIdOffset]);
    StringBuilder gid = new StringBuilder();
    for (int i = 0; i <= groupIdEnd; i++) {
        if (i > 0) {
            gid.append(".");
        }
        gid.append(pathParts[i]);
    }
    reference.setGroupId(gid.toString());
    return reference;
}
Also used : ProjectReference(org.apache.archiva.model.ProjectReference)

Aggregations

ProjectReference (org.apache.archiva.model.ProjectReference)20 Path (java.nio.file.Path)11 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 VersionedReference (org.apache.archiva.model.VersionedReference)3 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)3 LayoutException (org.apache.archiva.repository.LayoutException)3 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)2 ArtifactReference (org.apache.archiva.model.ArtifactReference)2 RepositoryException (org.apache.archiva.repository.RepositoryException)2 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)2 URI (java.net.URI)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1