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
85
86
87
88
89
90
91
92
93
94 @Parameter( property = "jarsigner.certchain", readonly = true, required = false )
95 private File certchain;
96
97 @Override
98 protected String getCommandlineInfo( final Commandline commandLine )
99 {
100 String commandLineInfo = commandLine != null ? commandLine.toString() : null;
101
102 if ( commandLineInfo != null )
103 {
104 commandLineInfo = StringUtils.replace( commandLineInfo, this.keypass, "'*****'" );
105 }
106
107 return commandLineInfo;
108 }
109
110 @Override
111 protected void preProcessArchive( final File archive )
112 throws MojoExecutionException
113 {
114 if ( removeExistingSignatures )
115 {
116 try
117 {
118 JarSignerUtil.unsignArchive( archive );
119 }
120 catch ( IOException e )
121 {
122 throw new MojoExecutionException( "Failed to unsign archive " + archive + ": " + e.getMessage(), e );
123 }
124 }
125 }
126
127
128
129
130 protected JarSignerRequest createRequest( File archive )
131 throws MojoExecutionException
132 {
133 JarSignerSignRequest request = new JarSignerSignRequest();
134 request.setSigfile( sigfile );
135 request.setTsaLocation( tsa );
136 request.setTsaAlias( tsacert );
137 request.setCertchain( certchain );
138
139
140 request.setKeypass( decrypt( keypass ) );
141 return request;
142 }
143
144 }