Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SiteStageDeployMojo |
|
| 0.0;0 |
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 | ||
23 | import org.apache.maven.plugin.MojoExecutionException; | |
24 | ||
25 | /** | |
26 | * Deploys the generated site to a staging or mock directory to the site URL | |
27 | * specified in the <code><distributionManagement></code> section of the | |
28 | * POM. It supports <code>scp</code> and <code>file</code> protocols for | |
29 | * deployment. | |
30 | * | |
31 | * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> | |
32 | * @version $Id$ | |
33 | * @goal stage-deploy | |
34 | * @requiresDependencyResolution test | |
35 | */ | |
36 | 0 | public class SiteStageDeployMojo |
37 | extends AbstractDeployMojo | |
38 | { | |
39 | /** | |
40 | * The staged site will be deployed to this URL. | |
41 | * | |
42 | * If you don't specify this, the default-value will be | |
43 | * "${project.distributionManagement.site.url}/staging", where "project" is | |
44 | * either the current project or, in a reactor build, the top level project | |
45 | * in the reactor. | |
46 | * <p> | |
47 | * Note that even if you specify this plugin parameter you still need to indicate | |
48 | * ${project.distributionManagement.site.url} at least in your top level project | |
49 | * in order for relative links between modules to be resolved correctly. | |
50 | * </p> | |
51 | * | |
52 | * @parameter expression="${stagingSiteURL}" | |
53 | * @see <a href="http://maven.apache.org/maven-model/maven.html#class_site">MavenModel#class_site</a> | |
54 | */ | |
55 | private String stagingSiteURL; | |
56 | ||
57 | /** | |
58 | * The identifier of the repository where the staging site will be deployed. This id will be used to lookup a | |
59 | * corresponding <code><server></code> entry from the <code>settings.xml</code>. If a matching | |
60 | * <code><server></code> entry is found, its configured credentials will be used for authentication. | |
61 | * | |
62 | * If this is not specified, then the corresponding value of <code>distributionManagement.site.id</code> | |
63 | * will be taken as default, unless this is not defined either then the String | |
64 | * <code>"stagingSite"</code> is used. (<strong>Note</strong>: | |
65 | * until v. 2.3 and 3.0-beta-3 the String <code>"stagingSite"</code> is always used.) | |
66 | * | |
67 | * @parameter expression="${stagingRepositoryId}" | |
68 | * | |
69 | * @since 2.0.1 | |
70 | */ | |
71 | private String stagingRepositoryId; | |
72 | ||
73 | @Override | |
74 | protected String getDeployRepositoryID() | |
75 | throws MojoExecutionException | |
76 | { | |
77 | 0 | stagingRepositoryId = stagingRepoId ( stagingRepositoryId ); |
78 | ||
79 | 0 | getLog().info( "Using this server ID for stage deploy: " + stagingRepositoryId ); |
80 | ||
81 | 0 | return stagingRepositoryId; |
82 | } | |
83 | ||
84 | @Override | |
85 | protected String getDeployRepositoryURL() | |
86 | throws MojoExecutionException | |
87 | { | |
88 | 0 | stagingSiteURL = stagingSiteURL( stagingSiteURL ); |
89 | ||
90 | 0 | getLog().info( "Using this base URL for stage deploy: " + stagingSiteURL ); |
91 | ||
92 | 0 | return stagingSiteURL; |
93 | } | |
94 | ||
95 | /** | |
96 | * Find the URL where staging will take place. | |
97 | * | |
98 | * @param usersStagingSiteURL The staging site URL as suggested by the user's configuration | |
99 | * | |
100 | * @return the site URL for staging | |
101 | */ | |
102 | private String stagingSiteURL( final String usersStagingSiteURL ) | |
103 | throws MojoExecutionException | |
104 | { | |
105 | 0 | String topLevelURL = null; |
106 | ||
107 | 0 | if ( usersStagingSiteURL != null ) |
108 | { | |
109 | // the user has specified a stagingSiteURL - use it | |
110 | 0 | getLog().debug( "stagingSiteURL specified by the user: " + usersStagingSiteURL ); |
111 | 0 | topLevelURL = usersStagingSiteURL; |
112 | } | |
113 | else | |
114 | { | |
115 | // The user didn't specify a URL, use the top level target dir | |
116 | 0 | topLevelURL = appendSlash( getRootSite( project ).getUrl() ) |
117 | + DEFAULT_STAGING_DIRECTORY; | |
118 | 0 | getLog().debug( "stagingSiteURL NOT specified, using the top level project: " + topLevelURL ); |
119 | } | |
120 | ||
121 | // Return either | |
122 | // usersURL | |
123 | // or | |
124 | // topLevelProjectURL + "staging" | |
125 | 0 | return topLevelURL; |
126 | } | |
127 | ||
128 | private String stagingRepoId( final String stagingRepoId ) | |
129 | { | |
130 | 0 | if ( stagingRepoId != null ) |
131 | { | |
132 | 0 | return stagingRepoId; |
133 | } | |
134 | ||
135 | try | |
136 | { | |
137 | 0 | return getSite( project ).getId(); |
138 | } | |
139 | 0 | catch ( MojoExecutionException ex ) |
140 | { | |
141 | 0 | return "stagingSite"; |
142 | } | |
143 | } | |
144 | } |