use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class RepositoryMetadataReaderTest method testLoadSimple.
@Test
public void testLoadSimple() throws XMLException {
Path defaultRepoDir = Paths.get("src/test/repositories/default-repository");
Path metadataFile = defaultRepoDir.resolve("org/apache/maven/shared/maven-downloader/maven-metadata.xml");
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read(metadataFile);
assertNotNull(metadata);
assertEquals("Group Id", "org.apache.maven.shared", metadata.getGroupId());
assertEquals("Artifact Id", "maven-downloader", metadata.getArtifactId());
assertEquals("Released Version", "1.1", metadata.getReleasedVersion());
assertEquals("List of Available Versions", 2, metadata.getAvailableVersions().size());
assertTrue("Available version 1.0", metadata.getAvailableVersions().contains("1.0"));
assertTrue("Available version 1.1", metadata.getAvailableVersions().contains("1.1"));
}
use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class RepositoryModelResolver method findTimeStampedSnapshotPom.
protected Path findTimeStampedSnapshotPom(String groupId, String artifactId, String version, String parentDirectory) {
// reading metadata if there
Path mavenMetadata = Paths.get(parentDirectory, METADATA_FILENAME);
if (Files.exists(mavenMetadata)) {
try {
ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read(mavenMetadata);
SnapshotVersion snapshotVersion = archivaRepositoryMetadata.getSnapshotVersion();
if (snapshotVersion != null) {
String lastVersion = snapshotVersion.getTimestamp();
int buildNumber = snapshotVersion.getBuildNumber();
String snapshotPath = StringUtils.replaceChars(groupId, '.', '/') + '/' + artifactId + '/' + version + '/' + artifactId + '-' + StringUtils.remove(version, "-" + VersionUtil.SNAPSHOT) + '-' + lastVersion + '-' + buildNumber + ".pom";
log.debug("use snapshot path {} for maven coordinate {}:{}:{}", snapshotPath, groupId, artifactId, version);
Path model = basedir.resolve(snapshotPath);
// model = pathTranslator.toFile( basedir, groupId, artifactId, lastVersion, filename );
if (Files.exists(model)) {
return model;
}
}
} catch (XMLException e) {
log.warn("fail to read {}, {}", mavenMetadata.toAbsolutePath(), e.getCause());
}
}
return null;
}
use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class RepositoryModelResolver method getModelFromProxy.
// FIXME: we need to do some refactoring, we cannot re-use the proxy components of archiva-proxy in maven2-repository
// because it's causing a cyclic dependency
private boolean getModelFromProxy(RemoteRepository remoteRepository, String groupId, String artifactId, String version, String filename) throws AuthorizationException, TransferFailedException, ResourceDoesNotExistException, WagonFactoryException, XMLException, IOException {
boolean success = false;
Path tmpMd5 = null;
Path tmpSha1 = null;
Path tmpResource = null;
String artifactPath = pathTranslator.toPath(groupId, artifactId, version, filename);
Path resource = Paths.get(targetRepository.getLocation()).resolve(artifactPath);
Path workingDirectory = createWorkingDirectory(targetRepository.getLocation().toString());
try {
Wagon wagon = null;
try {
String protocol = getProtocol(remoteRepository.getLocation().toString());
final NetworkProxy networkProxy = this.networkProxyMap.get(remoteRepository.getId());
wagon = wagonFactory.getWagon(new WagonFactoryRequest("wagon#" + protocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
if (wagon == null) {
throw new RuntimeException("Unsupported remote repository protocol: " + protocol);
}
boolean connected = connectToRepository(wagon, remoteRepository);
if (connected) {
tmpResource = workingDirectory.resolve(filename);
if (VersionUtil.isSnapshot(version)) {
// get the metadata first!
Path tmpMetadataResource = workingDirectory.resolve(METADATA_FILENAME);
String metadataPath = StringUtils.substringBeforeLast(artifactPath, "/") + "/" + METADATA_FILENAME;
wagon.get(addParameters(metadataPath, remoteRepository), tmpMetadataResource.toFile());
log.debug("Successfully downloaded metadata.");
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read(tmpMetadataResource);
// re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
SnapshotVersion snapshotVersion = metadata.getSnapshotVersion();
String timestampVersion = version;
if (snapshotVersion != null) {
timestampVersion = timestampVersion.substring(0, timestampVersion.length() - // remove SNAPSHOT from end
8);
timestampVersion = timestampVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
filename = artifactId + "-" + timestampVersion + ".pom";
artifactPath = pathTranslator.toPath(groupId, artifactId, version, filename);
log.debug("New artifactPath :{}", artifactPath);
}
}
log.info("Retrieving {} from {}", artifactPath, remoteRepository.getName());
wagon.get(addParameters(artifactPath, remoteRepository), tmpResource.toFile());
log.debug("Downloaded successfully.");
tmpSha1 = transferChecksum(wagon, remoteRepository, artifactPath, tmpResource, workingDirectory, ".sha1");
tmpMd5 = transferChecksum(wagon, remoteRepository, artifactPath, tmpResource, workingDirectory, ".md5");
}
} finally {
if (wagon != null) {
try {
wagon.disconnect();
} catch (ConnectionException e) {
log.warn("Unable to disconnect wagon.", e);
}
}
}
if (resource != null) {
synchronized (resource.toAbsolutePath().toString().intern()) {
Path directory = resource.getParent();
moveFileIfExists(tmpMd5, directory);
moveFileIfExists(tmpSha1, directory);
moveFileIfExists(tmpResource, directory);
success = true;
}
}
} finally {
org.apache.archiva.common.utils.FileUtils.deleteQuietly(workingDirectory);
}
return success;
}
use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class Maven2RepositoryMerger method updateVersionMetadata.
private void updateVersionMetadata(Path versionMetaDataFileInTargetRepo, ArtifactMetadata artifactMetadata, Date lastUpdatedTimestamp) throws RepositoryMetadataException {
ArchivaRepositoryMetadata versionMetadata = getMetadata(versionMetaDataFileInTargetRepo);
if (!Files.exists(versionMetaDataFileInTargetRepo)) {
versionMetadata.setGroupId(artifactMetadata.getNamespace());
versionMetadata.setArtifactId(artifactMetadata.getProject());
versionMetadata.setVersion(artifactMetadata.getProjectVersion());
}
versionMetadata.setLastUpdatedTimestamp(lastUpdatedTimestamp);
RepositoryMetadataWriter.write(versionMetadata, versionMetaDataFileInTargetRepo);
}
use of org.apache.archiva.model.ArchivaRepositoryMetadata in project archiva by apache.
the class Maven2RepositoryMerger method updateProjectMetadata.
private void updateProjectMetadata(Path projectMetaDataFileIntargetRepo, ArtifactMetadata artifactMetadata, Date lastUpdatedTimestamp, String timestamp) throws RepositoryMetadataException {
ArrayList<String> availableVersions = new ArrayList<>();
String latestVersion = artifactMetadata.getProjectVersion();
ArchivaRepositoryMetadata projectMetadata = getMetadata(projectMetaDataFileIntargetRepo);
if (Files.exists(projectMetaDataFileIntargetRepo)) {
availableVersions = (ArrayList<String>) projectMetadata.getAvailableVersions();
Collections.sort(availableVersions, VersionComparator.getInstance());
if (!availableVersions.contains(artifactMetadata.getVersion())) {
availableVersions.add(artifactMetadata.getVersion());
}
latestVersion = availableVersions.get(availableVersions.size() - 1);
} else {
availableVersions.add(artifactMetadata.getProjectVersion());
projectMetadata.setGroupId(artifactMetadata.getNamespace());
projectMetadata.setArtifactId(artifactMetadata.getProject());
}
if (projectMetadata.getGroupId() == null) {
projectMetadata.setGroupId(artifactMetadata.getNamespace());
}
if (projectMetadata.getArtifactId() == null) {
projectMetadata.setArtifactId(artifactMetadata.getProject());
}
projectMetadata.setLatestVersion(latestVersion);
projectMetadata.setAvailableVersions(availableVersions);
projectMetadata.setLastUpdated(timestamp);
projectMetadata.setLastUpdatedTimestamp(lastUpdatedTimestamp);
if (!VersionUtil.isSnapshot(artifactMetadata.getVersion())) {
projectMetadata.setReleasedVersion(latestVersion);
}
RepositoryMetadataWriter.write(projectMetadata, projectMetaDataFileIntargetRepo);
}
Aggregations