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 210214
Collapse All | Expand All

(-)a/java.api.common/src/org/netbeans/modules/java/api/common/project/BaseActionProvider.java (-20 / +32 lines)
Lines 73-78 Link Here
73
import java.util.Set;
73
import java.util.Set;
74
import java.util.StringTokenizer;
74
import java.util.StringTokenizer;
75
import java.util.TreeSet;
75
import java.util.TreeSet;
76
import java.util.concurrent.Callable;
76
import java.util.concurrent.atomic.AtomicBoolean;
77
import java.util.concurrent.atomic.AtomicBoolean;
77
import java.util.concurrent.atomic.AtomicReference;
78
import java.util.concurrent.atomic.AtomicReference;
78
import java.util.logging.Level;
79
import java.util.logging.Level;
Lines 144-149 Link Here
144
import org.openide.util.Lookup;
145
import org.openide.util.Lookup;
145
import org.openide.util.NbBundle.Messages;
146
import org.openide.util.NbBundle.Messages;
146
import org.openide.util.Parameters;
147
import org.openide.util.Parameters;
148
import org.openide.util.RequestProcessor;
147
import org.openide.util.Task;
149
import org.openide.util.Task;
148
import org.openide.util.TaskListener;
150
import org.openide.util.TaskListener;
149
import org.openide.util.lookup.Lookups;
151
import org.openide.util.lookup.Lookups;
Lines 202-207 Link Here
202
204
203
    private boolean serverExecution = false;
205
    private boolean serverExecution = false;
204
206
207
    private static RequestProcessor RP = new RequestProcessor("BaseActionProvider", 10); // NOI18N
208
205
    public BaseActionProvider(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, 
209
    public BaseActionProvider(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, 
206
            SourceRoots sourceRoots, SourceRoots testRoots, AntProjectHelper antProjectHelper, Callback callback) {
210
            SourceRoots sourceRoots, SourceRoots testRoots, AntProjectHelper antProjectHelper, Callback callback) {
207
        this.antProjectHelper = antProjectHelper;
211
        this.antProjectHelper = antProjectHelper;
Lines 453-459 Link Here
453
             * the default values (possibly incorrect) are used.
457
             * the default values (possibly incorrect) are used.
454
             */
458
             */
455
            private boolean doJavaChecks = true;
459
            private boolean doJavaChecks = true;
456
            ExecutorTask task;
460
            
457
461
458
            @Override
462
            @Override
459
            public void run () {
463
            public void run () {
Lines 461-474 Link Here
461
                    return;
465
                    return;
462
                }
466
                }
463
                called.set(true);
467
                called.set(true);
468
                doRunOnBackground();
469
            }
470
471
            private void doRunOnBackground() {
472
                RP.post(new Runnable() {
473
                    @Override
474
                    public void run() {
475
                        ExecutorTask task = null;
464
                try {
476
                try {
465
                    doRun();
477
                            task = doRun();
466
                } finally {
478
                } finally {
467
                    if (task != null) {
479
                    if (task != null) {
480
                                final ExecutorTask _task = task;
468
                        task.addTaskListener(new TaskListener() {
481
                        task.addTaskListener(new TaskListener() {
469
                            @org.netbeans.api.annotations.common.SuppressWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
482
                            @org.netbeans.api.annotations.common.SuppressWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
470
                            @Override public void taskFinished(Task _) {
483
                            @Override public void taskFinished(Task _) {
471
                                listener.finished(task.result() == 0);
484
                                        listener.finished(_task.result() == 0);
472
                            }
485
                            }
473
                        });
486
                        });
474
                    } else {
487
                    } else {
Lines 476-494 Link Here
476
                    }
489
                    }
477
                }
490
                }
478
            }
491
            }
492
                });
493
            }
