More syncs between PomClassicTransformer and PomTransformer

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@719494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2008-11-21 06:11:22 +00:00
parent 443d49730e
commit d78042d0d2
1 changed files with 94 additions and 45 deletions

View File

@ -219,6 +219,7 @@ public final class PomTransformer
} }
} }
props.removeAll( removeProperties ); props.removeAll( removeProperties );
for(ModelEventListener listener : eventListeners) for(ModelEventListener listener : eventListeners)
{ {
ModelDataSource ds = new DefaultModelDataSource(); ModelDataSource ds = new DefaultModelDataSource();
@ -245,9 +246,11 @@ public final class PomTransformer
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>(); List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
List<String> projectNames = new ArrayList<String>(); List<String> projectNames = new ArrayList<String>();
StringBuffer scmUrl = new StringBuffer(); StringBuilder projectUrl = new StringBuilder( 128 );
StringBuffer scmConnectionUrl = new StringBuffer(); StringBuilder siteUrl = new StringBuilder( 128 );
StringBuffer scmDeveloperUrl = new StringBuffer(); StringBuilder scmUrl = new StringBuilder( 128 );
StringBuilder scmConnectionUrl = new StringBuilder( 128 );
StringBuilder scmDeveloperUrl = new StringBuilder( 128 );
boolean containsBuildResources = false; boolean containsBuildResources = false;
boolean containsTestResources = false; boolean containsTestResources = false;
@ -352,55 +355,27 @@ public final class PomTransformer
tmp.removeAll( removeProperties ); tmp.removeAll( removeProperties );
} }
//SCM Rule // Project URL Rule
ModelProperty scmUrlProperty = getPropertyFor( ProjectUri.Scm.url, tmp ); adjustUrl( projectUrl, tmp, ProjectUri.url, projectNames );
if ( scmUrl.length() == 0 && scmUrlProperty != null ) // Site Rule
{ adjustUrl( siteUrl, tmp, ProjectUri.DistributionManagement.Site.url, projectNames );
scmUrl.append( scmUrlProperty.getResolvedValue() ); // SCM Rule
for ( String projectName : projectNames ) adjustUrl( scmUrl, tmp, ProjectUri.Scm.url, projectNames );
{ // SCM Connection Rule
scmUrl.append( "/" ).append( projectName ); adjustUrl( scmConnectionUrl, tmp, ProjectUri.Scm.connection, projectNames );
} // SCM Developer Rule
int index = tmp.indexOf( scmUrlProperty ); adjustUrl( scmDeveloperUrl, tmp, ProjectUri.Scm.developerConnection, projectNames );
tmp.remove( index );
tmp.add( index, new ModelProperty( ProjectUri.Scm.url, scmUrl.toString() ) );
}
//SCM Connection Rule
scmUrlProperty = getPropertyFor( ProjectUri.Scm.connection, tmp );
if ( scmConnectionUrl.length() == 0 && scmUrlProperty != null )
{
scmConnectionUrl.append( scmUrlProperty.getResolvedValue() );
for ( String projectName : projectNames )
{
scmConnectionUrl.append( "/" ).append( projectName );
}
int index = tmp.indexOf( scmUrlProperty );
tmp.remove( index );
tmp.add( index, new ModelProperty( ProjectUri.Scm.connection, scmConnectionUrl.toString() ) );
}
//SCM Developer Rule
scmUrlProperty = getPropertyFor( ProjectUri.Scm.developerConnection, tmp );
if ( scmDeveloperUrl.length() == 0 && scmUrlProperty != null )
{
scmDeveloperUrl.append( scmUrlProperty.getResolvedValue() );
for ( String projectName : projectNames )
{
scmDeveloperUrl.append( "/" ).append( projectName );
}
int index = tmp.indexOf( scmUrlProperty );
tmp.remove( index );
tmp.add( index, new ModelProperty( ProjectUri.Scm.developerConnection, scmDeveloperUrl.toString() ) );
}
//Project Name Inheritance Rule //Project Name Inheritance Rule
//Packaging Inheritance Rule //Packaging Inheritance Rule
//Profiles not inherited rule //Profiles not inherited rule
//parent.relativePath not inherited rule
for ( ModelProperty mp : tmp ) for ( ModelProperty mp : tmp )
{ {
String uri = mp.getUri(); String uri = mp.getUri();
if ( domainModels.indexOf( domainModel ) > 0 && ( uri.equals( ProjectUri.name ) || if ( domainModels.indexOf( domainModel ) > 0 && ( uri.equals( ProjectUri.name ) ||
uri.equals( ProjectUri.packaging ) || uri.startsWith( ProjectUri.Profiles.xUri ) ) ) uri.equals( ProjectUri.packaging ) || uri.startsWith( ProjectUri.Profiles.xUri ) )
|| uri.startsWith( ProjectUri.Parent.relativePath ))
{ {
clearedProperties.add( mp ); clearedProperties.add( mp );
} }
@ -460,9 +435,61 @@ public final class PomTransformer
modelProperties.removeAll( clearedProperties ); modelProperties.removeAll( clearedProperties );
} }
//Rule: Build plugin config overrides reporting plugin config
ModelDataSource source = new DefaultModelDataSource();
source.init( modelProperties, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
List<ModelContainer> reportContainers = source.queryFor( ProjectUri.Reporting.Plugins.Plugin.xUri );
for ( ModelContainer pluginContainer : source.queryFor( ProjectUri.Build.Plugins.Plugin.xUri ) )
{
ModelContainer transformedReportContainer = new ArtifactModelContainerFactory().create(
transformPlugin( pluginContainer.getProperties() ) );
for(ModelContainer reportContainer : reportContainers) {
ModelContainerAction action = transformedReportContainer.containerAction( reportContainer );
if ( action.equals( ModelContainerAction.JOIN ) )
{
source.join( transformedReportContainer, reportContainer );
break;
}
}
}
modelProperties = source.getModelProperties();
return modelProperties; return modelProperties;
} }
/**
* Adjusts an inherited URL to compensate for a child's relation/distance to the parent that defines the URL.
*
* @param url The buffer for the adjusted URL, must not be {@code null}.
* @param properties The model properties to update, must not be {@code null}.
* @param uri The URI of the model property defining the URL to adjust, must not be {@code null}.
* @param ids The artifact identifiers of the parent projects, starting with the least significant parent, must not
* be {@code null}.
*/
private void adjustUrl( StringBuilder url, List<ModelProperty> properties, String uri, List<String> ids )
{
if ( url.length() == 0 )
{
ModelProperty property = getPropertyFor( uri, properties );
if ( property != null )
{
url.append( property.getResolvedValue() );
for ( String id : ids )
{
if ( url.length() > 0 && url.charAt( url.length() - 1 ) != '/' )
{
url.append( '/' );
}
url.append( id );
}
int index = properties.indexOf( property );
properties.set( index, new ModelProperty( uri, url.toString() ) );
}
}
}
public void interpolateModelProperties(List<ModelProperty> modelProperties, public void interpolateModelProperties(List<ModelProperty> modelProperties,
List<InterpolatorProperty> interpolatorProperties, List<InterpolatorProperty> interpolatorProperties,
DomainModel domainModel) DomainModel domainModel)
@ -632,7 +659,7 @@ public final class PomTransformer
return transformedProperties; return transformedProperties;
} }
public static List<ModelProperty> transformPluginManagement( List<ModelProperty> modelProperties ) private static List<ModelProperty> transformPluginManagement( List<ModelProperty> modelProperties )
{ {
List<ModelProperty> transformedProperties = new ArrayList<ModelProperty>(); List<ModelProperty> transformedProperties = new ArrayList<ModelProperty>();
for ( ModelProperty mp : modelProperties ) for ( ModelProperty mp : modelProperties )
@ -646,5 +673,27 @@ public final class PomTransformer
} }
return transformedProperties; return transformedProperties;
} }
private static List<ModelProperty> transformPlugin( List<ModelProperty> modelProperties )
{
List<ModelProperty> transformedProperties = new ArrayList<ModelProperty>();
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().startsWith( ProjectUri.Build.Plugins.xUri ) )
{ if(mp.getUri().startsWith(ProjectUri.Build.Plugins.Plugin.configuration)
|| mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.groupId)
|| mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.artifactId)
|| mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.version)
|| mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.xUri ) )
{
transformedProperties.add( new ModelProperty(
mp.getUri().replace( ProjectUri.Build.Plugins.xUri, ProjectUri.Reporting.Plugins.xUri ),
mp.getResolvedValue() ) );
}
}
}
return transformedProperties;
}
} }