Skip to content

Commit

Permalink
[MNG-4645] Move Central repo definition out of Maven's core so it can…
Browse files Browse the repository at this point in the history
… be more easily changed
  • Loading branch information
ChristianSchulte authored and gnodet committed Jun 1, 2023
1 parent b2953c5 commit b2f9155
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 67 deletions.
35 changes: 32 additions & 3 deletions apache-maven/src/assembly/maven/conf/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,43 @@ under the License.
</properties>
</profile>
-->
<profile>
<id>maven:core:central-repo</id>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<!-- activeProfiles
| List of profiles that are active for all builds.
|
-->
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
<activeProfile>maven:core:central-repo</activeProfile>
<!--
activeProfile>anotherAlwaysActiveProfile</activeProfile>
-->
</activeProfiles>
-->
</settings>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -84,10 +83,6 @@ public MavenExecutionRequest populateDefaults(MavenExecutionRequest request)

populateDefaultPluginGroups(request);

injectDefaultRepositories(request);

injectDefaultPluginRepositories(request);

return request;
}

Expand All @@ -100,32 +95,6 @@ private void populateDefaultPluginGroups(MavenExecutionRequest request) {
request.addPluginGroup("org.codehaus.mojo");
}

private void injectDefaultRepositories(MavenExecutionRequest request)
throws MavenExecutionRequestPopulationException {
Set<String> definedRepositories = repositorySystem.getRepoIds(request.getRemoteRepositories());

if (!definedRepositories.contains(RepositorySystem.DEFAULT_REMOTE_REPO_ID)) {
try {
request.addRemoteRepository(repositorySystem.createDefaultRemoteRepository(request));
} catch (Exception e) {
throw new MavenExecutionRequestPopulationException("Cannot create default remote repository.", e);
}
}
}

private void injectDefaultPluginRepositories(MavenExecutionRequest request)
throws MavenExecutionRequestPopulationException {
Set<String> definedRepositories = repositorySystem.getRepoIds(request.getPluginArtifactRepositories());

if (!definedRepositories.contains(RepositorySystem.DEFAULT_REMOTE_REPO_ID)) {
try {
request.addPluginArtifactRepository(repositorySystem.createDefaultRemoteRepository(request));
} catch (Exception e) {
throw new MavenExecutionRequestPopulationException("Cannot create default remote repository.", e);
}
}
}

private void localRepository(MavenExecutionRequest request) throws MavenExecutionRequestPopulationException {
// ------------------------------------------------------------------------
// Local Repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

class DefaultMavenProjectBuilderTest extends AbstractMavenProjectTestCase {
Expand Down Expand Up @@ -133,10 +134,10 @@ void testBuildStubModelForMissingRemotePom() throws Exception {
assertNotNull(project.getArtifactId());

assertNotNull(project.getRemoteArtifactRepositories());
assertFalse(project.getRemoteArtifactRepositories().isEmpty());
assertTrue(project.getRemoteArtifactRepositories().isEmpty());

assertNotNull(project.getPluginArtifactRepositories());
assertFalse(project.getPluginArtifactRepositories().isEmpty());
assertTrue(project.getPluginArtifactRepositories().isEmpty());

assertNull(project.getParent());
assertNull(project.getParentArtifact());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void testExecutionConfigurationSubcollections() throws Exception {
@Test
void testMultipleRepositories() throws Exception {
PomTestWrapper pom = buildPom("multiple-repos/sub");
assertEquals(3, ((List<?>) pom.getValue("repositories")).size());
assertEquals(2, ((List<?>) pom.getValue("repositories")).size());
}

/** MNG-3965 */
Expand Down Expand Up @@ -1371,12 +1371,10 @@ private void testCompleteModel(PomTestWrapper pom) throws Exception {
assertEquals("org.apache.maven.its", pom.getValue("dependencies[1]/exclusions[1]/groupId"));
assertEquals("excluded-dep", pom.getValue("dependencies[1]/exclusions[1]/artifactId"));

assertEquals(2, ((List<?>) pom.getValue("repositories")).size());
assertEquals(1, ((List<?>) pom.getValue("repositories")).size());
assertEquals("project-remote-repo", pom.getValue("repositories[1]/id"));
assertEquals("https://project.url/remote", pom.getValue("repositories[1]/url"));
assertEquals("repo", pom.getValue("repositories[1]/name"));
assertEquals(RepositorySystem.DEFAULT_REMOTE_REPO_ID, pom.getValue("repositories[2]/id"));
assertEquals(RepositorySystem.DEFAULT_REMOTE_REPO_URL, pom.getValue("repositories[2]/url"));

assertEquals("test", pom.getValue("build/defaultGoal"));
assertEquals("coreit", pom.getValue("build/finalName"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,6 @@ under the License.
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<repositories>
<repository>
<id>central</id>
<name>Maven Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>

<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
Expand Down

0 comments on commit b2f9155

Please sign in to comment.