Lines 87-92
Link Here
|
87 |
import org.netbeans.modules.maven.api.output.OutputVisitor; |
87 |
import org.netbeans.modules.maven.api.output.OutputVisitor; |
88 |
import org.netbeans.modules.maven.junit.nodes.JUnitTestRunnerNodeFactory; |
88 |
import org.netbeans.modules.maven.junit.nodes.JUnitTestRunnerNodeFactory; |
89 |
import org.openide.filesystems.FileUtil; |
89 |
import org.openide.filesystems.FileUtil; |
|
|
90 |
import org.openide.util.Exceptions; |
90 |
import org.openide.util.Utilities; |
91 |
import org.openide.util.Utilities; |
91 |
|
92 |
|
92 |
/** |
93 |
/** |
Lines 95-113
Link Here
|
95 |
*/ |
96 |
*/ |
96 |
public class JUnitOutputListenerProvider implements OutputProcessor { |
97 |
public class JUnitOutputListenerProvider implements OutputProcessor { |
97 |
TestSession session; |
98 |
TestSession session; |
98 |
private Pattern runningPattern; |
99 |
private final Pattern runningPattern; |
99 |
private Pattern outDirPattern2; |
100 |
private final Pattern runningPattern2; |
100 |
private Pattern outDirPattern; |
101 |
private boolean useRunningPattern = true; |
|
|
102 |
private final Pattern outDirPattern2; |
103 |
private final Pattern outDirPattern; |
101 |
private File outputDir; |
104 |
private File outputDir; |
102 |
String runningTestClass; |
105 |
String runningTestClass; |
103 |
private final Set<String> usedNames; |
106 |
private final Set<String> usedNames; |
104 |
private final long startTimeStamp; |
107 |
private final long startTimeStamp; |
105 |
|
108 |
|
106 |
private static final Logger LOG = Logger.getLogger(JUnitOutputListenerProvider.class.getName()); |
109 |
private static final Logger LOG = Logger.getLogger(JUnitOutputListenerProvider.class.getName()); |
107 |
private RunConfig config; |
110 |
private final RunConfig config; |
108 |
|
111 |
|
109 |
public JUnitOutputListenerProvider(RunConfig config) { |
112 |
public JUnitOutputListenerProvider(RunConfig config) { |
110 |
runningPattern = Pattern.compile("(?:\\[surefire\\] )?Running (.*)", Pattern.DOTALL); //NOI18N |
113 |
runningPattern = Pattern.compile("(?:\\[surefire\\] )?Running (.*)", Pattern.DOTALL); //NOI18N |
|
|
114 |
runningPattern2 = Pattern.compile("Tests run: .+, Failures: .+, Errors: .+, Skipped: .+, Time elapsed: .+ - in (.*)"); |
111 |
outDirPattern = Pattern.compile("Surefire report directory\\: (.*)", Pattern.DOTALL); //NOI18N |
115 |
outDirPattern = Pattern.compile("Surefire report directory\\: (.*)", Pattern.DOTALL); //NOI18N |
112 |
outDirPattern2 = Pattern.compile("Setting reports dir\\: (.*)", Pattern.DOTALL); //NOI18N |
116 |
outDirPattern2 = Pattern.compile("Setting reports dir\\: (.*)", Pattern.DOTALL); //NOI18N |
113 |
this.config = config; |
117 |
this.config = config; |
Lines 143-159
Link Here
|
143 |
if (session == null) { |
147 |
if (session == null) { |
144 |
return; |
148 |
return; |
145 |
} |
149 |
} |
|
|
150 |
match = runningPattern2.matcher(line); |
151 |
if (match.matches()) { |
152 |
useRunningPattern = false; //we encountered a better way of tracking what is being run, use that. |
153 |
runningTestClass = null; |
154 |
System.out.println("match2=" + match.group(1)); |
155 |
if (outputDir != null) { |
156 |
System.out.println("generate test"); |
157 |
try { |
158 |
Thread.sleep(200); |
159 |
} catch (InterruptedException ex) { |
160 |
Exceptions.printStackTrace(ex); |
161 |
} |
162 |
generateTest(match.group(1), outputDir); |
163 |
} |
164 |
} |
165 |
if (useRunningPattern) { |
146 |
match = runningPattern.matcher(line); |
166 |
match = runningPattern.matcher(line); |
147 |
if (match.matches()) { |
167 |
if (match.matches()) { |
148 |
if (runningTestClass != null && outputDir != null) { |
168 |
if (runningTestClass != null && outputDir != null) { |
149 |
generateTest(); |
169 |
generateTest(runningTestClass, outputDir); |
150 |
} |
170 |
} |
151 |
runningTestClass = match.group(1); |
171 |
runningTestClass = match.group(1); |
152 |
} |
172 |
} |
153 |
} |
173 |
} |
|
|
174 |
} |
154 |
|
175 |
|
155 |
public @Override void sequenceStart(String sequenceId, OutputVisitor visitor) { |
176 |
public @Override void sequenceStart(String sequenceId, OutputVisitor visitor) { |
156 |
session = null; |
177 |
session = null; |
|
|
178 |
useRunningPattern = !usingSurefire215(config.getMavenProject()); |
157 |
} |
179 |
} |
158 |
|
180 |
|
159 |
//#179703 allow multiple sessions per project, in case there are multiple executions of surefire plugin. |
181 |
//#179703 allow multiple sessions per project, in case there are multiple executions of surefire plugin. |
Lines 285-290
Link Here
|
285 |
String v = PluginPropertyUtils.getPluginVersion(prj, Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_SUREFIRE); |
307 |
String v = PluginPropertyUtils.getPluginVersion(prj, Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_SUREFIRE); |
286 |
return v != null && new ComparableVersion(v).compareTo(new ComparableVersion("2.8")) >= 0; |
308 |
return v != null && new ComparableVersion(v).compareTo(new ComparableVersion("2.8")) >= 0; |
287 |
} |
309 |
} |
|
|
310 |
private boolean usingSurefire215(MavenProject prj) { |
311 |
String v = PluginPropertyUtils.getPluginVersion(prj, Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_SUREFIRE); |
312 |
return v != null && new ComparableVersion(v).compareTo(new ComparableVersion("2.15")) >= 0; |
313 |
} |
288 |
|
314 |
|
289 |
private boolean usingTestNG(MavenProject prj) { |
315 |
private boolean usingTestNG(MavenProject prj) { |
290 |
for (Artifact a : prj.getArtifacts()) { |
316 |
for (Artifact a : prj.getArtifacts()) { |
Lines 311-318
Link Here
|
311 |
if (session == null) { |
337 |
if (session == null) { |
312 |
return; |
338 |
return; |
313 |
} |
339 |
} |
314 |
if (runningTestClass != null && outputDir != null) { |
340 |
if (this.useRunningPattern && runningTestClass != null && outputDir != null) { |
315 |
generateTest(); |
341 |
generateTest(runningTestClass, outputDir); |
316 |
} |
342 |
} |
317 |
Manager.getInstance().sessionFinished(session); |
343 |
Manager.getInstance().sessionFinished(session); |
318 |
runningTestClass = null; |
344 |
runningTestClass = null; |
Lines 356-362
Link Here
|
356 |
} |
382 |
} |
357 |
|
383 |
|
358 |
|
384 |
|
359 |
private void generateTest() { |
385 |
private void generateTest(String runningTestClass, File outputDir) { |
360 |
String reportNameSuffix = PluginPropertyUtils.getPluginProperty(config.getMavenProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_SUREFIRE, "reportNameSuffix", "test", "surefire.reportNameSuffix"); |
386 |
String reportNameSuffix = PluginPropertyUtils.getPluginProperty(config.getMavenProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_SUREFIRE, "reportNameSuffix", "test", "surefire.reportNameSuffix"); |
361 |
String suffix = reportNameSuffix; |
387 |
String suffix = reportNameSuffix; |
362 |
if (suffix == null) { |
388 |
if (suffix == null) { |