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 java.io.File;
23  
24  import org.apache.maven.plugin.MojoExecutionException;
25  
26  /**
27   * Generates a site in a local staging or mock directory based on the site URL
28   * specified in the <code>&lt;distributionManagement&gt;</code> section of the
29   * POM.
30   * <p>
31   * It can be used to test that links between module sites in a multi module
32   * build works.
33   * </p>
34   *
35   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
36   * @version $Id: SiteStageMojo.html 816568 2012-05-08 12:09:38Z hboutemy $
37   * @goal stage
38   * @requiresDependencyResolution test
39   */
40  public class SiteStageMojo
41      extends AbstractDeployMojo
42  {
43      /**
44       * Staging directory location. This needs to be an absolute path, like
45       * <code>C:\stagingArea\myProject\</code> on Windows or
46       * <code>/stagingArea/myProject/</code> on Unix.
47       * If this is not specified, the site will be staged in ${project.build.directory}/staging.
48       *
49       * @parameter expression="${stagingDirectory}"
50       */
51      private File stagingDirectory;
52  
53      @Override
54      protected String getDeployRepositoryID()
55          throws MojoExecutionException
56      {
57          return "stagingLocal";
58      }
59  
60      @Override
61      protected String getDeployRepositoryURL()
62          throws MojoExecutionException
63      {
64          final String stageDir = ( stagingDirectory == null ) ? null : stagingDirectory.getAbsolutePath();
65          final String outputDir = getStagingDirectory( stageDir );
66  
67          getLog().info( "Using this base directory for staging: " + outputDir );
68  
69          final File outputDirectory = new File( outputDir );
70          // Safety
71          if ( !outputDirectory.exists() )
72          {
73              outputDirectory.mkdirs();
74          }
75  
76          return "file://" + outputDirectory.getAbsolutePath();
77      }
78  
79      /**
80       * Find the directory where staging will take place.
81       *
82       * @param usersStagingDirectory The staging directory as suggested by the user's configuration
83       *
84       * @return the directory for staging
85       */
86      private String getStagingDirectory( String usersStagingDirectory )
87      {
88          String topLevelURL = null;
89  
90          if ( usersStagingDirectory != null )
91          {
92              // the user has specified a stagingDirectory - use it
93              getLog().debug( "stagingDirectory specified by the user: " + usersStagingDirectory );
94              topLevelURL = usersStagingDirectory;
95          }
96          else
97          {
98              // The user didn't specify a URL, use the top level target dir
99              topLevelURL =
100                 getTopLevelBuildDirectory().getAbsolutePath() + "/" + DEFAULT_STAGING_DIRECTORY;
101             getLog().debug( "stagingDirectory NOT specified, using the top level project: " + topLevelURL );
102         }
103 
104         // Return either
105         //   usersURL
106         // or
107         //   topLevelProjectURL + "staging"
108         return topLevelURL;
109     }
110 }