Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 124313 | Differences between
and this patch

Collapse All | Expand All

(-)apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/ModuleActions.java (-4 / +89 lines)
 Lines 202-208    Link Here 
202
        } else if (command.equals(COMMAND_TEST)) {
202
        } else if (command.equals(COMMAND_TEST)) {
203
            return project.supportedTestTypes().contains("unit");
203
            return project.supportedTestTypes().contains("unit");
204
        } else if (command.equals(COMMAND_TEST_SINGLE)) {
204
        } else if (command.equals(COMMAND_TEST_SINGLE)) {
205
            return findTestSourcesForSources(context) != null || findTestSources(context, true) != null;
205
            return findTestSourcesForSources(context) != null || findTestSources(context, true) != null || findTestSourcesForFiles(context) != null;
206
        } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
206
        } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
207
            TestSources testSources = findTestSourcesForSources(context);
207
            TestSources testSources = findTestSourcesForSources(context);
208
            if (testSources == null)
208
            if (testSources == null)
 Lines 247-255    Link Here 
247
    private static final String SUBSTNG = "NGTest.java"; // NOI18N
247
    private static final String SUBSTNG = "NGTest.java"; // NOI18N
248
    
248
    
249
    private FileObject[] findSources(Lookup context) {
249
    private FileObject[] findSources(Lookup context) {
250
        return findSources(context, false, true);
251
    }
252
    
253
    private FileObject[] findSources(Lookup context, boolean findInPackages, boolean strict) {
250
        FileObject srcDir = project.getSourceDirectory();
254
        FileObject srcDir = project.getSourceDirectory();
251
        if (srcDir != null) {
255
        if (srcDir != null) {
252
            FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, ".java", true); // NOI18N
256
            FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, findInPackages ? null : ".java", strict); // NOI18N
253
            //System.err.println("findSources: srcDir=" + srcDir + " files=" + (files != null ? java.util.Arrays.asList(files) : null) + " context=" + context);
257
            //System.err.println("findSources: srcDir=" + srcDir + " files=" + (files != null ? java.util.Arrays.asList(files) : null) + " context=" + context);
254
            return files;
258
            return files;
255
        } else {
259
        } else {
 Lines 295-300    Link Here 
295
        }
299
        }
296
        return null;
300
        return null;
297
    }
301
    }
302
    @CheckForNull private FileObject[] findTestSourcesFOs(@NonNull Lookup context, boolean allowFolders, boolean strict) {
303
        TYPE: for (String testType : project.supportedTestTypes()) {
304
            FileObject testSrcDir = project.getTestSourceDirectory(testType);
305
            if (testSrcDir != null) {
306
                FileObject[] files = ActionUtils.findSelectedFiles(context, testSrcDir, null, strict);
307
                if (files != null) {
308
                    for (FileObject file : files) {
309
                        if (!(file.hasExt("java") || allowFolders && file.isFolder())) {
310
                            break TYPE;
311
                        }
312
                    }
313
                    return files;
314
                }
315
            }
316
        }
317
        return null;
318
    }
