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