479
494
480
            void doRun() {
495
            private ExecutorTask doRun() {
481
                Properties p = new Properties();
496
                Properties p = new Properties();
482
                String[] targetNames;
497
                String[] targetNames;
483
498
484
                targetNames = getTargetNames(command, context, p, doJavaChecks);
499
                targetNames = getTargetNames(command, context, p, doJavaChecks);
485
                if (targetNames == null) {
500
                if (targetNames == null) {
486
                    return;
501
                    return null;
487
                }
502
                }
488
                if (isCompileOnSaveEnabled) {
503
                if (isCompileOnSaveEnabled) {
489
                    if (COMMAND_BUILD.equals(command) && !allowAntBuild()) {
504
                    if (COMMAND_BUILD.equals(command) && !allowAntBuild()) {
490
                        showBuildActionWarning(context);
505
                        showBuildActionWarning(context);
491
                        return ;
506
                        return null;
492
                    }
507
                    }
493
                    Map<String, Object> execProperties = new HashMap<String, Object>();
508
                    Map<String, Object> execProperties = new HashMap<String, Object>();
494
509
Lines 518-537 Link Here
518
                                execProperties.put("applet.url", url);
533
                                execProperties.put("applet.url", url);
519
                                execProperties.put(JavaRunner.PROP_EXECUTE_FILE, file);
534
                                execProperties.put(JavaRunner.PROP_EXECUTE_FILE, file);
520
                                prepareSystemProperties(execProperties, command, false);
535
                                prepareSystemProperties(execProperties, command, false);
521
                                task =
536
                                return JavaRunner.execute(targetNames[0], execProperties);
522
                                JavaRunner.execute(targetNames[0], execProperties);
523
                            }
537
                            }
524
                        } catch (IOException ex) {
538
                        } catch (IOException ex) {
525
                            Exceptions.printStackTrace(ex);
539
                            Exceptions.printStackTrace(ex);
526
                        }
540
                        }
527
                        return;
541
                        return null;
528
                    }
542
                    }
529
                    if (!isServerExecution() && (COMMAND_RUN.equals(command) || COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command) || COMMAND_PROFILE.equals(command))) {
543
                    if (!isServerExecution() && (COMMAND_RUN.equals(command) || COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command) || COMMAND_PROFILE.equals(command))) {
530
                        prepareSystemProperties(execProperties, command, false);
544
                        prepareSystemProperties(execProperties, command, false);
531
                        AtomicReference<ExecutorTask> _task = new AtomicReference<ExecutorTask>();
545
                        AtomicReference<ExecutorTask> _task = new AtomicReference<ExecutorTask>();
532
                        bypassAntBuildScript(command, context, execProperties, _task);
546
                        bypassAntBuildScript(command, context, execProperties, _task);
533
                        task = _task.get();
547
                        return _task.get();
534
                        return ;
535
                    }
548
                    }
536
                    // for example RUN_SINGLE Java file with Servlet must be run on server and not locally
549
                    // for example RUN_SINGLE Java file with Servlet must be run on server and not locally
537
                    boolean serverExecution = p.getProperty(PROPERTY_RUN_SINGLE_ON_SERVER) != null;
550
                    boolean serverExecution = p.getProperty(PROPERTY_RUN_SINGLE_ON_SERVER) != null;
Lines 547-554 Link Here
547
                        }
560
                        }
548
                        AtomicReference<ExecutorTask> _task = new AtomicReference<ExecutorTask>();
561
                        AtomicReference<ExecutorTask> _task = new AtomicReference<ExecutorTask>();
549
                        bypassAntBuildScript(command, context, execProperties, _task);
562
                        bypassAntBuildScript(command, context, execProperties, _task);
550
                        task = _task.get();
563
                        return _task.get();
551
                        return;
552
                    }
564
                    }
553
                    String buildDir = evaluator.getProperty(ProjectProperties.BUILD_DIR);
565
                    String buildDir = evaluator.getProperty(ProjectProperties.BUILD_DIR);
554
                    if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command) || COMMAND_PROFILE_TEST_SINGLE.equals(command)) {
566
                    if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command) || COMMAND_PROFILE_TEST_SINGLE.equals(command)) {
Lines 561-573 Link Here
561
                                execProperties.put("tmp.dir", updateHelper.getAntProjectHelper().resolvePath(buildDir));
573
                                execProperties.put("tmp.dir", updateHelper.getAntProjectHelper().resolvePath(buildDir));
562
                            }
