Skip to content

Commit

Permalink
Fixing indentation in HabushuUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
georgit committed Dec 19, 2023
1 parent 94fe24a commit ff28e20
Showing 1 changed file with 85 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ private HabushuUtil() {
* @return the username for the server specified in Maven's settings.xml
*/
public static String findUsernameForServer(Settings settings, String serverId) {
Server server = settings.getServer(serverId);
return server != null ? server.getUsername() : null;
Server server = settings.getServer(serverId);
return server != null ? server.getUsername() : null;
}

public static String findPasswordForServer(Settings settings, String serverId, boolean decryptPassword) {
String password = "";
if (decryptPassword) {
password = decryptServerPassword(settings, serverId);
} else {
logger.warn(
"Detected use of plain-text password! This is a security risk! Please consider using an encrypted password!");
password = findPlaintextPasswordForServer(settings, serverId);
}
return password;
String password = "";
if (decryptPassword) {
password = decryptServerPassword(settings, serverId);
} else {
logger.warn(
"Detected use of plain-text password! This is a security risk! Please consider using an encrypted password!");
password = findPlaintextPasswordForServer(settings, serverId);
}
return password;
}

/**
Expand All @@ -55,8 +55,8 @@ public static String findPasswordForServer(Settings settings, String serverId, b
* @return the password for the specified server from Maven's settings.xml
*/
public static String findPlaintextPasswordForServer(Settings settings, String serverId) {
Server server = settings.getServer(serverId);
return server != null ? server.getPassword() : null;
Server server = settings.getServer(serverId);
return server != null ? server.getPassword() : null;
}

/**
Expand All @@ -65,15 +65,15 @@ public static String findPlaintextPasswordForServer(Settings settings, String se
* @param serverId the id of the server to decrypt the password for
*/
public static String decryptServerPassword(Settings settings, String serverId) {
String decryptedPassword = null;
String decryptedPassword = null;

try {
decryptedPassword = MavenPasswordDecoder.decryptPasswordForServer(settings, serverId);
} catch (PlexusCipherException | SecDispatcherException e) {
throw new HabushuException("Unable to decrypt stored passwords.", e);
}
try {
decryptedPassword = MavenPasswordDecoder.decryptPasswordForServer(settings, serverId);
} catch (PlexusCipherException | SecDispatcherException e) {
throw new HabushuException("Unable to decrypt stored passwords.", e);
}

return decryptedPassword;
return decryptedPassword;
}

/**
Expand All @@ -94,50 +94,50 @@ public static void runBashScript(String bashScriptPath) {
* INFO
*/
public static void runBashScript(String bashScriptPath, String[] parameters, boolean debug) {
logger.debug("Running bash script located at {}.", bashScriptPath);

try {
String[] command;
if (parameters != null && parameters.length > 0) {
command = new String[parameters.length + 1];

for (int i = 0; i < parameters.length; i++) {
command[i + 1] = parameters[i];
logger.debug("Running bash script located at {}.", bashScriptPath);

try {
String[] command;
if (parameters != null && parameters.length > 0) {
command = new String[parameters.length + 1];

for (int i = 0; i < parameters.length; i++) {
command[i + 1] = parameters[i];
}
} else {
command = new String[1];
}
command[0] = bashScriptPath;

Process process = Runtime.getRuntime().exec(command);

StringBuilder output = new StringBuilder();
String line;

BufferedReader stdInReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = stdInReader.readLine()) != null) {
output.append(line + "\n");
}

BufferedReader stdErrReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while ((line = stdErrReader.readLine()) != null) {
output.append(line + "\n");
}

if (debug) {
logger.debug(output.toString());
} else {
logger.info(output.toString());
}

int exitVal = process.waitFor();
if (exitVal != 0) {
throw new HabushuException("Error encountered when running bash script located at " + bashScriptPath
+ "\n Can run maven build with -X to see the output of the failed script.");
}
} catch (IOException | InterruptedException e) {
throw new HabushuException("Could not run bash script.", e);
}
} else {
command = new String[1];
}
command[0] = bashScriptPath;

Process process = Runtime.getRuntime().exec(command);

StringBuilder output = new StringBuilder();
String line;

BufferedReader stdInReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = stdInReader.readLine()) != null) {
output.append(line + "\n");
}

BufferedReader stdErrReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while ((line = stdErrReader.readLine()) != null) {
output.append(line + "\n");
}

if (debug) {
logger.debug(output.toString());
} else {
logger.info(output.toString());
}

int exitVal = process.waitFor();
if (exitVal != 0) {
throw new HabushuException("Error encountered when running bash script located at " + bashScriptPath
+ "\n Can run maven build with -X to see the output of the failed script.");
}
} catch (IOException | InterruptedException e) {
throw new HabushuException("Could not run bash script.", e);
}
}

/**
Expand All @@ -147,13 +147,13 @@ public static void runBashScript(String bashScriptPath, String[] parameters, boo
* @param filePath the path to the file
*/
public static void writeLinesToFile(String commands, String filePath) {
logger.debug("Writing lines to file located at {}.", filePath);
logger.debug("Writing lines to file located at {}.", filePath);

try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
writer.write(commands);
} catch (IOException e) {
throw new HabushuException("Could not write to file.", e);
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
writer.write(commands);
} catch (IOException e) {
throw new HabushuException("Could not write to file.", e);
}
}

/**
Expand All @@ -163,19 +163,19 @@ public static void writeLinesToFile(String commands, String filePath) {
* @param newFile the file location
*/
public static void createFileAndGivePermissions(File newFile) {
logger.debug("Creating new file at {}.", newFile.getAbsolutePath());
logger.debug("Creating new file at {}.", newFile.getAbsolutePath());

newFile = new File(newFile.getAbsolutePath());
newFile = new File(newFile.getAbsolutePath());

if (!newFile.exists()) {
try {
newFile.createNewFile();
} catch (IOException e) {
throw new HabushuException("Could not create new file.", e);
}
}
if (!newFile.exists()) {
try {
newFile.createNewFile();
} catch (IOException e) {
throw new HabushuException("Could not create new file.", e);
}
}

giveFullFilePermissions(newFile.getAbsolutePath());
giveFullFilePermissions(newFile.getAbsolutePath());
}

/**
Expand All @@ -184,13 +184,13 @@ public static void createFileAndGivePermissions(File newFile) {
* @param filePath the path to the file
*/
public static void giveFullFilePermissions(String filePath) {
File file = new File(filePath);
File file = new File(filePath);

if (file.exists()) {
file.setExecutable(true, false);
file.setReadable(true, false);
file.setWritable(true, false);
}
if (file.exists()) {
file.setExecutable(true, false);
file.setReadable(true, false);
file.setWritable(true, false);
}
}

}

0 comments on commit ff28e20

Please sign in to comment.