View Javadoc
1   package org.apache.maven.doxia.tools;
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  import java.util.List;
24  import java.util.Locale;
25  import java.util.Map;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.doxia.site.decoration.DecorationModel;
30  import org.apache.maven.project.MavenProject;
31  import org.apache.maven.reporting.MavenReport;
32  
33  /**
34   * Tool to play with <a href="http://maven.apache.org/doxia/">Doxia</a> objects
35   * like <code>DecorationModel</code>.
36   *
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
38   */
39  public interface SiteTool
40  {
41      /**
42       * The locale by default for a Maven Site.
43       *
44       * @see Locale#ROOT
45       */
46      Locale DEFAULT_LOCALE = Locale.ROOT;
47  
48      /**
49       * Get a skin artifact from one of the repositories.
50       *
51       * @param localRepository the Maven local repository, not null.
52       * @param remoteArtifactRepositories the Maven remote repositories, not null.
53       * @param decoration the Doxia site descriptor model, not null.
54       * @return the <code>Skin</code> artifact defined in a <code>DecorationModel</code> from a given project and a
55       * local repository
56       * @throws SiteToolException if any
57       */
58      Artifact getSkinArtifactFromRepository( ArtifactRepository localRepository,
59                                              List<ArtifactRepository> remoteArtifactRepositories,
60                                              DecorationModel decoration )
61          throws SiteToolException;
62  
63      /**
64       * Get a site descriptor from the project's site directory.
65       *
66       * @param siteDirectory the site directory, not null
67       * @param locale the locale wanted for the site descriptor, not null. Most specific
68       * to least specific lookup from <code>site_language_country_variant.xml</code>,
69       * <code>site_language_country.xml</code>, <code>site_language.xml}</code>,
70       * to <code>site.xml</code> as last resort for {@link Locale#ROOT}, if provided
71       * locale defines a variant and/or a country and/or a language.
72       * @return the most specific site descriptor file for the given locale
73       */ // used by maven-pdf-plugin (should not?)
74      File getSiteDescriptor( File siteDirectory, Locale locale );
75  
76      /**
77       * Interpolating several expressions in the site descriptor content. Actually, the expressions can be in
78       * the project, the environment variables and the specific properties like <code>encoding</code>.
79       * <p>
80       * For instance:
81       * <dl>
82       * <dt>${project.name}</dt>
83       * <dd>The value from the POM of:
84       * <p>
85       * &lt;project&gt;<br>
86       * &nbsp;&nbsp;&lt;name&gt;myProjectName&lt;/name&gt;<br>
87       * &lt;/project&gt;
88       * </p></dd>
89       * <dt>${my.value}</dt>
90       * <dd>The value from the POM of:
91       * <p>
92       * &lt;properties&gt;<br>
93       * &nbsp;&nbsp;&lt;my.value&gt;hello&lt;/my.value&gt;<br>
94       * &lt;/properties&gt;
95       * </p></dd>
96       * <dt>${JAVA_HOME}</dt>
97       * <dd>The value of JAVA_HOME in the environment variables</dd>
98       * </dl>
99       *
100      * @param props a map used for interpolation, not null.
101      * @param aProject a Maven project, not null.
102      * @param siteDescriptorContent the site descriptor file, not null.
103      * @return the interpolated site descriptor content.
104      * @throws SiteToolException if errors happened during the interpolation.
105      */ // used by maven-pdf-plugin (should not?)
106     String getInterpolatedSiteDescriptorContent( Map<String, String> props, MavenProject aProject,
107                                                  String siteDescriptorContent )
108         throws SiteToolException;
109 
110     /**
111      * Get a decoration model for a project.
112      *
113      * @param siteDirectory the site directory, may be null if project from repository
114      * @param locale the locale used for the i18n in DecorationModel, not null.
115      * See {@link #getSiteDescriptor(File, Locale)} for details.
116      * @param project the Maven project, not null.
117      * @param reactorProjects the Maven reactor projects, not null.
118      * @param localRepository the Maven local repository, not null.
119      * @param repositories the Maven remote repositories, not null.
120      * @return the <code>DecorationModel</code> object corresponding to the <code>site.xml</code> file with some
121      * interpolations.
122      * @throws SiteToolException if any
123      * @since 1.7, was previously with other parameter types and order
124      */
125     DecorationModel getDecorationModel( File siteDirectory, Locale locale, MavenProject project,
126                                         List<MavenProject> reactorProjects, ArtifactRepository localRepository,
127                                         List<ArtifactRepository> repositories )
128         throws SiteToolException;
129 
130     /**
131      * Populate the pre-defined <code>reports</code> menu of the decoration model,
132      * if used through <code>&lt;menu ref="reports"/&gt;</code>. Notice this menu reference is translated into
133      * 2 separate menus: "Project Information" and "Project Reports".
134      *
135      * @param decorationModel the Doxia Sitetools DecorationModel, not null.
136      * @param locale the locale used for the i18n in DecorationModel, not null.
137      * See {@link #getSiteDescriptor(File, Locale)} for details.
138      * @param reportsPerCategory reports per category to put in "Reports" or "Information" menus, not null.
139      * @see MavenReport#CATEGORY_PROJECT_INFORMATION
140      * @see MavenReport#CATEGORY_PROJECT_REPORTS
141      */
142     void populateReportsMenu( DecorationModel decorationModel, Locale locale,
143                               Map<String, List<MavenReport>> reportsPerCategory );
144 
145     /**
146      * Extracts from a comma-separated list the locales that are available in <code>site-tool</code>
147      * resource bundle.
148      *
149      * @param locales A comma separated list of locales
150      * @return a list of <code>Locale</code>s.
151      * @since 1.7, was previously getAvailableLocales(String)
152      */
153     List<Locale> getSiteLocales( String locales );
154 
155     /**
156      * Calculate the relative path between two URLs or between two files.
157      *
158      * For example:
159      * <dl>
160      * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org"</dt>
161      * <dd>return ""</dd>
162      * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org/plugins/maven-site-plugin/"</dt>
163      * <dd>return "../.."</dd>
164      * <dt>to = "http://maven.apache.org/plugins/maven-site-plugin/" and from = "http://maven.apache.org"</dt>
165      * <dd>return "plugins/maven-site-plugin"</dd>
166      * <dt>to = "/myproject/myproject-module1" and from = "/myproject/myproject"</dt>
167      * <dd>return "../myproject-module1"</dd>
168      * </dl>
169      * <b>Note</b>: The file separator depends on the system.
170      * Maven-specific urls are supported, like <code>dav:https://dav.codehaus.org/</code> or
171      * <code>scm:svn:https://svn.apache.org/repos/asf</code>.
172      *
173      * @param to the <code>to</code> url of file as string
174      * @param from the <code>from</code> url of file as string
175      * @return a relative path from <code>from</code> to <code>to</code>.
176      */
177     String getRelativePath( String to, String from );
178 
179     /**
180      * Returns the parent POM with interpolated URLs.
181      * If called from Maven 3, just returns <code>project.getParent()</code>, which is already
182      * interpolated. But when called from Maven 2, attempts to source this value from the
183      * <code>reactorProjects</code> parameters if available (reactor env model attributes
184      * are interpolated), or if the reactor is unavailable (-N) resorts to the
185      * <code>project.getParent().getUrl()</code> value which will NOT have been interpolated.
186      *
187      * @param aProject a Maven project, not null.
188      * @param reactorProjects the Maven reactor projects, not null.
189      * @param localRepository the Maven local repository, not null.
190      * @return the parent project with interpolated URLs.
191      */
192     MavenProject getParentProject( MavenProject aProject, List<MavenProject> reactorProjects,
193                                    ArtifactRepository localRepository );
194 }