1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package io.earcam.maven.plugin.netlify;
20
21 import static org.apache.maven.plugins.annotations.InstantiationStrategy.SINGLETON;
22 import static org.apache.maven.plugins.annotations.LifecyclePhase.SITE_DEPLOY;
23
24 import java.util.Objects;
25
26 import org.apache.maven.plugin.AbstractMojo;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.project.MavenProject;
32 import org.apache.maven.settings.Server;
33 import org.apache.maven.settings.Settings;
34
35
36
37
38 @Mojo(name = "upload", requiresProject = true, threadSafe = true, inheritByDefault = false, defaultPhase = SITE_DEPLOY, instantiationStrategy = SINGLETON)
39 public class NetlifyUploadMojo extends AbstractMojo {
40
41 @Parameter(defaultValue = "${settings}", readonly = true, required = true)
42 Settings settings;
43
44 @Parameter(defaultValue = "${project}", readonly = true, required = true)
45 MavenProject project;
46
47
48
49
50
51
52
53
54
55 @Parameter(property = "deploy.netlify.server.id", required = true)
56 String serverId;
57
58
59
60
61
62 @Parameter(property = "deploy.netlify.site.name", required = false)
63 String siteName;
64
65
66
67
68
69
70 @Parameter(property = "deploy.netlify.domain.custom", required = false)
71 String customDomain;
72
73
74
75
76
77 @Parameter(property = "deploy.netlify.site.create", defaultValue = "true", required = false)
78 boolean createSiteIfNotExists;
79
80
81
82
83 @Parameter(property = "deploy.netlify.skip", defaultValue = "false")
84 boolean skip;
85
86
87 @Override
88 public void execute() throws MojoExecutionException, MojoFailureException
89 {
90 if(skip) {
91 return;
92 }
93 NetlifyUploadLifecycleParticipant.shouldRun();
94 NetlifyUploadLifecycleParticipant.addPlugin(this);
95 }
96
97
98 String accessToken()
99 {
100 String token = server().getPassword();
101 Objects.requireNonNull(token, "Did not find Netlify access token as the '" + serverId + "' server password in settings.xml");
102 return token;
103 }
104
105
106 private Server server()
107 {
108 Server server = settings.getServer(serverId);
109 Objects.requireNonNull(server, "server with id '" + serverId + "' not found in settings.xml");
110 return server;
111 }
112
113
114
115
116
117
118
119
120 @SuppressWarnings("squid:S1133")
121 @Deprecated
122 public MavenProject getProject()
123 {
124 throw new UnsupportedOperationException("deprecated; never used");
125 }
126 }