mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use io.File#exists instead of nio.Files#exists due to poor performance with jdk 8
https://rules.sonarsource.com/java/RSPEC-3725 https://bugs.openjdk.java.net/browse/JDK-8153414 https://bugs.openjdk.java.net/browse/JDK-8154077
This commit is contained in:
+1
-2
@@ -14,7 +14,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -37,7 +36,7 @@ public class TestDiscoveryIndex implements Disposable {
|
||||
public TestDiscoveryIndex(final Project project, @NotNull Path basePath) {
|
||||
myBasePath = basePath;
|
||||
|
||||
if (Files.exists(basePath)) {
|
||||
if (basePath.toFile().exists()) {
|
||||
StartupManager.getInstance(project).registerPostStartupActivity(() -> ApplicationManager.getApplication().executeOnPooledThread(() -> {
|
||||
getHolder(); // proactively init with maybe io costly compact
|
||||
}));
|
||||
|
||||
+1
-1
@@ -308,7 +308,7 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
Set<String> unloadedModules = new HashSet<>();
|
||||
if (!myLoadUnloadedModules && Files.exists(workspaceFile)) {
|
||||
if (!myLoadUnloadedModules && workspaceFile.toFile().exists()) {
|
||||
Element unloadedModulesList = JDomSerializationUtil.findComponent(loadRootElement(workspaceFile), "UnloadedModulesList");
|
||||
for (Element element : JDOMUtil.getChildren(unloadedModulesList, "module")) {
|
||||
unloadedModules.add(element.getAttributeValue("name"));
|
||||
|
||||
+2
-2
@@ -81,7 +81,7 @@ class IconsClassGenerator(private val projectHome: File, val util: JpsModule, pr
|
||||
outFile = targetRoot.resolve("$className.java")
|
||||
}
|
||||
|
||||
val oldText = if (Files.exists(outFile)) Files.readAllBytes(outFile).toString(StandardCharsets.UTF_8) else null
|
||||
val oldText = if (outFile.toFile().exists()) Files.readAllBytes(outFile).toString(StandardCharsets.UTF_8) else null
|
||||
val newText = generate(module, className, packageName, customLoad, getCopyrightComment(oldText))
|
||||
|
||||
val oldLines = oldText?.lines() ?: emptyList()
|
||||
@@ -309,7 +309,7 @@ class IconsClassGenerator(private val projectHome: File, val util: JpsModule, pr
|
||||
assert(isIcon(imageFile)) { "Overriding icon should be valid: $iconName - $imageFile" }
|
||||
}
|
||||
|
||||
val size = if (Files.exists(imageFile)) imageSize(imageFile) else null
|
||||
val size = if (imageFile.toFile().exists()) imageSize(imageFile) else null
|
||||
val comment: String
|
||||
when {
|
||||
size != null -> comment = " // ${size.width}x${size.height}"
|
||||
|
||||
+2
-4
@@ -88,9 +88,7 @@ internal class ImageCollector(private val projectHome: Path, private val iconsOn
|
||||
|
||||
private fun processRoot(sourceRoot: JpsModuleSourceRoot) {
|
||||
val root = Paths.get(JpsPathUtil.urlToPath(sourceRoot.url))
|
||||
if (!Files.exists(root)) {
|
||||
return
|
||||
}
|
||||
if (!root.toFile().exists()) return
|
||||
|
||||
val answer = downToRoot(root, root, null, IconRobotsData(), 0)
|
||||
val iconsRoot = (if (answer == null || Files.isDirectory(answer)) answer else answer.parent) ?: return
|
||||
@@ -231,7 +229,7 @@ internal class ImageCollector(private val projectHome: Path, private val iconsOn
|
||||
|
||||
fun fork(dir: Path, root: Path): IconRobotsData {
|
||||
val robots = dir.resolve(ROBOTS_FILE_NAME)
|
||||
if (!Files.exists(robots)) {
|
||||
if (!robots.toFile().exists()) {
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.nio.file.attribute.BasicFileAttributes
|
||||
import java.nio.file.attribute.FileTime
|
||||
import java.util.*
|
||||
|
||||
fun Path.exists(): Boolean = Files.exists(this)
|
||||
fun Path.exists(): Boolean = this.toFile().exists()
|
||||
|
||||
fun Path.createDirectories(): Path {
|
||||
// symlink or existing regular file - Java SDK do this check, but with as `isDirectory(dir, LinkOption.NOFOLLOW_LINKS)`, i.e. links are not checked
|
||||
|
||||
@@ -68,7 +68,7 @@ public class TempDirectory extends TemporaryFolder {
|
||||
@Override
|
||||
public File newFolder(String directoryName) throws IOException {
|
||||
Path dir = Paths.get(getRoot().getPath(), directoryName);
|
||||
if (Files.exists(dir)) throw new IOException("Already exists: " + dir);
|
||||
if (dir.toFile().exists()) throw new IOException("Already exists: " + dir);
|
||||
Files.createDirectories(dir);
|
||||
return dir.toFile();
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class TempDirectory extends TemporaryFolder {
|
||||
@Override
|
||||
public File newFile(String fileName) throws IOException {
|
||||
Path file = Paths.get(getRoot().getPath(), fileName);
|
||||
if (Files.exists(file)) throw new IOException("Already exists: " + file);
|
||||
if (file.toFile().exists()) throw new IOException("Already exists: " + file);
|
||||
makeDirectories(file.getParent());
|
||||
Files.createFile(file);
|
||||
return file.toFile();
|
||||
|
||||
Reference in New Issue
Block a user