--- a/java.api.common/src/org/netbeans/modules/java/api/common/project/BaseActionProvider.java +++ a/java.api.common/src/org/netbeans/modules/java/api/common/project/BaseActionProvider.java @@ -52,6 +52,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; @@ -99,6 +100,7 @@ import org.netbeans.api.java.source.CompilationController; import org.netbeans.api.java.source.ElementHandle; import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.java.source.SourceUtils; import org.netbeans.api.java.source.ui.ScanDialog; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; @@ -144,6 +146,7 @@ import org.openide.util.Lookup; import org.openide.util.NbBundle.Messages; import org.openide.util.Parameters; +import org.openide.util.RequestProcessor; import org.openide.util.Task; import org.openide.util.TaskListener; import org.openide.util.lookup.Lookups; @@ -202,6 +205,8 @@ private boolean serverExecution = false; + private static RequestProcessor RP = new RequestProcessor("BaseActionProvider", 10); // NOI18N + public BaseActionProvider(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, SourceRoots sourceRoots, SourceRoots testRoots, AntProjectHelper antProjectHelper, Callback callback) { this.antProjectHelper = antProjectHelper; @@ -416,6 +421,15 @@ @Override public void invokeAction( final String command, final Lookup context ) throws IllegalArgumentException { assert EventQueue.isDispatchThread(); + RP.post(new Runnable() { + @Override + public void run() { + invokeAction_(command, context); + } + }); + } + + private void invokeAction_( final String command, final Lookup context ) throws IllegalArgumentException { if (COMMAND_DELETE.equals(command)) { DefaultProjectOperations.performDefaultDeleteOperation(project); return ; @@ -437,18 +451,12 @@ } final boolean isCompileOnSaveEnabled = isCompileOnSaveEnabled(); - final AtomicReference caller = new AtomicReference(Thread.currentThread()); - final AtomicBoolean called = new AtomicBoolean(false); // XXX prefer to call just if and when actually starting target, but that is hard to calculate here final ActionProgress listener = ActionProgress.start(context); class Action implements Runnable { /** - * True when the action always requires access to java model - */ - private boolean needsJavaModel = true; - /** * When true getTargetNames accesses java model, when false * the default values (possibly incorrect) are used. */ @@ -457,10 +465,6 @@ @Override public void run () { - if (!needsJavaModel && caller.get() != Thread.currentThread()) { - return; - } - called.set(true); try { doRun(); } finally { @@ -652,24 +656,38 @@ if (getJavaModelActions().contains(command) || (isCompileOnSaveEnabled && getScanSensitiveActions().contains(command))) { //Always have to run with java model - ScanDialog.runWhenScanFinished(action, commandName(command)); - } - else if (getScanSensitiveActions().contains(command)) { + showProgressBarWhileScanningIsInProgress(command); + action.run(); + } else if (getScanSensitiveActions().contains(command)) { //Run without model if not yet ready - try { - action.needsJavaModel = false; - invokeByJavaSource(action); - if (!called.get()) { - action.doJavaChecks = false; + action.doJavaChecks = !SourceUtils.isScanInProgress(); + action.run(); + } else { + //Does not need java model action.run(); } - } catch (IOException ex) { + } + + private void showProgressBarWhileScanningIsInProgress(final String command) { + assert !EventQueue.isDispatchThread(); + // wait for scanning to finish; below code will result into progress bar being shown + // and that's all: + try { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + ScanDialog.runWhenScanFinished(new Runnable() { + @Override + public void run() { + // do nothing here; + } + }, commandName(command)); + } + }); + } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); - } - } - else { - //Does not need java model - action.run(); + } catch (InvocationTargetException ex) { + Exceptions.printStackTrace(ex); } } @@ -741,21 +759,6 @@ protected void updateJavaRunnerClasspath(String command, Map execProperties) { } - //where - private static void invokeByJavaSource (final Runnable runnable) throws IOException { - Parameters.notNull("runnable", runnable); //NOI18N - final ClasspathInfo info = ClasspathInfo.create(JavaPlatform.getDefault().getBootstrapLibraries(), - ClassPathSupport.createClassPath(new URL[0]), - ClassPathSupport.createClassPath(new URL[0])); - final JavaSource js = JavaSource.create(info); - js.runWhenScanFinished(new org.netbeans.api.java.source.Task() { - @Override - public void run(final CompilationController controller) throws Exception { - runnable.run(); - } - }, true); - } - /** * Compatibility *