Skip to content

Commit

Permalink
Resolves mojohaus#960: displayDependencyUpdates should display update…
Browse files Browse the repository at this point in the history
…s from lesser segments

Resolves mojohaus#299: allowAnyUpdates should be ignored with a warning message if any of: allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates is set to false
  • Loading branch information
andrzejj0 committed May 27, 2023
1 parent 950dd80 commit 523b37a
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ private void testAllowUpdatesFromLesserSegments(String availableVersion) throws
setVariableValueToObject(this, "processDependencies", true);
setVariableValueToObject(this, "dependencyIncludes", singletonList(WildcardMatcher.WILDCARD));
setVariableValueToObject(this, "dependencyExcludes", emptyList());
setVariableValueToObject(this, "allowMajorUpdates", false);
this.outputFile = tempFile.getPath().toFile();
setPluginContext(new HashMap<>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.junit.Test;

import static org.apache.commons.codec.CharEncoding.UTF_8;
import static org.apache.maven.plugin.testing.ArtifactStubFactory.setVariableValueToObject;
import static org.codehaus.mojo.versions.utils.MockUtils.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -49,45 +50,42 @@ public class DisplayParentUpdatesMojoTest {

private TestChangeRecorder changeRecorder;
private Path tempFile;
private DisplayParentUpdatesMojo mojo;
private static RepositorySystem repositorySystem;

private static org.eclipse.aether.RepositorySystem aetherRepositorySystem;

@BeforeClass
public static void setUpStatic() {
repositorySystem = mockRepositorySystem();
aetherRepositorySystem = mockAetherRepositorySystem(new HashMap<String, String[]>() {
{
put("parent-artifact", new String[] {"7", "9"});
}
});
}

@Before
public void setUp() throws IllegalAccessException, IOException {
tempFile = Files.createTempFile("display-parent-updates", "txt");
changeRecorder = new TestChangeRecorder();
mojo =
new DisplayParentUpdatesMojo(
repositorySystem, aetherRepositorySystem, null, changeRecorder.asTestMap()) {
{
setProject(createProject());
reactorProjects = Collections.emptyList();
session = mockMavenSession();
outputFile = tempFile.toFile();
outputEncoding = UTF_8;
setPluginContext(new HashMap<String, String>());
}
};
}

@After
public void tearDown() throws IOException {
Files.deleteIfExists(tempFile);
}

private MavenProject createProject() {
private DisplayParentUpdatesMojo createMojo(
MavenProject project, org.eclipse.aether.RepositorySystem aetherRepositorySystem) {
return new DisplayParentUpdatesMojo(
repositorySystem, aetherRepositorySystem, null, changeRecorder.asTestMap()) {
{
setProject(project);
reactorProjects = Collections.emptyList();
session = mockMavenSession();
outputFile = tempFile.toFile();
outputEncoding = UTF_8;
setPluginContext(new HashMap<String, String>());
}
};
}

private MavenProject createProject(String parentVersion) {
return new MavenProject() {
{
setModel(new Model() {
Expand All @@ -102,7 +100,7 @@ private MavenProject createProject() {
{
setGroupId("default-group");
setArtifactId("parent-artifact");
setVersion("9");
setVersion(parentVersion);
}
});
}
Expand All @@ -111,8 +109,42 @@ private MavenProject createProject() {

@Test
public void testSingleDigitVersions() throws Exception {
DisplayParentUpdatesMojo mojo =
createMojo(createProject("9"), mockAetherRepositorySystem(new HashMap<String, String[]>() {
{
put("parent-artifact", new String[] {"7", "7.1", "7.0.1", "7.0.0-1", "9"});
}
}));
mojo.execute();
String output = String.join("", Files.readAllLines(tempFile));
assertThat(output, not(containsString("7")));
}

public void testAllowUpdatesFromLesserSegments(String availableVersion) throws Exception {
DisplayParentUpdatesMojo mojo =
createMojo(createProject("7"), mockAetherRepositorySystem(new HashMap<String, String[]>() {
{
put("parent-artifact", new String[] {availableVersion});
}
}));
setVariableValueToObject(mojo, "allowMajorUpdates", false);
mojo.execute();
String output = String.join("", Files.readAllLines(tempFile));
assertThat(output, containsString(availableVersion));
}

@Test
public void testAllowUpdatesFromLesserSegmentsMinor() throws Exception {
testAllowUpdatesFromLesserSegments("7.1");
}

@Test
public void testAllowUpdatesFromLesserSegmentsIncremental() throws Exception {
testAllowUpdatesFromLesserSegments("7.0.1");
}

@Test
public void testAllowUpdatesFromLesserSegmentsSubIncremental() throws Exception {
testAllowUpdatesFromLesserSegments("7.0.0-1");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
import static org.apache.commons.codec.CharEncoding.UTF_8;
import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.*;

/**
* Unit tests for {@link DisplayPropertyUpdatesMojo}
Expand All @@ -46,10 +45,13 @@ public class DisplayPropertyUpdatesMojoTest extends AbstractMojoTestCase {

private Path tempDir;

private Path tempFile;

@Before
public void setUp() throws Exception {
super.setUp();
tempDir = TestUtils.createTempDir("display-property-updates");
tempFile = Files.createTempFile(tempDir, "output", "");
}

@After
Expand All @@ -63,8 +65,6 @@ public void tearDown() throws Exception {

@Test
public void testPropertiesFromParent() throws Exception {
Path tempFile = Files.createTempFile(tempDir, "output", "");

TestUtils.copyDir(
Paths.get("src/test/resources/org/codehaus/mojo/display-property-updates/issue-367"), tempDir);
DisplayPropertyUpdatesMojo mojo = (DisplayPropertyUpdatesMojo)
Expand All @@ -83,8 +83,6 @@ public void testPropertiesFromParent() throws Exception {

@Test
public void testDisablePropertiesFromParent() throws Exception {
Path tempFile = Files.createTempFile(tempDir, "output", "");

TestUtils.copyDir(
Paths.get("src/test/resources/org/codehaus/mojo/display-property-updates/issue-367"), tempDir);
DisplayPropertyUpdatesMojo mojo = (DisplayPropertyUpdatesMojo)
Expand All @@ -100,4 +98,39 @@ public void testDisablePropertiesFromParent() throws Exception {
String.join("", Files.readAllLines(tempFile)),
not(matchesPattern(".*\\$\\{ver} \\.* 1\\.0\\.0 -> 2\\.0\\.0.*")));
}

private void testAllowUpdatesFromLesserSegments(String availableVersion) throws Exception {
TestUtils.copyDir(
Paths.get("src/test/resources/org/codehaus/mojo/display-property-updates/issue-960"), tempDir);
DisplayPropertyUpdatesMojo mojo = (DisplayPropertyUpdatesMojo)
mojoRule.lookupConfiguredMojo(tempDir.toFile(), "display-property-updates");
mojo.outputEncoding = UTF_8;
mojo.outputFile = tempFile.toFile();
mojo.setPluginContext(new HashMap<>());
mojo.aetherRepositorySystem = mockAetherRepositorySystem(new HashMap<String, String[]>() {
{
put("artifactA", new String[] {availableVersion, "2"});
}
});
mojo.includeParent = false;
setVariableValueToObject(mojo, "allowMajorUpdates", false);
mojo.execute();

assertThat(String.join("", Files.readAllLines(tempFile)), containsString(availableVersion));
}

@Test
public void testAllowUpdatesFromLesserSegmentsMinor() throws Exception {
testAllowUpdatesFromLesserSegments("1.1");
}

@Test
public void testAllowUpdatesFromLesserSegmentsIncremental() throws Exception {
testAllowUpdatesFromLesserSegments("1.0.1");
}

@Test
public void testAllowUpdatesFromLesserSegmentsSubIncremental() throws Exception {
testAllowUpdatesFromLesserSegments("1.0.0-1");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>default-group</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>

<properties>
<ver>1.0.0</ver>
</properties>

<dependencies>
<dependency>
<groupId>default-group</groupId>
<artifactId>artifactA</artifactId>
<version>${ver}</version>
</dependency>
</dependencies>
</project>

0 comments on commit 523b37a

Please sign in to comment.