Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@

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

## [3.0.0] - 2023-02-15

### Changed
- Update log4j dependency from 2.18.0 to 2.19.0
- Update maven-assembly-plugin dependency from 3.4.1 to 3.4.2
- Improve logger logic in ModuleRunner
- Renamed class from CommandHelper to CommandExecutor

### Added

- Unit tests and unit tests dependencies: JUnit and mockito
- Created ModuleTypeEnum to store module name and commands
- Created OpSystemEnum to store OS runner and option

### Removed

- Formatter class
- OsHelper class

## [2.0.0] - 2022-07-05

### Changed

- Update log4j dependency from 1.17.2 to 1.18.0
- Update log4j dependency from 2.17.2 to 2.18.0
- Update maven-assembly-plugin dependency from 3.3.0 to 3.4.0
- Split Scriptum class in other two classes
- Change jar entry point from Scriptum class to Main class
Expand Down
40 changes: 37 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>br.com.gaboso</groupId>
<artifactId>scriptum</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>

<organization>
<name>com.github.gaboso</name>
Expand All @@ -32,7 +32,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<log.version>2.18.0</log.version>
<log.version>2.19.0</log.version>
<junit.version>5.9.0</junit.version>
<mockito.version>5.1.1</mockito.version>
<surefire-plugin.version>3.0.0-M8</surefire-plugin.version>
</properties>

<dependencies>
Expand All @@ -46,6 +49,31 @@
<artifactId>log4j-core</artifactId>
<version>${log.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand All @@ -55,7 +83,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
Expand All @@ -77,6 +105,12 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
</plugin>
</plugins>
</build>

Expand Down
55 changes: 40 additions & 15 deletions src/main/java/com/github/gaboso/ModuleRunner.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.github.gaboso;

import com.github.gaboso.helper.CommandExecutor;
import com.github.gaboso.module.GitModule;
import com.github.gaboso.module.Module;
import com.github.gaboso.module.ModuleTypeEnum;
import com.github.gaboso.module.impl.BowerModule;
import com.github.gaboso.module.impl.GruntModule;
import com.github.gaboso.module.impl.MavenModule;
import com.github.gaboso.module.impl.NpmModule;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.util.Arrays;
Expand All @@ -17,40 +21,61 @@
*/
public class ModuleRunner {

private static final Logger LOGGER = LogManager.getLogger(ModuleRunner.class.getName());

private final GitModule gitModule;

private final List<Module> modules;

public ModuleRunner() {
Module bowerModule = new BowerModule();
Module gruntModule = new GruntModule();
Module mavenModule = new MavenModule();
Module npmModule = new NpmModule();
modules = Arrays.asList(bowerModule, gruntModule, mavenModule, npmModule);
CommandExecutor commandExecutor = new CommandExecutor();

this.gitModule = new GitModule(commandExecutor);

this.modules = Arrays.asList(
new BowerModule(commandExecutor),
new GruntModule(commandExecutor),
new MavenModule(commandExecutor),
new NpmModule(commandExecutor)
);
}

public void runAll(List<File> folders) {
for (File folder : folders) {
run(folder);
}
folders.forEach(this::run);
}

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

if (GitModule.isProject(path)) {
GitModule.executeCommands(folderName, path);
if (gitModule.isProject(path)) {
String typeName = ModuleTypeEnum.GIT.getTypeName();
printStartMessage(typeName, folderName);
gitModule.executeCommands(path);
printFinishMessage(typeName, folderName);
}

File[] listFiles = folder.listFiles();
if (listFiles == null) {
return;
}

for (Module module : modules) {
if (module.isProject(listFiles)) {
module.executeCommands(folderName, path);
}
}
modules.stream()
.filter(module -> module.isProject(listFiles))
.forEach(module -> {
String typeName = module.getType().getTypeName();
printStartMessage(typeName, folderName);
module.executeCommands(path);
printFinishMessage(typeName, folderName);
});
}

private void printStartMessage(String typeName, String folderName) {
LOGGER.info("--------- Starting update {} --- [ {} ] ---------", typeName, folderName);
}

private void printFinishMessage(String typeName, String folderName) {
LOGGER.info("--------- Finished update {} --- [ {} ] ---------", typeName, folderName);
}

}
25 changes: 0 additions & 25 deletions src/main/java/com/github/gaboso/format/Formatter.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.gaboso.helper;

import com.github.gaboso.format.Formatter;
import com.github.gaboso.os.OpSystemEnum;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -12,18 +12,14 @@
* @since 1.0
* Command Helper
*/
public class CommandHelper {
public class CommandExecutor {

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

private CommandHelper() {
}

public static void executeCMD(String path, String cmd, Formatter formatter) {
LOGGER.info(formatter.getMessageStartUpdate());

String runner = OsHelper.getRunner();
String option = OsHelper.getOption();
public void executeCMD(String path, String cmd) {
OpSystemEnum currentOs = OpSystemEnum.getCurrentOs();
String runner = currentOs.getRunner();
String option = currentOs.getOption();

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

Expand All @@ -46,7 +42,6 @@ public static void executeCMD(String path, String cmd, Formatter formatter) {
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
LOGGER.info(formatter.getMessageFinishUpdate());
}

}
24 changes: 0 additions & 24 deletions src/main/java/com/github/gaboso/helper/OsHelper.java

This file was deleted.

24 changes: 13 additions & 11 deletions src/main/java/com/github/gaboso/module/GitModule.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.github.gaboso.module;

import com.github.gaboso.format.Formatter;
import com.github.gaboso.helper.CommandHelper;
import com.github.gaboso.helper.OsHelper;
import com.github.gaboso.helper.CommandExecutor;
import com.github.gaboso.os.OpSystemEnum;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

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

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

private GitModule() {
private final CommandExecutor commandExecutor;

public GitModule(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
}

public static boolean isProject(String path) {
String runner = OsHelper.getRunner();
String option = OsHelper.getOption();
public boolean isProject(String path) {
OpSystemEnum currentOs = OpSystemEnum.getCurrentOs();
String runner = currentOs.getRunner();
String option = currentOs.getOption();

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

public static void executeCommands(String projectName, String projectPath) {
Formatter formatter = new Formatter("Git", projectName);

CommandHelper.executeCMD(projectPath, "git fetch && git pull origin", formatter);
public void executeCommands(String projectPath) {
String command = ModuleTypeEnum.GIT.getCommand();
commandExecutor.executeCMD(projectPath, command);
}

}
4 changes: 3 additions & 1 deletion src/main/java/com/github/gaboso/module/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public interface Module {

boolean isProject(File[] listFiles);

void executeCommands(String projectName, String projectPath);
void executeCommands(String projectPath);

ModuleTypeEnum getType();

}
30 changes: 30 additions & 0 deletions src/main/java/com/github/gaboso/module/ModuleTypeEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.gaboso.module;

/**
* @since 3.0.0
* ModuleTypeEnum
*/
public enum ModuleTypeEnum {

MAVEN("Maven", "mvn clean install -DskipTests=true"),
GRUNT("Grunt", "grunt"),
BOWER("Bower", "bower install && bower update"),
NPM("NPM", "npm install && npm update"),
GIT("Git", "git fetch && git pull origin");

private final String typeName;
private final String command;

ModuleTypeEnum(String name, String command) {
this.typeName = name;
this.command = command;
}

public String getTypeName() {
return typeName;
}

public String getCommand() {
return command;
}
}
Loading