This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 227541
Collapse All | Expand All

(-)maven.junit/src/org/netbeans/modules/maven/junit/JUnitOutputListenerProvider.java (-8 / +34 lines)
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) {
(-)maven/src/org/netbeans/modules/maven/output/TestOutputListenerProvider.java (-22 lines)
Lines 86-93 Link Here
86
        "mojo-execute#failsafe:integration-test" 
86
        "mojo-execute#failsafe:integration-test" 
87
    };
87
    };
88
    private final Pattern failSeparatePattern;
88
    private final Pattern failSeparatePattern;
89
    private final Pattern failWindowsPattern1;
90
    private final Pattern failWindowsPattern2;
91
    private final Pattern outDirPattern;
89
    private final Pattern outDirPattern;
92
    private final Pattern outDirPattern2;
90
    private final Pattern outDirPattern2;
93
    private final Pattern runningPattern;
91
    private final Pattern runningPattern;
Lines 97-109 Link Here
97
    
95
    
98
    String outputDir;
96
    String outputDir;
99
    String runningTestClass;
97
    String runningTestClass;
100
    private String delayedLine;
101
    
98
    
102
    /** Creates a new instance of TestOutputListenerProvider */
99
    /** Creates a new instance of TestOutputListenerProvider */
103
    public TestOutputListenerProvider() {
100
    public TestOutputListenerProvider() {
104
        failSeparatePattern = Pattern.compile("(?:\\[surefire\\] )?Tests run.*[<]* FAILURE[!]*[\\s]*", Pattern.DOTALL); //NOI18N
101
        failSeparatePattern = Pattern.compile("(?:\\[surefire\\] )?Tests run.*[<]* FAILURE[!]*[\\s]*", Pattern.DOTALL); //NOI18N
105
        failWindowsPattern1 = Pattern.compile("(?:\\[surefire\\] )?Tests run.*", Pattern.DOTALL); //NOI18N
106
        failWindowsPattern2 = Pattern.compile(".*[<]* FAILURE [!]*.*", Pattern.DOTALL); //NOI18N
107
        runningPattern = Pattern.compile("(?:\\[surefire\\] )?Running (.*)", Pattern.DOTALL); //NOI18N
102
        runningPattern = Pattern.compile("(?:\\[surefire\\] )?Running (.*)", Pattern.DOTALL); //NOI18N
108
        outDirPattern = Pattern.compile(".*(?:Surefire)?(?:Failsafe)? report directory\\: (.*)", Pattern.DOTALL); //NOI18N
103
        outDirPattern = Pattern.compile(".*(?:Surefire)?(?:Failsafe)? report directory\\: (.*)", Pattern.DOTALL); //NOI18N
109
        outDirPattern2 = Pattern.compile(".*Setting reports dir\\: (.*)", Pattern.DOTALL); //NOI18N
104
        outDirPattern2 = Pattern.compile(".*Setting reports dir\\: (.*)", Pattern.DOTALL); //NOI18N
Lines 115-130 Link Here
115
    
110
    
116
    @Override
111
    @Override
117
    public void processLine(String line, OutputVisitor visitor) {
112
    public void processLine(String line, OutputVisitor visitor) {
118
        if (delayedLine != null) {
119
            Matcher match = failWindowsPattern2.matcher(line);
120
            if (match.matches()) {
121
                visitor.setOutputListener(new TestOutputListener(runningTestClass, outputDir), true);
122
                visitor.setLine(delayedLine + line);
123
            } else {
124
                visitor.setLine(delayedLine + "\n" + line);
125
            }
126
            delayedLine = null;
127
        }
128
        Matcher match = outDirPattern.matcher(line);
113
        Matcher match = outDirPattern.matcher(line);
129
        if (match.matches()) {
114
        if (match.matches()) {
130
            outputDir = match.group(1);
115
            outputDir = match.group(1);
Lines 145-159 Link Here
145
            visitor.setOutputListener(new TestOutputListener(runningTestClass, outputDir), true);
130
            visitor.setOutputListener(new TestOutputListener(runningTestClass, outputDir), true);
146
            return;
131
            return;
147
        }
132
        }
148
        match = failWindowsPattern1.matcher(line);
149
        if (match.matches()) {
150
            //we should not get here but possibly can on windows..
151
            visitor.skipLine();
152
            delayedLine = line;
153
        }
133
        }
154
        
134
        
155
    }
156
    
157
    @Override
135
    @Override
158
    public String[] getRegisteredOutputSequences() {
136
    public String[] getRegisteredOutputSequences() {
159
        return TESTGOALS;
137
        return TESTGOALS;
(-)maven/test/unit/src/org/netbeans/modules/maven/output/TestOutputListenerProviderTest.java (-12 lines)
Lines 102-119 Link Here
102
        provider.processLine("Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.057 sec \r\r\t\n\r\n<<< FAILURE!        ", visitor);
102
        provider.processLine("Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.057 sec \r\r\t\n\r\n<<< FAILURE!        ", visitor);
103
        assertNotNull(visitor.getOutputListener());
103
        assertNotNull(visitor.getOutputListener());
104
        
104
        
105
        //behaviour on windows...
106
        visitor.resetVisitor();
107
        provider.processLine("[surefire] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.057 sec", visitor);
108
        assertNull(visitor.getOutputListener());
109
        assertTrue(visitor.isLineSkipped());
110
        visitor.resetVisitor();
111
        provider.processLine(" <<< FAILURE !!", visitor);
112
        assertNotNull(visitor.getOutputListener());
113
        assertEquals(visitor.getLine(), "[surefire] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.057 sec <<< FAILURE !!");
114
        assertFalse(visitor.isLineSkipped());
115
        visitor.resetVisitor();
116
        
117
        provider.sequenceFail("mojo-execute#surefire:test", visitor);
105
        provider.sequenceFail("mojo-execute#surefire:test", visitor);
118
        
106
        
119
    }
107
    }

Return to bug 227541