Skip to content

Commit 84be55d

Browse files
authored
Merge pull request #36 from Gaboso/feature/3.0.0
General refactoring in modules and lib updates
2 parents 8d764bb + 776aa9e commit 84be55d

24 files changed

Lines changed: 548 additions & 128 deletions

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [3.0.0] - 2023-02-15
6+
7+
### Changed
8+
- Update log4j dependency from 2.18.0 to 2.19.0
9+
- Update maven-assembly-plugin dependency from 3.4.1 to 3.4.2
10+
- Improve logger logic in ModuleRunner
11+
- Renamed class from CommandHelper to CommandExecutor
12+
13+
### Added
14+
15+
- Unit tests and unit tests dependencies: JUnit and mockito
16+
- Created ModuleTypeEnum to store module name and commands
17+
- Created OpSystemEnum to store OS runner and option
18+
19+
### Removed
20+
21+
- Formatter class
22+
- OsHelper class
23+
524
## [2.0.0] - 2022-07-05
625

726
### Changed
827

9-
- Update log4j dependency from 1.17.2 to 1.18.0
28+
- Update log4j dependency from 2.17.2 to 2.18.0
1029
- Update maven-assembly-plugin dependency from 3.3.0 to 3.4.0
1130
- Split Scriptum class in other two classes
1231
- Change jar entry point from Scriptum class to Main class

pom.xml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>br.com.gaboso</groupId>
88
<artifactId>scriptum</artifactId>
9-
<version>2.0.0</version>
9+
<version>3.0.0</version>
1010

1111
<organization>
1212
<name>com.github.gaboso</name>
@@ -32,7 +32,10 @@
3232
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3333
<maven.compiler.target>1.8</maven.compiler.target>
3434
<maven.compiler.source>1.8</maven.compiler.source>
35-
<log.version>2.18.0</log.version>
35+
<log.version>2.19.0</log.version>
36+
<junit.version>5.9.0</junit.version>
37+
<mockito.version>5.1.1</mockito.version>
38+
<surefire-plugin.version>3.0.0-M8</surefire-plugin.version>
3639
</properties>
3740

3841
<dependencies>
@@ -46,6 +49,31 @@
4649
<artifactId>log4j-core</artifactId>
4750
<version>${log.version}</version>
4851
</dependency>
52+
<dependency>
53+
<groupId>org.junit.jupiter</groupId>
54+
<artifactId>junit-jupiter-engine</artifactId>
55+
<version>${junit.version}</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.junit.jupiter</groupId>
60+
<artifactId>junit-jupiter-params</artifactId>
61+
<version>${junit.version}</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.mockito</groupId>
66+
<artifactId>mockito-core</artifactId>
67+
<version>${mockito.version}</version>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.mockito</groupId>
72+
<artifactId>mockito-junit-jupiter</artifactId>
73+
<version>${mockito.version}</version>
74+
<scope>test</scope>
75+
</dependency>
76+
4977
</dependencies>
5078

5179
<build>
@@ -55,7 +83,7 @@
5583
<plugin>
5684
<groupId>org.apache.maven.plugins</groupId>
5785
<artifactId>maven-assembly-plugin</artifactId>
58-
<version>3.4.1</version>
86+
<version>3.4.2</version>
5987
<configuration>
6088
<archive>
6189
<manifest>
@@ -77,6 +105,12 @@
77105
</execution>
78106
</executions>
79107
</plugin>
108+
109+
<plugin>
110+
<groupId>org.apache.maven.plugins</groupId>
111+
<artifactId>maven-surefire-plugin</artifactId>
112+
<version>${surefire-plugin.version}</version>
113+
</plugin>
80114
</plugins>
81115
</build>
82116

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.github.gaboso;
22

3+
import com.github.gaboso.helper.CommandExecutor;
34
import com.github.gaboso.module.GitModule;
45
import com.github.gaboso.module.Module;
6+
import com.github.gaboso.module.ModuleTypeEnum;
57
import com.github.gaboso.module.impl.BowerModule;
68
import com.github.gaboso.module.impl.GruntModule;
79
import com.github.gaboso.module.impl.MavenModule;
810
import com.github.gaboso.module.impl.NpmModule;
11+
import org.apache.logging.log4j.LogManager;
12+
import org.apache.logging.log4j.Logger;
913

1014
import java.io.File;
1115
import java.util.Arrays;
@@ -17,40 +21,61 @@
1721
*/
1822
public class ModuleRunner {
1923

24+
private static final Logger LOGGER = LogManager.getLogger(ModuleRunner.class.getName());
25+
26+
private final GitModule gitModule;
27+
2028
private final List<Module> modules;
2129

2230
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+
);
2841
}
2942

3043
public void runAll(List<File> folders) {
31-
for (File folder : folders) {
32-
run(folder);
33-
}
44+
folders.forEach(this::run);
3445
}
3546

3647
public void run(File folder) {
3748
String path = folder.getPath();
3849
String folderName = folder.getName();
3950

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);
4256
}
4357

