Skip to content

Commit

Permalink
Resolves #1137: using PomHelper.getGroupId if groupId of the current …
Browse files Browse the repository at this point in the history
…project root is empty (#1162)
  • Loading branch information
andrzejj0 authored Oct 22, 2024
1 parent 0102bd6 commit a49d2b5
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// so that the main project can be selected
Model rootModel = reactorModels.get(session.getCurrentProject().getFile());
if (groupId == null) {
groupId = rootModel.getGroupId();
groupId = PomHelper.getGroupId(rootModel);
}
if (artifactId == null) {
artifactId = rootModel.getArtifactId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.tuple.Triple;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.versions.utils.TestLog;
import org.codehaus.mojo.versions.utils.TestUtils;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -231,4 +234,18 @@ public void testIssue1042() throws Exception {
String.join("", Files.readAllLines(tempDir.resolve("child-webapp/pom.xml"))),
matchesRegex(".*\\Q<artifactId>child-webapp</artifactId>\\E\\s*" + "\\Q<version>1.0</version>\\E.*"));
}

@Test
public void testIssue1137() throws Exception {
TestUtils.copyDir(Paths.get("src/test/resources/org/codehaus/mojo/set/issue-1137"), tempDir);
TestLog testLog = new TestLog();
SetMojo mojo =
(SetMojo) mojoRule.lookupConfiguredMojo(tempDir.resolve("child").toFile(), "set");
setVariableValueToObject(mojo, "newVersion", "1.1");
setVariableValueToObject(mojo, "log", testLog);
mojo.execute();
assertThat(
testLog.getLoggedMessages().stream().map(Triple::getMiddle).collect(Collectors.joining("\n")),
not(containsString("Processing change of null:child")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>group</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>child</artifactId>
<version>1.0</version>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>child</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.codehaus.mojo.versions.utils;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.tuple.Triple;
import org.apache.maven.plugin.logging.Log;

public class TestLog implements Log {
private final List<Triple<LogLevel, CharSequence, Throwable>> loggedMessages = new ArrayList<>();

public List<Triple<LogLevel, CharSequence, Throwable>> getLoggedMessages() {
return loggedMessages;
}

@Override
public boolean isDebugEnabled() {
return false;
}

@Override
public void debug(CharSequence charSequence) {
debug(charSequence, null);
}

@Override
public void debug(CharSequence charSequence, Throwable throwable) {
loggedMessages.add(Triple.of(LogLevel.DEBUG, charSequence, throwable));
}

@Override
public void debug(Throwable throwable) {
debug(null, throwable);
}

@Override
public boolean isInfoEnabled() {
return false;
}

@Override
public void info(CharSequence charSequence) {
info(charSequence, null);
}

@Override
public void info(CharSequence charSequence, Throwable throwable) {
loggedMessages.add(Triple.of(LogLevel.INFO, charSequence, throwable));
}

@Override
public void info(Throwable throwable) {
info(null, throwable);
}

@Override
public boolean isWarnEnabled() {
return false;
}

@Override
public void warn(CharSequence charSequence) {
warn(charSequence, null);
}

@Override
public void warn(CharSequence charSequence, Throwable throwable) {
loggedMessages.add(Triple.of(LogLevel.WARN, charSequence, throwable));
}

@Override
public void warn(Throwable throwable) {
warn(null, throwable);
}

@Override
public boolean isErrorEnabled() {
return false;
}

@Override
public void error(CharSequence charSequence) {
error(charSequence, null);
}

@Override
public void error(CharSequence charSequence, Throwable throwable) {
loggedMessages.add(Triple.of(LogLevel.ERROR, charSequence, throwable));
}

@Override
public void error(Throwable throwable) {
error(null, throwable);
}

public enum LogLevel {
DEBUG,
INFO,
WARN,
ERROR
}
}

0 comments on commit a49d2b5

Please sign in to comment.