298
    @CheckForNull private TestSources findTestMethodSources(@NonNull Lookup context) {
319
    @CheckForNull private TestSources findTestMethodSources(@NonNull Lookup context) {
299
        SingleMethod meth = context.lookup(SingleMethod.class);
320
        SingleMethod meth = context.lookup(SingleMethod.class);
300
        if (meth != null) {
321
        if (meth != null) {
 Lines 328-339    Link Here 
328
    
349
    
329
    /** Find tests corresponding to selected sources.
350
    /** Find tests corresponding to selected sources.
330
     */
351
     */
331
    private TestSources findTestSourcesForSources(Lookup context) {
352
    TestSources findTestSourcesForSources(Lookup context) {
332
        String testType = "unit"; // NOI18N
353
        String testType = "unit"; // NOI18N
333
        FileObject[] sourceFiles = findSources(context);
354
        FileObject[] sourceFiles = findSources(context);
334
        if (sourceFiles == null) {
355
        if (sourceFiles == null) {
356
            // no source file selected. try folders
357
            sourceFiles = findSources(context, true, true);
358
            if (sourceFiles == null) {
335
            return null;
359
            return null;
336
        }
360
        }
361
        }
337
        FileObject testSrcDir = project.getTestSourceDirectory(testType);
362
        FileObject testSrcDir = project.getTestSourceDirectory(testType);
338
        if (testSrcDir == null) {
363
        if (testSrcDir == null) {
339
            return null;
364
            return null;
 Lines 347-357    Link Here 
347
	    if (matches != null) {
372
	    if (matches != null) {
348
		return new TestSources(matches, testType, testSrcDir, null);
373
		return new TestSources(matches, testType, testSrcDir, null);
349
	    } else {
374
	    } else {
375
		// no test files found. The selected FOs must be folders under source packages
376
                ArrayList<FileObject> testFOs = new ArrayList<FileObject>();
377
                for (FileObject file : sourceFiles) {
378
                    if (file.isFolder()) {
379
                        String relativePath = FileUtil.getRelativePath(srcDir, file);
380
                        if (relativePath != null && !relativePath.isEmpty()) {
381
                            FileObject testFO = FileUtil.toFileObject(new File(FileUtil.toFile(testSrcDir).getPath().concat(File.separator).concat(relativePath)));
382
                            if (testFO != null && testFO.getChildren().length != 0) {
383
                                testFOs.add(testFO);
384
                            }
385
                        }
386
                    }
387
                }
388
                if (testFOs.isEmpty()) {
350
		return null;
389
		return null;
351
	    }
390
	    }
391
                return new TestSources(testFOs.toArray(new FileObject[testFOs.size()]), testType, testSrcDir, null);
352
        }
392
        }
353
    }
393
    }
394
    }
354
    
395
    
396
    /** Find tests corresponding to selected files. 
397
     * Selected files might be under Source and/or Test Packages
398
     */
399
    @CheckForNull TestSources findTestSourcesForFiles(Lookup context) {
400
        String testType = "unit"; // NOI18N
401
        FileObject[] sourcesFOs = findSources(context, false, false);
402
        FileObject[] testSourcesFOs = findTestSourcesFOs(context, false, false);
403
        HashSet<FileObject> testFiles = new HashSet<FileObject>();
404
        FileObject testRoot = project.getTestSourceDirectory(testType);
405
        if (testRoot == null) {
406
            return null;
407
        }
408
        if (testSourcesFOs == null) {
409
            return findTestSources(context, true);
410
        } else {
411
            if (sourcesFOs == null) {
412
                return findTestSources(context, false);
413
            } else {
414
                testFiles.addAll(Arrays.asList(testSourcesFOs));
415
                //Try to find the test under the test roots
416
                FileObject srcRoot = project.getSourceDirectory();
417
                FileObject[] files2 = ActionUtils.regexpMapFiles(sourcesFOs, srcRoot, SRCDIRJAVA, testRoot, SUBST, true);
418
                if (files2 != null) {
419
                    for (FileObject fo : files2) {
420
                        if (!testFiles.contains(fo)) {
421
                            testFiles.add(fo);
422
                        }
423
                    }
424
                }
425
                FileObject[] files2NG = ActionUtils.regexpMapFiles(sourcesFOs, srcRoot, SRCDIRJAVA, testRoot, SUBSTNG, true);
426
                if (files2NG != null) {
427
                    for (FileObject fo : files2NG) {
428
                        if (!testFiles.contains(fo)) {
429
                            testFiles.add(fo);
430
                        }
431
                    }
432
                }
433
            }
434
        }
435
        return testFiles.isEmpty() ? null : new TestSources(testFiles.toArray(new FileObject[testFiles.size()]), testType, testRoot, null);
436
    }
437
    
355
    @Messages("MSG_no_source=No source to operate on.")
438
    @Messages("MSG_no_source=No source to operate on.")
356
    public void invokeAction(final String command, final Lookup context) throws IllegalArgumentException {
439
    public void invokeAction(final String command, final Lookup context) throws IllegalArgumentException {
357
        if (!canRunNoLock(command, project.getTestUserDirLockFile())) {
440
        if (!canRunNoLock(command, project.getTestUserDirLockFile())) {
 Lines 411-418    Link Here 
411
                    TestSources testSources = findTestSourcesForSources(context);
494
                    TestSources testSources = findTestSourcesForSources(context);
412
                    if (testSources == null) {
495
                    if (testSources == null) {
413
                        testSources = findTestSources(context, true);
496
                        testSources = findTestSources(context, true);
414
497
                        if(testSources == null) {
498
                            testSources = findTestSourcesForFiles(context);
415
                    }
499
                    }
500
                    }
416
                    p.setProperty("continue.after.failing.tests", "true");  //NOI18N
501
                    p.setProperty("continue.after.failing.tests", "true");  //NOI18N
417
                    targetNames = setupTestSingle(p, testSources);
502
                    targetNames = setupTestSingle(p, testSources);
418
                } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
503
                } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
(-)apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/ui/ModuleActionsTest.java (+60 lines)
 Lines 103-106    Link Here 
103
        assertEquals("null", String.valueOf(a.findTestSources(Lookups.fixed(oneTest, r), true)));
103
        assertEquals("null", String.valueOf(a.findTestSources(Lookups.fixed(oneTest, r), true)));
104
    }
104
    }
105
    
105
    
106
    public void testFindTestSourcesForSources() throws Exception {
107
        NbModuleProject p = generateStandaloneModule("p");
108
        FileObject source = p.getSourceDirectory();
109
        FileObject one = FileUtil.createData(source, "p/One.java");
110
        FileObject r = FileUtil.createData(source, "p/r.png");
111
        FileObject other = FileUtil.createData(source, "p/Other.java");
112
        FileObject pkg = source.getFileObject("p");
113
        FileObject third = FileUtil.createData(source, "p2/Third.java");
114
        
115
        FileObject test = p.getTestSourceDirectory("unit");
116
        FileObject oneTest = FileUtil.createData(test, "p/OneTest.java");
117
        FileObject otherTest = FileUtil.createData(test, "p/OtherTest.java");
118
        FileObject thirdTest = FileUtil.createData(test, "p2/ThirdTest.java");
119
        
120
        ModuleActions a = new ModuleActions(p);
121
        assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookup.EMPTY)));
122
        assertEquals("unit:p/OneTest.java", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(one))));
123
        assertEquals("unit:p/OneTest.java,p/OtherTest.java", String.valueOf(a.findTestSourcesForSources(Lookups.fixed(one, other))));
124
        assertEquals("unit:p/**", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(pkg))));
125
        assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(r))));
126
        assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookups.fixed(one, r))));
127
        assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookup.EMPTY)));
128
        assertEquals("unit:p/OneTest.java", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(one))));
129
        assertEquals("unit:p/OneTest.java,p/OtherTest.java", String.valueOf(a.findTestSourcesForSources(Lookups.fixed(one, other))));
130
        assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(r))));
131
        assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookups.fixed(one, r))));
106
}
132
}
133
134
    public void testFindTestSourcesForFiles() throws Exception {
135
        NbModuleProject p = generateStandaloneModule("p");
136
        FileObject source = p.getSourceDirectory();
137
        FileObject one = FileUtil.createData(source, "p/One.java");
138
        FileObject r = FileUtil.createData(source, "p/r.png");
139
        FileObject other = FileUtil.createData(source, "p/Other.java");
140
        FileObject pkg = source.getFileObject("p");
141
        FileObject third = FileUtil.createData(source, "p2/Third.java");
142
        
143
        FileObject test = p.getTestSourceDirectory("unit");
144
        FileObject oneTest = FileUtil.createData(test, "p/OneTest.java");
145
        FileObject otherTest = FileUtil.createData(test, "p/OtherTest.java");
146
        FileObject thirdTest = FileUtil.createData(test, "p2/ThirdTest.java");
147
        
148
        ModuleActions a = new ModuleActions(p);
149
        assertEquals("null", String.valueOf(a.findTestSourcesForFiles(Lookup.EMPTY)));
150
        String actual = String.valueOf(a.findTestSourcesForFiles(Lookups.fixed(oneTest, other, third)));
151
        String testType = "unit";
152
        String expOne = "p/OneTest.java";
153
        String expOther = "p/OtherTest.java";
154
        String expThird = "p2/ThirdTest.java";
155
        assertTrue(actual.startsWith(testType.concat(":")));
156
        assertTrue(actual.contains(expOne));
157
        assertTrue(actual.contains(expOther));
158
        assertTrue(actual.contains(expThird));
159
        
160
        actual = String.valueOf(a.findTestSourcesForFiles(Lookups.fixed(one, otherTest)));
161
        assertTrue(actual.startsWith(testType.concat(":")));
162
        assertTrue(actual.contains(expOne));
163
        assertTrue(actual.contains(expOther));
164
    }
