Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SiteStageMojo |
|
| 2.0;2 |
1 | package org.apache.maven.plugins.site; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.File; | |
23 | ||
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 | ||
29 | /** | |
30 | * Deploys the generated site to a local staging or mock directory based on the site URL | |
31 | * specified in the <code><distributionManagement></code> section of the | |
32 | * POM. | |
33 | * <p> | |
34 | * It can be used to test that links between module sites in a multi-module | |
35 | * build works. | |
36 | * </p> | |
37 | * | |
38 | * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> | |
39 | * @version $Id: SiteStageMojo.java 1380054 2012-09-02 21:00:00Z hboutemy $ | |
40 | */ | |
41 | @Mojo( name = "stage", requiresDependencyResolution = ResolutionScope.TEST ) | |
42 | 0 | public class SiteStageMojo |
43 | extends AbstractDeployMojo | |
44 | { | |
45 | /** | |
46 | * Staging directory location. This needs to be an absolute path, like | |
47 | * <code>C:\stagingArea\myProject\</code> on Windows or | |
48 | * <code>/stagingArea/myProject/</code> on Unix. | |
49 | * If this is not specified, the site will be staged in ${project.build.directory}/staging. | |
50 | */ | |
51 | @Parameter( property = "stagingDirectory" ) | |
52 | private File stagingDirectory; | |
53 | ||
54 | /** | |
55 | * Set this to 'true' to skip site generation and staging. | |
56 | * | |
57 | * @since 3.2 | |
58 | */ | |
59 | @Parameter( property = "maven.site.skip", defaultValue = "false" ) | |
60 | private boolean skip; | |
61 | ||
62 | @Override | |
63 | protected String getDeployRepositoryID() | |
64 | throws MojoExecutionException | |
65 | { | |
66 | 0 | return "stagingLocal"; |
67 | } | |
68 | ||
69 | @Override | |
70 | protected String getDeployRepositoryURL() | |
71 | throws MojoExecutionException | |
72 | { | |
73 | 0 | final String stageDir = ( stagingDirectory == null ) ? null : stagingDirectory.getAbsolutePath(); |
74 | 0 | final String outputDir = getStagingDirectory( stageDir ); |
75 | ||
76 | 0 | getLog().info( "Using this base directory for staging: " + outputDir ); |
77 | ||
78 | 0 | final File outputDirectory = new File( outputDir ); |
79 | // Safety | |
80 | 0 | if ( !outputDirectory.exists() ) |
81 | { | |
82 | 0 | outputDirectory.mkdirs(); |
83 | } | |
84 | ||
85 | 0 | return "file://" + outputDirectory.getAbsolutePath(); |
86 | } | |
87 | ||
88 | public void execute() | |
89 | throws MojoExecutionException | |
90 | { | |
91 | 0 | if ( skip ) |
92 | { | |
93 | 0 | getLog().info( "maven.site.skip = true: Skipping site staging" ); |
94 | 0 | return; |
95 | } | |
96 | ||
97 | 0 | super.execute(); |
98 | 0 | } |
99 | ||
100 | protected boolean isDeploy() | |
101 | { | |
102 | // this mojo is for staging, not deploy | |
103 | 0 | return false; |
104 | } | |
105 | ||
106 | /** | |
107 | * Find the directory where staging will take place. | |
108 | * | |
109 | * @param usersStagingDirectory The staging directory as suggested by the user's configuration | |
110 | * | |
111 | * @return the directory for staging | |
112 | */ | |
113 | private String getStagingDirectory( String usersStagingDirectory ) | |
114 | { | |
115 | 0 | String topLevelURL = null; |
116 | ||
117 | 0 | if ( usersStagingDirectory != null ) |
118 | { | |
119 | // the user has specified a stagingDirectory - use it | |
120 | 0 | getLog().debug( "stagingDirectory specified by the user: " + usersStagingDirectory ); |
121 | 0 | topLevelURL = usersStagingDirectory; |
122 | } | |
123 | else | |
124 | { | |
125 | // The user didn't specify a URL, use the top level target dir | |
126 | 0 | topLevelURL = |
127 | getTopLevelBuildDirectory().getAbsolutePath() + "/" + DEFAULT_STAGING_DIRECTORY; | |
128 | 0 | getLog().debug( "stagingDirectory NOT specified, using the top level project: " + topLevelURL ); |
129 | } | |
130 | ||
131 | // Return either | |
132 | // usersURL | |
133 | // or | |
134 | // topLevelProjectURL + "staging" | |
135 | 0 | return topLevelURL; |
136 | } | |
137 | } |