diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d31b95..ca1b9d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.6.8 + +* Fix 修复文件死锁问题 + ## 0.6.7 * Feature 优化代码,移除废弃的方法调用,并且做了低版本兼容 diff --git a/build.gradle.kts b/build.gradle.kts index a68921f..d3e657b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,6 +11,9 @@ version = properties("pluginVersion") repositories { mavenCentral() + maven { + url = uri("https://www.jetbrains.com/intellij-repository/releases") + } } // Configure Gradle IntelliJ Plugin diff --git a/gradle.properties b/gradle.properties index ca6a03a..ce4fdfd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -pluginVersion=0.6.7 +pluginVersion=0.6.8 #intellijVersion=2022.2.2 #intellijVersion=2023.1 #intellijVersion=2024.2 diff --git a/src/main/java/com/free2one/accessor/meta/MethodMetaDataRepository.java b/src/main/java/com/free2one/accessor/meta/MethodMetaDataRepository.java index 67da2b8..4b22003 100644 --- a/src/main/java/com/free2one/accessor/meta/MethodMetaDataRepository.java +++ b/src/main/java/com/free2one/accessor/meta/MethodMetaDataRepository.java @@ -5,10 +5,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.intellij.json.JsonFileType; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.application.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -36,30 +33,6 @@ public MethodMetaDataRepository(Project project) { this.basePath = project.getBasePath(); } -// public ClassMetadata getFromClassname(String classname) { -// Path phpFilePath = PathManager.findBinFile(getDir() + File.separator + decodeFileName(classname) + "." + fileExtension); -// if (Optional.ofNullable(phpFilePath).isEmpty()) { -// return null; -// } -// -// Gson gson = new GsonBuilder() -// .serializeNulls() -// .registerTypeAdapter(AccessorMethod.class, AccessorMethodDeserializerFactory.create()) -// .create(); -// VirtualFile file = VfsUtil.findFile(phpFilePath, true); -// if (Optional.ofNullable(file).isEmpty()) { -// return null; -// } -// -//// file.refresh(false, false); -// try { -// String json = new String(file.getInputStream().readAllBytes()); -// return gson.fromJson(json, ClassMetadata.class); -// } catch (IOException e) { -// throw new RuntimeException(e); -// } -// } - public ClassMetadata getFromClassname(String classname) { Path phpFilePath = PathManager.findBinFile(getDir() + File.separator + decodeFileName(classname) + "." + fileExtension); if (Optional.ofNullable(phpFilePath).isEmpty()) { @@ -76,11 +49,18 @@ public ClassMetadata getFromClassname(String classname) { return null; } -// WriteAction.run(() -> file.refresh(false, false)); - -// ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(() -> file.refresh(false, false))); - ApplicationManager.getApplication().invokeLater(() -> WriteAction.run(() -> file.refresh(false, false))); - +// ApplicationManager.getApplication().invokeLater(() -> { +// WriteAction.run(() -> file.refresh(false, false)); +// }, ModalityState.defaultModalityState()); + + // 判断文件是否上锁,上锁则等到解锁后再读取 + while (!file.isWritable()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } try { String json = new String(file.getInputStream().readAllBytes());