# HG changeset patch # Parent b6e684c1ec436aa9e85aa8b301f36366f64d7547 # User Jesse Glick #211005: suppress indexing only while builds are active. diff --git a/maven/manifest.mf b/maven/manifest.mf --- a/maven/manifest.mf +++ b/maven/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.maven/2 -OpenIDE-Module-Specification-Version: 2.46 +OpenIDE-Module-Specification-Version: 2.47 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/maven/layer.xml AutoUpdate-Show-In-Client: false diff --git a/maven/nbproject/project.xml b/maven/nbproject/project.xml --- a/maven/nbproject/project.xml +++ b/maven/nbproject/project.xml @@ -222,7 +222,7 @@ - 1.0 + 1.1 diff --git a/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java b/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java --- a/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java +++ b/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java @@ -55,7 +55,6 @@ import org.netbeans.modules.maven.execute.MavenExecutor; import org.netbeans.modules.maven.indexer.api.RepositoryIndexer; import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; -import org.netbeans.modules.project.indexingbridge.IndexingBridge; import org.netbeans.spi.project.AuxiliaryProperties; import org.openide.LifecycleManager; import org.openide.execution.ExecutionEngine; @@ -138,15 +137,7 @@ } private static ExecutorTask executeMavenImpl(String runtimeName, final MavenExecutor exec) { - ExecutorTask task = ExecutionEngine.getDefault().execute(runtimeName, new Runnable() { - @Override public void run() { - IndexingBridge.getDefault().runProtected(new Runnable() { - @Override public void run() { - exec.run(); - } - }); - } - }, exec.getInputOutput()); + ExecutorTask task = ExecutionEngine.getDefault().execute(runtimeName, exec, exec.getInputOutput()); exec.setTask(task); return task; } diff --git a/maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java b/maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java --- a/maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java +++ b/maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java @@ -50,6 +50,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.modules.maven.api.execute.RunConfig; import org.netbeans.modules.maven.api.output.ContextOutputProcessorFactory; @@ -58,6 +59,7 @@ import org.netbeans.modules.maven.api.output.OutputProcessorFactory; import org.netbeans.modules.maven.api.output.OutputVisitor; import org.netbeans.api.project.Project; +import org.netbeans.modules.project.indexingbridge.IndexingBridge; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.RequestProcessor; @@ -80,6 +82,7 @@ protected Set currentProcessors; protected Set toFinishProcessors; protected OutputVisitor visitor; + private final AtomicBoolean protectedMode = new AtomicBoolean(); // #211005 private RequestProcessor.Task sleepTask; private static final int SLEEP_DELAY = 5000; @@ -91,8 +94,21 @@ sleepTask = new RequestProcessor(AbstractOutputHandler.class).create(new Runnable() { public @Override void run() { hand.suspend(""); + exitProtectedMode(); } }); + enterProtectedMode(); + } + + private void enterProtectedMode() { + if (protectedMode.compareAndSet(false, true)) { + IndexingBridge.getDefault().enterProtectedMode(); + } + } + private void exitProtectedMode() { + if (protectedMode.compareAndSet(true, false)) { + IndexingBridge.getDefault().exitProtectedMode(); + } } protected abstract InputOutput getIO(); @@ -101,6 +117,7 @@ RequestProcessor.Task task = sleepTask; if (task != null) { task.schedule(SLEEP_DELAY); + enterProtectedMode(); } } @@ -110,6 +127,7 @@ if (task != null) { task.cancel(); sleepTask = null; + exitProtectedMode(); } } diff --git a/o.apache.tools.ant.module/nbproject/project.properties b/o.apache.tools.ant.module/nbproject/project.properties --- a/o.apache.tools.ant.module/nbproject/project.properties +++ b/o.apache.tools.ant.module/nbproject/project.properties @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.6 -spec.version.base=3.54.0 +spec.version.base=3.55.0 compile.ant.jar=${ant.core.lib} src-bridge.cp.extra=build/classes:${compile.ant.jar} extra.module.files=\ diff --git a/o.apache.tools.ant.module/nbproject/project.xml b/o.apache.tools.ant.module/nbproject/project.xml --- a/o.apache.tools.ant.module/nbproject/project.xml +++ b/o.apache.tools.ant.module/nbproject/project.xml @@ -98,7 +98,7 @@ - 1.0 + 1.1 diff --git a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java --- a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java +++ b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java @@ -62,6 +62,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -83,6 +84,7 @@ import org.apache.tools.ant.module.spi.AntSession; import org.apache.tools.ant.module.spi.TaskStructure; import org.netbeans.api.progress.ProgressHandle; +import org.netbeans.modules.project.indexingbridge.IndexingBridge; import org.openide.awt.StatusDisplayer; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -119,9 +121,11 @@ private final Runnable interestingOutputCallback; private final ProgressHandle handle; private boolean insideRunTask = false; // #95201 + private final AtomicBoolean protectedMode = new AtomicBoolean(); // #211005 private final RequestProcessor.Task sleepTask = new RequestProcessor(NbBuildLogger.class.getName(), 1, false, false).create(new Runnable() { public @Override void run() { handle.suspend(insideRunTask ? NbBundle.getMessage(NbBuildLogger.class, "MSG_sleep_running") : ""); + exitProtectedMode(); } }); private static final int SLEEP_DELAY = 5000; @@ -189,6 +193,18 @@ this.interestingOutputCallback = interestingOutputCallback; this.handle = handle; LOG.log(Level.FINE, "---- Initializing build of {0} \"{1}\" at verbosity {2} ----", new Object[] {origScript, displayName, verbosity}); + enterProtectedMode(); + } + + private void enterProtectedMode() { + if (protectedMode.compareAndSet(false, true)) { + IndexingBridge.getDefault().enterProtectedMode(); + } + } + private void exitProtectedMode() { + if (protectedMode.compareAndSet(true, false)) { + IndexingBridge.getDefault().exitProtectedMode(); + } } /** Try to stop running at the next safe point. */ @@ -204,6 +220,7 @@ } if (running) { handle.switchToIndeterminate(); + enterProtectedMode(); sleepTask.schedule(SLEEP_DELAY); } } @@ -219,6 +236,7 @@ err.close(); handle.finish(); sleepTask.cancel(); + exitProtectedMode(); } private void verifyRunning() { diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java --- a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java +++ b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java @@ -75,7 +75,6 @@ import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.netbeans.modules.options.java.api.JavaOptions; -import org.netbeans.modules.project.indexingbridge.IndexingBridge; import org.openide.ErrorManager; import org.openide.LifecycleManager; import org.openide.awt.Actions; @@ -539,11 +538,7 @@ for (RerunAction ra : ras) { setEnabledEQ(ra, false); } - IndexingBridge.getDefault().runProtected(new Runnable() { - @Override public void run() { - ok = AntBridge.getInterface().run(buildFile, targetNames, in.get(), out, err, properties, verbosity, displayName, interestingOutputCallback, handle, io); - } - }); + ok = AntBridge.getInterface().run(buildFile, targetNames, in.get(), out, err, properties, verbosity, displayName, interestingOutputCallback, handle, io); } finally { if (io != null) { diff --git a/parsing.api/nbproject/project.properties b/parsing.api/nbproject/project.properties --- a/parsing.api/nbproject/project.properties +++ b/parsing.api/nbproject/project.properties @@ -3,7 +3,7 @@ javac.source=1.6 javadoc.apichanges=${basedir}/apichanges.xml javadoc.arch=${basedir}/arch.xml -spec.version.base=1.52.0 +spec.version.base=1.53.0 test.config.stableBTD.includes=**/*Test.class test.config.stableBTD.excludes=\ diff --git a/parsing.api/nbproject/project.xml b/parsing.api/nbproject/project.xml --- a/parsing.api/nbproject/project.xml +++ b/parsing.api/nbproject/project.xml @@ -118,7 +118,7 @@ - 1.0 + 1.1 diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/IndexingBridgeImpl.java b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/IndexingBridgeImpl.java deleted file mode 100644 --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/IndexingBridgeImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2012 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2012 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.parsing.impl.indexing; - -import java.util.concurrent.Callable; -import org.netbeans.modules.parsing.api.indexing.IndexingManager; -import org.netbeans.modules.project.indexingbridge.IndexingBridge; -import org.openide.util.lookup.ServiceProvider; - -@ServiceProvider(service=IndexingBridge.class) -public class IndexingBridgeImpl extends IndexingBridge { - - @Override public T runProtected(Callable operation) throws Exception { - return IndexingManager.getDefault().runProtected(operation); - } - -} diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java +++ b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java @@ -111,6 +111,7 @@ import org.netbeans.modules.parsing.spi.ParseException; import org.netbeans.modules.parsing.spi.Parser; import org.netbeans.modules.parsing.spi.indexing.*; +import org.netbeans.modules.project.indexingbridge.IndexingBridge; import org.openide.filesystems.FileChangeAdapter; import org.openide.filesystems.FileChangeListener; import org.openide.filesystems.FileEvent; @@ -4945,16 +4946,17 @@ } } - public void enterProtectedMode() { + public void enterProtectedMode(@NullAllowed Long id) { synchronized (todo) { - protectedOwners.add(Thread.currentThread().getId()); + protectedOwners.add(id); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Entering protected mode: {0}", protectedOwners.size()); //NOI18N + // Call toString() now since exitProtectedMode might run before the log handler formats the record: + LOGGER.log(Level.FINE, "Entering protected mode: {0}", protectedOwners.toString()); //NOI18N } } } - public void exitProtectedMode(Runnable followupTask) { + public void exitProtectedMode(@NullAllowed Long id, @NullAllowed Runnable followupTask) { synchronized (todo) { if (protectedOwners.isEmpty()) { throw new IllegalStateException("Calling exitProtectedMode without enterProtectedMode"); //NOI18N @@ -4967,9 +4969,9 @@ } followupTasks.add(followupTask); } - protectedOwners.remove(Thread.currentThread().getId()); + protectedOwners.remove(id); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Exiting protected mode: {0}", protectedOwners.size()); //NOI18N + LOGGER.log(Level.FINE, "Exiting protected mode: {0}", protectedOwners.toString()); //NOI18N } if (protectedOwners.isEmpty()) { @@ -5194,6 +5196,17 @@ return w; } } + + @ServiceProvider(service=IndexingBridge.class) + public static class IndexingBridgeImpl extends IndexingBridge { + @Override public void enterProtectedMode() { + RepositoryUpdater.getDefault().getWorker().enterProtectedMode(null); + } + @Override public void exitProtectedMode() { + RepositoryUpdater.getDefault().getWorker().exitProtectedMode(null, null); + } + } + } // End of Task class private static final class DependenciesContext { @@ -5343,12 +5356,12 @@ @Override public void enterProtectedMode() { - getWorker().enterProtectedMode(); + getWorker().enterProtectedMode(Thread.currentThread().getId()); } @Override public void exitProtectedMode(Runnable followUpTask) { - getWorker().exitProtectedMode(followUpTask); + getWorker().exitProtectedMode(Thread.currentThread().getId(), followUpTask); } @Override diff --git a/project.indexingbridge/manifest.mf b/project.indexingbridge/manifest.mf --- a/project.indexingbridge/manifest.mf +++ b/project.indexingbridge/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.project.indexingbridge OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/indexingbridge/Bundle.properties -OpenIDE-Module-Specification-Version: 1.0 +OpenIDE-Module-Specification-Version: 1.1 diff --git a/project.indexingbridge/src/org/netbeans/modules/project/indexingbridge/IndexingBridge.java b/project.indexingbridge/src/org/netbeans/modules/project/indexingbridge/IndexingBridge.java --- a/project.indexingbridge/src/org/netbeans/modules/project/indexingbridge/IndexingBridge.java +++ b/project.indexingbridge/src/org/netbeans/modules/project/indexingbridge/IndexingBridge.java @@ -42,39 +42,37 @@ package org.netbeans.modules.project.indexingbridge; -import java.util.concurrent.Callable; import org.openide.util.Lookup; /** - * @see org.netbeans.modules.parsing.api.indexing.IndexingManager + * Allows parser indexing to be temporarily suppressed. + * Unlike {@code org.netbeans.modules.parsing.api.indexing.IndexingManager} + * this is not block-scoped. Every call to {@link #enterProtectedMode} must + * eventually be matched by exactly one call to {@link #exitProtectedMode}. + * It is irrelevant which thread makes each call. It is permissible to make + * multiple enter calls so long as an equal number of exit calls are eventually + * made as well. */ public abstract class IndexingBridge { protected IndexingBridge() {} - public abstract T runProtected(Callable operation) throws Exception; + /** + * Begin suppression of indexing. + */ + public abstract void enterProtectedMode(); - public final void runProtected(final Runnable operation) { - try { - runProtected(new Callable() { - @Override public Void call() throws Exception { - operation.run(); - return null; - } - }); - } catch (RuntimeException x) { - throw x; - } catch (Exception x) { - throw new AssertionError(x); - } - } + /** + * End suppression of indexing. + * Indexing may resume if this is the last matching call. + */ + public abstract void exitProtectedMode(); public static IndexingBridge getDefault() { IndexingBridge b = Lookup.getDefault().lookup(IndexingBridge.class); return b != null ? b : new IndexingBridge() { - @Override public T runProtected(Callable operation) throws Exception { - return operation.call(); - } + @Override public void enterProtectedMode() {} + @Override public void exitProtectedMode() {} }; } diff --git a/projectui/nbproject/project.properties b/projectui/nbproject/project.properties --- a/projectui/nbproject/project.properties +++ b/projectui/nbproject/project.properties @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.6 -spec.version.base=1.32.0 +spec.version.base=1.33.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff --git a/projectui/nbproject/project.xml b/projectui/nbproject/project.xml --- a/projectui/nbproject/project.xml +++ b/projectui/nbproject/project.xml @@ -99,7 +99,7 @@ - 1.0 + 1.1 diff --git a/projectui/src/org/netbeans/modules/project/ui/groups/Group.java b/projectui/src/org/netbeans/modules/project/ui/groups/Group.java --- a/projectui/src/org/netbeans/modules/project/ui/groups/Group.java +++ b/projectui/src/org/netbeans/modules/project/ui/groups/Group.java @@ -396,8 +396,8 @@ toOpen.removeAll(oldOpen); assert !toClose.contains(null) : toClose; assert !toOpen.contains(null) : toOpen; - IndexingBridge.getDefault().runProtected(new Runnable() { - @Override public void run() { + IndexingBridge.getDefault().enterProtectedMode(); + try { h.progress(Group_progress_closing(toClose.size()), 110); opl.close(toClose.toArray(new Project[toClose.size()]), false); h.switchToIndeterminate(); @@ -406,8 +406,9 @@ if (g != null) { opl.setMainProject(g.getMainProject()); } - } - }); + } finally { + IndexingBridge.getDefault().exitProtectedMode(); + } } finally { ProjectUtilities.WaitCursor.hide(); h.finish();