1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.site.deploy;
20
21 import java.io.File;
22
23 import org.apache.maven.model.Site;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.plugins.annotations.Parameter;
27 import org.apache.maven.plugins.annotations.ResolutionScope;
28 import org.apache.maven.project.MavenProject;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 @Mojo(name = "stage", requiresDependencyResolution = ResolutionScope.TEST)
45 public class SiteStageMojo extends AbstractStagingMojo {
46
47
48
49
50
51
52
53
54 @Parameter(property = "stagingDirectory")
55 private File stagingDirectory;
56
57 @Override
58 public void execute() throws MojoExecutionException {
59 if (skip) {
60 getLog().info("maven.site.skip = true: Skipping site staging");
61 return;
62 }
63
64 super.execute();
65 }
66
67 @Override
68 protected boolean isDeploy() {
69 return false;
70 }
71
72 @Override
73 protected Site determineDeploySite() throws MojoExecutionException {
74 Site staging = new Site();
75 staging.setId("stagingLocal");
76
77 final File outputDirectory = determineStagingDirectory();
78 getLog().info("Using this base directory for staging: " + outputDirectory);
79
80
81 if (!outputDirectory.exists()) {
82 outputDirectory.mkdirs();
83 }
84
85 staging.setUrl("file://" + outputDirectory.getAbsolutePath());
86
87 return staging;
88 }
89
90
91
92
93
94
95 private File determineStagingDirectory() {
96 if (stagingDirectory != null) {
97
98 getLog().debug("stagingDirectory specified by the user: " + stagingDirectory);
99 return stagingDirectory;
100 }
101
102
103 File defaultStagingDirectory = new File(getExecutionRootBuildDirectory(), DEFAULT_STAGING_DIRECTORY);
104 getLog().debug("stagingDirectory NOT specified, using the execution root project: " + defaultStagingDirectory);
105 return defaultStagingDirectory;
106 }
107
108
109
110
111
112
113
114 protected File getExecutionRootBuildDirectory() {
115
116 final MavenProject executionRootProject = mavenSession.getTopLevelProject();
117
118
119 final File buildDirectory;
120
121 if (executionRootProject == null) {
122 getLog().debug("No execution root project found in the reactor, using the current project.");
123
124 buildDirectory = new File(project.getBuild().getDirectory());
125 } else {
126 getLog().debug("Using the execution root project found in the reactor: "
127 + executionRootProject.getArtifactId());
128
129 buildDirectory = new File(executionRootProject.getBuild().getDirectory());
130 }
131
132 return buildDirectory;
133 }
134 }