Skip to content

Commit 856bda5

Browse files
authored
Merge pull request #365 from shuzijun/gradle
fix compatibility
2 parents bcbf6a1 + 9eb3bb2 commit 856bda5

19 files changed

+176
-1397
lines changed

src/main/java/com/shuzijun/leetcode/plugin/model/PluginConstant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ public class PluginConstant {
5555

5656
public static final String LEETCODE_EDITOR_GROUP = ACTION_PREFIX + ".editor.group";
5757

58-
58+
public static final String LEETCODE_EDITOR_TIMER_STATUS_BAR_ID = PLUGIN_ID + "-TimerStatusBar";
5959
}

src/main/java/com/shuzijun/leetcode/plugin/setting/PersistentConfig.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.shuzijun.leetcode.plugin.setting;
22

3+
import com.intellij.credentialStore.CredentialAttributes;
4+
import com.intellij.credentialStore.Credentials;
35
import com.intellij.ide.passwordSafe.PasswordSafe;
4-
import com.intellij.ide.passwordSafe.PasswordSafeException;
56
import com.intellij.openapi.components.*;
67
import com.intellij.util.xmlb.XmlSerializerUtil;
78
import com.shuzijun.leetcode.plugin.model.Config;
@@ -18,7 +19,7 @@
1819
/**
1920
* @author shuzijun
2021
*/
21-
@State(name = "PersistentConfig" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX+"-config.xml", roamingType = RoamingType.DISABLED)})
22+
@State(name = "PersistentConfig" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX + "-config.xml", roamingType = RoamingType.DISABLED)})
2223
public class PersistentConfig implements PersistentStateComponent<PersistentConfig> {
2324

2425
public static String PATH = "leetcode" + File.separator + "editor";
@@ -67,24 +68,16 @@ public String getTempFilePath() {
6768
return getConfig().getFilePath() + File.separator + PATH + File.separator + initConfig.get(INITNAME).getAlias() + File.separator;
6869
}
6970

70-
public void savePassword(String password) {
71-
try {
72-
PasswordSafe.getInstance().storePassword
73-
(null, this.getClass(), PluginConstant.PLUGIN_ID, password != null ? password : "");
74-
} catch (PasswordSafeException exception) {
75-
MessageUtils.showAllWarnMsg("warning", "Failed to save password");
71+
public void savePassword(String password, String username) {
72+
if(username == null || password == null){
73+
return;
7674
}
75+
PasswordSafe.getInstance().set(new CredentialAttributes(PluginConstant.PLUGIN_ID, username, this.getClass()), new Credentials(username, password==null?"":password));
7776
}
7877

79-
public String getPassword() {
80-
if (getConfig().getVersion() != null) {
81-
try {
82-
return PasswordSafe.getInstance().getPassword(null, this.getClass(), PluginConstant.PLUGIN_ID);
83-
} catch (PasswordSafeException exception) {
84-
MessageUtils.showAllWarnMsg("warning", "Password acquisition failed");
85-
return null;
86-
}
87-
78+
public String getPassword(String username) {
79+
if (getConfig().getVersion() != null && username != null) {
80+
return PasswordSafe.getInstance().getPassword(new CredentialAttributes(PluginConstant.PLUGIN_ID, username, this.getClass()));
8881
}
8982
return null;
9083

src/main/java/com/shuzijun/leetcode/plugin/setting/ProjectConfig.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@
1616
* @author shuzijun
1717
*/
1818
@State(name = "LeetcodeEditor" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX+"/editor.xml")})
19-
public class ProjectConfig implements ProjectComponent, PersistentStateComponent<ProjectConfig.InnerState> {
19+
public class ProjectConfig implements PersistentStateComponent<ProjectConfig.InnerState> {
2020

2121
public Map<String, LeetcodeEditor> idProjectConfig = new HashMap<>();
2222

23-
public ProjectConfig(Project project) {
24-
25-
}
26-
2723
@Nullable
2824
public static ProjectConfig getInstance(Project project) {
29-
return ServiceManager.getService(project, ProjectConfig.class);
25+
return project.getService(ProjectConfig.class);
3026
}
3127

3228
private InnerState innerState = new InnerState();
@@ -81,15 +77,4 @@ public String getComponentName() {
8177
return this.getClass().getName();
8278
}
8379

84-
public void initComponent() {
85-
}
86-
87-
public void disposeComponent() {
88-
}
89-
90-
public void projectOpened() {
91-
}
92-
93-
public void projectClosed() {
94-
}
9580
}

src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private void loadSetting() {
163163
Config config = PersistentConfig.getInstance().getInitConfig();
164164
if (config != null) {
165165
userNameField.setText(config.getLoginName());
166-
passwordField.setText(PersistentConfig.getInstance().getPassword());
166+
passwordField.setText(PersistentConfig.getInstance().getPassword(config.getLoginName()));
167167
if (StringUtils.isNotBlank(config.getFilePath())) {
168168
fileFolderBtn.setText(config.getFilePath());
169169
}
@@ -216,7 +216,7 @@ public boolean isModified() {
216216
Config currentState = new Config();
217217
process(currentState);
218218
if (currentState.isModified(config)) {
219-
if (passwordField.getText() != null && passwordField.getText().equals(PersistentConfig.getInstance().getPassword())) {
219+
if (passwordField.getText() != null && passwordField.getText().equals(PersistentConfig.getInstance().getPassword(config.getLoginName()))) {
220220
return false;
221221
} else {
222222
return true;
@@ -239,7 +239,7 @@ public void apply() {
239239
file.mkdirs();
240240
}
241241
PersistentConfig.getInstance().setInitConfig(config);
242-
PersistentConfig.getInstance().savePassword(passwordField.getText());
242+
PersistentConfig.getInstance().savePassword(passwordField.getText(),config.getLoginName());
243243
CustomTreeCellRenderer.loaColor();
244244
TimerBarWidget.loaColor();
245245
}

src/main/java/com/shuzijun/leetcode/plugin/timer/TimerBarWidget.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package com.shuzijun.leetcode.plugin.timer;
22

33
import com.intellij.openapi.project.Project;
4-
import com.intellij.openapi.util.SystemInfo;
54
import com.intellij.openapi.wm.CustomStatusBarWidget;
65
import com.intellij.openapi.wm.StatusBar;
7-
import com.intellij.openapi.wm.StatusBarWidget;
86
import com.shuzijun.leetcode.plugin.model.Config;
97
import com.shuzijun.leetcode.plugin.model.PluginConstant;
108
import com.shuzijun.leetcode.plugin.setting.PersistentConfig;
119
import org.apache.commons.lang.StringUtils;
1210
import org.jetbrains.annotations.NotNull;
13-
import org.jetbrains.annotations.Nullable;
1411

1512
import javax.swing.*;
1613
import java.awt.*;
@@ -147,15 +144,5 @@ public void reset() {
147144
label.setVisible(false);
148145
}
149146

150-
@Nullable
151-
public StatusBarWidget.WidgetPresentation getPresentation() {
152-
return this.getPresentation(SystemInfo.isMac ? StatusBarWidget.PlatformType.MAC : StatusBarWidget.PlatformType.DEFAULT);
153-
}
154-
155-
@Nullable
156-
public StatusBarWidget.WidgetPresentation getPresentation(@NotNull StatusBarWidget.PlatformType type) {
157-
return null;
158-
}
159-
160147

161148
}
Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,55 @@
11
package com.shuzijun.leetcode.plugin.timer;
22

33
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.util.Disposer;
5+
import com.intellij.openapi.wm.StatusBar;
46
import com.intellij.openapi.wm.StatusBarWidget;
5-
import com.intellij.openapi.wm.StatusBarWidgetProvider;
7+
import com.intellij.openapi.wm.StatusBarWidgetFactory;
8+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
9+
import org.jetbrains.annotations.Nls;
10+
import org.jetbrains.annotations.NonNls;
611
import org.jetbrains.annotations.NotNull;
7-
import org.jetbrains.annotations.Nullable;
812

913

1014
/**
1115
* @author shuzijun
1216
*/
13-
public class TimerStatusBarWidgetProvider implements StatusBarWidgetProvider {
14-
@Nullable
17+
public class TimerStatusBarWidgetProvider implements StatusBarWidgetFactory {
18+
19+
private TimerBarWidget timerBarWidget;
20+
21+
@Override
22+
public @NonNls @NotNull String getId() {
23+
return PluginConstant.LEETCODE_EDITOR_TIMER_STATUS_BAR_ID;
24+
}
25+
26+
@Override
27+
public @Nls @NotNull String getDisplayName() {
28+
return PluginConstant.LEETCODE_EDITOR_TIMER_STATUS_BAR_ID;
29+
}
30+
31+
@Override
32+
public boolean isAvailable(@NotNull Project project) {
33+
return true;
34+
}
35+
36+
@Override
37+
public @NotNull StatusBarWidget createWidget(@NotNull Project project) {
38+
if (timerBarWidget == null) {
39+
timerBarWidget = new TimerBarWidget(project);
40+
}
41+
return timerBarWidget;
42+
}
43+
44+
@Override
45+
public void disposeWidget(@NotNull StatusBarWidget widget) {
46+
if (timerBarWidget != null) {
47+
Disposer.dispose(timerBarWidget);
48+
}
49+
}
50+
1551
@Override
16-
public StatusBarWidget getWidget(@NotNull Project project) {
17-
return new TimerBarWidget(project);
52+
public boolean canBeEnabledOn(@NotNull StatusBar statusBar) {
53+
return false;
1854
}
1955
}

src/main/java/com/shuzijun/leetcode/plugin/utils/FileUtils.java

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
package com.shuzijun.leetcode.plugin.utils;
22

3-
import com.intellij.openapi.application.Application;
43
import com.intellij.openapi.application.ApplicationManager;
5-
import com.intellij.openapi.application.TransactionGuard;
6-
import com.intellij.openapi.application.WriteAction;
74
import com.intellij.openapi.fileEditor.FileDocumentManager;
85
import com.intellij.openapi.fileEditor.FileEditorManager;
96
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
107
import com.intellij.openapi.project.Project;
11-
import com.intellij.openapi.util.ThrowableComputable;
128
import com.intellij.openapi.vfs.LocalFileSystem;
139
import com.intellij.openapi.vfs.VfsUtil;
1410
import com.intellij.openapi.vfs.VirtualFile;
1511
import com.intellij.openapi.vfs.newvfs.RefreshQueue;
16-
import com.intellij.util.ExceptionUtil;
1712
import com.shuzijun.leetcode.plugin.model.CodeTypeEnum;
1813
import com.shuzijun.leetcode.plugin.model.Constant;
1914
import com.shuzijun.leetcode.plugin.model.LeetcodeEditor;
@@ -25,7 +20,6 @@
2520
import java.util.ArrayList;
2621
import java.util.LinkedList;
2722
import java.util.List;
28-
import java.util.concurrent.atomic.AtomicReference;
2923
import java.util.function.BiConsumer;
3024

3125
/**
@@ -244,40 +238,11 @@ public static void openFileEditorAndSaveState(File file, Project project, Questi
244238
public static void saveEditDocument(VirtualFile file){
245239
if (FileDocumentManager.getInstance().isFileModified(file)) {
246240
try {
247-
ThrowableComputable<Boolean, Throwable> action = new ThrowableComputable<Boolean, Throwable>() {
248-
@Override
249-
public Boolean compute() throws Throwable {
241+
ApplicationManager.getApplication().invokeLaterOnWriteThread((() -> {
242+
ApplicationManager.getApplication().runWriteAction(() -> {
250243
FileDocumentManager.getInstance().saveDocument(FileDocumentManager.getInstance().getDocument(file));
251-
return true;
252-
}
253-
};
254-
255-
256-
Application application = ApplicationManager.getApplication();
257-
if (application.isDispatchThread()) {
258-
ApplicationManager.getApplication().runWriteAction(action);
259-
} else {
260-
if (application.isReadAccessAllowed()) {
261-
LogUtils.LOG.error("Must not start write action from within read action in the other thread - deadlock is coming");
262-
}
263-
264-
AtomicReference<Boolean> result = new AtomicReference();
265-
AtomicReference<Throwable> exception = new AtomicReference();
266-
TransactionGuard.getInstance().submitTransactionAndWait(() -> {
267-
try {
268-
result.set(WriteAction.compute(action));
269-
} catch (Throwable var4) {
270-
exception.set(var4);
271-
}
272-
273244
});
274-
Throwable t = (Throwable) exception.get();
275-
if (t != null) {
276-
t.addSuppressed(new RuntimeException());
277-
ExceptionUtil.rethrowUnchecked(t);
278-
throw t;
279-
}
280-
}
245+
}));
281246
} catch (Throwable ignore) {
282247
LogUtils.LOG.error("自动保存文件错误", ignore);
283248
}

src/main/java/com/shuzijun/leetcode/plugin/utils/HttpRequestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.shuzijun.leetcode.plugin.utils;
22

3-
import com.shuzijun.leetcode.plugin.utils.io.HttpRequests;
3+
import com.intellij.util.io.HttpRequests;
44
import org.apache.commons.lang3.StringUtils;
55
import org.apache.http.HttpHeaders;
66
import org.jetbrains.annotations.NotNull;

src/main/java/com/shuzijun/leetcode/plugin/utils/MTAUtils.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
package com.shuzijun.leetcode.plugin.utils;
22

3-
import com.intellij.ide.plugins.PluginManager;
4-
import com.intellij.openapi.extensions.PluginId;
5-
import com.intellij.openapi.util.SystemInfo;
63
import com.shuzijun.leetcode.plugin.model.Config;
7-
import com.shuzijun.leetcode.plugin.model.PluginConstant;
8-
import com.shuzijun.leetcode.plugin.utils.io.HttpRequests;
9-
import org.apache.http.client.utils.URIBuilder;
104

11-
import java.awt.*;
12-
import java.net.URI;
13-
import java.util.Calendar;
14-
import java.util.Locale;
155
import java.util.concurrent.ExecutorService;
166
import java.util.concurrent.Executors;
177

@@ -59,7 +49,7 @@ public ClickTask(Config config, String actionsId) {
5949

6050
@Override
6151
public void run() {
62-
try {
52+
/* try {
6353
if (version == null) {
6454
version = PluginManager.getPlugin(PluginId.getId(PluginConstant.PLUGIN_ID)).getVersion()
6555
.replace("v", "").replaceAll("-|_", ".");
@@ -98,7 +88,7 @@ public void run() {
9888
HttpRequests.request(uri.toURL().toString()).userAgent(userAgent).tryConnect();
9989
10090
} catch (Exception e) {
101-
}
91+
}*/
10292
}
10393
}
10494
}

src/main/java/com/shuzijun/leetcode/plugin/utils/MessageUtils.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import com.intellij.notification.Notification;
44
import com.intellij.notification.NotificationType;
55
import com.intellij.notification.Notifications;
6-
import com.intellij.openapi.components.ProjectComponent;
7-
import com.intellij.openapi.components.ServiceManager;
6+
import com.intellij.openapi.components.Service;
87
import com.intellij.openapi.project.Project;
98
import com.intellij.openapi.ui.MessageType;
109
import com.intellij.openapi.ui.popup.Balloon;
1110
import com.intellij.openapi.ui.popup.BalloonBuilder;
1211
import com.intellij.openapi.ui.popup.JBPopupFactory;
1312
import com.intellij.ui.JBColor;
1413
import com.intellij.ui.awt.RelativePoint;
15-
import com.shuzijun.leetcode.plugin.model.Constant;
1614
import com.shuzijun.leetcode.plugin.model.PluginConstant;
1715
import org.jetbrains.annotations.Nullable;
1816

@@ -22,7 +20,8 @@
2220
/**
2321
* @author shuzijun
2422
*/
25-
public class MessageUtils implements ProjectComponent {
23+
@Service
24+
public final class MessageUtils {
2625

2726
private Project project;
2827

@@ -32,7 +31,7 @@ public MessageUtils(Project project) {
3231

3332
@Nullable
3433
public static MessageUtils getInstance(Project project) {
35-
return ServiceManager.getService(project, MessageUtils.class);
34+
return project.getService(MessageUtils.class);
3635
}
3736

3837

@@ -67,15 +66,5 @@ public String getComponentName() {
6766
return this.getClass().getName();
6867
}
6968

70-
public void initComponent() {
71-
}
72-
73-
public void disposeComponent() {
74-
}
7569

76-
public void projectOpened() {
77-
}
78-
79-
public void projectClosed() {
80-
}
8170
}

0 commit comments

Comments
 (0)