View Javadoc

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