Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JarsignerSignMojo |
|
| 8.0;8 |
1 | package org.apache.maven.plugins.jarsigner; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.File; | |
23 | ||
24 | import org.codehaus.plexus.util.StringUtils; | |
25 | import org.codehaus.plexus.util.cli.Commandline; | |
26 | ||
27 | /** | |
28 | * Signs a project artifact and attachments using jarsigner. | |
29 | * | |
30 | * @author <a href="cs@schulte.it">Christian Schulte</a> | |
31 | * @version $Id: JarsignerSignMojo.java 795388 2009-07-18 15:43:59Z bentmann $ | |
32 | * @goal sign | |
33 | * @phase package | |
34 | */ | |
35 | 0 | public class JarsignerSignMojo |
36 | extends AbstractJarsignerMojo | |
37 | { | |
38 | ||
39 | /** | |
40 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
41 | * | |
42 | * @parameter expression="${jarsigner.keystore}" | |
43 | */ | |
44 | private String keystore; | |
45 | ||
46 | /** | |
47 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
48 | * | |
49 | * @parameter expression="${jarsigner.storepass}" | |
50 | */ | |
51 | private String storepass; | |
52 | ||
53 | /** | |
54 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
55 | * | |
56 | * @parameter expression="${jarsigner.keypass}" | |
57 | */ | |
58 | private String keypass; | |
59 | ||
60 | /** | |
61 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
62 | * | |
63 | * @parameter expression="${jarsigner.sigfile}" | |
64 | */ | |
65 | private String sigfile; | |
66 | ||
67 | /** | |
68 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
69 | * | |
70 | * @parameter expression="${jarsigner.storetype}" | |
71 | */ | |
72 | private String storetype; | |
73 | ||
74 | /** | |
75 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
76 | * | |
77 | * @parameter expression="${jarsigner.providerName}" | |
78 | */ | |
79 | private String providerName; | |
80 | ||
81 | /** | |
82 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
83 | * | |
84 | * @parameter expression="${jarsigner.providerClass}" | |
85 | */ | |
86 | private String providerClass; | |
87 | ||
88 | /** | |
89 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
90 | * | |
91 | * @parameter expression="${jarsigner.providerArg}" | |
92 | */ | |
93 | private String providerArg; | |
94 | ||
95 | /** | |
96 | * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>. | |
97 | * | |
98 | * @parameter expression="${jarsigner.alias}" | |
99 | * @required | |
100 | */ | |
101 | private String alias; | |
102 | ||
103 | protected Commandline getCommandline( final File archive, final Commandline commandLine ) | |
104 | { | |
105 | 0 | if ( archive == null ) |
106 | { | |
107 | 0 | throw new NullPointerException( "archive" ); |
108 | } | |
109 | 0 | if ( commandLine == null ) |
110 | { | |
111 | 0 | throw new NullPointerException( "commandLine" ); |
112 | } | |
113 | ||
114 | 0 | if ( !StringUtils.isEmpty( this.keystore ) ) |
115 | { | |
116 | 0 | commandLine.createArg().setValue( "-keystore" ); |
117 | 0 | commandLine.createArg().setValue( this.keystore ); |
118 | } | |
119 | 0 | if ( !StringUtils.isEmpty( this.storepass ) ) |
120 | { | |
121 | 0 | commandLine.createArg().setValue( "-storepass" ); |
122 | 0 | commandLine.createArg().setValue( this.storepass ); |
123 | } | |
124 | 0 | if ( !StringUtils.isEmpty( this.keypass ) ) |
125 | { | |
126 | 0 | commandLine.createArg().setValue( "-keypass" ); |
127 | 0 | commandLine.createArg().setValue( this.keypass ); |
128 | } | |
129 | 0 | if ( !StringUtils.isEmpty( this.storetype ) ) |
130 | { | |
131 | 0 | commandLine.createArg().setValue( "-storetype" ); |
132 | 0 | commandLine.createArg().setValue( this.storetype ); |
133 | } | |
134 | 0 | if ( !StringUtils.isEmpty( this.providerName ) ) |
135 | { | |
136 | 0 | commandLine.createArg().setValue( "-providerName" ); |
137 | 0 | commandLine.createArg().setValue( this.providerName ); |
138 | } | |
139 | 0 | if ( !StringUtils.isEmpty( this.providerClass ) ) |
140 | { | |
141 | 0 | commandLine.createArg().setValue( "-providerClass" ); |
142 | 0 | commandLine.createArg().setValue( this.providerClass ); |
143 | } | |
144 | 0 | if ( !StringUtils.isEmpty( this.providerArg ) ) |
145 | { | |
146 | 0 | commandLine.createArg().setValue( "-providerArg" ); |
147 | 0 | commandLine.createArg().setValue( this.providerArg ); |
148 | } | |
149 | 0 | if ( !StringUtils.isEmpty( this.sigfile ) ) |
150 | { | |
151 | 0 | commandLine.createArg().setValue( "-sigfile" ); |
152 | 0 | commandLine.createArg().setValue( this.sigfile ); |
153 | } | |
154 | ||
155 | 0 | commandLine.createArg().setFile( archive ); |
156 | ||
157 | 0 | if ( !StringUtils.isEmpty( this.alias ) ) |
158 | { | |
159 | 0 | commandLine.createArg().setValue( this.alias ); |
160 | } | |
161 | ||
162 | 0 | return commandLine; |
163 | } | |
164 | ||
165 | protected String getCommandlineInfo( final Commandline commandLine ) | |
166 | { | |
167 | 0 | String commandLineInfo = commandLine != null ? commandLine.toString() : null; |
168 | ||
169 | 0 | if ( commandLineInfo != null ) |
170 | { | |
171 | 0 | commandLineInfo = StringUtils.replace( commandLineInfo, this.keypass, "'*****'" ); |
172 | 0 | commandLineInfo = StringUtils.replace( commandLineInfo, this.storepass, "'*****'" ); |
173 | } | |
174 | ||
175 | 0 | return commandLineInfo; |
176 | } | |
177 | ||
178 | } |