Skip to content

Commit

Permalink
Merge pull request apache#7728 from mbien/mvn-submodule-testwindow-fix
Browse files Browse the repository at this point in the history
Fix test window for multi-module maven projects
  • Loading branch information
mbien authored Sep 7, 2024
2 parents 0c51738 + 7ecdbc4 commit 4c81ffe
Showing 1 changed file with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public JUnitOutputListenerProvider(RunConfig config) {
outDirPattern = Pattern.compile ("(?:\\[INFO\\] )?Surefire report directory\\: (?<" + GROUP_FILE_NAME + ">.*)", Pattern.DOTALL); //NOI18N
outDirPattern2 = Pattern.compile("(?:\\[INFO\\] )?Setting reports dir\\: (?<" + GROUP_FILE_NAME + ">.*)", Pattern.DOTALL); //NOI18N
this.config = config;
usedNames = new HashSet<String>();
usedNames = new HashSet<>();
startTimeStamp = System.currentTimeMillis();
runningTestClasses = new ArrayList<String>();
runningTestClassesInParallel = new ArrayList<String>();
runningTestClasses = new ArrayList<>();
runningTestClassesInParallel = new ArrayList<>();
surefireRunningInParallel = isSurefireRunningInParallel();
}

Expand Down Expand Up @@ -262,7 +262,7 @@ static boolean isFullJavaId(String possibleNewRunningTestClass) {
// http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#reportsDirectory
reportsDirectory = getReportsDirectory(
Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_SUREFIRE,
"test", "${project.build.directory}/surefire-reports"); //NOI81N
"test", visitor, "${project.build.directory}/surefire-reports"); //NOI81N
}
reportNameSuffix = PluginPropertyUtils.getPluginProperty(
config.getMavenProject(), Constants.GROUP_APACHE_PLUGINS,
Expand All @@ -272,7 +272,7 @@ static boolean isFullJavaId(String possibleNewRunningTestClass) {
} else if ("mojo-execute#failsafe:integration-test".equals(sequenceId)) { //NOI81N
reportsDirectory = getReportsDirectory(
Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_FAILSAFE,
"integration-test", "${project.build.directory}/failsafe-reports"); //NOI81N
"integration-test", visitor, "${project.build.directory}/failsafe-reports"); //NOI81N
reportNameSuffix = PluginPropertyUtils.getPluginProperty(
config.getMavenProject(), Constants.GROUP_APACHE_PLUGINS,
Constants.PLUGIN_FAILSAFE, "reportNameSuffix", "integration-test", //NOI81N
Expand Down Expand Up @@ -313,14 +313,26 @@ static boolean isFullJavaId(String possibleNewRunningTestClass) {
}
}

private String getReportsDirectory(String groupId, String artifactId, String goal, String fallbackExpression) {
String reportsDirectory = PluginPropertyUtils.getPluginProperty(config.getMavenProject(),
private String getReportsDirectory(String groupId, String artifactId, String goal, OutputVisitor visitor, String fallbackExpression) {
MavenProject currentProject = null;
// get maven module from context if available
OutputVisitor.Context context = visitor.getContext();
if (context != null && context.getCurrentProject() != null) {
NbMavenProject subProject = context.getCurrentProject().getLookup().lookup(NbMavenProject.class);
if (subProject != null) {
currentProject = subProject.getMavenProject();
}
}
if (currentProject == null) {
currentProject = config.getMavenProject();
}
String reportsDirectory = PluginPropertyUtils.getPluginProperty(currentProject,
groupId, artifactId, "reportsDirectory", goal, null); // NOI18N
if (null == reportsDirectory) {
if (reportsDirectory == null) {
// fallback to default value
try {
Object defaultValue = PluginPropertyUtils
.createEvaluator(config.getMavenProject())
.createEvaluator(currentProject)
.evaluate(fallbackExpression);
if (defaultValue instanceof String) {
reportsDirectory = (String) defaultValue;
Expand Down Expand Up @@ -409,7 +421,7 @@ void rerun() {
void rerun(Set<Testcase> tests) {
RunConfig brc = RunUtils.cloneRunConfig(config);
StringBuilder tst = new StringBuilder();
Map<String, Collection<String>> methods = new HashMap<String, Collection<String>>();
Map<String, Collection<String>> methods = new HashMap<>();
//#222776 calculate the approximate space the failed tests will occupy on the cmd line.
//important on windows which places a limit on the length.
int windowslimitcount = 0;
Expand All @@ -418,7 +430,7 @@ void rerun(Set<Testcase> tests) {
if (tc.getClassName() != null) {
Collection<String> lst = methods.get(tc.getClassName());
if (lst == null) {
lst = new ArrayList<String>();
lst = new ArrayList<>();
methods.put(tc.getClassName(), lst);
windowslimitcount = windowslimitcount + tc.getClassName().length() + 1; // + 1 for ,
}
Expand Down Expand Up @@ -594,7 +606,7 @@ static Trouble constructTrouble(@NonNull String type, @NullAllowed String messag
}
if (text != null) {
String[] strs = StringUtils.split(text, "\n");
List<String> lines = new ArrayList<String>();
List<String> lines = new ArrayList<>();
if (message != null) {
lines.add(message);
}
Expand Down Expand Up @@ -753,16 +765,14 @@ private void generateTest() {
junitManager.displayOutput(session, FileUtils.fileRead(output), false);
}
}
} catch (IOException x) {
LOG.log(Level.WARNING, "parsing " + report, x);
} catch (ParseException x) {
} catch (IOException | ParseException x) {
LOG.log(Level.WARNING, "parsing " + report, x);
}
}

private void logText(String text, Testcase test, boolean failure) {
StringTokenizer tokens = new StringTokenizer(text, "\n"); //NOI18N
List<String> lines = new ArrayList<String>();
List<String> lines = new ArrayList<>();
while (tokens.hasMoreTokens()) {
lines.add(tokens.nextToken());
}
Expand Down

0 comments on commit 4c81ffe

Please sign in to comment.