Skip to content

Commit

Permalink
a reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 12, 2024
1 parent 5949378 commit 299d82a
Showing 1 changed file with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,46 @@

import java.io.File;

public class ReporterThatCreatesAnApprovalScript implements ApprovalFailureReporter {
private static String fileName = "approval_script";
private static File scriptFile = null;
static {
initializeFile();

}

private static void initializeFile() {
if (scriptFile != null) {return;}
if (SystemUtils.isWindowsEnvironment()) {
initializeWindows();
} else {
initializeLinux();
}
SimpleLogger.event("Created approval script:\n" + scriptFile.getAbsolutePath());
}

private static void initializeLinux() {
scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "/" + fileName + ".sh");
FileUtils.createIfNeeded(scriptFile.getAbsolutePath());
FileUtils.writeFile(scriptFile, "#!/bin/bash\n");
scriptFile.setExecutable(true);
}

private static void initializeWindows() {
scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "\\" + fileName + ".bat");
FileUtils.createIfNeeded(scriptFile.getAbsolutePath());
FileUtils.writeFile(scriptFile, "");
public class ReporterThatCreatesAnApprovalScript implements ApprovalFailureReporter
{
private static String fileName = "approval_script";
private static File scriptFile = null;
static
{
initializeFile();
}
private static void initializeFile()
{
if (scriptFile != null)
{ return; }
if (SystemUtils.isWindowsEnvironment())
{
initializeWindows();
}

@Override
public boolean report(String received, String approved) {
String commandLine = ClipboardReporter.getCommandLine(received, approved);
FileUtils.appendToFile(scriptFile, commandLine + "\n");
return true;
else
{
initializeLinux();
}
SimpleLogger.event("Created approval script:\n" + scriptFile.getAbsolutePath());
}
private static void initializeLinux()
{
scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "/" + fileName + ".sh");
FileUtils.createIfNeeded(scriptFile.getAbsolutePath());
FileUtils.writeFile(scriptFile, "#!/bin/bash\n");
scriptFile.setExecutable(true);
}
private static void initializeWindows()
{
scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "\\" + fileName + ".bat");
FileUtils.createIfNeeded(scriptFile.getAbsolutePath());
FileUtils.writeFile(scriptFile, "");
}
@Override
public boolean report(String received, String approved)
{
String commandLine = ClipboardReporter.getCommandLine(received, approved);
FileUtils.appendToFile(scriptFile, commandLine + "\n");
return true;
}
}

0 comments on commit 299d82a

Please sign in to comment.