# HG changeset patch # User Alexander Simon # Date 1441712647 -10800 # Tue Sep 08 14:44:07 2015 +0300 # Node ID 3d45cbccb23c5ca715a4f1b3a05544396928f0ba # Parent 3deb0e7d45620887042b36f902652dc863aee864 fixed Bug #242340 org.netbeans.modules.progress.ui.RunOffEDTImpl.runOffEventThreadCustomDialogImpl: LowPerformance took 64795 ms. diff --git a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/MakeActionProvider.java b/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/MakeActionProvider.java --- a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/MakeActionProvider.java +++ b/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/MakeActionProvider.java @@ -141,6 +141,7 @@ import org.netbeans.modules.nativeexecution.api.util.ShellValidationSupport.ShellValidationStatus; import org.netbeans.modules.nativeexecution.api.util.WindowsSupport; import org.netbeans.modules.remote.spi.FileSystemProvider; +import org.netbeans.spi.project.ActionProgress; import org.netbeans.spi.project.ActionProvider; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; @@ -223,6 +224,7 @@ private static final String DEBUG_TEST_STEP = "debug-test"; // NOI18N private static final String DEBUG_STEPINTO_TEST_STEP = "debug-stepinto-test"; // NOI18N private static final RequestProcessor RP = new RequestProcessor("Make Action RP", 1);// NOI18N + private static final boolean PARALLEL_POST = "true".equals(System.getProperty("org.netbeans.modules.cnd.makeproject.parallel-build", "false")); public MakeActionProvider(MakeProject project) { this.project = project; @@ -332,24 +334,39 @@ confs.add(activeConf); } final String finalCommand = command; + ActionProgress progress; + if (PARALLEL_POST) { + progress = null; + } else { + progress = ActionProgress.start(context); + } - CancellableTask actionWorker = new CancellableTask() { + CancellableTask actionWorker = new CancellableTask(progress) { @Override protected void runImpl() { final ArrayList actionEvents = new ArrayList<>(); for (MakeConfiguration conf : confs) { - addAction(actionEvents, pd, conf, finalCommand, context, cancelled); + if (!addAction(actionEvents, pd, conf, finalCommand, context, cancelled)) { + if (!cancelled.isCanceled()) { + cancelled.actionProgress.finished(false); + } + return; + } } // Execute actions - if (actionEvents.size() > 0 && !cancelled.isCanceled()) { - RP.post(new NamedRunnable("Make Project Action Worker") { //NOI18N + if (!cancelled.isCanceled()) { + if (actionEvents.size() > 0) { + RP.post(new NamedRunnable("Make Project Action Worker") { //NOI18N - @Override - protected void runImpl() { - ProjectActionSupport.getInstance().fireActionPerformed(actionEvents.toArray(new ProjectActionEvent[actionEvents.size()])); - } - }); + @Override + protected void runImpl() { + ProjectActionSupport.getInstance().fireActionPerformed(actionEvents.toArray(new ProjectActionEvent[actionEvents.size()]),null, cancelled.actionProgress); + } + }); + } else { + cancelled.actionProgress.finished(false); + } } } }; @@ -364,7 +381,7 @@ } public void invokeCustomAction(final MakeConfigurationDescriptor pd, final MakeConfiguration conf, final ProjectActionHandler customProjectActionHandler) { - CancellableTask actionWorker = new CancellableTask() { + CancellableTask actionWorker = new CancellableTask(null) { @Override protected void runImpl() { @@ -400,7 +417,7 @@ } } // start validation phase - wrapper = new CancellableTask() { + wrapper = new CancellableTask(actionWorker.cancelled.actionProgress) { @Override public boolean cancel() { @@ -451,12 +468,12 @@ } } - private void addAction(ArrayList actionEvents, + private boolean addAction(ArrayList actionEvents, MakeConfigurationDescriptor pd, MakeConfiguration conf, String command, Lookup context, CanceledState cancelled) throws IllegalArgumentException { if (cancelled.isCanceled()) { - return; + return false; } AtomicBoolean validated = new AtomicBoolean(false); @@ -464,7 +481,7 @@ String[] targetNames = getTargetNames(command, conf, context); if (targetNames == null || targetNames.length == 0) { - return; + return false; } for (int i = 0; i < targetNames.length; i++) { @@ -477,15 +494,16 @@ if (delegate != null) { for (String target : delegate) { if (!addTarget(target, actionEvents, pd, conf, context, cancelled, validated)) { - break; + return false; } } } else { if (!addTarget(targetName, actionEvents, pd, conf, context, cancelled, validated)) { - break; + return false; } } } + return true; } private boolean addTarget(String targetName, ArrayList actionEvents, @@ -1948,6 +1966,12 @@ } private abstract static class CancellableTask implements Runnable, Cancellable { + private volatile Thread thread; + protected final CanceledState cancelled; + + CancellableTask(ActionProgress actionProgress) { + cancelled = new CanceledState(actionProgress); + } protected abstract void runImpl(); @@ -1967,20 +1991,22 @@ } return true; } - - private volatile Thread thread; - protected final CanceledState cancelled = new CanceledState(); } private static final class CanceledState { private final AtomicBoolean cancelled = new AtomicBoolean(false); private final AtomicBoolean interruptable = new AtomicBoolean(true); + final ActionProgress actionProgress; - private CanceledState() { + private CanceledState(ActionProgress actionProgress) { + this.actionProgress = actionProgress; } public synchronized void cancel() { cancelled.set(true); + if (actionProgress != null) { + actionProgress.finished(false); + } } public synchronized boolean isCanceled() { diff --git a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/api/ProjectActionSupport.java b/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/api/ProjectActionSupport.java --- a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/api/ProjectActionSupport.java +++ b/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/api/ProjectActionSupport.java @@ -101,6 +101,7 @@ import org.netbeans.modules.nativeexecution.api.util.ProcessUtils; import org.netbeans.modules.nativeexecution.api.util.ProcessUtils.ExitStatus; import org.netbeans.modules.remote.spi.FileSystemProvider; +import org.netbeans.spi.project.ActionProgress; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.LifecycleManager; @@ -254,7 +255,11 @@ } public void fireActionPerformed(ProjectActionEvent[] paes, ProjectActionHandler preferredHandler) { - submitTask(new EventsProcessor(paes, preferredHandler)); + fireActionPerformed(paes, null, null); + } + + public void fireActionPerformed(ProjectActionEvent[] paes, ProjectActionHandler preferredHandler, ActionProgress actionProgress) { + submitTask(new EventsProcessor(paes, preferredHandler, actionProgress)); } private static void submitTask(final EventsProcessor eventsProcessor) { @@ -347,12 +352,14 @@ private List additional; private final ProjectActionHandler customHandler; private final FileOperationsNotifier fon; + private final ActionProgress actionProgress; - public EventsProcessor(ProjectActionEvent[] paes, ProjectActionHandler customHandler) { + public EventsProcessor(ProjectActionEvent[] paes, ProjectActionHandler customHandler, ActionProgress actionProgress) { this.paes = paes; this.customHandler = customHandler; fon = getFileOperationsNotifier(paes); tabs = IOTabsController.getDefault().openTabsGroup(getTabName(paes), MakeOptions.getInstance().getReuse()); + this.actionProgress = actionProgress; } private Action[] getActions(String name) { @@ -442,12 +449,14 @@ final AtomicInteger currentEventIndex = new AtomicInteger(-1); final AtomicReference currentIORef = new AtomicReference<>(null); - + final AtomicBoolean result = new AtomicBoolean(true); + try { for (final ProjectActionEvent currentEvent : paes) { currentEventIndex.incrementAndGet(); if (!ProjectActionSupport.checkProject(currentEvent)) { + result.set(false); return; } @@ -464,6 +473,7 @@ if ((isRunAction || type == PredefinedType.CHECK_EXECUTABLE)) { if (!checkExecutable(currentEvent)) { + result.set(false); return; } } @@ -573,6 +583,7 @@ try { stopAction.setEnabled(false); stepFailed.set(rc != 0); + result.set(rc == 0); if (additional != null) { for (Action action : additional) { try { @@ -625,6 +636,9 @@ rerunModAction.setEnabled(true); stopAction.setEnabled(false); fon.finishAll(); + if (actionProgress != null) { + actionProgress.finished(result.get()); + } } }