use of org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata in project maven-plugins by apache.
the class TestCopyDependenciesMojo2 method createExpandedVersionArtifact.
private Artifact createExpandedVersionArtifact(String baseVersion, String groupId, String artifactId, String scope, String type, String classifier) throws IOException {
Artifact expandedSnapshot = this.stubFactory.createArtifact(groupId, artifactId, VersionRange.createFromVersion(baseVersion), scope, type, classifier, false);
Snapshot snapshot = new Snapshot();
snapshot.setTimestamp("20130710.122148");
snapshot.setBuildNumber(1);
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata(expandedSnapshot, snapshot);
String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
expandedSnapshot.setResolvedVersion(StringUtils.replace(baseVersion, Artifact.SNAPSHOT_VERSION, newVersion));
expandedSnapshot.addMetadata(metadata);
return expandedSnapshot;
}
use of org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata in project maven-plugins by apache.
the class RepositoryUtils method getDependencyUrlFromRepository.
/**
* @param artifact not null
* @param repo not null
* @return the artifact url in the given repo for the given artifact. If it is a snapshot artifact, the version
* will be the timestamp and the build number from the metadata. Could return null if the repo is blacklisted.
*/
public String getDependencyUrlFromRepository(Artifact artifact, ArtifactRepository repo) {
if (repo.isBlacklisted()) {
return null;
}
Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact);
// Try to get the last artifact repo name depending the snapshot version
if ((artifact.isSnapshot() && repo.getSnapshots().isEnabled())) {
if (artifact.getBaseVersion().equals(artifact.getVersion())) {
// Try to resolve it if not already done
if (artifact.getMetadataList() == null || artifact.getMetadataList().isEmpty()) {
try {
resolve(artifact);
} catch (ArtifactResolutionException e) {
log.error("Artifact: " + artifact.getId() + " could not be resolved.");
} catch (ArtifactNotFoundException e) {
log.error("Artifact: " + artifact.getId() + " was not found.");
}
}
for (ArtifactMetadata m : artifact.getMetadataList()) {
if (m instanceof SnapshotArtifactRepositoryMetadata) {
SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata) m;
Metadata metadata = snapshotMetadata.getMetadata();
Versioning versioning = metadata.getVersioning();
if (versioning == null || versioning.getSnapshot() == null || versioning.getSnapshot().isLocalCopy() || versioning.getSnapshot().getTimestamp() == null) {
continue;
}
// create the version according SnapshotTransformation
String version = StringUtils.replace(copyArtifact.getVersion(), Artifact.SNAPSHOT_VERSION, versioning.getSnapshot().getTimestamp()) + "-" + versioning.getSnapshot().getBuildNumber();
copyArtifact.setVersion(version);
}
}
}
}
return repo.getUrl() + "/" + repo.pathOf(copyArtifact);
}
use of org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata in project che by eclipse.
the class CheArtifactResolver method resolveOrig.
private void resolveOrig(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
if (artifact == null) {
return;
}
if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
File systemFile = artifact.getFile();
if (systemFile == null) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
}
if (!systemFile.exists()) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
}
if (!systemFile.isFile()) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
}
artifact.setResolved(true);
return;
}
if (!artifact.isResolved()) {
ArtifactResult result;
try {
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
// Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
result = repoSystem.resolveArtifact(session, artifactRequest);
} catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e);
} else {
throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
}
}
artifact.selectVersion(result.getArtifact().getVersion());
artifact.setFile(result.getArtifact().getFile());
artifact.setResolved(true);
if (artifact.isSnapshot()) {
Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
if (matcher.matches()) {
Snapshot snapshot = new Snapshot();
snapshot.setTimestamp(matcher.group(2));
try {
snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
} catch (NumberFormatException e) {
logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
}
}
}
}
}
use of org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata in project intellij-community by JetBrains.
the class CustomMaven3ArtifactResolver method resolveOld.
private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
if (artifact == null) {
return;
}
if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
File systemFile = artifact.getFile();
if (systemFile == null) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
}
if (!systemFile.exists()) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
}
if (!systemFile.isFile()) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
}
artifact.setResolved(true);
return;
}
if (!artifact.isResolved()) {
ArtifactResult result;
try {
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
// Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
result = repoSystem.resolveArtifact(session, artifactRequest);
} catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e);
} else {
throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
}
}
artifact.selectVersion(result.getArtifact().getVersion());
artifact.setFile(result.getArtifact().getFile());
artifact.setResolved(true);
if (artifact.isSnapshot()) {
Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
if (matcher.matches()) {
Snapshot snapshot = new Snapshot();
snapshot.setTimestamp(matcher.group(2));
try {
snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
} catch (NumberFormatException e) {
logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
}
}
}
}
}
use of org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata in project intellij-community by JetBrains.
the class CustomMaven30ArtifactResolver method resolveOld.
private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
if (artifact == null) {
return;
}
if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
File systemFile = artifact.getFile();
if (systemFile == null) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
}
if (!systemFile.exists()) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
}
if (!systemFile.isFile()) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
}
artifact.setResolved(true);
return;
}
if (!artifact.isResolved()) {
ArtifactResult result;
try {
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
// Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
result = repoSystem.resolveArtifact(session, artifactRequest);
} catch (org.sonatype.aether.resolution.ArtifactResolutionException e) {
if (e.getCause() instanceof org.sonatype.aether.transfer.ArtifactNotFoundException) {
throw new ArtifactNotFoundException(e.getMessage(), artifact, remoteRepositories, e) {
};
} else {
throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
}
}
artifact.selectVersion(result.getArtifact().getVersion());
artifact.setFile(result.getArtifact().getFile());
artifact.setResolved(true);
if (artifact.isSnapshot()) {
Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
if (matcher.matches()) {
Snapshot snapshot = new Snapshot();
snapshot.setTimestamp(matcher.group(2));
try {
snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
} catch (NumberFormatException e) {
logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
}
}
}
}
}
Aggregations