1
1
package codeine .plugins ;
2
2
3
- import java .util .List ;
4
- import java .util .Map ;
5
-
6
- import javax .inject .Inject ;
7
-
8
- import org .apache .log4j .Logger ;
9
-
3
+ import codeine .executer .ThreadPoolUtils ;
10
4
import codeine .jsons .global .ExperimentalConfJsonStore ;
11
5
import codeine .jsons .project .ProjectJson ;
12
6
import codeine .model .Constants ;
13
7
import codeine .model .Result ;
14
8
import codeine .utils .os_process .ProcessExecuter .ProcessExecuterBuilder ;
15
-
16
9
import com .google .common .collect .Lists ;
17
10
import com .google .common .collect .Maps ;
11
+ import java .util .List ;
12
+ import java .util .Map ;
13
+ import java .util .concurrent .ThreadPoolExecutor ;
14
+ import javax .inject .Inject ;
15
+ import org .apache .log4j .Logger ;
18
16
19
17
public class AfterProjectModifyPlugin {
20
18
21
19
@ Inject private ExperimentalConfJsonStore experimentalConfJsonStore ;
22
20
23
21
private static final Logger log = Logger .getLogger (AfterProjectModifyPlugin .class );
22
+ private ThreadPoolExecutor executor = ThreadPoolUtils
23
+ .newThreadPool (1 , "AfterProjectModifyPlugin" );
24
24
25
25
public enum StatusChange {add ,remove ,modify }
26
26
@@ -34,10 +34,42 @@ public void call(ProjectJson projectJson, StatusChange newStatus, String usernam
34
34
env .put (Constants .EXECUTION_ENV_PROJECT_STATUS , String .valueOf (newStatus ));
35
35
env .put (Constants .EXECUTION_ENV_PROJECT_NAME , projectJson .name ());
36
36
env .put (Constants .EXECUTION_ENV_USER_NAME , username );
37
- log .info ("executing " + after_project_modify_plugin );
38
- Result result = new ProcessExecuterBuilder (cmd ).timeoutInMinutes (2 ).env (env ).build ().execute ();
39
- log .info ("calling after_project_modify_plugin for project " + projectJson .name () + " finished " + result .toStringLong ());
37
+ if (experimentalConfJsonStore .get ().after_project_modify_plugin_async ()) {
38
+ log .info ("Queuing after_project_modify_plugin run" );
39
+ executor .execute (
40
+ new PluginRunnable (after_project_modify_plugin , cmd , env , projectJson ));
41
+ }
42
+ else {
43
+ log .info ("executing " + after_project_modify_plugin );
44
+ Result result = new ProcessExecuterBuilder (cmd ).timeoutInMinutes (2 ).env (env ).build ().execute ();
45
+ log .info ("calling after_project_modify_plugin for project " + projectJson .name () + " finished " + result .toStringLong ());
46
+ }
47
+
48
+
40
49
}
41
50
}
42
51
52
+ private static class PluginRunnable implements Runnable {
53
+
54
+ private final String after_project_modify_plugin ;
55
+ private final List <String > cmd ;
56
+ private final Map <String , String > env ;
57
+ private final ProjectJson projectJson ;
58
+
59
+ PluginRunnable (String after_project_modify_plugin , List <String > cmd ,
60
+ Map <String , String > env ,
61
+ ProjectJson projectJson ) {
62
+ this .after_project_modify_plugin = after_project_modify_plugin ;
63
+ this .cmd = cmd ;
64
+ this .env = env ;
65
+ this .projectJson = projectJson ;
66
+ }
67
+
68
+ @ Override
69
+ public void run () {
70
+ log .info ("executing " + after_project_modify_plugin );
71
+ Result result = new ProcessExecuterBuilder (cmd ).timeoutInMinutes (2 ).env (env ).build ().execute ();
72
+ log .info ("calling after_project_modify_plugin for project " + projectJson .name () + " finished " + result .toStringLong ());
73
+ }
74
+ }
43
75
}
0 commit comments