1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.doxia.tools;
20
21 import java.io.File;
22 import java.util.List;
23 import java.util.Locale;
24 import java.util.Map;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.doxia.site.SiteModel;
28 import org.apache.maven.doxia.site.Skin;
29 import org.apache.maven.execution.MavenExecutionRequest;
30 import org.apache.maven.project.MavenProject;
31 import org.apache.maven.reporting.MavenReport;
32 import org.eclipse.aether.RepositorySystemSession;
33 import org.eclipse.aether.repository.RemoteRepository;
34
35 /**
36 * Tool to play with <a href="http://maven.apache.org/doxia/">Doxia</a> objects
37 * like <code>SiteModel</code>.
38 *
39 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
40 */
41 public interface SiteTool {
42 /**
43 * The locale by default for a Maven Site.
44 *
45 * @see Locale#ROOT
46 */
47 Locale DEFAULT_LOCALE = Locale.ROOT;
48
49 /**
50 * Get a skin artifact from one of the repositories.
51 *
52 * @param repoSession the repository system session, not null.
53 * @param remoteProjectRepositories the Maven remote project repositories, not null.
54 * @param skin the Skin model, not null.
55 * @return the <code>Skin</code> artifact defined in a <code>SiteModel</code> from a given project
56 * @throws SiteToolException if any
57 */
58 Artifact getSkinArtifactFromRepository(
59 RepositorySystemSession repoSession, List<RemoteRepository> remoteProjectRepositories, Skin skin)
60 throws SiteToolException;
61
62 /**
63 * Get a site descriptor from the project's site directory.
64 *
65 * @param siteDirectory the site directory, not null
66 * @param locale the locale wanted for the site descriptor, not null. Most specific
67 * to least specific lookup from <code>site_language_country_variant.xml</code>,
68 * <code>site_language_country.xml</code>, <code>site_language.xml}</code>,
69 * to <code>site.xml</code> as last resort for {@link Locale#ROOT}, if provided
70 * locale defines a variant and/or a country and/or a language.
71 * @return the most specific site descriptor file for the given locale
72 */
73 File getSiteDescriptor(File siteDirectory, Locale locale);
74
75 /**
76 * Interpolating several expressions in the site descriptor content. Actually, the expressions can be in
77 * the project, the environment variables and the specific properties like <code>encoding</code>.
78 * <p>
79 * For instance:
80 * <dl>
81 * <dt>${project.name}</dt>
82 * <dd>The value from the POM of:
83 * <p>
84 * <project><br>
85 * <name>myProjectName</name><br>
86 * </project>
87 * </p></dd>
88 * <dt>${my.value}</dt>
89 * <dd>The value from the POM of:
90 * <p>
91 * <properties><br>
92 * <my.value>hello</my.value><br>
93 * </properties>
94 * </p></dd>
95 * <dt>${JAVA_HOME}</dt>
96 * <dd>The value of JAVA_HOME in the environment variables</dd>
97 * </dl>
98 *
99 * @param props a map used for interpolation, not null.
100 * @param aProject a Maven project, not null.
101 * @param siteDescriptorContent the site descriptor file, not null.
102 * @return the interpolated site descriptor content.
103 * @throws SiteToolException if errors happened during the interpolation.
104 * @deprecated since 2.1.0, use {@link #getSiteModel(File, Locale, MavenExecutionRequest, MavenProject, List, RepositorySystemSession, List)} instead
105 */
106 @Deprecated
107 // used by maven-pdf-plugin (should not?)
108 String getInterpolatedSiteDescriptorContent(
109 Map<String, String> props, MavenProject aProject, String siteDescriptorContent) throws SiteToolException;
110
111 /**
112 * Get a site model for a project.
113 *
114 * @param siteDirectory the site directory, may be null if project from repository
115 * @param locale the locale used for the i18n in SiteModel, not null.
116 * See {@link #getSiteDescriptor(File, Locale)} for details.
117 * @param project the Maven project, not null.
118 * @param reactorProjects the Maven reactor projects, not null.
119 * @param repoSession the repository system session, not null.
120 * @param remoteProjectRepositories the Maven remote project repositories, not null.
121 * @return the <code>SiteModel</code> object corresponding to the <code>site.xml</code> file with some
122 * interpolations.
123 * @throws SiteToolException if any
124 * @since 1.7, was previously with other parameter types and order
125 * @deprecated since 2.1.0, use {@link #getSiteModel(File, Locale, MavenExecutionRequest, MavenProject, List, RepositorySystemSession, List)} instead
126 */
127 @Deprecated
128 SiteModel getSiteModel(
129 File siteDirectory,
130 Locale locale,
131 MavenProject project,
132 List<MavenProject> reactorProjects,
133 RepositorySystemSession repoSession,
134 List<RemoteRepository> remoteProjectRepositories)
135 throws SiteToolException;
136
137 /**
138 * Get a site model for a project.
139 *
140 * @param siteDirectory the site directory, may be null if project from repository
141 * @param locale the locale used for the i18n in SiteModel, not null.
142 * See {@link #getSiteDescriptor(File, Locale)} for details.
143 * @param project the Maven project, not null.
144 * @param request the Maven execution request, not null. This is needed to get the user properties and the system properties for interpolation.
145 * @param reactorProjects the Maven reactor projects, not null.
146 * @param repoSession the repository system session, not null.
147 * @param remoteProjectRepositories the Maven remote project repositories, not null.
148 * @return the <code>SiteModel</code> object corresponding to the <code>site.xml</code> file with some
149 * interpolations.
150 * @throws SiteToolException if any
151 * @since 2.1.0, was previously with other parameter types and order
152 */
153 SiteModel getSiteModel(
154 File siteDirectory,
155 Locale locale,
156 MavenExecutionRequest request,
157 MavenProject project,
158 List<MavenProject> reactorProjects,
159 RepositorySystemSession repoSession,
160 List<RemoteRepository> remoteProjectRepositories)
161 throws SiteToolException;
162
163 /**
164 * Populate the pre-defined <code>reports</code> menu of the site model,
165 * if used through <code><menu ref="reports"/></code>. Notice this menu reference is translated into
166 * 2 separate menus: "Project Information" and "Project Reports".
167 *
168 * @param siteModel the Doxia Sitetools SiteModel, not null.
169 * @param locale the locale used for the i18n in SiteModel, not null.
170 * See {@link #getSiteDescriptor(File, Locale)} for details.
171 * @param reportsPerCategory reports per category to put in "Reports" or "Information" menus, not null.
172 * @see MavenReport#CATEGORY_PROJECT_INFORMATION
173 * @see MavenReport#CATEGORY_PROJECT_REPORTS
174 */
175 void populateReportsMenu(SiteModel siteModel, Locale locale, Map<String, List<MavenReport>> reportsPerCategory);
176
177 /**
178 * Extracts from a comma-separated list the locales that are available in <code>site-tool</code>
179 * resource bundle.
180 *
181 * @param locales A comma separated list of locales
182 * @return a list of <code>Locale</code>s.
183 * @since 1.7, was previously getAvailableLocales(String)
184 */
185 List<Locale> getSiteLocales(String locales);
186
187 /**
188 * Calculate the relative path between two URLs or between two files.
189 *
190 * For example:
191 * <dl>
192 * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org"</dt>
193 * <dd>return ""</dd>
194 * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org/plugins/maven-site-plugin/"</dt>
195 * <dd>return "../.."</dd>
196 * <dt>to = "http://maven.apache.org/plugins/maven-site-plugin/" and from = "http://maven.apache.org"</dt>
197 * <dd>return "plugins/maven-site-plugin"</dd>
198 * <dt>to = "/myproject/myproject-module1" and from = "/myproject/myproject"</dt>
199 * <dd>return "../myproject-module1"</dd>
200 * </dl>
201 * <b>Note</b>: The file separator depends on the system.
202 * Maven-specific urls are supported, like <code>dav:https://dav.codehaus.org/</code> or
203 * <code>scm:svn:https://svn.apache.org/repos/asf</code>.
204 *
205 * @param to the <code>to</code> url of file as string
206 * @param from the <code>from</code> url of file as string
207 * @return a relative path from <code>from</code> to <code>to</code>.
208 */
209 String getRelativePath(String to, String from);
210 }