|
1 | 1 | package com.github.gaboso; |
2 | 2 |
|
| 3 | +import com.github.gaboso.helper.CommandExecutor; |
3 | 4 | import com.github.gaboso.module.GitModule; |
4 | 5 | import com.github.gaboso.module.Module; |
| 6 | +import com.github.gaboso.module.ModuleTypeEnum; |
5 | 7 | import com.github.gaboso.module.impl.BowerModule; |
6 | 8 | import com.github.gaboso.module.impl.GruntModule; |
7 | 9 | import com.github.gaboso.module.impl.MavenModule; |
8 | 10 | import com.github.gaboso.module.impl.NpmModule; |
| 11 | +import org.apache.logging.log4j.LogManager; |
| 12 | +import org.apache.logging.log4j.Logger; |
9 | 13 |
|
10 | 14 | import java.io.File; |
11 | 15 | import java.util.Arrays; |
|
17 | 21 | */ |
18 | 22 | public class ModuleRunner { |
19 | 23 |
|
| 24 | + private static final Logger LOGGER = LogManager.getLogger(ModuleRunner.class.getName()); |
| 25 | + |
| 26 | + private final GitModule gitModule; |
| 27 | + |
20 | 28 | private final List<Module> modules; |
21 | 29 |
|
22 | 30 | public ModuleRunner() { |
23 | | - Module bowerModule = new BowerModule(); |
24 | | - Module gruntModule = new GruntModule(); |
25 | | - Module mavenModule = new MavenModule(); |
26 | | - Module npmModule = new NpmModule(); |
27 | | - modules = Arrays.asList(bowerModule, gruntModule, mavenModule, npmModule); |
| 31 | + CommandExecutor commandExecutor = new CommandExecutor(); |
| 32 | + |
| 33 | + this.gitModule = new GitModule(commandExecutor); |
| 34 | + |
| 35 | + this.modules = Arrays.asList( |
| 36 | + new BowerModule(commandExecutor), |
| 37 | + new GruntModule(commandExecutor), |
| 38 | + new MavenModule(commandExecutor), |
| 39 | + new NpmModule(commandExecutor) |
| 40 | + ); |
28 | 41 | } |
29 | 42 |
|
30 | 43 | public void runAll(List<File> folders) { |
31 | | - for (File folder : folders) { |
32 | | - run(folder); |
33 | | - } |
| 44 | + folders.forEach(this::run); |
34 | 45 | } |
35 | 46 |
|
36 | 47 | public void run(File folder) { |
37 | 48 | String path = folder.getPath(); |
38 | 49 | String folderName = folder.getName(); |
39 | 50 |
|
40 | | - if (GitModule.isProject(path)) { |
41 | | - GitModule.executeCommands(folderName, path); |
| 51 | + if (gitModule.isProject(path)) { |
| 52 | + String typeName = ModuleTypeEnum.GIT.getTypeName(); |
| 53 | + printStartMessage(typeName, folderName); |
| 54 | + gitModule.executeCommands(path); |
| 55 | + printFinishMessage(typeName, folderName); |
42 | 56 | } |
43 | 57 |
|
44 | 58 | File[] listFiles = folder.listFiles(); |
45 | 59 | if (listFiles == null) { |
46 | 60 | return; |
47 | 61 | } |
48 | 62 |
|
49 | | - for (Module module : modules) { |
50 | | - if (module.isProject(listFiles)) { |
51 | | - module.executeCommands(folderName, path); |
52 | | - } |
53 | | - } |
| 63 | + modules.stream() |
| 64 | + .filter(module -> module.isProject(listFiles)) |
| 65 | + .forEach(module -> { |
| 66 | + String typeName = module.getType().getTypeName(); |
| 67 | + printStartMessage(typeName, folderName); |
| 68 | + module.executeCommands(path); |
| 69 | + printFinishMessage(typeName, folderName); |
| 70 | + }); |
| 71 | + } |
| 72 | + |
| 73 | + private void printStartMessage(String typeName, String folderName) { |
| 74 | + LOGGER.info("--------- Starting update {} --- [ {} ] ---------", typeName, folderName); |
| 75 | + } |
| 76 | + |
| 77 | + private void printFinishMessage(String typeName, String folderName) { |
| 78 | + LOGGER.info("--------- Finished update {} --- [ {} ] ---------", typeName, folderName); |
54 | 79 | } |
55 | 80 |
|
56 | 81 | } |
0 commit comments