1 | /** | | 1 | /** |
2 | * Returns a string representation of the object for error messages | | 2 | * Execute the task. |
3 | * and the like | | 3 | * @throws BuildException on error |
4 | * @return a string representation of the object. | | 4 | */ |
5 | */ | | 5 | public void execute() throws BuildException { |
6 | public String toString() { | | 6 | |
7 | StringBuffer buffer = new StringBuffer(); | | 7 | if (null == alias) { |
8 | buffer.append(namespace != null ? namespace : "(anonymous)"); | | 8 | throw new BuildException("alias attribute must be set"); |
9 | buffer.append(' '); | | 9 | } |
10 | buffer.append(url != null ? (url + " ") : ""); | | 10 | |
11 | buffer.append(file != null ? file.getAbsolutePath() : ""); | | 11 | if (null == storepass) { |
12 | return buffer.toString(); | | 12 | throw new BuildException("storepass attribute must be set"); |
13 | } | | 13 | } |
| | | 14 | |
| | | 15 | if (null == dname && null == expandedDname) { |
| | | 16 | throw new BuildException("dname must be set"); |
| | | 17 | } |
| | | 18 | |
| | | 19 | final StringBuffer sb = new StringBuffer(); |
| | | 20 | |
| | | 21 | sb.append("-genkey "); |
| | | 22 | |
| | | 23 | if (verbose) { |
| | | 24 | sb.append("-v "); |
| | | 25 | } |
| | | 26 | |
| | | 27 | sb.append("-alias \""); |
| | | 28 | sb.append(alias); |
| | | 29 | sb.append("\" "); |
| | | 30 | |
| | | 31 | if (null != dname) { |
| | | 32 | sb.append("-dname \""); |
| | | 33 | sb.append(dname); |
| | | 34 | sb.append("\" "); |
| | | 35 | } |
| | | 36 | |
| | | 37 | if (null != expandedDname) { |
| | | 38 | sb.append("-dname \""); |
| | | 39 | sb.append(expandedDname); |
| | | 40 | sb.append("\" "); |
| | | 41 | } |
| | | 42 | |
| | | 43 | if (null != keystore) { |
| | | 44 | sb.append("-keystore \""); |
| | | 45 | sb.append(keystore); |
| | | 46 | sb.append("\" "); |
| | | 47 | } |
| | | 48 | |
| | | 49 | if (null != storepass) { |
| | | 50 | sb.append("-storepass \""); |
| | | 51 | sb.append(storepass); |
| | | 52 | sb.append("\" "); |
| | | 53 | } |
| | | 54 | |
| | | 55 | if (null != storetype) { |
| | | 56 | sb.append("-storetype \""); |
| | | 57 | sb.append(storetype); |
| | | 58 | sb.append("\" "); |
| | | 59 | } |
| | | 60 | |
| | | 61 | sb.append("-keypass \""); |
| | | 62 | if (null != keypass) { |
| | | 63 | sb.append(keypass); |
| | | 64 | } else { |
| | | 65 | sb.append(storepass); |
| | | 66 | } |
| | | 67 | sb.append("\" "); |
| | | 68 | |
| | | 69 | if (null != sigalg) { |
| | | 70 | sb.append("-sigalg \""); |
| | | 71 | sb.append(sigalg); |
| | | 72 | sb.append("\" "); |
| | | 73 | } |
| | | 74 | |
| | | 75 | if (null != keyalg) { |
| | | 76 | sb.append("-keyalg \""); |
| | | 77 | sb.append(keyalg); |
| | | 78 | sb.append("\" "); |
| | | 79 | } |
| | | 80 | |
| | | 81 | |
| | | 82 | if (0 < keysize) { |
| | | 83 | sb.append("-keysize \""); |
| | | 84 | sb.append(keysize); |
| | | 85 | sb.append("\" "); |
| | | 86 | } |
| | | 87 | |
| | | 88 | if (0 < validity) { |
| | | 89 | sb.append("-validity \""); |
| | | 90 | sb.append(validity); |
| | | 91 | sb.append("\" "); |
| | | 92 | } |
| | | 93 | |
| | | 94 | log("Generating Key for " + alias); |
| | | 95 | final ExecTask cmd = new ExecTask(this); |
| | | 96 | cmd.setExecutable(JavaEnvUtils.getJdkExecutable("keytool")); |
| | | 97 | Commandline.Argument arg = cmd.createArg(); |
| | | 98 | arg.setLine(sb.toString()); |
| | | 99 | cmd.setFailonerror(true); |
| | | 100 | cmd.setTaskName(getTaskName()); |
| | | 101 | cmd.execute(); |
| | | 102 | } |