Skip to content

Commit

Permalink
Respect mirror exclude statements.
Browse files Browse the repository at this point in the history
A Maven mirror can be configured with excludes, that are in the form of \!repo-name. In those cases it's wrong to replace the repository with the global mirror. Excluded repositories should be kept in the project repositories.
  • Loading branch information
Tõnis Pool authored and mark-vieira committed Jan 25, 2016
1 parent 2be4e81 commit 9c9d6c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ public class MavenSettingsPlugin implements Plugin<Project> {

private void createMirrorRepository(Project project, Mirror mirror, Closure predicate) {
boolean mirrorFound = false
List<String> excludedRepositoryNames = mirror.mirrorOf.split(',').findAll { it.startsWith("!") }.collect { it.substring(1) }
project.repositories.all { repo ->
if (repo instanceof MavenArtifactRepository && repo.name != ArtifactRepositoryContainer.DEFAULT_MAVEN_LOCAL_REPO_NAME
&& !repo.url.equals(URI.create(mirror.url)) && predicate(repo)) {
&& !repo.url.equals(URI.create(mirror.url)) && predicate(repo) && !excludedRepositoryNames.contains(repo.getName())) {
project.repositories.remove(repo)
mirrorFound = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ class MavenSettingsPluginTest extends AbstractMavenSettingsTest {
assertThat(project.repositories, hasItem(hasProperty('name', equalTo('MavenLocal'))))
}

@Test
void respectsMirrorExcludes() {
withSettings {
mirrors.add new Mirror(id: 'myrepo', mirrorOf: '*,!some-repo', url: 'http://maven.foo.bar')
}

addPluginWithSettings()

project.with {
repositories {
mavenLocal()
mavenCentral()
maven {
name "some-repo"
url "https://example.com"
}
maven {
name "some-other-repo"
url "https://example.com"
}
}
}

project.evaluate()

assertThat(project.repositories, hasSize(3))
assertThat(project.repositories, hasItem(hasProperty('name', equalTo('myrepo'))))
assertThat(project.repositories, hasItem(hasProperty('name', equalTo('MavenLocal'))))
assertThat(project.repositories, hasItem(hasProperty('name', equalTo('some-repo'))))
}

@Test
void declareExternalMirrorWithFileRepo() {
withSettings {
Expand Down

0 comments on commit 9c9d6c8

Please sign in to comment.