165
    
166
}
(-)j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/resources/build-impl.xsl (-1 / +1 lines)
 Lines 2368-2374    Link Here 
2368
            <target name="-do-test-run">
2368
            <target name="-do-test-run">
2369
                <xsl:attribute name="if">have.tests</xsl:attribute>
2369
                <xsl:attribute name="if">have.tests</xsl:attribute>
2370
                <xsl:attribute name="depends">init,compile-test,-pre-test-run</xsl:attribute>
2370
                <xsl:attribute name="depends">init,compile-test,-pre-test-run</xsl:attribute>
2371
                <carproject:test testincludes="**/*Test.java"/>
2371
                <carproject:test testincludes="**/*Test.java" includes="${{includes}}"/>
2372
            </target>
2372
            </target>
2373
            
2373
            
2374
            <target name="-post-test-run">
2374
            <target name="-post-test-run">
(-)j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/resources/build-impl.xsl (-1 / +1 lines)
 Lines 2345-2351    Link Here 
2345
            <target name="-do-test-run">
2345
            <target name="-do-test-run">
2346
                <xsl:attribute name="if">have.tests</xsl:attribute>
2346
                <xsl:attribute name="if">have.tests</xsl:attribute>
2347
                <xsl:attribute name="depends">init,compile-test,-pre-test-run</xsl:attribute>
2347
                <xsl:attribute name="depends">init,compile-test,-pre-test-run</xsl:attribute>
2348
                <ejbjarproject2:test testincludes="**/*Test.java"/>
2348
                <ejbjarproject2:test testincludes="**/*Test.java" includes="${{includes}}"/>
2349
            </target>
2349
            </target>
2350
            
2350
            
2351
            <target name="-post-test-run">
2351
            <target name="-post-test-run">
(-)java.api.common/src/org/netbeans/modules/java/api/common/project/BaseActionProvider.java (-38 / +152 lines)
 Lines 483-495    Link Here 
483
                if (targetNames == null) {
483
                if (targetNames == null) {
484
                    return;
484
                    return;
485
                }
485
                }
486
                final String command2execute;
487
                if(COMMAND_TEST_SINGLE.equals(command) && targetNames.length == 1 && targetNames[0].equals(COMMAND_TEST)) {
488
                    //multiple files or package(s) selected so we need to call test target instead of test-single
489
                    command2execute = COMMAND_TEST;
490
                    p.put("nb.internal.action.name", command2execute);
491
                } else {
492
                    command2execute = command;
493
                }
486
                if (isCompileOnSaveEnabled) {
494
                if (isCompileOnSaveEnabled) {
487
                    if (COMMAND_BUILD.equals(command) && !allowAntBuild()) {
495
                    if (COMMAND_BUILD.equals(command2execute) && !allowAntBuild()) {
488
                        showBuildActionWarning(context);
496
                        showBuildActionWarning(context);
489
                        return ;
497
                        return ;
490
                    }
498
                    }
491
                    Map<String, Object> execProperties = new HashMap<String, Object>();
499
                    Map<String, Object> execProperties = new HashMap<String, Object>();
492
                    execProperties.put("nb.internal.action.name", command);
500
                    execProperties.put("nb.internal.action.name", command2execute);
493
501
494
                    copyMultiValue(ProjectProperties.RUN_JVM_ARGS, execProperties);
502
                    copyMultiValue(ProjectProperties.RUN_JVM_ARGS, execProperties);
495
                    prepareWorkDir(execProperties);
503
                    prepareWorkDir(execProperties);
 Lines 516-522    Link Here 
516
                                String url = p.getProperty("applet.url");
524
                                String url = p.getProperty("applet.url");
517
                                execProperties.put("applet.url", url);
525
                                execProperties.put("applet.url", url);
518
                                execProperties.put(JavaRunner.PROP_EXECUTE_FILE, file);
526
                                execProperties.put(JavaRunner.PROP_EXECUTE_FILE, file);
519
                                prepareSystemProperties(execProperties, command, context, false);
527
                                prepareSystemProperties(execProperties, command2execute, context, false);
520
                                task =
528
                                task =
521
                                JavaRunner.execute(targetNames[0], execProperties);
529
                                JavaRunner.execute(targetNames[0], execProperties);
522
                            }
530
                            }
 Lines 525-574    Link Here 
525
                        }
533
                        }
526
                        return;
534
                        return;
527
                    }
535
                    }
528
                    if (!isServerExecution() && (COMMAND_RUN.equals(command) || COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command) || COMMAND_PROFILE.equals(command))) {
536
                    if (!isServerExecution() && (COMMAND_RUN.equals(command2execute) || COMMAND_DEBUG.equals(command2execute) || COMMAND_DEBUG_STEP_INTO.equals(command2execute) || COMMAND_PROFILE.equals(command2execute))) {
529
                        prepareSystemProperties(execProperties, command, context, false);
537
                        prepareSystemProperties(execProperties, command2execute, context, false);
530
                        AtomicReference<ExecutorTask> _task = new AtomicReference<ExecutorTask>();
538
                        AtomicReference<ExecutorTask> _task = new AtomicReference<ExecutorTask>();
531
                        bypassAntBuildScript(command, context, execProperties, _task);
539
                        bypassAntBuildScript(command2execute, context, execProperties, _task);
532
                        task = _task.get();
540
                        task = _task.get();
533
                        return ;
541
                        return ;
534
                    }
542
                    }
535
                    // for example RUN_SINGLE Java file with Servlet must be run on server and not locally
543
                    // for example RUN_SINGLE Java file with Servlet must be run on server and not locally
536
                    boolean serverExecution = p.getProperty(PROPERTY_RUN_SINGLE_ON_SERVER) != null;
544
                    boolean serverExecution = p.getProperty(PROPERTY_RUN_SINGLE_ON_SERVER) != null;
537
                    p.remove(PROPERTY_RUN_SINGLE_ON_SERVER);
545
                    p.remove(PROPERTY_RUN_SINGLE_ON_SERVER);
