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 |