Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move expression: {blah} no value System.out to logs #1119

Merged
Merged
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 @@ -471,6 +471,7 @@ public static boolean setProjectParentVersion(final ModifiedPomXMLEventReader po
* @param oldVersion The old version of the dependency.
* @param newVersion The new version of the dependency.
* @param model The model to getModel the project properties from.
* @param logger The logger to use.
* @return <code>true</code> if a replacement was made.
* @throws XMLStreamException if something went wrong.
*/
Expand All @@ -481,7 +482,8 @@ public static boolean setDependencyVersion(
final String artifactId,
final String oldVersion,
final String newVersion,
final Model model)
final Model model,
final Log logger)
throws XMLStreamException {
Stack<String> stack = new Stack<>();
String path = "";
Expand Down Expand Up @@ -564,11 +566,11 @@ public static boolean setDependencyVersion(
&& PATTERN_PROJECT_DEPENDENCY_VERSION.matcher(path).matches()) {
if ("groupId".equals(elementName)) {
haveGroupId =
groupId.equals(evaluate(pom.getElementText().trim(), implicitProperties));
groupId.equals(evaluate(pom.getElementText().trim(), implicitProperties, logger));
path = stack.pop();
} else if ("artifactId".equals(elementName)) {
haveArtifactId =
artifactId.equals(evaluate(pom.getElementText().trim(), implicitProperties));
artifactId.equals(evaluate(pom.getElementText().trim(), implicitProperties, logger));
path = stack.pop();
} else if ("version".equals(elementName)) {
pom.mark(0);
Expand Down Expand Up @@ -617,9 +619,10 @@ public static boolean setDependencyVersion(
*
* @param expr The expression to evaluate.
* @param properties The properties to substitute.
* @param logger The logger to use.
* @return The evaluated expression.
*/
public static String evaluate(String expr, Map<String, String> properties) {
public static String evaluate(String expr, Map<String, String> properties, Log logger) {
if (expr == null) {
return null;
}
Expand All @@ -634,15 +637,15 @@ public static String evaluate(String expr, Map<String, String> properties) {
if (exprStartDelimiter >= 0) {
if (exprStartDelimiter > 0) {
value = value.substring(0, exprStartDelimiter)
+ evaluate(value.substring(exprStartDelimiter), properties);
+ evaluate(value.substring(exprStartDelimiter), properties, logger);
} else {
value = evaluate(value.substring(exprStartDelimiter), properties);
value = evaluate(value.substring(exprStartDelimiter), properties, logger);
}
}
} else {
// TODO find a way to log that and not use this System.out!!
// this class could be a component with logger injected !!
System.out.println("expression: " + expression + " no value ");
// Because we work with the raw model, without interpolation, unevaluatable expressions are not
// unexpected
logger.debug("expression: " + expression + " no value ");
}
return value == null ? expr : value;
})
Expand All @@ -656,10 +659,10 @@ public static String evaluate(String expr, Map<String, String> properties) {
if (index > 0 && expr.charAt(index - 1) == '$') {
retVal += expr.substring(index + 1, lastIndex + 1);
} else {
retVal += evaluate(expr.substring(index, lastIndex + 1), properties);
retVal += evaluate(expr.substring(index, lastIndex + 1), properties, logger);
}

retVal += evaluate(expr.substring(lastIndex + 1), properties);
retVal += evaluate(expr.substring(lastIndex + 1), properties, logger);
return retVal;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class AbstractVersionChanger implements VersionChanger {

private final ModifiedPomXMLEventReader pom;

private final Log log;
protected final Log log;

public AbstractVersionChanger(Model model, ModifiedPomXMLEventReader pom, Log log) {
this.model = model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void apply(DependencyVersionChange versionChange) throws XMLStreamExcepti
versionChange.getArtifactId(),
versionChange.getOldVersion(),
versionChange.getNewVersion(),
getModel())) {
getModel(),
log)) {
info(" Updating dependency " + versionChange.getGroupId() + ":" + versionChange.getArtifactId());
info(" from version " + versionChange.getOldVersion() + " to " + versionChange.getNewVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ && getProject().getParent() != null
dep.getArtifactId(),
dep.getVersion(),
newVersion,
getProject().getModel())) {
getProject().getModel(),
getLog())) {
if (getLog().isInfoEnabled()) {
getLog().info("Updated " + toString(dep) + " to version " + newVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.orElse(Collections.emptyList())
.stream()
.map(e -> ExtensionBuilder.newBuilder()
.withGroupId(PomHelper.evaluate(e.getGroupId(), properties))
.withArtifactId(PomHelper.evaluate(e.getArtifactId(), properties))
.withVersion(PomHelper.evaluate(e.getVersion(), properties))
.withGroupId(PomHelper.evaluate(e.getGroupId(), properties, getLog()))
.withArtifactId(
PomHelper.evaluate(e.getArtifactId(), properties, getLog()))
.withVersion(PomHelper.evaluate(e.getVersion(), properties, getLog()))
.build()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ protected void lockSnapshots(ModifiedPomXMLEventReader pom, Collection<Dependenc
dep.getArtifactId(),
version,
lockedVersion.get(),
getProject().getModel())) {
getProject().getModel(),
getLog())) {
getLog().info("Locked " + toString(dep) + " to version " + lockedVersion.get());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ private void resolveRanges(ModifiedPomXMLEventReader pom, Collection<Dependency>
artifact.getArtifactId(),
dep.getVersion(),
artifactVersion,
getProject().getModel())) {
getProject().getModel(),
getLog())) {
getLog().debug("Version set to " + artifactVersion + " for dependency: " + artifact);
} else {
getLog().debug("Could not find the version tag for dependency " + artifact + " in project "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ private void unlockSnapshots(
dep.getArtifactId(),
dep.getVersion(),
unlockedVersion,
getProject().getModel())) {
getProject().getModel(),
getLog())) {

getChangeRecorder()
.recordChange(DefaultDependencyChangeRecord.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ private void useReactor(ModifiedPomXMLEventReader pom, Collection<Dependency> de
dep.getArtifactId(),
dep.getVersion(),
project.getVersion(),
getProject().getModel())) {
getProject().getModel(),
getLog())) {
getLog().info("Updated " + toString(dep) + " to version " + project.getVersion());
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void testReplaceSnapshotWithRelease()
try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class)))
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class), any()))
.thenReturn(true);
pomHelper
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
Expand All @@ -145,7 +145,7 @@ public void testUpgrade()
try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class)))
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class), any()))
.thenReturn(true);
pomHelper
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
Expand All @@ -172,7 +172,7 @@ public void testDowngrade()
try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class)))
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class), any()))
.thenReturn(true);
pomHelper
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
Expand Down Expand Up @@ -201,7 +201,7 @@ public void testFailIfNotReplaced()
try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class)))
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class), any()))
.thenReturn(true);
pomHelper
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testNoTimestampedDependencyFoundNull()
LockSnapshotsMojo mojo = createMojo(repositorySystem);
try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenThrow(new RuntimeException("Not supposed to modify the dependency"));
mojo.lockSnapshots(null, mojo.project.getDependencies());
}
Expand All @@ -103,7 +103,7 @@ public void testNoTimestampedDependencyFoundSameVersion()
LockSnapshotsMojo mojo = createMojo(repositorySystem);
try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenThrow(new RuntimeException("Not supposed to modify the dependency"));
mojo.lockSnapshots(null, mojo.project.getDependencies());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testDontUpgradeToBeta()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
pomHelper
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
Expand Down Expand Up @@ -135,7 +135,7 @@ public void testAllowDowngrade()
try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class)))
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class), any()))
.thenReturn(true);
pomHelper
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
Expand Down Expand Up @@ -167,7 +167,7 @@ public void testDisallowDowngrade()
try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class)))
any(), anyString(), anyString(), anyString(), anyString(), any(Model.class), any()))
.thenReturn(true);
pomHelper
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testDependenciesDowngradeIncremental()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand Down Expand Up @@ -157,7 +157,7 @@ public void testDependenciesDowngradeMinor()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand All @@ -181,7 +181,7 @@ public void testDependenciesDowngradeMajor()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand All @@ -208,7 +208,7 @@ public void testDependencyManagementDowngrade()
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
.thenReturn(mojo.getProject().getModel());
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ public void testParentDowngrade()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand Down Expand Up @@ -283,7 +283,7 @@ public void testPoisonDependencyVersion()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand All @@ -304,7 +304,7 @@ public void testIgnoredVersions()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand All @@ -327,7 +327,7 @@ public void testIncludeFilter()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand All @@ -353,7 +353,7 @@ public void testExcludeFilter()

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any()))
.when(() -> PomHelper.setDependencyVersion(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(true);
mojo.update(null);
}
Expand Down
Loading