mirror of https://github.com/apache/maven.git
[MNG-7959] User controlled rewrite (#1351)
Extra handling if redirection happens within same GAV. --- https://issues.apache.org/jira/browse/MNG-7959
This commit is contained in:
parent
9596255cbf
commit
ad5e085ebe
|
@ -43,6 +43,17 @@ public class ArtifactDescriptorUtils {
|
|||
return pomArtifact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates POM artifact out of passed in artifact by dropping classifier (if exists) and rewriting extension to
|
||||
* "pom". Unconditionally, unlike {@link #toPomArtifact(Artifact)} that does this only for artifacts without
|
||||
* classifiers.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static Artifact toPomArtifactUnconditionally(Artifact artifact) {
|
||||
return new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
|
||||
}
|
||||
|
||||
public static RemoteRepository toRemoteRepository(Repository repository) {
|
||||
RemoteRepository.Builder builder =
|
||||
new RemoteRepository.Builder(repository.getId(), repository.getLayout(), repository.getUrl());
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.LinkedHashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.ArtifactModelSource;
|
||||
|
@ -129,9 +128,9 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
|
|||
throws ArtifactDescriptorException {
|
||||
RequestTrace trace = RequestTrace.newChild(request.getTrace(), request);
|
||||
|
||||
Set<String> visited = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> visited = new LinkedHashSet<>();
|
||||
for (Artifact a = request.getArtifact(); ; ) {
|
||||
Artifact pomArtifact = ArtifactDescriptorUtils.toPomArtifact(a);
|
||||
Artifact pomArtifact = ArtifactDescriptorUtils.toPomArtifactUnconditionally(a);
|
||||
try {
|
||||
VersionRequest versionRequest =
|
||||
new VersionRequest(a, request.getRepositories(), request.getRequestContext());
|
||||
|
@ -239,15 +238,26 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
|
|||
|
||||
Artifact relocatedArtifact = getRelocation(session, result, model);
|
||||
if (relocatedArtifact != null) {
|
||||
result.addRelocation(a);
|
||||
a = relocatedArtifact;
|
||||
result.setArtifact(a);
|
||||
if (withinSameGav(relocatedArtifact, a)) {
|
||||
result.setArtifact(relocatedArtifact);
|
||||
return model; // they share same model
|
||||
} else {
|
||||
result.addRelocation(a);
|
||||
a = relocatedArtifact;
|
||||
result.setArtifact(a);
|
||||
}
|
||||
} else {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean withinSameGav(Artifact a1, Artifact a2) {
|
||||
return Objects.equals(a1.getGroupId(), a2.getGroupId())
|
||||
&& Objects.equals(a1.getArtifactId(), a2.getArtifactId())
|
||||
&& Objects.equals(a1.getVersion(), a2.getVersion());
|
||||
}
|
||||
|
||||
private Properties toProperties(Map<String, String> dominant, Map<String, String> recessive) {
|
||||
Properties props = new Properties();
|
||||
if (recessive != null) {
|
||||
|
|
Loading…
Reference in New Issue