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