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