Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.apache.maven.doxia.tools;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import org.apache.commons.io.FilenameUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.doxia.site.decoration.Banner;
import org.apache.maven.doxia.site.decoration.DecorationModel;
import org.apache.maven.doxia.site.decoration.Menu;
import org.apache.maven.doxia.site.decoration.MenuItem;
import org.apache.maven.doxia.site.decoration.Skin;
import org.apache.maven.doxia.site.decoration.inheritance.DecorationModelInheritanceAssembler;
import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader;
import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Writer;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Site;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reporting.MavenReport;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.ObjectBasedValueSource;
import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
import org.codehaus.plexus.interpolation.PrefixedPropertiesValueSource;
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* Default implementation of the site tool.
*
* @author Vincent Siveton
* @version $Id: DefaultSiteTool.java 1763022 2016-10-01 16:31:29Z hboutemy $
*/
@Component( role = SiteTool.class )
public class DefaultSiteTool
extends AbstractLogEnabled
implements SiteTool
{
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
/**
* The component that is used to resolve additional artifacts required.
*/
@Requirement
private ArtifactResolver artifactResolver;
/**
* The component used for creating artifact instances.
*/
@Requirement
private ArtifactFactory artifactFactory;
/**
* Internationalization.
*/
@Requirement
protected I18N i18n;
/**
* The component for assembling inheritance.
*/
@Requirement
protected DecorationModelInheritanceAssembler assembler;
/**
* Project builder (deprecated in Maven 3: should use ProjectBuilder, which will avoid
* issues like DOXIASITETOOLS-166)
*/
@Requirement
protected MavenProjectBuilder mavenProjectBuilder;
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/** {@inheritDoc} */
public Artifact getSkinArtifactFromRepository( ArtifactRepository localRepository,
List remoteArtifactRepositories,
DecorationModel decoration )
throws SiteToolException
{
checkNotNull( "localRepository", localRepository );
checkNotNull( "remoteArtifactRepositories", remoteArtifactRepositories );
checkNotNull( "decoration", decoration );
Skin skin = decoration.getSkin();
if ( skin == null )
{
skin = Skin.getDefaultSkin();
}
String version = skin.getVersion();
Artifact artifact;
try
{
if ( version == null )
{
version = Artifact.RELEASE_VERSION;
}
VersionRange versionSpec = VersionRange.createFromVersionSpec( version );
artifact = artifactFactory.createDependencyArtifact( skin.getGroupId(), skin.getArtifactId(), versionSpec,
"jar", null, null );
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
}
catch ( InvalidVersionSpecificationException e )
{
throw new SiteToolException( "InvalidVersionSpecificationException: The skin version '" + version
+ "' is not valid: " + e.getMessage(), e );
}
catch ( ArtifactResolutionException e )
{
throw new SiteToolException( "ArtifactResolutionException: Unable to find skin", e );
}
catch ( ArtifactNotFoundException e )
{
throw new SiteToolException( "ArtifactNotFoundException: The skin does not exist: " + e.getMessage(), e );
}
return artifact;
}
/** {@inheritDoc} */
public Artifact getDefaultSkinArtifact( ArtifactRepository localRepository,
List remoteArtifactRepositories )
throws SiteToolException
{
return getSkinArtifactFromRepository( localRepository, remoteArtifactRepositories, new DecorationModel() );
}
/** {@inheritDoc} */
public String getRelativePath( String to, String from )
{
checkNotNull( "to", to );
checkNotNull( "from", from );
URL toUrl = null;
URL fromUrl = null;
String toPath = to;
String fromPath = from;
try
{
toUrl = new URL( to );
}
catch ( MalformedURLException e )
{
try
{
toUrl = new File( getNormalizedPath( to ) ).toURI().toURL();
}
catch ( MalformedURLException e1 )
{
getLogger().warn( "Unable to load a URL for '" + to + "': " + e.getMessage() );
}
}
try
{
fromUrl = new URL( from );
}
catch ( MalformedURLException e )
{
try
{
fromUrl = new File( getNormalizedPath( from ) ).toURI().toURL();
}
catch ( MalformedURLException e1 )
{
getLogger().warn( "Unable to load a URL for '" + from + "': " + e.getMessage() );
}
}
if ( toUrl != null && fromUrl != null )
{
// URLs, determine if they share protocol and domain info
if ( ( toUrl.getProtocol().equalsIgnoreCase( fromUrl.getProtocol() ) )
&& ( toUrl.getHost().equalsIgnoreCase( fromUrl.getHost() ) )
&& ( toUrl.getPort() == fromUrl.getPort() ) )
{
// shared URL domain details, use URI to determine relative path
toPath = toUrl.getFile();
fromPath = fromUrl.getFile();
}
else
{
// don't share basic URL information, no relative available
return to;
}
}
else if ( ( toUrl != null && fromUrl == null ) || ( toUrl == null && fromUrl != null ) )
{
// one is a URL and the other isn't, no relative available.
return to;
}
// either the two locations are not URLs or if they are they
// share the common protocol and domain info and we are left
// with their URI information
String relativePath = getRelativeFilePath( fromPath, toPath );
if ( relativePath == null )
{
relativePath = to;
}
if ( getLogger().isDebugEnabled() && !relativePath.toString().equals( to ) )
{
getLogger().debug( "Mapped url: " + to + " to relative path: " + relativePath );
}
return relativePath;
}
private static String getRelativeFilePath( final String oldPath, final String newPath )
{
// normalize the path delimiters
String fromPath = new File( oldPath ).getPath();
String toPath = new File( newPath ).getPath();
// strip any leading slashes if its a windows path
if ( toPath.matches( "^\\[a-zA-Z]:" ) )
{
toPath = toPath.substring( 1 );
}
if ( fromPath.matches( "^\\[a-zA-Z]:" ) )
{
fromPath = fromPath.substring( 1 );
}
// lowercase windows drive letters.
if ( fromPath.startsWith( ":", 1 ) )
{
fromPath = Character.toLowerCase( fromPath.charAt( 0 ) ) + fromPath.substring( 1 );
}
if ( toPath.startsWith( ":", 1 ) )
{
toPath = Character.toLowerCase( toPath.charAt( 0 ) ) + toPath.substring( 1 );
}
// check for the presence of windows drives. No relative way of
// traversing from one to the other.
if ( ( toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) )
&& ( !toPath.substring( 0, 1 ).equals( fromPath.substring( 0, 1 ) ) ) )
{
// they both have drive path element but they don't match, no
// relative path
return null;
}
if ( ( toPath.startsWith( ":", 1 ) && !fromPath.startsWith( ":", 1 ) )
|| ( !toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) ) )
{
// one has a drive path element and the other doesn't, no relative
// path.
return null;
}
final String relativePath = buildRelativePath( toPath, fromPath, File.separatorChar );
return relativePath.toString();
}
/** {@inheritDoc} */
public File getSiteDescriptor( File siteDirectory, Locale locale )
{
checkNotNull( "siteDirectory", siteDirectory );
final Locale llocale = ( locale == null ) ? new Locale( "" ) : locale;
File siteDescriptor = new File( siteDirectory, "site_" + llocale.getLanguage() + ".xml" );
if ( !siteDescriptor.isFile() )
{
siteDescriptor = new File( siteDirectory, "site.xml" );
}
return siteDescriptor;
}
/**
* Get a site descriptor from one of the repositories.
*
* @param project the Maven project, not null.
* @param localRepository the Maven local repository, not null.
* @param repositories the Maven remote repositories, not null.
* @param locale the locale wanted for the site descriptor. If not null, searching for
* site_localeLanguage.xml, otherwise searching for site.xml.
* @return the site descriptor into the local repository after download of it from repositories or null if not
* found in repositories.
* @throws SiteToolException if any
*/
File getSiteDescriptorFromRepository( MavenProject project, ArtifactRepository localRepository,
List repositories, Locale locale )
throws SiteToolException
{
checkNotNull( "project", project );
checkNotNull( "localRepository", localRepository );
checkNotNull( "repositories", repositories );
final Locale llocale = ( locale == null ) ? new Locale( "" ) : locale;
try
{
return resolveSiteDescriptor( project, localRepository, repositories, llocale );
}
catch ( ArtifactNotFoundException e )
{
getLogger().debug( "ArtifactNotFoundException: Unable to locate site descriptor: " + e );
return null;
}
catch ( ArtifactResolutionException e )
{
throw new SiteToolException( "ArtifactResolutionException: Unable to locate site descriptor: "
+ e.getMessage(), e );
}
catch ( IOException e )
{
throw new SiteToolException( "IOException: Unable to locate site descriptor: " + e.getMessage(), e );
}
}
/**
* Read site descriptor content from Reader, adding support for deprecated ${reports},
* ${parentProject} and ${modules} tags.
*
* @param reader
* @return the input content interpolated with deprecated tags
* @throws IOException
*/
private String readSiteDescriptor( Reader reader, String projectId )
throws IOException
{
String siteDescriptorContent = IOUtil.toString( reader );
// This is to support the deprecated ${reports}, ${parentProject} and ${modules} tags.
Properties props = new Properties();
props.put( "reports", "