538
                    if (!serverExecution && (COMMAND_RUN_SINGLE.equals(command) || COMMAND_DEBUG_SINGLE.equals(command) || COMMAND_PROFILE_SINGLE.equals(command))) {
546
                    if (!serverExecution && (COMMAND_RUN_SINGLE.equals(command2execute) || COMMAND_DEBUG_SINGLE.equals(command2execute) || COMMAND_PROFILE_SINGLE.equals(command2execute))) {
539
                        prepareSystemProperties(execProperties, command, context, false);
547
                        prepareSystemProperties(execProperties, command2execute, context, false);
540
                        if (COMMAND_RUN_SINGLE.equals(command)) {
548
                        if (COMMAND_RUN_SINGLE.equals(command2execute)) {
541
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("run.class"));
549
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("run.class"));
542
                        } else if (COMMAND_DEBUG_SINGLE.equals(command)) {
550
                        } else if (COMMAND_DEBUG_SINGLE.equals(command2execute)) {
543
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("debug.class")); 
551
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("debug.class")); 
544
                        } else {
552
                        } else {
545
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("profile.class"));
553
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("profile.class"));
546
                        }
554
                        }
547
                        AtomicReference<ExecutorTask> _task = new AtomicReference<ExecutorTask>();
555
                        AtomicReference<ExecutorTask> _task = new AtomicReference<ExecutorTask>();
548
                        bypassAntBuildScript(command, context, execProperties, _task);
556
                        bypassAntBuildScript(command2execute, context, execProperties, _task);
549
                        task = _task.get();
557
                        task = _task.get();
550
                        return;
558
                        return;
551
                    }
559
                    }
552
                    String buildDir = evaluator.getProperty(ProjectProperties.BUILD_DIR);
560
                    String buildDir = evaluator.getProperty(ProjectProperties.BUILD_DIR);
553
                    if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command) || COMMAND_PROFILE_TEST_SINGLE.equals(command)) {
561
                    if (COMMAND_TEST_SINGLE.equals(command2execute) || COMMAND_DEBUG_TEST_SINGLE.equals(command2execute) || COMMAND_PROFILE_TEST_SINGLE.equals(command2execute)) {
554
                        @SuppressWarnings("MismatchedReadAndWriteOfArray")
562
                        @SuppressWarnings("MismatchedReadAndWriteOfArray")
555
                        FileObject[] files = findTestSources(context, true);
563
                        FileObject[] files = findTestSources(context, true);
556
                        try {
564
                        try {
557
                            prepareSystemProperties(execProperties, command, context, true);
565
                            prepareSystemProperties(execProperties, command2execute, context, true);
558
                            execProperties.put(JavaRunner.PROP_EXECUTE_FILE, files[0]);
566
                            execProperties.put(JavaRunner.PROP_EXECUTE_FILE, files[0]);
559
                            if (buildDir != null) { // #211543
567
                            if (buildDir != null) { // #211543
560
                                execProperties.put("tmp.dir", updateHelper.getAntProjectHelper().resolvePath(buildDir));
568
                                execProperties.put("tmp.dir", updateHelper.getAntProjectHelper().resolvePath(buildDir));
561
                            }
569
                            }
562
                            updateJavaRunnerClasspath(command, execProperties);
570
                            updateJavaRunnerClasspath(command2execute, execProperties);
563
                            task =
571
                            task =
564
                            JavaRunner.execute(command.equals(COMMAND_TEST_SINGLE) ? JavaRunner.QUICK_TEST : (COMMAND_DEBUG_TEST_SINGLE.equals(command) ? JavaRunner.QUICK_TEST_DEBUG :JavaRunner.QUICK_TEST_PROFILE),
572
                            JavaRunner.execute(command2execute.equals(COMMAND_TEST_SINGLE) ? JavaRunner.QUICK_TEST : (COMMAND_DEBUG_TEST_SINGLE.equals(command2execute) ? JavaRunner.QUICK_TEST_DEBUG :JavaRunner.QUICK_TEST_PROFILE),
565
                                               execProperties);
573
                                               execProperties);
566
                        } catch (IOException ex) {
574
                        } catch (IOException ex) {
567
                            Exceptions.printStackTrace(ex);
575
                            Exceptions.printStackTrace(ex);
568
                        }
576
                        }
569
                        return;
577
                        return;
570
                    }
578
                    }
571
                    if (SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command)) {
579
                    if (SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command2execute) || SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command2execute)) {
572
                        SingleMethod methodSpec = findTestMethods(context)[0];
580
                        SingleMethod methodSpec = findTestMethods(context)[0];
573
                        try {
581
                        try {
574
                            execProperties.put("methodname", methodSpec.getMethodName());//NOI18N
582
                            execProperties.put("methodname", methodSpec.getMethodName());//NOI18N
 Lines 576-584    Link Here 
576
                            if (buildDir != null) {
584
                            if (buildDir != null) {
577
                                execProperties.put("tmp.dir",updateHelper.getAntProjectHelper().resolvePath(buildDir));
585
                                execProperties.put("tmp.dir",updateHelper.getAntProjectHelper().resolvePath(buildDir));
578
                            }
586
                            }
579
                            updateJavaRunnerClasspath(command, execProperties);
587
                            updateJavaRunnerClasspath(command2execute, execProperties);
580
                            task =
588
                            task =
581
                            JavaRunner.execute(command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) ? JavaRunner.QUICK_TEST : JavaRunner.QUICK_TEST_DEBUG,
589
                            JavaRunner.execute(command2execute.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) ? JavaRunner.QUICK_TEST : JavaRunner.QUICK_TEST_DEBUG,
582
                                                  execProperties);
590
                                                  execProperties);
583
                        } catch (IOException ex) {
591
                        } catch (IOException ex) {
584
                            Exceptions.printStackTrace(ex);
592
                            Exceptions.printStackTrace(ex);
 Lines 586-597    Link Here 
586
                        return;
594
                        return;
587
                    }
595
                    }
588
                }
596
                }
589
                collectStartupExtenderArgs(p, command);
597
                collectStartupExtenderArgs(p, command2execute);
590
                Set<String> concealedProperties = collectAdditionalProperties(p, command, context);
598
                Set<String> concealedProperties = collectAdditionalProperties(p, command2execute, context);
591
                if (targetNames.length == 0) {
599
                if (targetNames.length == 0) {
592
                    targetNames = null;
600
                    targetNames = null;
593
                }
601
                }
594
                if (isCompileOnSaveEnabled && !NO_SYNC_COMMANDS.contains(command)) {
602
                if (isCompileOnSaveEnabled && !NO_SYNC_COMMANDS.contains(command2execute)) {
595
                    p.put("nb.wait.for.caches", "true");
603
                    p.put("nb.wait.for.caches", "true");
596
                }
604
                }
597
                final Callback cb = getCallback();
605
                final Callback cb = getCallback();
 Lines 607-613    Link Here 
607
                        DialogDisplayer.getDefault().notify(nd);
