1 package org.apache.maven.plugins.jarsigner;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugins.annotations.LifecyclePhase;
24 import org.apache.maven.plugins.annotations.Mojo;
25 import org.apache.maven.plugins.annotations.Parameter;
26 import org.apache.maven.shared.jarsigner.JarSignerRequest;
27 import org.apache.maven.shared.jarsigner.JarSignerSignRequest;
28 import org.apache.maven.shared.jarsigner.JarSignerUtil;
29 import org.apache.maven.shared.utils.StringUtils;
30 import org.apache.maven.shared.utils.cli.Commandline;
31
32 import java.io.File;
33 import java.io.IOException;
34
35
36
37
38
39
40
41
42 @Mojo( name = "sign", defaultPhase = LifecyclePhase.PACKAGE )
43 public class JarsignerSignMojo
44 extends AbstractJarsignerMojo
45 {
46
47
48
49
50 @Parameter( property = "jarsigner.keypass" )
51 private String keypass;
52
53
54
55
56 @Parameter( property = "jarsigner.sigfile" )
57 private String sigfile;
58
59
60
61
62
63
64
65 @Parameter( property = "jarsigner.removeExistingSignatures", defaultValue = "false" )
66 private boolean removeExistingSignatures;
67
68
69
70
71
72
73 @Parameter( property = "jarsigner.tsa" )
74 private String tsa;
75
76
77
78
79
80
81 @Parameter( property = "jarsigner.tsacert" )
82 private String tsacert;
83
84 @Override
85 protected String getCommandlineInfo( final Commandline commandLine )
86 {
87 String commandLineInfo = commandLine != null ? commandLine.toString() : null;
88
89 if ( commandLineInfo != null )
90 {
91 commandLineInfo = StringUtils.replace( commandLineInfo, this.keypass, "'*****'" );
92 }
93
94 return commandLineInfo;
95 }
96
97 @Override
98 protected void preProcessArchive( final File archive )
99 throws MojoExecutionException
100 {
101 if ( removeExistingSignatures )
102 {
103 try
104 {
105 JarSignerUtil.unsignArchive( archive );
106 }
107 catch ( IOException e )
108 {
109 throw new MojoExecutionException( "Failed to unsign archive " + archive + ": " + e.getMessage(), e );
110 }
111 }
112 }
113
114
115
116
117 protected JarSignerRequest createRequest( File archive )
118 throws MojoExecutionException
119 {
120 JarSignerSignRequest request = new JarSignerSignRequest();
121 request.setSigfile( sigfile );
122 request.setTsaLocation( tsa );
123 request.setTsaAlias( tsacert );
124
125
126 request.setKeypass( decrypt( keypass ) );
127 return request;
128 }
129
130 }