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