Skip to content

Commit

Permalink
Fixed code quality issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mentiflectax committed Dec 27, 2014
1 parent 233364f commit d9b354b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target/
jcabi-ssl-maven-plugin.iml
.idea/
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<exclude>findbugs:.*</exclude>
<exclude>xml:/src/it/settings.xml</exclude>
</excludes>
<license>file:${basedir}/LICENSE.txt</license>
</configuration>
</plugin>
</plugins>
Expand Down
53 changes: 44 additions & 9 deletions src/main/java/com/jcabi/ssl/maven/plugin/Keytool.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.io.FileUtils;
Expand All @@ -54,6 +55,15 @@
@ToString
@EqualsAndHashCode(of = { "keystore", "password" })
final class Keytool {
/**
* Localhost, input to the keytool.
*/
public static final String LOCALHOST = "localhost";

/**
* Platform-dependent line separator.
*/
public static final String NEWLINE = System.getProperty("line.separator");

/**
* Keystore location.
Expand Down Expand Up @@ -94,7 +104,7 @@ public void genkey() throws IOException {
final Process proc = this.proc(
"-genkeypair",
"-alias",
"localhost",
Keytool.LOCALHOST,
"-keyalg",
"RSA",
"-keysize",
Expand All @@ -105,13 +115,13 @@ public void genkey() throws IOException {
final PrintWriter writer = new PrintWriter(
new OutputStreamWriter(proc.getOutputStream())
);
writer.print("localhost\n");
writer.print("ACME Co.\n");
writer.print("software developers\n");
writer.print("San Francisco\n");
writer.print("California\n");
writer.print("US\n");
writer.print("yes\n");
writer.print(this.appendNewLine(Keytool.LOCALHOST));
writer.print(this.appendNewLine("ACME Co."));
writer.print(this.appendNewLine("software developers"));
writer.print(this.appendNewLine("San Francisco"));
writer.print(this.appendNewLine("California"));
writer.print(this.appendNewLine("US"));
writer.print(this.appendNewLine(this.createLocaleDependentYes()));
writer.close();
new VerboseProcess(proc).stdout();
Logger.info(
Expand Down Expand Up @@ -145,6 +155,32 @@ public void imprt(final File file, final String pwd) throws IOException {
).stdout();
}

/**
* Creates a string, which consists of string with an appended
* platform-dependent line separator.
* @param text Text, to which the line separator needs to be appended
* @return Contents of text with appended line separator
*/
private String appendNewLine(final String text) {
return String.format("%s%s", text, NEWLINE);
}

/**
* Creates a text, which represents "yes" in either English or German
* language, depending on the locale.
* @return Return "Ja", if the locale is German, "Yes" otherwise.
*/
private String createLocaleDependentYes() {
final String language = Locale.getDefault().getLanguage();
final String yes;
if ("de".equals(language)) {
yes = "Ja";
} else {
yes = "Yes";
}
return yes;
}

/**
* Create process builder.
* @param args Arguments
Expand All @@ -171,5 +207,4 @@ private ProcessBuilder proc(final String... args) throws IOException {
cmds.add(this.keystore);
return new ProcessBuilder(cmds);
}

}

0 comments on commit d9b354b

Please sign in to comment.