package org.apache.maven.model.inheritance; /* * 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.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginContainer; import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.Reporting; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.ModelProblemCollector; import org.apache.maven.model.merge.MavenModelMerger; import org.codehaus.plexus.component.annotations.Component; /** * Handles inheritance of model values. * * @author Benjamin Bentmann */ @Component( role = InheritanceAssembler.class ) public class DefaultInheritanceAssembler implements InheritanceAssembler { private InheritanceModelMerger merger = new InheritanceModelMerger(); @Override public void assembleModelInheritance( Model child, Model parent, ModelBuildingRequest request, ModelProblemCollector problems ) { Map
* * @param child The child model, must not benull
.
* @param parent The parent model, may be null
.
* @return The path adjustment, can be empty but never null
.
*/
private String getChildPathAdjustment( Model child, Model parent )
{
String adjustment = "";
if ( parent != null )
{
String childName = child.getArtifactId();
/*
* This logic exists only for the sake of backward-compat with 2.x (MNG-5000). In generally, it is wrong to
* base URL inheritance on the project directory names as this information is unavailable for POMs in the
* repository. In other words, projects where artifactId != projectDirName will see different effective URLs
* depending on how the POM was constructed.
*/
File childDirectory = child.getProjectDirectory();
if ( childDirectory != null )
{
childName = childDirectory.getName();
}
for ( String module : parent.getModules() )
{
module = module.replace( '\\', '/' );
if ( module.regionMatches( true, module.length() - 4, ".xml", 0, 4 ) )
{
module = module.substring( 0, module.lastIndexOf( '/' ) + 1 );
}
String moduleName = module;
if ( moduleName.endsWith( "/" ) )
{
moduleName = moduleName.substring( 0, moduleName.length() - 1 );
}
int lastSlash = moduleName.lastIndexOf( '/' );
moduleName = moduleName.substring( lastSlash + 1 );
if ( moduleName.equals( childName ) && lastSlash >= 0 )
{
adjustment = module.substring( 0, lastSlash );
break;
}
}
}
return adjustment;
}
protected static class InheritanceModelMerger
extends MavenModelMerger
{
@Override
protected void mergePluginContainer_Plugins( PluginContainer target, PluginContainer source,
boolean sourceDominant, Map