615
                        DialogDisplayer.getDefault().notify(nd);
608
                    } else {
616
                    } else {
609
                        if (cb2 != null) {
617
                        if (cb2 != null) {
610
                            cb2.antTargetInvocationStarted(command, context);
618
                            cb2.antTargetInvocationStarted(command2execute, context);
611
                        }
619
                        }
612
                        try {
620
                        try {
613
                            task = ActionUtils.runTarget(buildFo, targetNames, p, concealedProperties);
621
                            task = ActionUtils.runTarget(buildFo, targetNames, p, concealedProperties);
 Lines 623-641    Link Here 
623
                                        }
631
                                        }
624
                                    } finally {
632
                                    } finally {
625
                                        if (cb2 != null) {
633
                                        if (cb2 != null) {
626
                                            cb2.antTargetInvocationFinished(command, context, task.result());
634
                                            cb2.antTargetInvocationFinished(command2execute, context, task.result());
627
                                        }
635
                                        }
628
                                    }
636
                                    }
629
                                }
637
                                }
630
                            });
638
                            });
631
                        } catch (IOException ex) {
639
                        } catch (IOException ex) {
632
                            if (cb2 != null) {
640
                            if (cb2 != null) {
633
                                cb2.antTargetInvocationFailed(command, context);
641
                                cb2.antTargetInvocationFailed(command2execute, context);
634
                            }
642
                            }
635
                            throw ex;
643
                            throw ex;
636
                        } catch (RuntimeException ex) {
644
                        } catch (RuntimeException ex) {
637
                            if (cb2 != null) {
645
                            if (cb2 != null) {
638
                                cb2.antTargetInvocationFailed(command, context);
646
                                cb2.antTargetInvocationFailed(command2execute, context);
639
                            }
647
                            }
640
                            throw ex;
648
                            throw ex;
641
                        }
649
                        }
 Lines 800-810    Link Here 
800
            targetNames = getCommands().get(command);
808
            targetNames = getCommands().get(command);
