mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[jps] making JavaModuleIndexImpl thread-safe; dropping deprecated override (IDEA-348044)
GitOrigin-RevId: b61858bab99c86229f5b2da6dea0f29699549d2b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0ab52a8c9a
commit
62998ad94f
@@ -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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.jps.model.java.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -9,63 +9,50 @@ import org.jetbrains.jps.model.java.JavaModuleIndex;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
|
||||
import org.jetbrains.jps.util.JpsPathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class JavaModuleIndexImpl extends JpsElementBase<JavaModuleIndexImpl> implements JavaModuleIndex {
|
||||
private static final String SOURCE_SUFFIX = ":S";
|
||||
private static final String TEST_SUFFIX = ":T";
|
||||
private static final String MODULE_INFO_FILE = "module-info.java";
|
||||
private static final File NULL_FILE = new File("-");
|
||||
|
||||
private final Map<String, File> myMapping;
|
||||
private final JpsCompilerExcludes myExcludes;
|
||||
|
||||
public JavaModuleIndexImpl(@NotNull JpsCompilerExcludes excludes) {
|
||||
myMapping = new HashMap<>();
|
||||
myMapping = new ConcurrentHashMap<>();
|
||||
myExcludes = excludes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaModuleIndexImpl createCopy() {
|
||||
JavaModuleIndexImpl copy = new JavaModuleIndexImpl(myExcludes);
|
||||
copy.myMapping.putAll(myMapping);
|
||||
return copy;
|
||||
public @Nullable File getModuleInfoFile(@NotNull JpsModule module, boolean forTests) {
|
||||
var key = module.getName() + (forTests ? TEST_SUFFIX : SOURCE_SUFFIX);
|
||||
var file = myMapping.computeIfAbsent(key, __ -> findModuleInfoFile(module, forTests));
|
||||
return file == NULL_FILE ? null : file;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public File getModuleInfoFile(@NotNull JpsModule module, boolean forTests) {
|
||||
String key = module.getName() + (forTests ? TEST_SUFFIX : SOURCE_SUFFIX);
|
||||
private File findModuleInfoFile(JpsModule module, boolean forTests) {
|
||||
var rootType = forTests ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
|
||||
|
||||
if (myMapping.containsKey(key)) {
|
||||
return myMapping.get(key);
|
||||
}
|
||||
|
||||
File file = findModuleInfoFile(module, forTests ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE);
|
||||
myMapping.put(key, file);
|
||||
return file;
|
||||
}
|
||||
|
||||
private File findModuleInfoFile(JpsModule module, JavaSourceRootType rootType) {
|
||||
for (JpsModuleSourceRoot root : module.getSourceRoots()) {
|
||||
for (var root : module.getSourceRoots()) {
|
||||
if (rootType.equals(root.getRootType())) {
|
||||
File file = new File(JpsPathUtil.urlToOsPath(root.getUrl()), MODULE_INFO_FILE);
|
||||
var file = new File(JpsPathUtil.urlToOsPath(root.getUrl()), MODULE_INFO_FILE);
|
||||
if (file.isFile() && !myExcludes.isExcluded(file)) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return NULL_FILE;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void dropCache() {
|
||||
myMapping.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user