4458
File[] listFiles = folder.listFiles();
4559
if (listFiles == null) {
4660
return;
4761
}
4862

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);
5479
}
5580

5681
}

src/main/java/com/github/gaboso/format/Formatter.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/java/com/github/gaboso/helper/CommandHelper.java renamed to src/main/java/com/github/gaboso/helper/CommandExecutor.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.gaboso.helper;
22

3-
import com.github.gaboso.format.Formatter;
3+
import com.github.gaboso.os.OpSystemEnum;
44
import org.apache.logging.log4j.LogManager;
55
import org.apache.logging.log4j.Logger;
66

@@ -12,18 +12,14 @@
1212
* @since 1.0
1313
* Command Helper
1414
*/
15-
public class CommandHelper {
15+
public class CommandExecutor {
1616

17-
private static final Logger LOGGER = LogManager.getLogger(CommandHelper.class.getName());
17+
private static final Logger LOGGER = LogManager.getLogger(CommandExecutor.class.getName());
1818

19-
private CommandHelper() {
20-
}
21-
22-
public static void executeCMD(String path, String cmd, Formatter formatter) {
23-
LOGGER.info(formatter.getMessageStartUpdate());
24-
25-
String runner = OsHelper.getRunner();
26-
String option = OsHelper.getOption();
19+
public void executeCMD(String path, String cmd) {
20+
OpSystemEnum currentOs = OpSystemEnum.getCurrentOs();
21+
String runner = currentOs.getRunner();
22+
String option = currentOs.getOption();
2723

2824
String command = "cd " + path + "/ && " + cmd;
2925

@@ -46,7 +42,6 @@ public static void executeCMD(String path, String cmd, Formatter formatter) {
4642
} catch (IOException e) {
4743
LOGGER.error(e.getMessage(), e);
4844
}
49-
LOGGER.info(formatter.getMessageFinishUpdate());
5045
}
5146

5247
}

src/main/java/com/github/gaboso/helper/OsHelper.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/main/java/com/github/gaboso/module/GitModule.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.github.gaboso.module;
22

3-
import com.github.gaboso.format.Formatter;
4-
import com.github.gaboso.helper.CommandHelper;
5-
import com.github.gaboso.helper.OsHelper;
3+
import com.github.gaboso.helper.CommandExecutor;
4+
import com.github.gaboso.os.OpSystemEnum;
65
import org.apache.logging.log4j.LogManager;
76
import org.apache.logging.log4j.Logger;
87

@@ -18,12 +17,16 @@ public class GitModule {
1817

1918
private static final Logger LOGGER = LogManager.getLogger(GitModule.class.getName());
2019

21-
private GitModule() {
20+
private final CommandExecutor commandExecutor;
21+
22+
public GitModule(CommandExecutor commandExecutor) {
23+
this.commandExecutor = commandExecutor;
2224
}
2325

24-
public static boolean isProject(String path) {
25-
String runner = OsHelper.getRunner();
26-
String option = OsHelper.getOption();
26+
public boolean isProject(String path) {
27+
OpSystemEnum currentOs = OpSystemEnum.getCurrentOs();
28+
String runner = currentOs.getRunner();
29+
String option = currentOs.getOption();
2730

2831
ProcessBuilder builder = new ProcessBuilder(runner, option, "cd " + path + "/ && git rev-parse --is-inside-work-tree");
2932
builder.redirectErrorStream(true);
@@ -40,10 +43,9 @@ public static boolean isProject(String path) {
4043
return false;
4144
}
4245

43-
public static void executeCommands(String projectName, String projectPath) {
44-
Formatter formatter = new Formatter("Git", projectName);
45-
46-
CommandHelper.executeCMD(projectPath, "git fetch && git pull origin", formatter);
46+
public void executeCommands(String projectPath) {
47+
String command = ModuleTypeEnum.GIT.getCommand();
48+
commandExecutor.executeCMD(projectPath, command);
4749
}
4850

4951
}

src/main/java/com/github/gaboso/module/Module.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public interface Module {
66

77
boolean isProject(File[] listFiles);
88

9-
void executeCommands(String projectName, String projectPath);
9+
void executeCommands(String projectPath);
10+
11+
ModuleTypeEnum getType();
1012

1113
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.gaboso.module;
2+
3+
/**
4+
* @since 3.0.0
5+
* ModuleTypeEnum
6+
*/
7+
public enum ModuleTypeEnum {
8+
9+
MAVEN("Maven", "mvn clean install -DskipTests=true"),
10+
GRUNT("Grunt", "grunt"),
11+
BOWER("Bower", "bower install && bower update"),
12+
NPM("NPM", "npm install && npm update"),
13+
GIT("Git", "git fetch && git pull origin");
14+
15+
private final String typeName;
16+
private final String command;
17+
18+
ModuleTypeEnum(String name, String command) {
19+
this.typeName = name;
20+
this.command = command;
21+
}
22+
23+
public String getTypeName() {
24+
return typeName;
25+
}
26+
27+
public String getCommand() {
28+
return command;
29+
}
30+
}

0 commit comments

Comments
 (0)