@@ -37,9 +37,16 @@ public static File searchGitRepositoriesAndCreateScriptFile(File directory, Stri
37
37
LOGGER .info ("Start searching git repositories in '{}' path." , directory .getAbsolutePath ());
38
38
List <File > repositoriesToRunCommand = new ArrayList <>();
39
39
searchGitRepositories (directory , repositoriesToRunCommand );
40
+ if (AppConfig .getInstance ().appWasClosed ()) {
41
+ return null ;
42
+ }
40
43
LOGGER .info ("'{}' git repositories were found to run command." , repositoriesToRunCommand .size ());
41
44
try {
42
- return createAndFillScriptFileWithCommand (command , repositoriesToRunCommand );
45
+ final File scriptFile = createAndFillScriptFileWithCommand (command , repositoriesToRunCommand );
46
+ if (AppConfig .getInstance ().appWasClosed ()) {
47
+ removeScriptFile (scriptFile );
48
+ }
49
+ return scriptFile ;
43
50
} catch (IOException e ) {
44
51
LOGGER .error ("Something goes wrong with creation temp script file with command." , e );
45
52
}
@@ -48,20 +55,17 @@ public static File searchGitRepositoriesAndCreateScriptFile(File directory, Stri
48
55
}
49
56
50
57
public static void executeScriptFileWithCommand (File scriptFile ) {
58
+ if (scriptFile == null || AppConfig .getInstance ().appWasClosed ()) {
59
+ return ;
60
+ }
51
61
try {
52
62
LOGGER .info ("Start executing script file '{}'." , scriptFile .getAbsolutePath ());
53
63
executeScriptFile (scriptFile );
54
64
LOGGER .info ("Finish executing git command." );
55
65
} catch (IOException e ) {
56
66
LOGGER .error ("Something goes wrong with executing temp script file with command." , e );
57
67
} finally {
58
- if (scriptFile != null && scriptFile .exists ()) {
59
- if (scriptFile .delete ()) {
60
- LOGGER .info ("Temp script file '{}' was removed." , scriptFile .getAbsolutePath ());
61
- } else {
62
- LOGGER .warn ("Temp script file '{}' with command wasn't removed." , scriptFile .getAbsolutePath ());
63
- }
64
- }
68
+ removeScriptFile (scriptFile );
65
69
}
66
70
}
67
71
@@ -107,6 +111,9 @@ private static File createAndFillScriptFileWithCommand(String gitCommand, List<F
107
111
writer .write ("#!/bin/bash\n " );
108
112
writer .write ("echo -e \" \\ 033[0;32m\" \" " + gitCommand + "\" \" \\ 033[0m\" \n " );
109
113
for (File currentFolder : repositoriesToRunCommand ) {
114
+ if (AppConfig .getInstance ().appWasClosed ()) {
115
+ break ;
116
+ }
110
117
writer .write ("cd \" " + currentFolder .getAbsolutePath ().replace ("\\ " , "\\ \\ " ) + "\" \n " );
111
118
writer .write ("echo -e \" \\ 033[0;36m\" $PWD \" \\ 033[0m\" \n " );
112
119
@@ -118,6 +125,9 @@ private static File createAndFillScriptFileWithCommand(String gitCommand, List<F
118
125
}
119
126
120
127
private static void searchGitRepositories (File folder , List <File > repositoriesToRunCommand ) {
128
+ if (AppConfig .getInstance ().appWasClosed ()) {
129
+ return ;
130
+ }
121
131
if (isGitRepository (folder )) {
122
132
repositoriesToRunCommand .add (folder );
123
133
} else {
@@ -136,6 +146,16 @@ private static void searchGitRepositories(File folder, List<File> repositoriesTo
136
146
}
137
147
}
138
148
149
+ private static void removeScriptFile (File scriptFile ) {
150
+ if (scriptFile != null && scriptFile .exists ()) {
151
+ if (scriptFile .delete ()) {
152
+ LOGGER .info ("Temp script file '{}' was removed." , scriptFile .getAbsolutePath ());
153
+ } else {
154
+ LOGGER .warn ("Temp script file '{}' with command wasn't removed." , scriptFile .getAbsolutePath ());
155
+ }
156
+ }
157
+ }
158
+
139
159
private static boolean isGitRepository (File folder ) {
140
160
File gitFolder = new File (folder , ".git" );
141
161
return gitFolder .exists () && gitFolder .isDirectory ();
0 commit comments