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