574
                            }
563
                            updateJavaRunnerClasspath(command, execProperties);
575
                            updateJavaRunnerClasspath(command, execProperties);
564
                            task =
576
                            return JavaRunner.execute(command.equals(COMMAND_TEST_SINGLE) ? JavaRunner.QUICK_TEST : (COMMAND_DEBUG_TEST_SINGLE.equals(command) ? JavaRunner.QUICK_TEST_DEBUG :JavaRunner.QUICK_TEST_PROFILE),
565
                            JavaRunner.execute(command.equals(COMMAND_TEST_SINGLE) ? JavaRunner.QUICK_TEST : (COMMAND_DEBUG_TEST_SINGLE.equals(command) ? JavaRunner.QUICK_TEST_DEBUG :JavaRunner.QUICK_TEST_PROFILE),
566
                                               execProperties);
577
                                               execProperties);
567
                        } catch (IOException ex) {
578
                        } catch (IOException ex) {
568
                            Exceptions.printStackTrace(ex);
579
                            Exceptions.printStackTrace(ex);
569
                        }
580
                        }
570
                        return;
581
                        return null;
571
                    }
582
                    }
572
                    if (SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command)) {
583
                    if (SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command)) {
573
                        SingleMethod methodSpec = findTestMethods(context)[0];
584
                        SingleMethod methodSpec = findTestMethods(context)[0];
Lines 578-590 Link Here
578
                                execProperties.put("tmp.dir",updateHelper.getAntProjectHelper().resolvePath(buildDir));
589
                                execProperties.put("tmp.dir",updateHelper.getAntProjectHelper().resolvePath(buildDir));
579
                            }
590
                            }
580
                            updateJavaRunnerClasspath(command, execProperties);
591
                            updateJavaRunnerClasspath(command, execProperties);
581
                            task =
592
                            return JavaRunner.execute(command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) ? JavaRunner.QUICK_TEST : JavaRunner.QUICK_TEST_DEBUG,
582
                            JavaRunner.execute(command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) ? JavaRunner.QUICK_TEST : JavaRunner.QUICK_TEST_DEBUG,
583
                                                  execProperties);
593
                                                  execProperties);
584
                        } catch (IOException ex) {
594
                        } catch (IOException ex) {
585
                            Exceptions.printStackTrace(ex);
595
                            Exceptions.printStackTrace(ex);
586
                        }
596
                        }
587
                        return;
597
                        return null;
588
                    }
598
                    }
589
                }
599
                }
590
                collectStartupExtenderArgs(p, command);
600
                collectStartupExtenderArgs(p, command);
Lines 612-618 Link Here
612
                            cb2.antTargetInvocationStarted(command, context);
622
                            cb2.antTargetInvocationStarted(command, context);
613
                        }
623
                        }
614
                        try {
624
                        try {
615
                            task = ActionUtils.runTarget(buildFo, targetNames, p);
625
                            final ExecutorTask task = ActionUtils.runTarget(buildFo, targetNames, p);
616
                            task.addTaskListener(new TaskListener() {
626
                            task.addTaskListener(new TaskListener() {
617
                                @Override
627
                                @Override
618
                                public void taskFinished(Task _) {
628
                                public void taskFinished(Task _) {
Lines 630-635 Link Here
630
                                    }
640
                                    }
631
                                }
641
                                }
632
                            });
642
                            });
643
                            return task;
633
                        } catch (IOException ex) {
644
                        } catch (IOException ex) {
634
                            if (cb2 != null) {
645
                            if (cb2 != null) {
635
                                cb2.antTargetInvocationFailed(command, context);
646
                                cb2.antTargetInvocationFailed(command, context);
Lines 646-651 Link Here
646
                catch (IOException e) {
657
                catch (IOException e) {
647
                    ErrorManager.getDefault().notify(e);
658
                    ErrorManager.getDefault().notify(e);
648
                }
659
                }
660
                return null;
649
            }
661
            }
650
        }
662
        }
651
        final Action action = new Action();
663
        final Action action = new Action();

Return to bug 210214