1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.atlassian.theplugin.idea.config.serverconfig.defaultCredentials;
17
18 import com.atlassian.theplugin.idea.config.serverconfig.ProductConnector;
19 import com.atlassian.theplugin.idea.TestConnectionProcessor;
20 import com.atlassian.theplugin.ConnectionWrapper;
21 import com.atlassian.theplugin.util.PluginUtil;
22 import com.atlassian.theplugin.commons.bamboo.BambooServerFacadeImpl;
23 import com.atlassian.theplugin.commons.crucible.CrucibleServerFacadeImpl;
24 import com.atlassian.theplugin.jira.JIRAServerFacadeImpl;
25
26
27
28
29 public class TestConnectionThread extends Thread {
30 private static final int CHECK_CANCEL_INTERVAL = 500;
31 private final TestConnectionProcessor testConnectionProcessor;
32 private final ServerDataExt server;
33
34 public TestConnectionThread(@org.jetbrains.annotations.NotNull String s, TestConnectionProcessor testConnectionProcessor,
35 ServerDataExt server) {
36 super(s);
37 this.testConnectionProcessor = testConnectionProcessor;
38 this.server = server;
39 }
40
41 @Override
42 public void run() {
43 ProductConnector productConnector;
44 ConnectionWrapper testConnector;
45 switch (server.getServerType()) {
46 case JIRA_SERVER:
47 productConnector = new ProductConnector(JIRAServerFacadeImpl.getInstance());
48 break;
49
50 case BAMBOO_SERVER:
51 productConnector = new ProductConnector(BambooServerFacadeImpl.getInstance(PluginUtil.getLogger()));
52 break;
53
54 case CRUCIBLE_SERVER:
55 case FISHEYE_SERVER:
56 productConnector = new ProductConnector(CrucibleServerFacadeImpl.getInstance());
57 break;
58
59 default:
60 return;
61
62 }
63 testConnector = new ConnectionWrapper(productConnector, server.getServerData(), "testing connection");
64
65 testConnector.start();
66 while (testConnector.getConnectionState() == ConnectionWrapper.ConnectionState.NOT_FINISHED) {
67 try {
68 if (false) {
69 testConnector.setInterrupted();
70
71 break;
72 } else {
73 java.lang.Thread.sleep(CHECK_CANCEL_INTERVAL);
74 }
75 } catch (InterruptedException e) {
76
77 }
78 }
79
80 if (testConnector.getConnectionState() == ConnectionWrapper.ConnectionState.SUCCEEDED) {
81 testConnectionProcessor.onSuccess();
82 } else {
83 testConnectionProcessor.onError(testConnector.getErrorMessage());
84 }
85
86 }
87
88
89 }