Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/MNG-7338-au…
Browse files Browse the repository at this point in the history
…tomatic-non-interactive-mode-in-ci
  • Loading branch information
gnodet committed Jun 1, 2023
2 parents 1549a2a + b2953c5 commit 197df78
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import javax.inject.Singleton;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -58,6 +60,7 @@ private enum ValidationReportLevel {
NONE, // mute validation completely (validation issue collection still happens, it is just not reported!)
INLINE, // inline, each "internal" problem one line next to mojo invocation
SUMMARY, // at end, list of plugin GAVs along with "internal" issues
BRIEF, // synonym to SUMMARY
VERBOSE // at end, list of plugin GAVs along with detailed report of ANY validation issues
}

Expand Down Expand Up @@ -160,12 +163,11 @@ private void reportSessionCollectedValidationIssues(MavenSession mavenSession) {
return; // we were asked to not report anything OR reporting already happened inline
}
ConcurrentHashMap<String, PluginValidationIssues> issuesMap = pluginIssues(mavenSession.getRepositorySession());
if (!issuesMap.isEmpty()) {

EnumSet<IssueLocality> issueLocalitiesToReport = validationReportLevel == ValidationReportLevel.VERBOSE
? EnumSet.allOf(IssueLocality.class)
: EnumSet.of(IssueLocality.INTERNAL);
EnumSet<IssueLocality> issueLocalitiesToReport = validationReportLevel == ValidationReportLevel.VERBOSE
? EnumSet.allOf(IssueLocality.class)
: EnumSet.of(IssueLocality.INTERNAL);

if (hasAnythingToReport(issuesMap, issueLocalitiesToReport)) {
logger.warn("");
logger.warn("Plugin {} validation issues were detected in following plugin(s)", issueLocalitiesToReport);
logger.warn("");
Expand Down Expand Up @@ -226,6 +228,16 @@ private void reportSessionCollectedValidationIssues(MavenSession mavenSession) {
}
}

private boolean hasAnythingToReport(
Map<String, PluginValidationIssues> issuesMap, EnumSet<IssueLocality> issueLocalitiesToReport) {
for (PluginValidationIssues issues : issuesMap.values()) {
if (hasAnythingToReport(issues, issueLocalitiesToReport)) {
return true;
}
}
return false;
}

private boolean hasAnythingToReport(PluginValidationIssues issues, EnumSet<IssueLocality> issueLocalitiesToReport) {
for (IssueLocality issueLocality : issueLocalitiesToReport) {
Set<String> pluginIssues = issues.pluginIssues.get(issueLocality);
Expand All @@ -251,16 +263,12 @@ private String pluginDeclaration(MavenSession mavenSession, MojoDescriptor mojoD
if (location.contains("://")) {
stringBuilder.append(" (").append(location).append(")");
} else {
File rootBasedir = mavenSession.getTopLevelProject().getBasedir();
File locationFile = new File(location);
if (location.startsWith(rootBasedir.getPath())) {
stringBuilder
.append(" (")
.append(rootBasedir.toPath().relativize(locationFile.toPath()))
.append(")");
} else {
stringBuilder.append(" (").append(location).append(")");
Path topDirectory = mavenSession.getTopDirectory();
Path locationPath = Paths.get(location).toAbsolutePath().normalize();
if (locationPath.startsWith(topDirectory)) {
locationPath = topDirectory.relativize(locationPath);
}
stringBuilder.append(" (").append(locationPath).append(")");
}
}
stringBuilder.append(" @ line ").append(inputLocation.getLineNumber());
Expand All @@ -275,8 +283,12 @@ private String pluginOccurrence(MavenSession mavenSession) {
String result = prj.getGroupId() + ":" + prj.getArtifactId() + ":" + prj.getVersion();
File currentPom = prj.getFile();
if (currentPom != null) {
File rootBasedir = mavenSession.getTopLevelProject().getBasedir();
result += " (" + rootBasedir.toPath().relativize(currentPom.toPath()) + ")";
Path topDirectory = mavenSession.getTopDirectory();
Path current = currentPom.toPath().toAbsolutePath().normalize();
if (current.startsWith(topDirectory)) {
current = topDirectory.relativize(current);
}
result += " (" + current + ")";
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.cli.event;

import java.io.File;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -336,8 +337,12 @@ public void projectStarted(ExecutionEvent event) {
File currentPom = project.getFile();
if (currentPom != null) {
MavenSession session = event.getSession();
File rootBasedir = session.getTopLevelProject().getBasedir();
logger.info(" from " + rootBasedir.toPath().relativize(currentPom.toPath()));
Path topDirectory = session.getTopDirectory();
Path current = currentPom.toPath().toAbsolutePath().normalize();
if (current.startsWith(topDirectory)) {
current = topDirectory.relativize(current);
}
logger.info(" from " + current);
}

// ----------[ packaging ]----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void testProjectStarted() {
when(rootProject.getBasedir()).thenReturn(basedir);
MavenSession session = mock(MavenSession.class);
when(session.getTopLevelProject()).thenReturn(rootProject);
when(session.getTopDirectory()).thenReturn(basedir.toPath());
when(event.getSession()).thenReturn(session);

// execute
Expand Down Expand Up @@ -112,6 +113,7 @@ void testProjectStartedOverflow() {
MavenSession session = mock(MavenSession.class);
when(session.getTopLevelProject()).thenReturn(project);
when(event.getSession()).thenReturn(session);
when(session.getTopDirectory()).thenReturn(basedir.toPath());

// execute
executionEventLogger.projectStarted(event);
Expand Down

0 comments on commit 197df78

Please sign in to comment.