Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #323 from ispong/latest
Browse files Browse the repository at this point in the history
🐛 fix command utils log file always in process
  • Loading branch information
ispong committed Oct 11, 2022
2 parents 344ca59 + 270757f commit 0b40cca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public static int execute(String command, String logPath, long waitingTime) {
DefaultExecutor executor = new DefaultExecutor();
CommandLine cmdLine = generateCommandLine(command);

try {
try (FileOutputStream fileOutputStream = new FileOutputStream(logPath, true)) {

// set log file path
FileOutputStream fileOutputStream = new FileOutputStream(logPath, true);
PumpStreamHandler streamHandler =
new PumpStreamHandler(fileOutputStream, fileOutputStream, null);
executor.setStreamHandler(streamHandler);
Expand All @@ -106,7 +106,6 @@ public static int execute(String command, String logPath, long waitingTime) {

// execute command
return executor.execute(cmdLine);

} catch (IOException e) {
log.debug(e.getMessage());
throw new OxygenException("execute command error");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.isxcode.oxygen.core;

import com.isxcode.oxygen.core.command.CommandUtils;
import com.isxcode.oxygen.core.file.FileUtils;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;

public class CommandUtilsTests {

@Test
@SneakyThrows
public void testCommand() {

System.out.println(CommandUtils.executeBack("dir"));

System.out.println(CommandUtils.execute("dir"));

System.out.println(CommandUtils.execute("dir", "command.log"));

System.out.println(CommandUtils.execute("dir"));
FileUtils.recursionDeleteFile("command.log");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,33 @@

public class FileUtilsTests {

private final String dirPath = "file";

@Test
public void testGenerateDir() {

FileUtils.generateDirs("test");
FileUtils.generateDirs(dirPath);
}

@Test
public void testGenerateFile() {

FileUtils.generateFile("test" + File.separator + "file" + File.separator + "file1.test");
FileUtils.generateFile(dirPath + File.separator + "file1.txt");
}

@Test
public void testStringToFile() {

FileUtils.StringToFile(
"hello",
"test" + File.separator + "file" + File.separator + "file2.test",
StandardOpenOption.WRITE);
"hello", dirPath + File.separator + "file2.txt", StandardOpenOption.WRITE);
}

@Test
public void testCopyResourceFile() {

FileUtils.copyResourceFile(
"application-test.yml",
"test" + File.separator + "file" + File.separator + "file3.test",
StandardOpenOption.WRITE);
}

@Test
public void testRecursionDeleteFile() {
"application-test.yml", dirPath + File.separator + "file3.txt", StandardOpenOption.WRITE);

FileUtils.recursionDeleteFile("test");
FileUtils.recursionDeleteFile(dirPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FreemarkerUtilsTests {
public void testContentToFile() {

try {
FreemarkerUtils.contentToFile(templateContent, dog, "freemarker1.log");
FreemarkerUtils.contentToFile(templateContent, dog, "freemarker1.txt");
} catch (OxygenException e) {
System.out.println(e.getMessage());
throw e;
Expand All @@ -56,7 +56,7 @@ public void testContentToString() {
public void testTemplateToFile() {

try {
FreemarkerUtils.templateToFile(templateName, dog, "freemarker2.log");
FreemarkerUtils.templateToFile(templateName, dog, "freemarker2.txt");
} catch (OxygenException e) {
System.out.println(e.getMessage());
throw e;
Expand All @@ -72,5 +72,8 @@ public void testTemplateToString() {
System.out.println(e.getMessage());
throw e;
}

FileUtils.recursionDeleteFile("freemarker1.txt");
FileUtils.recursionDeleteFile("freemarker2.txt");
}
}

0 comments on commit 0b40cca

Please sign in to comment.