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