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 import java.util.List;
23
24 import org.apache.maven.model.Site;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28 import org.apache.maven.plugins.annotations.ResolutionScope;
29 import org.apache.maven.project.MavenProject;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 @Mojo(name = "stage", requiresDependencyResolution = ResolutionScope.TEST)
46 public class SiteStageMojo extends AbstractStagingMojo {
47
48
49
50
51
52
53
54
55 @Parameter(property = "stagingDirectory")
56 private File stagingDirectory;
57
58 @Override
59 public void execute() throws MojoExecutionException {
60 if (skip) {
61 getLog().info("maven.site.skip = true: Skipping site staging");
62 return;
63 }
64
65 super.execute();
66 }
67
68 @Override
69 protected boolean isDeploy() {
70 return false;
71 }
72
73 @Override
74 protected Site determineDeploySite() throws MojoExecutionException {
75 Site staging = new Site();
76 staging.setId("stagingLocal");
77
78 final File outputDirectory = determineStagingDirectory();
79 getLog().info("Using this base directory for staging: " + outputDirectory);
80
81
82 if (!outputDirectory.exists()) {
83 outputDirectory.mkdirs();
84 }
85
86 staging.setUrl("file://" + outputDirectory.getAbsolutePath());
87
88 return staging;
89 }
90
91
92
93
94
95
96 private File determineStagingDirectory() {
97 if (stagingDirectory != null) {
98
99 getLog().debug("stagingDirectory specified by the user: " + stagingDirectory);
100 return stagingDirectory;
101 }
102
103
104 File defaultStagingDirectory = new File(getExecutionRootBuildDirectory(), DEFAULT_STAGING_DIRECTORY);
105 getLog().debug("stagingDirectory NOT specified, using the execution root project: " + defaultStagingDirectory);
106 return defaultStagingDirectory;
107 }
108
109
110
111
112
113
114
115 protected File getExecutionRootBuildDirectory() {
116
117 final MavenProject executionRootProject = getExecutionRootProject(reactorProjects);
118
119
120 final File buildDirectory;
121
122 if (executionRootProject == null) {
123 getLog().debug("No execution root project found in the reactor, using the current project.");
124
125 buildDirectory = new File(project.getBuild().getDirectory());
126 } else {
127 getLog().debug("Using the execution root project found in the reactor: "
128 + executionRootProject.getArtifactId());
129
130 buildDirectory = new File(executionRootProject.getBuild().getDirectory());
131 }
132
133 return buildDirectory;
134 }
135
136
137
138
139
140
141
142
143 private static MavenProject getExecutionRootProject(List<MavenProject> reactorProjects) {
144 if (reactorProjects == null) {
145 return null;
146 }
147
148
149 for (MavenProject reactorProject : reactorProjects) {
150 if (reactorProject.isExecutionRoot()) {
151 return reactorProject;
152 }
153 }
154 return null;
155 }
156 }