1
2
3
4
5 package com.jcabi.ssl.maven.plugin;
6
7 import com.jcabi.log.Logger;
8 import java.io.File;
9 import java.io.IOException;
10 import org.apache.commons.codec.digest.DigestUtils;
11 import org.apache.maven.plugin.AbstractMojo;
12 import org.apache.maven.plugin.MojoFailureException;
13 import org.apache.maven.project.MavenProject;
14 import org.slf4j.impl.StaticLoggerBinder;
15
16
17
18
19
20
21
22
23 public final class KeygenMojo extends AbstractMojo {
24
25
26
27
28
29
30
31 private transient MavenProject project;
32
33
34
35
36
37 private transient boolean skip;
38
39
40
41
42
43
44 private transient File keystore;
45
46
47
48
49
50
51 private transient File cacerts;
52
53
54
55
56 private transient Keystore store;
57
58
59
60
61 private transient Cacerts truststore;
62
63
64
65
66 public KeygenMojo() {
67 this(
68 null, new Keystore(DigestUtils.md5Hex(KeygenMojo.class.getName())),
69 null
70 );
71 }
72
73
74
75
76
77
78
79 public KeygenMojo(final MavenProject prj, final Keystore str,
80 final Cacerts crt) {
81 super();
82 this.project = prj;
83 this.store = str;
84 this.truststore = crt;
85 }
86
87
88
89
90
91 public void setSkip(final boolean skp) {
92 this.skip = skp;
93 }
94
95 @Override
96 public void execute() throws MojoFailureException {
97 StaticLoggerBinder.getSingleton().setMavenLog(this.getLog());
98 if (this.skip) {
99 Logger.info(this, "execution skipped because of 'skip' option");
100 return;
101 }
102 try {
103 if (this.truststore == null) {
104 this.truststore = new Cacerts(this.cacerts);
105 }
106 if (!this.store.isActive()) {
107 this.store.activate(this.keystore);
108 this.truststore.imprt();
109 }
110 } catch (final IOException ex) {
111 throw new IllegalStateException(ex);
112 }
113 this.store.populate(this.project.getProperties());
114 this.truststore.populate(this.project.getProperties());
115 Logger.info(this, "Keystore is active: %s", this.store);
116 }
117
118 }