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 import java.io.IOException; 24 import java.io.InputStream; 25 26 import java.util.List; 27 import java.util.Properties; 28 29 import org.apache.maven.artifact.repository.ArtifactRepository; 30 import org.apache.maven.artifact.versioning.ComparableVersion; 31 import org.apache.maven.doxia.tools.SiteTool; 32 import org.apache.maven.plugin.AbstractMojo; 33 import org.apache.maven.project.MavenProject; 34 35 import org.codehaus.plexus.i18n.I18N; 36 import org.codehaus.plexus.util.IOUtil; 37 import org.codehaus.plexus.util.ReaderFactory; 38 39 /** 40 * Base class for site mojos. 41 * 42 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 43 */ 44 public abstract class AbstractSiteMojo 45 extends AbstractMojo 46 { 47 /** 48 * A comma separated list of locales supported by Maven. The first valid token will be the default Locale 49 * for this instance of the Java Virtual Machine. 50 * 51 * @parameter expression="${locales}" 52 */ 53 protected String locales; 54 55 /** 56 * SiteTool. 57 * 58 * @component 59 */ 60 protected SiteTool siteTool; 61 62 /** 63 * Internationalization. 64 * 65 * @component 66 */ 67 protected I18N i18n; 68 69 /** 70 * Directory containing the site.xml file and the source for apt, fml and xdoc docs. 71 * 72 * @parameter default-value="${basedir}/src/site" 73 */ 74 protected File siteDirectory; 75 76 /** 77 * The maven project. 78 * 79 * @parameter default-value="${project}" 80 * @required 81 * @readonly 82 */ 83 protected MavenProject project; 84 85 /** 86 * The local repository. 87 * 88 * @parameter default-value="${localRepository}" 89 * @readonly 90 */ 91 protected ArtifactRepository localRepository; 92 93 /** 94 * The reactor projects. 95 * 96 * @parameter default-value="${reactorProjects}" 97 * @required 98 * @readonly 99 */ 100 protected List<MavenProject> reactorProjects; 101 102 /** 103 * Specifies the input encoding. 104 * 105 * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}" 106 */ 107 private String inputEncoding; 108 109 /** 110 * Specifies the output encoding. 111 * 112 * @parameter expression="${outputEncoding}" default-value="${project.reporting.outputEncoding}" 113 */ 114 private String outputEncoding; 115 116 /** 117 * Gets the input files encoding. 118 * 119 * @return The input files encoding, never <code>null</code>. 120 */ 121 protected String getInputEncoding() 122 { 123 return ( inputEncoding == null ) ? ReaderFactory.ISO_8859_1 : inputEncoding; 124 } 125 126 /** 127 * Gets the effective reporting output files encoding. 128 * 129 * @return The effective reporting output file encoding, never <code>null</code>. 130 */ 131 protected String getOutputEncoding() 132 { 133 return ( outputEncoding == null ) ? ReaderFactory.UTF_8 : outputEncoding; 134 } 135 136 /** 137 * Check the current Maven version to see if it's Maven 3.0 or newer. 138 */ 139 protected boolean isMaven3OrMore() 140 { 141 return new ComparableVersion( getMavenVersion() ).compareTo( new ComparableVersion( "3.0" ) ) >= 0; 142 } 143 144 protected String getMavenVersion() 145 { 146 // This relies on the fact that MavenProject is the in core classloader 147 // and that the core classloader is for the maven-core artifact 148 // and that should have a pom.properties file 149 // if this ever changes, we will have to revisit this code. 150 final Properties properties = new Properties(); 151 final InputStream in = 152 MavenProject.class.getClassLoader().getResourceAsStream( "META-INF/maven/org.apache.maven/maven-core/pom.properties" ); 153 try 154 { 155 properties.load( in ); 156 } 157 catch ( IOException ioe ) 158 { 159 return ""; 160 } 161 finally 162 { 163 IOUtil.close( in ); 164 } 165 166 return properties.getProperty( "version" ).trim(); 167 } 168 }