in src/main/java/org/apache/sling/feature/maven/ProjectHelper.java [345:410]
public static Artifact getOrResolveArtifact(
final MavenProject project,
final MavenSession session,
final ArtifactHandlerManager artifactHandlerManager,
final RepositorySystem repoSystem,
final ArtifactId id) {
@SuppressWarnings("unchecked")
Map<String, Artifact> cache = (Map<String, Artifact>) project.getContextValue(ARTIFACT_CACHE);
if (cache == null) {
cache = new ConcurrentHashMap<>();
project.setContextValue(ARTIFACT_CACHE, cache);
}
Artifact result = cache.get(id.toMvnId());
if (result == null) {
result = findArtifact(id, project.getAttachedArtifacts());
if (result == null) {
result = findArtifact(id, project.getDependencyArtifacts());
if (result == null) {
if (isLocalProjectArtifact(project, id)) {
for (final Map.Entry<String, Feature> entry :
getFeatures(project).entrySet()) {
if (entry.getValue().getId().equals(id)) {
final Artifact artifact = new DefaultArtifact(
id.getGroupId(),
id.getArtifactId(),
id.getVersion(),
Artifact.SCOPE_PROVIDED,
id.getType(),
id.getClassifier(),
null);
artifact.setFile(createTmpFeatureFile(project, entry.getValue()));
result = artifact;
break;
}
}
}
if (result == null) {
try {
org.eclipse.aether.artifact.Artifact prjArtifact =
new org.eclipse.aether.artifact.DefaultArtifact(
id.getGroupId(),
id.getArtifactId(),
id.getClassifier(),
null, // extension retrieved via artifactTye
id.getVersion(),
RepositoryUtils.newArtifactType(
id.getType(),
artifactHandlerManager.getArtifactHandler(id.getType())));
ArtifactRequest artifactRequest =
new ArtifactRequest(prjArtifact, project.getRemoteProjectRepositories(), null);
ArtifactResult artifactResult =
repoSystem.resolveArtifact(session.getRepositorySession(), artifactRequest);
result = RepositoryUtils.toArtifact(artifactResult.getArtifact());
} catch (final org.eclipse.aether.resolution.ArtifactResolutionException e) {
throw new RuntimeException("Unable to get artifact for " + id.toMvnId(), e);
}
}
}
}
cache.put(id.toMvnId(), result);
}
return result;
}