do not use runPostStartupActivitiesRegisteredDynamically in tests explicitly

GitOrigin-RevId: 7fd383c5d7fc98071d77a5a3ad43319279d479d2
This commit is contained in:
Vladimir Krivosheev
2020-06-01 17:04:12 +02:00
committed by intellij-monorepo-bot
parent 09e1157e31
commit 2acb8aa019
8 changed files with 48 additions and 104 deletions

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.framework.detection.impl;
import com.intellij.framework.detection.DetectedFrameworkDescription;
@@ -36,14 +22,14 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
public class DetectedFrameworksData {
public final class DetectedFrameworksData {
private static final Logger LOG = Logger.getInstance(DetectedFrameworksData.class);
private PersistentHashMap<Integer,TIntHashSet> myExistentFrameworkFiles;
private PersistentHashMap<Integer, TIntHashSet> myExistentFrameworkFiles;
private final TIntObjectHashMap<TIntHashSet> myNewFiles;
private final MultiMap<Integer, DetectedFrameworkDescription> myDetectedFrameworks;
private final Object myLock = new Object();
public DetectedFrameworksData(Project project) {
public DetectedFrameworksData(@NotNull Project project) {
myDetectedFrameworks = new MultiMap<>();
Path file = ProjectUtil.getProjectCachePath(project, FrameworkDetectorRegistryImpl.getDetectionDirPath(), true).resolve("files");
myNewFiles = new TIntObjectHashMap<>();

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.framework.detection.impl;
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
@@ -39,6 +39,9 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
@@ -54,7 +57,7 @@ public final class FrameworkDetectionManager implements FrameworkDetectionIndexL
doRunDetection();
}
};
private final Set<Integer> myDetectorsToProcess = new HashSet<>();
private final IntSet myDetectorsToProcess = new IntOpenHashSet();
private final Project myProject;
private MergingUpdateQueue myDetectionQueue;
private final Object myLock = new Object();
@@ -71,11 +74,11 @@ public final class FrameworkDetectionManager implements FrameworkDetectionIndexL
doInitialize();
}
StartupManager.getInstance(myProject).registerPostStartupActivity(() -> {
final Collection<Integer> ids = FrameworkDetectorRegistry.getInstance().getAllDetectorIds();
StartupManager.getInstance(myProject).runAfterOpened(() -> {
int[] ids = FrameworkDetectorRegistry.getInstance().getAllDetectorIds();
synchronized (myLock) {
myDetectorsToProcess.clear();
myDetectorsToProcess.addAll(ids);
myDetectorsToProcess.addAll(IntArrayList.wrap(ids));
}
queueDetection();
});
@@ -132,7 +135,7 @@ public final class FrameworkDetectionManager implements FrameworkDetectionIndexL
@Override
public void fileUpdated(@NotNull VirtualFile file, @NotNull Integer detectorId) {
synchronized (myLock) {
myDetectorsToProcess.add(detectorId);
myDetectorsToProcess.add(detectorId.intValue());
}
queueDetection();
}
@@ -144,13 +147,14 @@ public final class FrameworkDetectionManager implements FrameworkDetectionIndexL
}
private void doRunDetection() {
Set<Integer> detectorsToProcess;
IntSet detectorsToProcess;
synchronized (myLock) {
detectorsToProcess = new HashSet<>(myDetectorsToProcess);
detectorsToProcess.addAll(myDetectorsToProcess);
detectorsToProcess = new IntOpenHashSet(myDetectorsToProcess);
myDetectorsToProcess.clear();
}
if (detectorsToProcess.isEmpty()) return;
if (detectorsToProcess.isEmpty()) {
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Starting framework detectors: " + detectorsToProcess);
@@ -272,7 +276,13 @@ public final class FrameworkDetectionManager implements FrameworkDetectionIndexL
return getValidDetectedFrameworks();
}
private static void ensureIndexIsUpToDate(@NotNull Project project, final Collection<Integer> detectors) {
private static void ensureIndexIsUpToDate(@NotNull Project project, int[] detectors) {
for (int detectorId : detectors) {
FileBasedIndex.getInstance().getValues(FrameworkDetectionIndex.NAME, detectorId, GlobalSearchScope.projectScope(project));
}
}
private static void ensureIndexIsUpToDate(@NotNull Project project, Collection<Integer> detectors) {
for (Integer detectorId : detectors) {
FileBasedIndex.getInstance().getValues(FrameworkDetectionIndex.NAME, detectorId, GlobalSearchScope.projectScope(project));
}

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.framework.detection.impl;
import com.intellij.framework.FrameworkType;
@@ -52,7 +38,7 @@ public abstract class FrameworkDetectorRegistry {
@NotNull
public abstract Collection<Integer> getDetectorIds(@NotNull FileType fileType);
public abstract Collection<Integer> getAllDetectorIds();
public abstract int[] getAllDetectorIds();
@NotNull
public abstract MultiMap<FileType, Pair<ElementPattern<FileContent>, Integer>> getDetectorsMap();

View File

@@ -15,8 +15,10 @@ import com.intellij.patterns.ElementPattern;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.indexing.FileContent;
import com.intellij.util.io.PathKt;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TObjectIntHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import org.jetbrains.annotations.NotNull;
import java.io.*;
@@ -28,8 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public final class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegistry implements Disposable {
private static final Logger LOG = Logger.getInstance(FrameworkDetectorRegistryImpl.class);
private static final int REGISTRY_VERSION = 0;
private TObjectIntHashMap<String> myDetectorIds;
private TIntObjectHashMap<FrameworkDetector> myDetectorById;
private Object2IntMap<String> myDetectorIds;
private Int2ObjectMap<FrameworkDetector> myDetectorById;
private MultiMap<FileType, Integer> myDetectorsByFileType;
private int myDetectorsVersion;
private volatile MultiMap<FileType, Pair<ElementPattern<FileContent>, Integer>> myDetectorsMap;
@@ -50,8 +52,8 @@ public final class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegist
@Override
public void extensionRemoved(@NotNull FrameworkDetector detector, @NotNull PluginDescriptor pluginDescriptor) {
if (myDetectorIds.contains(detector.getDetectorId())) {
int id = myDetectorIds.remove(detector.getDetectorId());
if (myDetectorIds.containsKey(detector.getDetectorId())) {
int id = myDetectorIds.removeInt(detector.getDetectorId());
myDetectorById.remove(id);
myDetectorsByFileType.remove(detector.getFileType(), id);
onDetectorsChanged();
@@ -67,7 +69,7 @@ public final class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegist
newDetectors.put(detector.getDetectorId(), detector);
}
myDetectorIds = new TObjectIntHashMap<>();
myDetectorIds = new Object2IntOpenHashMap<>();
final Path file = getDetectorsRegistryFile();
int maxId = REGISTRY_VERSION;
if (Files.exists(file)) {
@@ -114,10 +116,10 @@ public final class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegist
for (String newDetector : newDetectors.keySet()) {
myDetectorIds.put(newDetector, myNextId.getAndIncrement());
}
myDetectorById = new TIntObjectHashMap<>();
myDetectorById = new Int2ObjectOpenHashMap<>();
myDetectorsByFileType = new MultiMap<>();
for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
final int id = myDetectorIds.get(detector.getDetectorId());
final int id = myDetectorIds.getInt(detector.getDetectorId());
myDetectorsByFileType.putValue(detector.getFileType(), id);
myDetectorById.put(id, detector);
LOG.debug("'" + detector.getDetectorId() + "' framework detector: id = " + id);
@@ -137,7 +139,7 @@ public final class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegist
output.writeInt(detectors.length);
for (FrameworkDetector detector : detectors) {
output.writeUTF(detector.getDetectorId());
output.writeInt(myDetectorIds.get(detector.getDetectorId()));
output.writeInt(myDetectorIds.getInt(detector.getDetectorId()));
output.writeInt(detector.getDetectorVersion());
}
}
@@ -203,7 +205,7 @@ public final class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegist
@NotNull
@Override
public List<? extends FrameworkType> getFrameworkTypes() {
final List<FrameworkType> types = new ArrayList<>();
List<FrameworkType> types = new ArrayList<>();
for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
types.add(detector.getFrameworkType());
}
@@ -217,7 +219,7 @@ public final class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegist
@Override
public int getDetectorId(@NotNull FrameworkDetector detector) {
return myDetectorIds.get(detector.getDetectorId());
return myDetectorIds.getInt(detector.getDetectorId());
}
@Override
@@ -232,13 +234,8 @@ public final class FrameworkDetectorRegistryImpl extends FrameworkDetectorRegist
}
@Override
public Collection<Integer> getAllDetectorIds() {
final int[] ids = myDetectorIds.getValues();
final List<Integer> result = new ArrayList<>();
for (int id : ids) {
result.add(id);
}
return result;
public int[] getAllDetectorIds() {
return myDetectorIds.values().toIntArray();
}
@Override

View File

@@ -36,7 +36,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
@@ -180,17 +179,6 @@ public class StartupManagerImpl extends StartupManagerEx {
});
}
/**
* @deprecated Use {@link com.intellij.testFramework.PlatformTestUtil#loadAndOpenProject(Path)} in tests.
*/
@TestOnly
@Deprecated
public void runStartupActivities() {
if (!myStartupActivitiesPassed) {
runStartUpActivities(null);
}
}
// Must be executed in a pooled thread outside of project loading modal task. The only exclusion - test mode.
private void runPostStartupActivities() {
LOG.assertTrue(myStartupActivitiesPassed);
@@ -233,7 +221,6 @@ public class StartupManagerImpl extends StartupManagerEx {
return;
}
//noinspection TestOnlyProblems
runPostStartupActivitiesRegisteredDynamically();
dumbAwareActivity.end();
@@ -308,8 +295,7 @@ public class StartupManagerImpl extends StartupManagerEx {
}
}
@TestOnly
public final void runPostStartupActivitiesRegisteredDynamically() {
private void runPostStartupActivitiesRegisteredDynamically() {
if (postStartupActivitiesPassed) {
return;
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.properties;
import com.intellij.codeInsight.JavaCodeInsightTestCase;
@@ -8,11 +8,9 @@ import com.intellij.find.findUsages.FindUsagesManager;
import com.intellij.find.findUsages.FindUsagesOptions;
import com.intellij.find.findUsages.JavaClassFindUsagesOptions;
import com.intellij.find.impl.FindManagerImpl;
import com.intellij.ide.startup.impl.StartupManagerImpl;
import com.intellij.lang.findUsages.LanguageFindUsages;
import com.intellij.lang.properties.psi.Property;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.PsiReference;
@@ -35,12 +33,8 @@ public class PropertiesFindUsagesTest extends JavaCodeInsightTestCase {
return PluginPathManager.getPluginHomePath("java-i18n") + "/";
}
private void initProperties() {
((StartupManagerImpl)StartupManager.getInstance(myProject)).runPostStartupActivitiesRegisteredDynamically();
}
public void testFindUsages() throws Exception {
configureByFile(BASE_PATH+"xx.properties", BASE_PATH);
initProperties();
PsiReference[] references = findReferences();
assertEquals(1, references.length);
@@ -48,7 +42,6 @@ public class PropertiesFindUsagesTest extends JavaCodeInsightTestCase {
}
public void testFindUsagesInPropValue() throws Exception {
configureByFile(BASE_PATH+"Y.java", BASE_PATH);
initProperties();
UsageInfo[] usages = findUsages();
assertEquals(1, usages.length);
@@ -58,7 +51,6 @@ public class PropertiesFindUsagesTest extends JavaCodeInsightTestCase {
public void testFindUsagesInConditionalExpression() {
configureByFiles(BASE_PATH, BASE_PATH + "conditional.properties", BASE_PATH + "Conditional.java");
initProperties();
PsiElement element = myFile.findElementAt(myEditor.getCaretModel().getOffset());
Property prop = PsiTreeUtil.getNonStrictParentOfType(element, Property.class);

View File

@@ -1,14 +1,12 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.properties;
import com.intellij.codeInsight.JavaCodeInsightTestCase;
import com.intellij.codeInsight.TargetElementUtil;
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction;
import com.intellij.ide.startup.impl.StartupManagerImpl;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPolyVariantReference;
import com.intellij.psi.PsiReference;
@@ -75,7 +73,6 @@ public class PropertiesResolveTest extends JavaCodeInsightTestCase {
private void configure(@NonNls final String fileName) throws Exception {
configureByFile(BASE_PATH + fileName, BASE_PATH);
((StartupManagerImpl)StartupManager.getInstance(myProject)).runPostStartupActivitiesRegisteredDynamically();
}
private PropertiesFile findPropertiesFile() {

View File

@@ -1,28 +1,18 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.properties;
import com.intellij.ide.startup.impl.StartupManagerImpl;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.Property;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.refactoring.BaseRefactoringProcessor;
import com.intellij.refactoring.MultiFileTestCase;
import com.intellij.refactoring.rename.RenameProcessor;
import junit.framework.Assert;
import org.jetbrains.annotations.NotNull;
public class RenamePropertyTest extends MultiFileTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
((StartupManagerImpl)StartupManager.getInstance(myProject)).runPostStartupActivitiesRegisteredDynamically();
}
public void testBundle() {
doTest("xxx.properties","a.b","c.d");
}
@@ -33,7 +23,7 @@ public class RenamePropertyTest extends MultiFileTestCase {
fail("Conflict was not detected");
}
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
Assert.assertEquals("New property name 'c.d' hides existing property", e.getMessage());
assertEquals("New property name 'c.d' hides existing property", e.getMessage());
return;
}
fail("Conflict was not detected");