-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MENFORCER-447] RequireNoRepositories skip repositories defined in se…
…ttings.xml Maven 4 model contains repositories defined in settings.xml As workaround we exclude repositories defined in settings.xml Add assertions also for positive IT tests
- Loading branch information
1 parent
6a84681
commit df55a75
Showing
5 changed files
with
145 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
import org.apache.maven.model.Repository; | ||
import org.apache.maven.model.RepositoryPolicy; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; | ||
import org.apache.maven.settings.Settings; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
@@ -44,14 +44,14 @@ | |
* @author <a href="mailto:[email protected]">Brett Porter</a> | ||
* @author <a href="mailto:[email protected]">Karl Heinz Marbaise</a> | ||
*/ | ||
public class TestRequireNoRepositories { | ||
class TestRequireNoRepositories { | ||
|
||
private RequireNoRepositories rule; | ||
|
||
private MavenSession session; | ||
|
||
@BeforeEach | ||
public void before() throws ExpressionEvaluationException { | ||
void before() { | ||
session = mock(MavenSession.class); | ||
|
||
rule = new RequireNoRepositories(session); | ||
|
@@ -90,6 +90,7 @@ private void setupSortedProjects(List<MavenProject> projectList) { | |
ProjectDependencyGraph pdg = mock(ProjectDependencyGraph.class); | ||
when(session.getProjectDependencyGraph()).thenReturn(pdg); | ||
when(pdg.getSortedProjects()).thenReturn(projectList); | ||
when(session.getSettings()).thenReturn(mock(Settings.class)); | ||
} | ||
|
||
private Repository createRepository(String id, String url) { | ||
|
@@ -160,7 +161,7 @@ private MavenProject addEmptyPluginRepository(MavenProject project) { | |
* This model contains a single module maven project without any repository. | ||
*/ | ||
@Test | ||
public void testAllBannedNoRepositories() throws EnforcerRuleException { | ||
void testAllBannedNoRepositories() throws EnforcerRuleException { | ||
MavenProject baseProject = createStandAloneProject(); | ||
setupSortedProjects(Collections.singletonList(baseProject)); | ||
|
||
|
@@ -171,7 +172,7 @@ public void testAllBannedNoRepositories() throws EnforcerRuleException { | |
* The model contains a single repository which is is not allowed by the default rules. | ||
*/ | ||
@Test | ||
public void testAllBannedWithRepository() { | ||
void testAllBannedWithRepository() { | ||
assertThrows(EnforcerRuleException.class, () -> { | ||
MavenProject baseProject = createStandAloneProject(); | ||
addRepository(baseProject, createRepository("repo", "http://example.com/repo")); | ||
|
@@ -185,7 +186,7 @@ public void testAllBannedWithRepository() { | |
* The model contains a single plugin repository which is is not allowed by the default rules. | ||
*/ | ||
@Test | ||
public void testAllBannedWithPluginRepository() { | ||
void testAllBannedWithPluginRepository() { | ||
assertThrows(EnforcerRuleException.class, () -> { | ||
MavenProject baseProject = createStandAloneProject(); | ||
addPluginRepository(baseProject, createRepository("repo", "http://example.com/repo")); | ||
|
@@ -199,7 +200,7 @@ public void testAllBannedWithPluginRepository() { | |
* The model contains a single repository which is allowed by setting allowedRepositories to the id. | ||
*/ | ||
@Test | ||
public void testAllBannedWithAllowedRepositories() throws EnforcerRuleException { | ||
void testAllBannedWithAllowedRepositories() throws EnforcerRuleException { | ||
final String repositoryId = "repo"; | ||
rule.setAllowedRepositories(Collections.singletonList(repositoryId)); | ||
|
||
|
@@ -214,7 +215,7 @@ public void testAllBannedWithAllowedRepositories() throws EnforcerRuleException | |
* The model contains a single repository. Turned off ban repositories. | ||
*/ | ||
@Test | ||
public void testRepositoriesNotBannedWithSingleRepository() throws EnforcerRuleException { | ||
void testRepositoriesNotBannedWithSingleRepository() throws EnforcerRuleException { | ||
final String repositoryId = "repo"; | ||
|
||
rule.setBanRepositories(false); | ||
|
@@ -230,7 +231,7 @@ public void testRepositoriesNotBannedWithSingleRepository() throws EnforcerRuleE | |
* The model contains no repository at all. Turned off ban repositories. | ||
*/ | ||
@Test | ||
public void testRepositoriesNotBannedWithOutAnyRepository() throws EnforcerRuleException { | ||
void testRepositoriesNotBannedWithOutAnyRepository() throws EnforcerRuleException { | ||
rule.setBanRepositories(false); | ||
|
||
MavenProject baseProject = createStandAloneProject(); | ||
|
@@ -244,7 +245,7 @@ public void testRepositoriesNotBannedWithOutAnyRepository() throws EnforcerRuleE | |
* plugin repositories. | ||
*/ | ||
@Test | ||
public void testAllBannedWithAllowedPluginRepositories() throws EnforcerRuleException { | ||
void testAllBannedWithAllowedPluginRepositories() throws EnforcerRuleException { | ||
final String repositoryId = "repo"; | ||
rule.setAllowedPluginRepositories(Collections.singletonList(repositoryId)); | ||
|
||
|
@@ -259,7 +260,7 @@ public void testAllBannedWithAllowedPluginRepositories() throws EnforcerRuleExce | |
* The model contains a single plugin repository. Turned off ban plugin repositories. | ||
*/ | ||
@Test | ||
public void testPluginRepositoriesNotBannedWithSinglePluginRepository() throws EnforcerRuleException { | ||
void testPluginRepositoriesNotBannedWithSinglePluginRepository() throws EnforcerRuleException { | ||
final String repositoryId = "repo"; | ||
|
||
rule.setBanPluginRepositories(false); | ||
|
@@ -275,7 +276,7 @@ public void testPluginRepositoriesNotBannedWithSinglePluginRepository() throws E | |
* The model contains no repository at all. Turned off ban plugin repositories. | ||
*/ | ||
@Test | ||
public void testPluginRepositoriesNotBannedWithOutAnyRepository() throws EnforcerRuleException { | ||
void testPluginRepositoriesNotBannedWithOutAnyRepository() throws EnforcerRuleException { | ||
rule.setBanPluginRepositories(false); | ||
|
||
MavenProject baseProject = createStandAloneProject(); | ||
|
@@ -285,7 +286,7 @@ public void testPluginRepositoriesNotBannedWithOutAnyRepository() throws Enforce | |
} | ||
|
||
@Test | ||
public void testAllBannedWithSnapshotRepository() { | ||
void testAllBannedWithSnapshotRepository() { | ||
assertThrows(EnforcerRuleException.class, () -> { | ||
MavenProject baseProject = createStandAloneProject(); | ||
addRepository(baseProject, createSnapshotRepository("repo", "http://example.com/repo")); | ||
|
@@ -296,7 +297,7 @@ public void testAllBannedWithSnapshotRepository() { | |
} | ||
|
||
@Test | ||
public void testAllBannedWithSnapshotRepositoryAllowedRepositories() throws EnforcerRuleException { | ||
void testAllBannedWithSnapshotRepositoryAllowedRepositories() throws EnforcerRuleException { | ||
final String repositoryId = "repo"; | ||
rule.setAllowedRepositories(Collections.singletonList(repositoryId)); | ||
|
||
|
@@ -308,7 +309,7 @@ public void testAllBannedWithSnapshotRepositoryAllowedRepositories() throws Enfo | |
} | ||
|
||
@Test | ||
public void testAllBannedWithSnapshotRepositoryAndSetAllowSnapshotRepositories() throws EnforcerRuleException { | ||
void testAllBannedWithSnapshotRepositoryAndSetAllowSnapshotRepositories() throws EnforcerRuleException { | ||
final String repositoryId = "repo"; | ||
rule.setAllowSnapshotRepositories(true); | ||
|
||
|
@@ -320,8 +321,7 @@ public void testAllBannedWithSnapshotRepositoryAndSetAllowSnapshotRepositories() | |
} | ||
|
||
@Test | ||
public void testAllBannedWithSnapshotPluginRepositoryAndSetAllowSnapshotPluginRepositories() | ||
throws EnforcerRuleException { | ||
void testAllBannedWithSnapshotPluginRepositoryAndSetAllowSnapshotPluginRepositories() throws EnforcerRuleException { | ||
final String repositoryId = "repo"; | ||
rule.setAllowSnapshotPluginRepositories(true); | ||
|
||
|
@@ -333,7 +333,7 @@ public void testAllBannedWithSnapshotPluginRepositoryAndSetAllowSnapshotPluginRe | |
} | ||
|
||
@Test | ||
public void testAllBannedWithEmptyRepository() throws EnforcerRuleException { | ||
void testAllBannedWithEmptyRepository() throws EnforcerRuleException { | ||
MavenProject baseProject = createStandAloneProject(); | ||
addEmptyRepository(baseProject); | ||
setupSortedProjects(Collections.singletonList(baseProject)); | ||
|
@@ -342,7 +342,7 @@ public void testAllBannedWithEmptyRepository() throws EnforcerRuleException { | |
} | ||
|
||
@Test | ||
public void testAllBannedWithEmptyPluginRepository() throws EnforcerRuleException { | ||
void testAllBannedWithEmptyPluginRepository() throws EnforcerRuleException { | ||
MavenProject baseProject = createStandAloneProject(); | ||
addEmptyPluginRepository(baseProject); | ||
setupSortedProjects(Collections.singletonList(baseProject)); | ||
|
20 changes: 20 additions & 0 deletions
20
maven-enforcer-plugin/src/it/projects/require-no-repositories/verify.groovy
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,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.text.contains( '[INFO] Rule 0: org.apache.maven.enforcer.rules.RequireNoRepositories executed' ) |
20 changes: 20 additions & 0 deletions
20
maven-enforcer-plugin/src/it/projects/require-no-repositories_mm/verify.groovy
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,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.text.contains( '[INFO] Rule 0: org.apache.maven.enforcer.rules.RequireNoRepositories executed' ) |
20 changes: 20 additions & 0 deletions
20
maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/verify.groovy
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,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.text.contains( '[INFO] Rule 0: org.apache.maven.enforcer.rules.RequireNoRepositories executed' ) |