Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ protected String determineRepoUrl(String envRepoUrl, Settings settings) {
// otherwise mirror from settings
if (settings.getMirrors() != null && !settings.getMirrors().isEmpty()) {
for (Mirror current : settings.getMirrors()) {
if ("*".equals(current.getMirrorOf())) {
getLog().debug("Using repo URL from * mirror in settings file.");
if ("*".equals(current.getMirrorOf()) || "central".equals(current.getMirrorOf())) {
getLog().debug("Using repo URL from " + current.getMirrorOf() + " mirror in settings file.");
return current.getUrl();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
package org.apache.maven.plugins.wrapper;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Settings;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -76,4 +81,50 @@ void slashRepoUrlNotUsed() {
// then
assertEquals(WrapperMojo.DEFAULT_REPOURL, determinedRepoUrl);
}

@Test
void centralMirrorIsUsed() {
// given
Settings settings = new Settings();
Mirror centralMirror = centralMirror();
List<Mirror> mirrors = Collections.singletonList(centralMirror);

settings.setMirrors(mirrors);
WrapperMojo wrapperMojo = new WrapperMojo();

// when
String determinedRepoUrl = wrapperMojo.determineRepoUrl("/", settings);

// then
assertEquals(centralMirror.getUrl(), determinedRepoUrl);
}

@Test
void testWildCardMirror() {
// given
Settings settings = new Settings();
Mirror wildcard = new Mirror();
wildcard.setId("wild-card-mirror");
wildcard.setMirrorOf("*");
wildcard.setUrl("https://my.custom-wildcard.repo/maven2/");
Mirror centralMirror = centralMirror();
List<Mirror> mirrors = Arrays.asList(wildcard, centralMirror);
settings.setMirrors(mirrors);
WrapperMojo wrapperMojo = new WrapperMojo();

// when
String determinedRepoUrl = wrapperMojo.determineRepoUrl("/", settings);

// then
assertEquals(wildcard.getUrl(), determinedRepoUrl);
}

private static Mirror centralMirror() {
Mirror centralMirror = new Mirror();
centralMirror.setId("central-mirror");
String centralMirrorURL = "https://my.custom.repo/maven2/";
centralMirror.setMirrorOf("central");
centralMirror.setUrl(centralMirrorURL);
return centralMirror;
}
}