-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
With some improvements. It accepts user property with CSV entries for relocations. To toy with it, use `-Dmaven.relocations.entries` user property, for example create `.mvn/maven.config` file with contents: ``` -Dmaven.relocations.entries=entry1,entry2,... ``` It accepts CSV (comma delimited) of entries, while entry form is as: ``` GAV>GAV ``` Where left GAV can contain `*` for any elem (so `*:*:*` would mean ALL, something you don't want). Right GAV is either fully specified, or also can contain `*`, then it behaves as "ordinary relocation": the coordinate is preserved from relocated artifact. Finally, if right hand GAV is absent (line looks like "GAV>"). the left hand matching GAV is banned fully (from resolving). Note: the ">" means project level, while ">>" means global (whole session level, so even plugins will get relocated artifacts) relocation. Examples: ``` -Dmaven.relocations.entries=org.foo:*:*>,org.here:*:*>org.there:*:*,javax.inject:javax.inject:1>>jakarta.inject:jakarta.inject:1.0.5 ``` Meaning: 3 entries, ban `org.foo` group (exactly, so `org.foo.bar` is allowed), relocate `org.here` to `org.there` and finally **globally relocate** (see ">>") `javax.inject:javax.inject:1` to `jakarta.inject:jakarta.inject:1.0.5` --- https://issues.apache.org/jira/browse/MNG-7959
- Loading branch information
Showing
6 changed files
with
393 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...der/src/main/java/org/apache/maven/repository/internal/MavenArtifactRelocationSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.maven.repository.internal; | ||
|
||
import org.apache.maven.model.Model; | ||
import org.eclipse.aether.RepositorySystemSession; | ||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.resolution.ArtifactDescriptorRequest; | ||
|
||
/** | ||
* Maven relocation source. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
public interface MavenArtifactRelocationSource { | ||
/** | ||
* Returns {@link Artifact} instance where to relocate to, or {@code null}. | ||
* | ||
* @param session The session, never {@code null}. | ||
* @param request The artifact descriptor request, never {@code null}. | ||
* @param model The artifact model, never {@code null}. | ||
* @return The {@link Artifact} to relocate to, or {@code null} if no relocation wanted. | ||
*/ | ||
Artifact relocatedTarget(RepositorySystemSession session, ArtifactDescriptorRequest request, Model model); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
.../maven/repository/internal/relocation/DistributionManagementArtifactRelocationSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.maven.repository.internal.relocation; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.apache.maven.model.DistributionManagement; | ||
import org.apache.maven.model.Model; | ||
import org.apache.maven.model.Relocation; | ||
import org.apache.maven.repository.internal.MavenArtifactRelocationSource; | ||
import org.apache.maven.repository.internal.RelocatedArtifact; | ||
import org.eclipse.aether.RepositorySystemSession; | ||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.resolution.ArtifactDescriptorRequest; | ||
import org.eclipse.sisu.Priority; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Relocation source from standard distribution management. This is the "one and only" relocation implementation that | ||
* existed in Maven 3 land, uses POM distributionManagement/relocation. | ||
* <p> | ||
* Note: this component should kick-in last regarding relocations. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
@Singleton | ||
@Named | ||
@Priority(5) | ||
@SuppressWarnings("checkstyle:MagicNumber") | ||
public final class DistributionManagementArtifactRelocationSource implements MavenArtifactRelocationSource { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(DistributionManagementArtifactRelocationSource.class); | ||
|
||
@Override | ||
public Artifact relocatedTarget(RepositorySystemSession session, ArtifactDescriptorRequest request, Model model) { | ||
DistributionManagement distMgmt = model.getDistributionManagement(); | ||
if (distMgmt != null) { | ||
Relocation relocation = distMgmt.getRelocation(); | ||
if (relocation != null) { | ||
Artifact result = new RelocatedArtifact( | ||
request.getArtifact(), | ||
relocation.getGroupId(), | ||
relocation.getArtifactId(), | ||
null, | ||
null, | ||
relocation.getVersion(), | ||
relocation.getMessage()); | ||
LOGGER.debug( | ||
"The artifact {} has been relocated to {}: {}", | ||
request.getArtifact(), | ||
result, | ||
relocation.getMessage()); | ||
return result; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.