# HG changeset patch # User Alexander Simon # Date 1469117567 -10800 # Thu Jul 21 19:12:47 2016 +0300 # Node ID 7fe718d2b0db481c2a73a9da47c553d156b20c9e # Parent fdd1984322477ebce0f7495d33dafc788613fa6e 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/MakeActionProviderImpl.java b/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/MakeActionProviderImpl.java --- a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/MakeActionProviderImpl.java +++ b/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/MakeActionProviderImpl.java @@ -137,6 +137,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.openide.LifecycleManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; @@ -203,6 +204,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 MakeActionProviderImpl(MakeProject project) { this.project = project; @@ -312,24 +314,38 @@ 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, getCancelled())) { + if (!getCancelled().isCanceled()) { + getCancelled().getActionProgress().finished(false); + } + return; + } } // Execute actions - if (actionEvents.size() > 0 && !cancelled.isCanceled()) { - RP.post(new NamedRunnable("Make Project Action Worker") { //NOI18N - - @Override - protected void runImpl() { - ProjectActionSupport.getInstance().fireActionPerformed(actionEvents.toArray(new ProjectActionEvent[actionEvents.size()])); - } - }); + if (!getCancelled().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()]),null, getCancelled().getActionProgress()); + } + }); + } else { + getCancelled().getActionProgress().finished(false); + } } } }; @@ -344,12 +360,12 @@ } 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() { ArrayList actionEvents = new ArrayList<>(); - addAction(actionEvents, pd, conf, MakeActionProviderImpl.COMMAND_CUSTOM_ACTION, null, cancelled); + addAction(actionEvents, pd, conf, MakeActionProviderImpl.COMMAND_CUSTOM_ACTION, null, getCancelled()); ProjectActionSupport.getInstance().fireActionPerformed( actionEvents.toArray(new ProjectActionEvent[actionEvents.size()]), customProjectActionHandler); @@ -380,7 +396,7 @@ } } // start validation phase - wrapper = new CancellableTask() { + wrapper = new CancellableTask(actionWorker.getCancelled().getActionProgress()) { @Override public boolean cancel() { @@ -419,12 +435,12 @@ NbBundle.getMessage(MakeActionProviderImpl.class, "MSG_Validate_Host", record.getDisplayName())); } - 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); @@ -432,7 +448,7 @@ String[] targetNames = getTargetNames(command, conf, context); if (targetNames == null || targetNames.length == 0) { - return; + return false; } for (int i = 0; i < targetNames.length; i++) { @@ -454,6 +470,7 @@ } } } + return true; } private boolean addTarget(String targetName, ArrayList actionEvents, 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 @@ -58,7 +58,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.Action; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; @@ -98,6 +97,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.LifecycleManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; @@ -107,7 +107,6 @@ import org.openide.util.RequestProcessor; import org.openide.util.Utilities; import org.openide.windows.IOProvider; -import org.openide.windows.InputOutput; /** * Most of the code here came from DefaultProjectActionHandler as result of @@ -241,9 +240,12 @@ } public void fireActionPerformed(ProjectActionEvent[] paes, ProjectActionHandler preferredHandler) { - submitTask(new EventsProcessorImpl(paes, preferredHandler)); + fireActionPerformed(paes, null, null); } + public void fireActionPerformed(ProjectActionEvent[] paes, ProjectActionHandler preferredHandler, ActionProgress actionProgress) { + submitTask(new EventsProcessorImpl(paes, preferredHandler, actionProgress)); + } private static void submitTask(final EventsProcessorImpl eventsProcessor) { tasksProcessor.post(eventsProcessor); } @@ -330,13 +332,15 @@ private final ProjectActionHandler customHandler; private final FileOperationsNotifier fon; private final EventsProcessorActions epa; + private final ActionProgress actionProgress; - public EventsProcessorImpl(ProjectActionEvent[] paes, ProjectActionHandler customHandler) { + public EventsProcessorImpl(ProjectActionEvent[] paes, ProjectActionHandler customHandler, ActionProgress actionProgress) { this.paes = paes; this.customHandler = customHandler; epa = EventsProcessorActions.getEventsProcessorActionsFactory().getEventsProcessorActions(this); fon = getFileOperationsNotifier(paes); tabs = IOTabsController.getDefault().openTabsGroup(getTabName(paes), MakeOptions.getInstance().getReuse()); + this.actionProgress = actionProgress; } @Override @@ -402,12 +406,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; } @@ -425,6 +431,7 @@ if ((isRunAction || type == PredefinedType.CHECK_EXECUTABLE)) { if (!checkExecutable(currentEvent)) { + result.set(false); return; } } @@ -518,6 +525,7 @@ try { epa.setEnableStopAction(false); stepFailed.set(rc != 0); + result.set(rc == 0); if (epa.getAdditional() != null) { epa.getAdditional().forEach((action) -> { try { @@ -570,6 +578,9 @@ epa.setEnableRerunModAction(true); epa.setEnableStopAction(false); fon.finishAll(); + if (actionProgress != null) { + actionProgress.finished(result.get()); + } } } diff --git a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/uiapi/LongOperation.java b/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/uiapi/LongOperation.java --- a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/uiapi/LongOperation.java +++ b/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/uiapi/LongOperation.java @@ -40,6 +40,7 @@ package org.netbeans.modules.cnd.makeproject.uiapi; import java.util.concurrent.atomic.AtomicBoolean; +import org.netbeans.spi.project.ActionProgress; import org.openide.util.Cancellable; import org.openide.util.Lookup; @@ -51,12 +52,17 @@ public static final class CanceledState { private final AtomicBoolean cancelled = new AtomicBoolean(false); private final AtomicBoolean interruptable = new AtomicBoolean(true); + private 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() { @@ -70,10 +76,20 @@ public synchronized boolean isInterruptable(){ return interruptable.get(); } + + public ActionProgress getActionProgress() { + return actionProgress; + } } public abstract static class CancellableTask implements Runnable, Cancellable { + private volatile Thread thread; + private final CanceledState cancelled; + public CancellableTask(ActionProgress actionProgress) { + cancelled = new CanceledState(actionProgress); + } + protected abstract void runImpl(); @Override @@ -93,8 +109,9 @@ return true; } - private volatile Thread thread; - protected final CanceledState cancelled = new CanceledState(); + public CanceledState getCancelled() { + return cancelled; + } } public abstract void executeLongOperation(CancellableTask task, String title, String message);