Lines 52-57
Link Here
|
52 |
import java.io.File; |
52 |
import java.io.File; |
53 |
import java.io.IOException; |
53 |
import java.io.IOException; |
54 |
import java.io.InputStream; |
54 |
import java.io.InputStream; |
|
|
55 |
import java.lang.reflect.InvocationTargetException; |
55 |
import java.net.URL; |
56 |
import java.net.URL; |
56 |
import java.nio.charset.Charset; |
57 |
import java.nio.charset.Charset; |
57 |
import java.nio.charset.IllegalCharsetNameException; |
58 |
import java.nio.charset.IllegalCharsetNameException; |
Lines 99-104
Link Here
|
99 |
import org.netbeans.api.java.source.CompilationController; |
100 |
import org.netbeans.api.java.source.CompilationController; |
100 |
import org.netbeans.api.java.source.ElementHandle; |
101 |
import org.netbeans.api.java.source.ElementHandle; |
101 |
import org.netbeans.api.java.source.JavaSource; |
102 |
import org.netbeans.api.java.source.JavaSource; |
|
|
103 |
import org.netbeans.api.java.source.SourceUtils; |
102 |
import org.netbeans.api.java.source.ui.ScanDialog; |
104 |
import org.netbeans.api.java.source.ui.ScanDialog; |
103 |
import org.netbeans.api.project.FileOwnerQuery; |
105 |
import org.netbeans.api.project.FileOwnerQuery; |
104 |
import org.netbeans.api.project.Project; |
106 |
import org.netbeans.api.project.Project; |
Lines 144-149
Link Here
|
144 |
import org.openide.util.Lookup; |
146 |
import org.openide.util.Lookup; |
145 |
import org.openide.util.NbBundle.Messages; |
147 |
import org.openide.util.NbBundle.Messages; |
146 |
import org.openide.util.Parameters; |
148 |
import org.openide.util.Parameters; |
|
|
149 |
import org.openide.util.RequestProcessor; |
147 |
import org.openide.util.Task; |
150 |
import org.openide.util.Task; |
148 |
import org.openide.util.TaskListener; |
151 |
import org.openide.util.TaskListener; |
149 |
import org.openide.util.lookup.Lookups; |
152 |
import org.openide.util.lookup.Lookups; |
Lines 202-207
Link Here
|
202 |
|
205 |
|
203 |
private boolean serverExecution = false; |
206 |
private boolean serverExecution = false; |
204 |
|
207 |
|
|
|
208 |
private static RequestProcessor RP = new RequestProcessor("BaseActionProvider", 10); // NOI18N |
209 |
|
205 |
public BaseActionProvider(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, |
210 |
public BaseActionProvider(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, |
206 |
SourceRoots sourceRoots, SourceRoots testRoots, AntProjectHelper antProjectHelper, Callback callback) { |
211 |
SourceRoots sourceRoots, SourceRoots testRoots, AntProjectHelper antProjectHelper, Callback callback) { |
207 |
this.antProjectHelper = antProjectHelper; |
212 |
this.antProjectHelper = antProjectHelper; |
Lines 416-421
Link Here
|
416 |
@Override |
421 |
@Override |
417 |
public void invokeAction( final String command, final Lookup context ) throws IllegalArgumentException { |
422 |
public void invokeAction( final String command, final Lookup context ) throws IllegalArgumentException { |
418 |
assert EventQueue.isDispatchThread(); |
423 |
assert EventQueue.isDispatchThread(); |
|
|
424 |
RP.post(new Runnable() { |
425 |
@Override |
426 |
public void run() { |
427 |
invokeAction_(command, context); |
428 |
} |
429 |
}); |
430 |
} |
431 |
|
432 |
private void invokeAction_( final String command, final Lookup context ) throws IllegalArgumentException { |
419 |
if (COMMAND_DELETE.equals(command)) { |
433 |
if (COMMAND_DELETE.equals(command)) { |
420 |
DefaultProjectOperations.performDefaultDeleteOperation(project); |
434 |
DefaultProjectOperations.performDefaultDeleteOperation(project); |
421 |
return ; |
435 |
return ; |
Lines 437-454
Link Here
|
437 |
} |
451 |
} |
438 |
|
452 |
|
439 |
final boolean isCompileOnSaveEnabled = isCompileOnSaveEnabled(); |
453 |
final boolean isCompileOnSaveEnabled = isCompileOnSaveEnabled(); |
440 |
final AtomicReference<Thread> caller = new AtomicReference<Thread>(Thread.currentThread()); |
|
|
441 |
final AtomicBoolean called = new AtomicBoolean(false); |
442 |
// XXX prefer to call just if and when actually starting target, but that is hard to calculate here |
454 |
// XXX prefer to call just if and when actually starting target, but that is hard to calculate here |
443 |
final ActionProgress listener = ActionProgress.start(context); |
455 |
final ActionProgress listener = ActionProgress.start(context); |
444 |
|
456 |
|
445 |
class Action implements Runnable { |
457 |
class Action implements Runnable { |
446 |
|
458 |
|
447 |
/** |
459 |
/** |
448 |
* True when the action always requires access to java model |
|
|
449 |
*/ |
450 |
private boolean needsJavaModel = true; |
451 |
/** |
452 |
* When true getTargetNames accesses java model, when false |
460 |
* When true getTargetNames accesses java model, when false |
453 |
* the default values (possibly incorrect) are used. |
461 |
* the default values (possibly incorrect) are used. |
454 |
*/ |
462 |
*/ |
Lines 457-466
Link Here
|
457 |
|
465 |
|
458 |
@Override |
466 |
@Override |
459 |
public void run () { |
467 |
public void run () { |
460 |
if (!needsJavaModel && caller.get() != Thread.currentThread()) { |
|
|
461 |
return; |
462 |
} |
463 |
called.set(true); |
464 |
try { |
468 |
try { |
465 |
doRun(); |
469 |
doRun(); |
466 |
} finally { |
470 |
} finally { |
Lines 652-675
Link Here
|
652 |
|
656 |
|
653 |
if (getJavaModelActions().contains(command) || (isCompileOnSaveEnabled && getScanSensitiveActions().contains(command))) { |
657 |
if (getJavaModelActions().contains(command) || (isCompileOnSaveEnabled && getScanSensitiveActions().contains(command))) { |
654 |
//Always have to run with java model |
658 |
//Always have to run with java model |
655 |
ScanDialog.runWhenScanFinished(action, commandName(command)); |
659 |
showProgressBarWhileScanningIsInProgress(command); |
656 |
} |
660 |
action.run(); |
657 |
else if (getScanSensitiveActions().contains(command)) { |
661 |
} else if (getScanSensitiveActions().contains(command)) { |
658 |
//Run without model if not yet ready |
662 |
//Run without model if not yet ready |
659 |
try { |
663 |
action.doJavaChecks = !SourceUtils.isScanInProgress(); |
660 |
action.needsJavaModel = false; |
664 |
action.run(); |
661 |
invokeByJavaSource(action); |
665 |
} else { |
662 |
if (!called.get()) { |
666 |
//Does not need java model |
663 |
action.doJavaChecks = false; |
|
|
664 |
action.run(); |
667 |
action.run(); |
665 |
} |
668 |
} |
666 |
} catch (IOException ex) { |
669 |
} |
|
|
670 |
|
671 |
private void showProgressBarWhileScanningIsInProgress(final String command) { |
672 |
assert !EventQueue.isDispatchThread(); |
673 |
// wait for scanning to finish; below code will result into progress bar being shown |
674 |
// and that's all: |
675 |
try { |
676 |
SwingUtilities.invokeAndWait(new Runnable() { |
677 |
@Override |
678 |
public void run() { |
679 |
ScanDialog.runWhenScanFinished(new Runnable() { |
680 |
@Override |
681 |
public void run() { |
682 |
// do nothing here; |
683 |
} |
684 |
}, commandName(command)); |
685 |
} |
686 |
}); |
687 |
} catch (InterruptedException ex) { |
667 |
Exceptions.printStackTrace(ex); |
688 |
Exceptions.printStackTrace(ex); |
668 |
} |
689 |
} catch (InvocationTargetException ex) { |
669 |
} |
690 |
Exceptions.printStackTrace(ex); |
670 |
else { |
|
|
671 |
//Does not need java model |
672 |
action.run(); |
673 |
} |
691 |
} |
674 |
} |
692 |
} |
675 |
|
693 |
|
Lines 741-761
Link Here
|
741 |
protected void updateJavaRunnerClasspath(String command, Map<String, Object> execProperties) { |
759 |
protected void updateJavaRunnerClasspath(String command, Map<String, Object> execProperties) { |
742 |
} |
760 |
} |
743 |
|
761 |
|
744 |
//where |
|
|
745 |
private static void invokeByJavaSource (final Runnable runnable) throws IOException { |
746 |
Parameters.notNull("runnable", runnable); //NOI18N |
747 |
final ClasspathInfo info = ClasspathInfo.create(JavaPlatform.getDefault().getBootstrapLibraries(), |
748 |
ClassPathSupport.createClassPath(new URL[0]), |
749 |
ClassPathSupport.createClassPath(new URL[0])); |
750 |
final JavaSource js = JavaSource.create(info); |
751 |
js.runWhenScanFinished(new org.netbeans.api.java.source.Task<CompilationController>() { |
752 |
@Override |
753 |
public void run(final CompilationController controller) throws Exception { |
754 |
runnable.run(); |
755 |
} |
756 |
}, true); |
757 |
} |
758 |
|
759 |
/** |
762 |
/** |
760 |
* Compatibility |
763 |
* Compatibility |
761 |
* |
764 |
* |