801
        } else if ( command.equals( COMMAND_TEST_SINGLE ) ) {
809
        } else if ( command.equals( COMMAND_TEST_SINGLE ) ) {
802
            p.setProperty("ignore.failing.tests", "true");  //NOI18N
810
            p.setProperty("ignore.failing.tests", "true");  //NOI18N
803
            final FileObject[] files = findTestSources(context, true);
811
            final FileObject[] files = findTestSourcesForFiles(context);
804
            if (files == null) {
812
            if (files == null) {
805
                return null;
813
                return null;
806
            }
814
            }
815
            if(files.length == 1 && files[0].isData()) {
816
                //one file or a package containing one file selected
807
            targetNames = setupTestSingle(p, files);            
817
            targetNames = setupTestSingle(p, files);            
818
            } else {
819
                //multiple files or package(s) selected
820
                targetNames = setupTestFilesOrPackages(p, files);
821
            }
808
        } else if ( command.equals( COMMAND_DEBUG_TEST_SINGLE ) ) {
822
        } else if ( command.equals( COMMAND_DEBUG_TEST_SINGLE ) ) {
809
            final FileObject[] files = findTestSources(context, true);
823
            final FileObject[] files = findTestSources(context, true);
810
            if (files == null) {
824
            if (files == null) {
 Lines 1194-1199    Link Here 
1194
        return new String[] {"test-single"}; // NOI18N
1208
        return new String[] {"test-single"}; // NOI18N
1195
    }
1209
    }
1196
1210
1211
    private String[] setupTestFilesOrPackages(Properties p, FileObject[] files) {
1212
        if (files != null) {
1213
            FileObject root = getRoot(projectTestRoots.getRoots(), files[0]);
1214
            p.setProperty("includes", ActionUtils.antIncludesList(files, root).replace("**", "**/*Test.java")); // NOI18N
1215
        }
1216
        return new String[]{"test"}; // NOI18N
1217
    }
1218
1197
    private String[] setupDebugTestSingle(Properties p, FileObject[] files) {
1219
    private String[] setupDebugTestSingle(Properties p, FileObject[] files) {
1198
        FileObject[] testSrcPath = projectTestRoots.getRoots();
1220
        FileObject[] testSrcPath = projectTestRoots.getRoots();
1199
        FileObject root = getRoot(testSrcPath, files[0]);
1221
        FileObject root = getRoot(testSrcPath, files[0]);
 Lines 1271-1278    Link Here 
1271
                    || findSourcesAndPackages( context, projectTestRoots.getRoots()) != null;
1293
                    || findSourcesAndPackages( context, projectTestRoots.getRoots()) != null;
1272
        }
1294
        }
1273
        else if ( command.equals( COMMAND_TEST_SINGLE ) ) {
1295
        else if ( command.equals( COMMAND_TEST_SINGLE ) ) {
1274
            FileObject[] fos = findTestSources(context, true);
1296
            FileObject[] fos = findTestSourcesForFiles(context);
1275
            return fos != null && fos.length == 1;
1297
            return fos != null;
1276
        }
1298
        }
1277
        else if ( command.equals( COMMAND_DEBUG_TEST_SINGLE ) ) {
1299
        else if ( command.equals( COMMAND_DEBUG_TEST_SINGLE ) ) {
1278
            FileObject[] fos = findTestSources(context, true);
1300
            FileObject[] fos = findTestSources(context, true);
 Lines 1373-1381    Link Here 
1373
     */
1395
     */
1374
    @org.netbeans.api.annotations.common.SuppressWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
1396
    @org.netbeans.api.annotations.common.SuppressWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
1375
    private @CheckForNull FileObject[] findSources(Lookup context) {
1397
    private @CheckForNull FileObject[] findSources(Lookup context) {
1398
        return findSources(context, true, false);
1399
    }
1400
    
1401
    /**
1402
     * Find selected source files
1403
     *
1404
     * @param context the lookup in which files should be found
1405
     * @param strict if true, all files in the selection have to be accepted
1406
     * @param findInPackages if true, all files under a selected package in the selection will also be checked
1407
     */
1408
    @org.netbeans.api.annotations.common.SuppressWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
1409
    private @CheckForNull FileObject[] findSources(Lookup context, boolean strict, boolean findInPackages) {
1376
        FileObject[] srcPath = projectSourceRoots.getRoots();
1410
        FileObject[] srcPath = projectSourceRoots.getRoots();
1377
        for (int i=0; i< srcPath.length; i++) {
1411
        for (int i=0; i< srcPath.length; i++) {
1378
            FileObject[] files = ActionUtils.findSelectedFiles(context, srcPath[i], ".java", true); // NOI18N
1412
            FileObject[] files = ActionUtils.findSelectedFiles(context, srcPath[i], findInPackages ? null : ".java", strict); // NOI18N
1379
            if (files != null) {
1413
            if (files != null) {
1380
                return files;
1414
                return files;
1381
            }
1415
            }
 Lines 1416-1449    Link Here 
1416
     */
1450
     */
1417
    @org.netbeans.api.annotations.common.SuppressWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
1451
    @org.netbeans.api.annotations.common.SuppressWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
1418
    private @CheckForNull FileObject[] findTestSources(Lookup context, boolean checkInSrcDir) {
1452
    private @CheckForNull FileObject[] findTestSources(Lookup context, boolean checkInSrcDir) {
1453
        return findTestSources(context, checkInSrcDir, true, false);
1454
    }
1455
    
1456
    /**
1457
     * Find selected tests and/or tests which belong to selected source files
1458
     *
1459
     * @param context the lookup in which files should be found
1460
     * @param checkInSrcDir if true, tests which belong to selected source files will be searched for
1461
     * @param strict if true, all files in the selection have to be accepted
1462
     * @param findInPackages if true, all files under a selected package in the selection will also be checked
1463
     */
1464
    @org.netbeans.api.annotations.common.SuppressWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
1465
    private @CheckForNull FileObject[] findTestSources(Lookup context, boolean checkInSrcDir, boolean strict, boolean findInPackages) {
1419
        //XXX: Ugly, should be rewritten
1466
        //XXX: Ugly, should be rewritten
1420
        FileObject[] testSrcPath = projectTestRoots.getRoots();
1467
        FileObject[] testSrcPaths = projectTestRoots.getRoots();
1421
        for (int i=0; i< testSrcPath.length; i++) {
1468
        for (FileObject testSrcPath : testSrcPaths) {
1422
            FileObject[] files = ActionUtils.findSelectedFiles(context, testSrcPath[i], ".java", true); // NOI18N
1469
            FileObject[] files = ActionUtils.findSelectedFiles(context, testSrcPath, findInPackages ? null : ".java", strict); // NOI18N
1470
            ArrayList<FileObject> testFOs = new ArrayList<>();
1423
            if (files != null) {
1471
            if (files != null) {
1424
                return files;
1472
                for (FileObject file : files) {
1473
                    if ((file.hasExt("java") || findInPackages && file.isFolder())) {
1474
                        testFOs.add(file);
1425
            }
1475
            }
1426
        }
1476
        }
1427
        if (checkInSrcDir && testSrcPath.length>0) {
1477
                return testFOs.toArray(new FileObject[testFOs.size()]);
1428
            FileObject[] files = findSources (context);
1478
            }
1479
        }
1480
        if (checkInSrcDir && testSrcPaths.length>0) {
1481
            FileObject[] files = findSources (context, strict, findInPackages);
1429
            if (files != null) {
1482
            if (files != null) {
1430
                //Try to find the test under the test roots
1483
                //Try to find the test under the test roots
1431
                FileObject srcRoot = getRoot(projectSourceRoots.getRoots(),files[0]);
1484
                FileObject srcRoot = getRoot(projectSourceRoots.getRoots(),files[0]);
1432
                for (int i=0; i<testSrcPath.length; i++) {
1485
                for (FileObject testSrcPath : testSrcPaths) {
1433
                    FileObject[] files2 = ActionUtils.regexpMapFiles(files,srcRoot, SRCDIRJAVA, testSrcPath[i], SUBST, true);
1486
                    FileObject[] files2 = ActionUtils.regexpMapFiles(files, srcRoot, SRCDIRJAVA, testSrcPath, SUBST, strict);
1434
                    if (files2 != null) {
1487
                    if (files2 != null) {
1435
                        return files2;
1488
                        return files2;
1436
                    }
1489
                    }
1437
                    FileObject[] files2NG = ActionUtils.regexpMapFiles(files, srcRoot, SRCDIRJAVA, testSrcPath[i], SUBSTNG, true);
1490
                    FileObject[] files2NG = ActionUtils.regexpMapFiles(files, srcRoot, SRCDIRJAVA, testSrcPath, SUBSTNG, strict);
1438
                    if (files2NG != null) {
1491
                    if (files2NG != null) {
1439
                        return files2NG;
1492
                        return files2NG;
1440
                    }
1493
                    }
1441
                }
1494
                }
1495
                // no test files found. The selected FOs must be folders under source packages
1496
                files = ActionUtils.findSelectedFiles(context, srcRoot, findInPackages ? null : ".java", strict); // NOI18N
1497
                ArrayList<FileObject> testFOs = new ArrayList<>();
1498
                if (files != null) {
1499
                    for (FileObject file : files) {
1500
                        if (findInPackages && file.isFolder()) {
1501
                            String relativePath = FileUtil.getRelativePath(srcRoot, file);
1502
                            if (relativePath != null) {
1503
                                for (FileObject testSrcPath : testSrcPaths) {
1504
                                    FileObject testFO = FileUtil.toFileObject(new File(FileUtil.toFile(testSrcPath).getPath().concat(File.separator).concat(relativePath)));
1505
                                    if (testFO != null) {
1506
                                        testFOs.add(testFO);
1442
            }
1507
            }
1443
        }
1508
        }
1509
                            }
1510
                        }
1511
                    }
1512
                    return testFOs.toArray(new FileObject[testFOs.size()]);
1513
                }
1514
            }
1515
        }
1444
        return null;
1516
        return null;
1445
    }
1517
    }
1446
1518
1519
    /**
1520
     * Find selected tests and tests which belong to selected source files
1521
     * when package(s) or multiple files are selected.
1522
     *
1523
     * @param context the lookup in which files should be found
1524
     */
1525
    @org.netbeans.api.annotations.common.SuppressWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
1526
    private @CheckForNull FileObject[] findTestSourcesForFiles(Lookup context) {
1527
        FileObject[] sourcesFOs = findSources(context, false, true);
1528
        FileObject[] testSourcesFOs = findTestSources(context, false, false, true);
1529
        HashSet<FileObject> testFiles = new HashSet<>();
1530
        if(testSourcesFOs == null) {
1531
            return findTestSources(context, true, false, true);
1532
        } else {
1533
            if(sourcesFOs == null) {
1534
                return testSourcesFOs;
1535
            } else {
1536
                testFiles.addAll(Arrays.asList(testSourcesFOs));
1537
                //Try to find the test under the test roots
1538
                FileObject srcRoot = getRoot(projectSourceRoots.getRoots(),sourcesFOs[0]);
1539
                for (FileObject testRoot : projectTestRoots.getRoots()) {
1540
                    FileObject[] files2 = ActionUtils.regexpMapFiles(sourcesFOs, srcRoot, SRCDIRJAVA, testRoot, SUBST, true);
1541
                    if (files2 != null) {
1542
                        for (FileObject fo : files2) {
1543
                            if(!testFiles.contains(fo)) {
1544
                                testFiles.add(fo);
1545
                            }
1546
                        }
1547
                    }
1548
                    FileObject[] files2NG = ActionUtils.regexpMapFiles(sourcesFOs, srcRoot, SRCDIRJAVA, testRoot, SUBSTNG, true);
1549
                    if (files2NG != null) {
1550
                        for (FileObject fo : files2NG) {
1551
                            if(!testFiles.contains(fo)) {
1552
                                testFiles.add(fo);
1553
                            }
1554
                        }
1555
                    }
1556
                }
1557
            }
1558
        }
1559
        return testFiles.isEmpty() ? null : testFiles.toArray(new FileObject[testFiles.size()]);
1560
    }
1447
1561
1448
    /**
1562
    /**
1449
     * Finds single method specification objects corresponding to JUnit test
1563
     * Finds single method specification objects corresponding to JUnit test
(-)java.j2seproject/src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl (-1 / +1 lines)
 Lines 2397-2403    Link Here 
2397
            <target name="-do-test-run">
2397
            <target name="-do-test-run">
2398
                <xsl:attribute name="if">have.tests</xsl:attribute>
2398
                <xsl:attribute name="if">have.tests</xsl:attribute>
2399
                <xsl:attribute name="depends">init,compile-test,-pre-test-run</xsl:attribute>
2399
                <xsl:attribute name="depends">init,compile-test,-pre-test-run</xsl:attribute>
2400
                <j2seproject3:test testincludes="**/*Test.java"/>
2400
                <j2seproject3:test testincludes="**/*Test.java" includes="${{includes}}"/>
2401
            </target>
2401
            </target>
2402
            
2402
            
2403
            <target name="-post-test-run">
2403
            <target name="-post-test-run">
(-)java.project/src/org/netbeans/spi/java/project/support/ui/Bundle.properties (+4 lines)
 Lines 75-77    Link Here 
75
ACSD_excludesLabel=Excludes pattern
75
ACSD_excludesLabel=Excludes pattern
76
ACSN_IncludeExcludeVisualizerPanel=Include Exclude Panel
76
ACSN_IncludeExcludeVisualizerPanel=Include Exclude Panel
77
ACSD_IncludeExcludeVisualizerPanel=Include and Exclude patterns for project
77
ACSD_IncludeExcludeVisualizerPanel=Include and Exclude patterns for project
78
79
# Name of package action
80
# {0} - # of selected packages
81
LBL_TestPackageAction_Name=T&est {0,choice,0#Package|1#Package|1<Packages}
(-)java.project/src/org/netbeans/spi/java/project/support/ui/PackageViewChildren.java (+4 lines)
 Lines 99-104    Link Here 
99
import org.openide.util.Exceptions;
99
import org.openide.util.Exceptions;
100
import org.openide.util.ImageUtilities;
100
import org.openide.util.ImageUtilities;
101
import org.openide.util.Lookup;
101
import org.openide.util.Lookup;
102
import org.openide.util.NbBundle;
102
import org.openide.util.NbBundle.Messages;
103
import org.openide.util.NbBundle.Messages;
103
import org.openide.util.RequestProcessor;
104
import org.openide.util.RequestProcessor;
104
import org.openide.util.WeakListeners;
105
import org.openide.util.WeakListeners;
 Lines 133-138    Link Here 
133
    private final RequestProcessor.Task visibility_refresh;
134
    private final RequestProcessor.Task visibility_refresh;
134
    private FileChangeListener wfcl;    // Weak listener on the system filesystem
135
    private FileChangeListener wfcl;    // Weak listener on the system filesystem
135
    private ChangeListener wvqcl;       // Weak listener on the VisibilityQuery
136
    private ChangeListener wvqcl;       // Weak listener on the VisibilityQuery
137
    private final Action testPackageAction;
136
138
137
    /**
139
    /**
138
     * Creates children based on a single source root.
140
     * Creates children based on a single source root.
 Lines 142-147    Link Here 
142
        
144
        
143
        // Sem mas dat cache a bude to uplne nejrychlejsi na svete
145
        // Sem mas dat cache a bude to uplne nejrychlejsi na svete
144
        names2nodes = Collections.synchronizedMap(new TreeMap<String,Object>());
146
        names2nodes = Collections.synchronizedMap(new TreeMap<String,Object>());
147
        testPackageAction = FileSensitiveActions.fileCommandAction(ActionProvider.COMMAND_TEST_SINGLE, NbBundle.getMessage(PackageViewChildren.class, "LBL_TestPackageAction_Name"), null);
145
        this.root = group.getRootFolder();
148
        this.root = group.getRootFolder();
146
        this.group = group;
149
        this.group = group;
147
        visibility_refresh = VISIBILITY_CHANGE_RP.create(new Runnable() {
150
        visibility_refresh = VISIBILITY_CHANGE_RP.create(new Runnable() {
 Lines 757-762    Link Here 
757
                        else if ( superActions[i] instanceof FileSystemAction ) {
760
                        else if ( superActions[i] instanceof FileSystemAction ) {
758
                            actionList.add (null); // insert separator and new action
761
                            actionList.add (null); // insert separator and new action
759
                            actionList.add (FileSensitiveActions.fileCommandAction(ActionProvider.COMMAND_COMPILE_SINGLE, LBL_CompilePackage_Action(), null));                           
762
                            actionList.add (FileSensitiveActions.fileCommandAction(ActionProvider.COMMAND_COMPILE_SINGLE, LBL_CompilePackage_Action(), null));                           
763
                            actionList.add (testPackageAction);
760
                            actionList.addAll((List<Action>) org.openide.util.Utilities.actionsForPath("Projects/package/Actions"));
764
                            actionList.addAll((List<Action>) org.openide.util.Utilities.actionsForPath("Projects/package/Actions"));
761
                        }
765
                        }
762
                        
766
                        
(-)maven/src/org/netbeans/modules/maven/execute/ActionToGoalUtils.java (+45 lines)
 Lines 46-54    Link Here 
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.io.StringReader;
47
import java.io.StringReader;
48
import java.io.StringWriter;
48
import java.io.StringWriter;
49
import java.net.URI;
49
import java.util.ArrayList;
50
import java.util.ArrayList;
51
import java.util.Collection;
50
import java.util.Collections;
52
import java.util.Collections;
51
import java.util.HashMap;
53
import java.util.HashMap;
54
import java.util.HashSet;
52
import java.util.Iterator;
55
import java.util.Iterator;
53
import java.util.List;
56
import java.util.List;
54
import java.util.Map;
57
import java.util.Map;
 Lines 72-78    Link Here 
72
import org.netbeans.spi.project.ActionProvider;
75
import org.netbeans.spi.project.ActionProvider;
73
import org.openide.filesystems.FileObject;
76
import org.openide.filesystems.FileObject;
74
import org.openide.filesystems.FileUtil;
77
import org.openide.filesystems.FileUtil;
78
import org.openide.loaders.DataObject;
75
import org.openide.util.Lookup;
79
import org.openide.util.Lookup;
80
import org.openide.util.Utilities;
76
import org.openide.windows.InputOutput;
81
import org.openide.windows.InputOutput;
77
82
78
/**
83
/**
 Lines 169-179    Link Here 
169
            rc.setActivatedProfiles(acts);
174
            rc.setActivatedProfiles(acts);
170
            Map<String, String> props = new HashMap<String, String>(rc.getProperties());
175
            Map<String, String> props = new HashMap<String, String>(rc.getProperties());
171
            props.putAll(configs.getActiveConfiguration().getProperties());
176
            props.putAll(configs.getActiveConfiguration().getProperties());
177
            if (ActionProvider.COMMAND_TEST_SINGLE.equals(action)) {
178
                String testProperty = props.get("test");
179
                // multiple files were selected from both source and test packages and "Test Files" action was invoked on them
180
                if (testProperty != null && testProperty.equals("${packageClassName}")) {
181
                    Collection<? extends FileObject> candidates = lookup.lookupAll(FileObject.class);
182
                    if (candidates.isEmpty()) { // should not be for DataNode selections, but for compatibility
183
                        Collection<? extends DataObject> compatibilityCandidates = lookup.lookupAll(DataObject.class);
184
                        if (compatibilityCandidates.isEmpty()) {// shortcut - just not a file selection at all
185
                            List<FileObject> _candidates = new ArrayList<FileObject>();
186
                            for (DataObject d : compatibilityCandidates) {
187
                                _candidates.add(d.getPrimaryFile());
188
                            }
189
                            candidates = _candidates;
190
                        }
191
                    }
192
                    HashSet<String> test = new HashSet<String>();
193
                    addSelectedFiles(project, false, candidates, test);
194
                    addSelectedFiles(project, true, candidates, test);
195
                    String toString = test.toString().replace(" ", "");
196
                    props.put("test", toString.substring(1, toString.length() - 1));
197
                }
198
            }
172
            rc.addProperties(props);
199
            rc.addProperties(props);
173
        }
200
        }
174
        return rc;
201
        return rc;
175
    }
202
    }
176
203
204
    private static void addSelectedFiles(NbMavenProjectImpl project, boolean testRoots, Collection<? extends FileObject> candidates, HashSet<String> test) {
205
        URI[] roots = project.getSourceRoots(testRoots);
206
        for (URI uri : roots) {
207
            FileObject root = FileUtil.toFileObject(Utilities.toFile(uri));
208
            for (FileObject candidate : candidates) {
209
                String relativePath = FileUtil.getRelativePath(root, candidate);
210
                if (relativePath != null) {
211
                    if(testRoots) {
212
                        relativePath = relativePath.replace(".java", "").replace('/', '.');
213
                    } else {
214
                        relativePath = relativePath.replace(".java", "Test").replace('/', '.');
215
                    }
216
                    test.add(relativePath);
217
                }
218
            }
219
        }
220
    }
221
177
    public static boolean isActionEnable(String action, NbMavenProjectImpl project, Lookup lookup) {
222
    public static boolean isActionEnable(String action, NbMavenProjectImpl project, Lookup lookup) {
178
       
223
       
179
        M2ConfigProvider configs = project.getLookup().lookup(M2ConfigProvider.class);
224
        M2ConfigProvider configs = project.getLookup().lookup(M2ConfigProvider.class);
(-)projectui/src/org/netbeans/modules/project/ui/actions/Bundle.properties (-1 / +3 lines)
 Lines 80-88    Link Here 
80
LBL_RunMainProjectAction_Name=&Run {0,choice,-1#Main Project|0#Project|1#Project ({1})|1<{0} Projects}
80
LBL_RunMainProjectAction_Name=&Run {0,choice,-1#Main Project|0#Project|1#Project ({1})|1<{0} Projects}
81
81
82
82
83
# Name of 1-off actions
84
# {0} - # of selected files
83
LBL_RunSingleAction_Name=Run &File
85
LBL_RunSingleAction_Name=Run &File
84
# {0,choice,0#File|1#"{1}"|1<Files}
86
# {0,choice,0#File|1#"{1}"|1<Files}
85
LBL_TestSingleAction_Name=T&est File
87
LBL_TestSingleAction_Name=T&est {0,choice,0#File|1#File|1<Files}
86
#{0,choice,0#File|1#"{1}"|1<Files}
88
#{0,choice,0#File|1#"{1}"|1<Files}
87
89
88
# OpenProject.java
90
# OpenProject.java
(-)web.project/src/org/netbeans/modules/web/project/resources/build-impl.xsl (-1 / +1 lines)
 Lines 2665-2671    Link Here 
2665
            <target name="-do-test-run">
2665
            <target name="-do-test-run">
2666
                <xsl:attribute name="if">have.tests</xsl:attribute>
2666
                <xsl:attribute name="if">have.tests</xsl:attribute>
2667
                <xsl:attribute name="depends">init,compile-test,-pre-test-run</xsl:attribute>
2667
                <xsl:attribute name="depends">init,compile-test,-pre-test-run</xsl:attribute>
2668
                <webproject2:test testincludes="**/*Test.java"/>
2668
                <webproject2:test testincludes="**/*Test.java" includes="${{includes}}"/>
2669
            </target>
2669
            </target>
2670
            
2670
            
2671
            <target name="-post-test-run">
2671
            <target name="-post-test-run">

Return to bug 124313
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo