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);
}
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());
}
}
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);
}
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);
}
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;
}
Aggregations