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.JarSignerUtil;
28 import org.apache.maven.shared.jarsigner.JarSignerVerifyRequest;
29
30 import java.io.File;
31 import java.io.IOException;
32
33
34
35
36
37
38
39
40 @Mojo( name = "verify", defaultPhase = LifecyclePhase.VERIFY )
41 public class JarsignerVerifyMojo
42 extends AbstractJarsignerMojo
43 {
44
45
46
47
48 @Parameter( property = "jarsigner.certs", defaultValue = "false" )
49 private boolean certs;
50
51
52
53
54
55
56
57
58
59 @Parameter( property = "jarsigner.errorWhenNotSigned", defaultValue = "false" )
60 private boolean errorWhenNotSigned;
61
62
63
64
65 protected JarSignerRequest createRequest( File archive )
66 {
67 JarSignerVerifyRequest request = new JarSignerVerifyRequest();
68 request.setCerts( certs );
69 return request;
70 }
71
72 @Override
73 protected void preProcessArchive( File archive )
74 throws MojoExecutionException
75 {
76 super.preProcessArchive( archive );
77
78 if ( errorWhenNotSigned )
79 {
80
81
82 boolean archiveSigned;
83 try
84 {
85 archiveSigned = JarSignerUtil.isArchiveSigned( archive );
86 }
87 catch ( IOException e )
88 {
89 throw new MojoExecutionException( "Failed to check if archive " + archive + " is signed: "
90 + e.getMessage(), e );
91 }
92
93 if ( !archiveSigned )
94 {
95
96
97 throw new MojoExecutionException( getMessage( "archiveNotSigned", archive ) );
98 }
99 }
100 }
101 }