mirror of https://github.com/apache/maven.git
Moved legacy builder code to maven-mercury. Moved over interpolator code from model-builder to maven-project-builder to reduce the dependencies. Reduce the amount of parsing to and from model properties.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@764568 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bd45522faf
commit
ae476bf2fa
|
@ -73,9 +73,9 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.builder.PomInterpolatorTag;
|
||||
import org.apache.maven.project.builder.PomTransformer;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.interpolator.PomInterpolatorTag;
|
||||
import org.apache.maven.project.builder.legacy.PomTransformer;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.apache.maven.realm.MavenRealmManager;
|
||||
import org.apache.maven.realm.RealmManagementException;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||
import org.apache.maven.project.builder.legacy.PomClassicDomainModel;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.codehaus.plexus.util.WriterFactory;
|
||||
|
@ -171,16 +171,6 @@ public class PomTestWrapper
|
|||
return ( pomFile != null ) ? pomFile.getParentFile() : null;
|
||||
}
|
||||
|
||||
public String getValueOfProjectUri( String projectUri, boolean withResolvedValue )
|
||||
throws IOException
|
||||
{
|
||||
if ( projectUri.contains( "#collection" ) || projectUri.contains( "#set" ) )
|
||||
{
|
||||
throw new IllegalArgumentException( "projectUri: contains a collection or set" );
|
||||
}
|
||||
return asMap( withResolvedValue ).get( projectUri );
|
||||
}
|
||||
|
||||
public void setValueOnModel( String expression, Object value )
|
||||
{
|
||||
context.setValue( expression, value );
|
||||
|
|
|
@ -30,9 +30,9 @@ import org.apache.maven.mercury.builder.api.DependencyProcessor;
|
|||
import org.apache.maven.mercury.builder.api.DependencyProcessorException;
|
||||
import org.apache.maven.mercury.builder.api.MetadataReader;
|
||||
import org.apache.maven.mercury.builder.api.MetadataReaderException;
|
||||
import org.apache.maven.project.builder.PomInterpolatorTag;
|
||||
import org.apache.maven.project.builder.PomTransformer;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.interpolator.PomInterpolatorTag;
|
||||
import org.apache.maven.project.builder.legacy.PomTransformer;
|
||||
import org.apache.maven.shared.model.DomainModel;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.apache.maven.mercury.builder.api.DependencyProcessor;
|
|||
import org.apache.maven.mercury.builder.api.DependencyProcessorException;
|
||||
import org.apache.maven.mercury.builder.api.MetadataReader;
|
||||
import org.apache.maven.mercury.builder.api.MetadataReaderException;
|
||||
import org.apache.maven.project.processor.ProcessorContext;
|
||||
import org.apache.maven.project.builder.ProcessorContext;
|
||||
import org.apache.maven.shared.model.DomainModel;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
@ -62,7 +62,7 @@ public class MavenDependencyProcessor2
|
|||
{
|
||||
throw new MetadataReaderException( "Failed to create domain model. Message = " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
/*
|
||||
try
|
||||
{
|
||||
MavenDomainModel model = new MavenDomainModel(ProcessorContext.build(domainModels, interpolatorProperties));
|
||||
|
@ -72,5 +72,7 @@ public class MavenDependencyProcessor2
|
|||
{
|
||||
throw new MetadataReaderException( "Unable to transform model", e );
|
||||
}
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.maven.mercury.artifact.ArtifactMetadata;
|
||||
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||
import org.apache.maven.project.builder.PomTransformer;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory;
|
||||
import org.apache.maven.project.builder.factories.ExclusionModelContainerFactory;
|
||||
import org.apache.maven.project.builder.legacy.PomClassicDomainModel;
|
||||
import org.apache.maven.project.builder.legacy.PomTransformer;
|
||||
import org.apache.maven.project.builder.profile.ProfileContext;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.builder;
|
||||
package org.apache.maven.project.builder.legacy;
|
||||
|
||||
import org.apache.maven.shared.model.ModelDataSource;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.builder;
|
||||
package org.apache.maven.project.builder.legacy;
|
||||
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
|
@ -0,0 +1,441 @@
|
|||
package org.apache.maven.project.builder.legacy;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.ModelMarshaller;
|
||||
import org.apache.maven.shared.model.InputStreamDomainModel;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Provides a wrapper for the maven model.
|
||||
*/
|
||||
public class PomClassicDomainModel implements InputStreamDomainModel
|
||||
{
|
||||
|
||||
/**
|
||||
* Bytes containing the underlying model
|
||||
*/
|
||||
private byte[] inputBytes;
|
||||
|
||||
/**
|
||||
* History of joins and deletes of model properties
|
||||
*/
|
||||
private String eventHistory;
|
||||
|
||||
private String id;
|
||||
|
||||
private File file;
|
||||
|
||||
private File parentFile;
|
||||
|
||||
private File projectDirectory;
|
||||
|
||||
private List<ModelProperty> modelProperties;
|
||||
|
||||
private int lineageCount;
|
||||
|
||||
private boolean isMostSpecialized = false;
|
||||
|
||||
private String parentGroupId = null, parentArtifactId = null, parentVersion = null, parentId = null, parentRelativePath;
|
||||
|
||||
private Model model;
|
||||
|
||||
public Model getModel() throws IOException
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
InputStream is;
|
||||
try {
|
||||
is = getInputStream();
|
||||
} catch (Exception e1) {
|
||||
throw new IOException("inputStream not set");
|
||||
}
|
||||
|
||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
try
|
||||
{
|
||||
model = reader.read( is, false ) ;
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( List<ModelProperty> modelProperties )
|
||||
{
|
||||
this.modelProperties = modelProperties;
|
||||
try
|
||||
{
|
||||
String xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
|
||||
inputBytes = xml.getBytes( "UTF-8" );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new IllegalStateException( "Unmarshalling of model properties failed", e );
|
||||
}
|
||||
initializeProperties( modelProperties );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( List<ModelProperty> modelProperties, boolean isMostSpecialized )
|
||||
{
|
||||
this( modelProperties );
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param inputStream input stream of the maven model
|
||||
* @throws IOException if there is a problem constructing the model
|
||||
*/
|
||||
public PomClassicDomainModel( InputStream inputStream )
|
||||
throws IOException
|
||||
{
|
||||
if ( inputStream == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "inputStream: null" );
|
||||
}
|
||||
this.inputBytes = IOUtil.toByteArray( inputStream );
|
||||
modelProperties = getModelProperties();
|
||||
initializeProperties( modelProperties );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( InputStream inputStream, boolean isMostSpecialized )
|
||||
throws IOException
|
||||
{
|
||||
this( inputStream );
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
private void initializeProperties(List<ModelProperty> modelProperties)
|
||||
{
|
||||
String groupId = null, artifactId = null, version = null;
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
if(mp.getUri().equals(ProjectUri.groupId))
|
||||
{
|
||||
groupId = mp.getResolvedValue();
|
||||
}
|
||||
else if(mp.getUri().equals(ProjectUri.artifactId))
|
||||
{
|
||||
artifactId = mp.getResolvedValue();
|
||||
}
|
||||
else if(mp.getUri().equals(ProjectUri.version))
|
||||
{
|
||||
version = mp.getResolvedValue();
|
||||
}
|
||||
else if(mp.getUri().equals(ProjectUri.Parent.artifactId))
|
||||
{
|
||||
parentArtifactId = mp.getResolvedValue();
|
||||
}
|
||||
else if(mp.getUri().equals(ProjectUri.Parent.groupId))
|
||||
{
|
||||
parentGroupId = mp.getResolvedValue();
|
||||
}
|
||||
else if(mp.getUri().equals(ProjectUri.Parent.version))
|
||||
{
|
||||
parentVersion = mp.getResolvedValue();
|
||||
}
|
||||
else if(mp.getUri().equals(ProjectUri.Parent.relativePath))
|
||||
{
|
||||
parentRelativePath = mp.getResolvedValue();
|
||||
}
|
||||
|
||||
if(groupId != null && artifactId != null && version != null && parentGroupId != null &&
|
||||
parentArtifactId != null && parentVersion != null & parentRelativePath != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( groupId == null && parentGroupId != null)
|
||||
{
|
||||
groupId = parentGroupId;
|
||||
}
|
||||
if( artifactId == null && parentArtifactId != null)
|
||||
{
|
||||
artifactId = parentArtifactId;
|
||||
}
|
||||
if( version == null && parentVersion != null )
|
||||
{
|
||||
version = parentVersion;
|
||||
}
|
||||
|
||||
if(parentGroupId != null && parentArtifactId != null && parentVersion != null)
|
||||
{
|
||||
parentId = parentGroupId + ":" + parentArtifactId + ":" + parentVersion;
|
||||
}
|
||||
|
||||
if(parentRelativePath == null)
|
||||
{
|
||||
parentRelativePath = ".." + File.separator + "pom.xml";
|
||||
}
|
||||
|
||||
id = groupId + ":" + artifactId + ":" + version;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( File file )
|
||||
throws IOException
|
||||
{
|
||||
this( new FileInputStream( file ) );
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel(Model model2) {
|
||||
this.model = model2;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel(Model model2, boolean b) {
|
||||
this.model = model2;
|
||||
this.isMostSpecialized = b;
|
||||
}
|
||||
|
||||
public File getParentFile()
|
||||
{
|
||||
return parentFile;
|
||||
}
|
||||
|
||||
public void setParentFile( File parentFile )
|
||||
{
|
||||
this.parentFile = parentFile;
|
||||
}
|
||||
|
||||
public String getParentGroupId() {
|
||||
return parentGroupId;
|
||||
}
|
||||
|
||||
public String getParentArtifactId() {
|
||||
return parentArtifactId;
|
||||
}
|
||||
|
||||
public String getParentVersion() {
|
||||
return parentVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* This should only be set for projects that are in the build. Setting for poms in the repo may cause unstable behavior.
|
||||
*
|
||||
* @param projectDirectory
|
||||
*/
|
||||
public void setProjectDirectory(File projectDirectory)
|
||||
{
|
||||
this.projectDirectory = projectDirectory;
|
||||
}
|
||||
|
||||
public File getProjectDirectory()
|
||||
{
|
||||
return projectDirectory;
|
||||
}
|
||||
|
||||
public boolean isPomInBuild()
|
||||
{
|
||||
return projectDirectory != null;
|
||||
}
|
||||
|
||||
public String getParentId() throws IOException
|
||||
{
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public String getRelativePathOfParent()
|
||||
{
|
||||
return parentRelativePath;
|
||||
}
|
||||
|
||||
public String getId() throws IOException
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public boolean matchesParentOf( PomClassicDomainModel domainModel ) throws IOException
|
||||
{
|
||||
if ( domainModel == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "domainModel: null" );
|
||||
}
|
||||
|
||||
return getId().equals(domainModel.getParentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XML model as string
|
||||
*
|
||||
* @return XML model as string
|
||||
*/
|
||||
public String asString()
|
||||
{
|
||||
try
|
||||
{
|
||||
return IOUtil.toString( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) );
|
||||
}
|
||||
catch ( IOException ioe )
|
||||
{
|
||||
// should not occur: everything is in-memory
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
|
||||
*/
|
||||
public InputStream getInputStream()
|
||||
{
|
||||
byte[] copy = new byte[inputBytes.length];
|
||||
System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
|
||||
//System.out.println(new String(copy));
|
||||
return new ByteArrayInputStream( copy );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return file of pom. May be null.
|
||||
*/
|
||||
public File getFile()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
public List<ModelProperty> getModelProperties() throws IOException
|
||||
{
|
||||
if(modelProperties == null)
|
||||
{
|
||||
Set<String> s = new HashSet<String>();
|
||||
//TODO: Should add all collections from ProjectUri
|
||||
s.addAll(PomTransformer.URIS);
|
||||
s.add(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri);
|
||||
s.add(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri);
|
||||
s.add(ProjectUri.Dependencies.Dependency.Exclusions.xUri);
|
||||
s.add(ProjectUri.Build.Plugins.Plugin.Executions.xUri);
|
||||
s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI);
|
||||
s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri);
|
||||
s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.configuration);
|
||||
s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.configuration);
|
||||
//TODO: More profile info
|
||||
s.add(ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Executions.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.Dependency.Exclusions.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.Execution.Goals.xURI);
|
||||
s.add(ProjectUri.Profiles.Profile.Reporting.Plugins.Plugin.ReportSets.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.Reporting.Plugins.Plugin.ReportSets.ReportSet.configuration);
|
||||
s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.Execution.configuration);
|
||||
s.add(ProjectUri.Profiles.Profile.properties);
|
||||
s.add(ProjectUri.Profiles.Profile.modules);
|
||||
s.add(ProjectUri.Profiles.Profile.Dependencies.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration);
|
||||
|
||||
modelProperties = ModelMarshaller.marshallXmlToModelProperties(
|
||||
getInputStream(), ProjectUri.baseUri, s );
|
||||
}
|
||||
return new ArrayList<ModelProperty>(modelProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.DomainModel#getEventHistory()
|
||||
*/
|
||||
public String getEventHistory()
|
||||
{
|
||||
return eventHistory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.DomainModel#setEventHistory(String)
|
||||
*/
|
||||
public void setEventHistory( String eventHistory )
|
||||
{
|
||||
if ( eventHistory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "eventHistory: null" );
|
||||
}
|
||||
this.eventHistory = eventHistory;
|
||||
}
|
||||
|
||||
public int getLineageCount()
|
||||
{
|
||||
return lineageCount;
|
||||
}
|
||||
|
||||
public void setLineageCount( int lineageCount )
|
||||
{
|
||||
this.lineageCount = lineageCount;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel createCopy()
|
||||
{
|
||||
List<ModelProperty> props = new ArrayList<ModelProperty>();
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
props.add(mp.createCopyOfOriginal());
|
||||
}
|
||||
|
||||
return new PomClassicDomainModel(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this.asString.equals(o.asString()), otherwise false.
|
||||
*
|
||||
* @param o domain model
|
||||
* @return true if this.asString.equals(o.asString()), otherwise false.
|
||||
*/
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
try {
|
||||
return o instanceof PomClassicDomainModel && getId().equals( ( (PomClassicDomainModel) o ).getId() );
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMostSpecialized()
|
||||
{
|
||||
return isMostSpecialized;
|
||||
}
|
||||
|
||||
public void setMostSpecialized( boolean isMostSpecialized )
|
||||
{
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf( id );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.builder;
|
||||
package org.apache.maven.project.builder.legacy;
|
||||
|
||||
import org.apache.maven.shared.model.DomainModelFactory;
|
||||
import org.apache.maven.shared.model.DomainModel;
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.builder;
|
||||
package org.apache.maven.project.builder.legacy;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -25,11 +25,14 @@ import java.util.*;
|
|||
|
||||
import org.apache.maven.shared.model.*;
|
||||
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.rules.*;
|
||||
import org.apache.maven.project.builder.factories.PluginExecutionIdModelContainerFactory;
|
||||
import org.apache.maven.project.builder.factories.AlwaysJoinModelContainerFactory;
|
||||
import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory;
|
||||
import org.apache.maven.project.builder.factories.IdModelContainerFactory;
|
||||
import org.apache.maven.project.builder.interpolator.PomInterpolatorTag;
|
||||
|
||||
/**
|
||||
* Provides methods for transforming model properties into a domain model for the pom classic format and vice versa.
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.builder;
|
||||
package org.apache.maven.project.builder.legacy;
|
||||
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.builder;
|
||||
package org.apache.maven.project.builder.legacy;
|
||||
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
|
@ -5,8 +5,8 @@ import org.apache.maven.shared.model.ModelDataSource;
|
|||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||
import org.apache.maven.project.builder.TransformerRule;
|
||||
import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
|
||||
import java.util.List;
|
|
@ -3,7 +3,7 @@ package org.apache.maven.project.builder.rules;
|
|||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.TransformerRemovalRule;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRemovalRule;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
|
@ -1,8 +1,8 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.DataSourceRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory;
|
||||
import org.apache.maven.project.builder.legacy.DataSourceRule;
|
||||
import org.apache.maven.shared.model.*;
|
||||
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.TransformerRemovalRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRemovalRule;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.TransformerRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRule;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
import static org.apache.maven.project.builder.PomTransformer.getPropertyFor;
|
||||
|
||||
import static org.apache.maven.project.builder.legacy.PomTransformer.getPropertyFor;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -2,9 +2,9 @@ package org.apache.maven.project.builder.rules;
|
|||
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
import org.apache.maven.project.builder.TransformerRule;
|
||||
import org.apache.maven.project.builder.PomTransformer;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.legacy.PomTransformer;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRule;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.TransformerRemovalRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.PomTransformer;
|
||||
import org.apache.maven.project.builder.legacy.PomTransformer;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRemovalRule;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.TransformerRemovalRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRemovalRule;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.TransformerRemovalRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory;
|
||||
import org.apache.maven.project.builder.factories.PluginExecutionIdModelContainerFactory;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRemovalRule;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
import org.apache.maven.shared.model.ModelDataSource;
|
|
@ -1,8 +1,8 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.TransformerRemovalRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.PomTransformer;
|
||||
import org.apache.maven.project.builder.legacy.PomTransformer;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRemovalRule;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
import org.apache.maven.shared.model.ModelDataSource;
|
|
@ -1,9 +1,9 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.PomTransformer;
|
||||
import org.apache.maven.project.builder.JoinRule;
|
||||
import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory;
|
||||
import org.apache.maven.project.builder.legacy.JoinRule;
|
||||
import org.apache.maven.project.builder.legacy.PomTransformer;
|
||||
import org.apache.maven.shared.model.*;
|
||||
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.TransformerRemovalRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRemovalRule;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.project.builder.TransformerRemovalRule;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.project.builder.legacy.TransformerRemovalRule;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,47 +1,38 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.ModelMarshaller;
|
||||
import org.apache.maven.shared.model.InputStreamDomainModel;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides a wrapper for the maven model.
|
||||
*/
|
||||
public class PomClassicDomainModel implements InputStreamDomainModel
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.project.builder.interpolator.DomainModel;
|
||||
import org.apache.maven.project.builder.interpolator.ModelProperty;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.WriterFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
public class PomClassicDomainModel implements DomainModel
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -49,11 +40,6 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
*/
|
||||
private byte[] inputBytes;
|
||||
|
||||
/**
|
||||
* History of joins and deletes of model properties
|
||||
*/
|
||||
private String eventHistory;
|
||||
|
||||
private String id;
|
||||
|
||||
private File file;
|
||||
|
@ -74,74 +60,8 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
|
||||
public Model getModel() throws IOException
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
InputStream is;
|
||||
try {
|
||||
is = getInputStream();
|
||||
} catch (Exception e1) {
|
||||
throw new IOException("inputStream not set");
|
||||
}
|
||||
|
||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
try
|
||||
{
|
||||
model = reader.read( is, false ) ;
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( List<ModelProperty> modelProperties )
|
||||
{
|
||||
this.modelProperties = modelProperties;
|
||||
try
|
||||
{
|
||||
String xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
|
||||
inputBytes = xml.getBytes( "UTF-8" );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new IllegalStateException( "Unmarshalling of model properties failed", e );
|
||||
}
|
||||
initializeProperties( modelProperties );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( List<ModelProperty> modelProperties, boolean isMostSpecialized )
|
||||
{
|
||||
this( modelProperties );
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param inputStream input stream of the maven model
|
||||
* @throws IOException if there is a problem constructing the model
|
||||
*/
|
||||
public PomClassicDomainModel( InputStream inputStream )
|
||||
throws IOException
|
||||
{
|
||||
if ( inputStream == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "inputStream: null" );
|
||||
}
|
||||
this.inputBytes = IOUtil.toByteArray( inputStream );
|
||||
modelProperties = getModelProperties();
|
||||
initializeProperties( modelProperties );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( InputStream inputStream, boolean isMostSpecialized )
|
||||
throws IOException
|
||||
{
|
||||
this( inputStream );
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
private void initializeProperties(List<ModelProperty> modelProperties)
|
||||
{
|
||||
|
@ -212,17 +132,54 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
public PomClassicDomainModel( File file )
|
||||
throws IOException
|
||||
{
|
||||
this( new FileInputStream( file ) );
|
||||
this( new FileInputStream( file ) );
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( InputStream is )
|
||||
throws IOException
|
||||
{
|
||||
this.inputBytes = IOUtil.toByteArray( is);
|
||||
|
||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
try
|
||||
{
|
||||
model = reader.read( new ByteArrayInputStream( inputBytes ), false ) ;
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
|
||||
modelProperties = getModelProperties();
|
||||
initializeProperties( modelProperties );
|
||||
|
||||
public PomClassicDomainModel(Model model2) {
|
||||
this.model = model2;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel(Model model) throws IOException {
|
||||
this (model, false);
|
||||
}
|
||||
|
||||
public PomClassicDomainModel(Model model2, boolean b) {
|
||||
this.model = model2;
|
||||
public PomClassicDomainModel(Model model, boolean b) throws IOException {
|
||||
this.model = model;
|
||||
this.isMostSpecialized = b;
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Writer out = null;
|
||||
MavenXpp3Writer writer = new MavenXpp3Writer();
|
||||
try
|
||||
{
|
||||
out = WriterFactory.newXmlWriter( baos );
|
||||
writer.write( out, model );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( out != null )
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
inputBytes = baos.toByteArray();
|
||||
}
|
||||
|
||||
public File getParentFile()
|
||||
|
@ -318,7 +275,6 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
{
|
||||
byte[] copy = new byte[inputBytes.length];
|
||||
System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
|
||||
//System.out.println(new String(copy));
|
||||
return new ByteArrayInputStream( copy );
|
||||
}
|
||||
|
||||
|
@ -336,7 +292,7 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
{
|
||||
Set<String> s = new HashSet<String>();
|
||||
//TODO: Should add all collections from ProjectUri
|
||||
s.addAll(PomTransformer.URIS);
|
||||
s.addAll(URIS);
|
||||
s.add(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri);
|
||||
s.add(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri);
|
||||
s.add(ProjectUri.Dependencies.Dependency.Exclusions.xUri);
|
||||
|
@ -359,32 +315,11 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
s.add(ProjectUri.Profiles.Profile.Dependencies.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration);
|
||||
|
||||
modelProperties = ModelMarshaller.marshallXmlToModelProperties(
|
||||
getInputStream(), ProjectUri.baseUri, s );
|
||||
modelProperties = marshallXmlToModelProperties(getInputStream(), ProjectUri.baseUri, s );
|
||||
}
|
||||
return new ArrayList<ModelProperty>(modelProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.DomainModel#getEventHistory()
|
||||
*/
|
||||
public String getEventHistory()
|
||||
{
|
||||
return eventHistory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.DomainModel#setEventHistory(String)
|
||||
*/
|
||||
public void setEventHistory( String eventHistory )
|
||||
{
|
||||
if ( eventHistory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "eventHistory: null" );
|
||||
}
|
||||
this.eventHistory = eventHistory;
|
||||
}
|
||||
|
||||
public int getLineageCount()
|
||||
{
|
||||
return lineageCount;
|
||||
|
@ -395,17 +330,6 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
this.lineageCount = lineageCount;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel createCopy()
|
||||
{
|
||||
List<ModelProperty> props = new ArrayList<ModelProperty>();
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
props.add(mp.createCopyOfOriginal());
|
||||
}
|
||||
|
||||
return new PomClassicDomainModel(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this.asString.equals(o.asString()), otherwise false.
|
||||
*
|
||||
|
@ -436,5 +360,223 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
{
|
||||
return String.valueOf( id );
|
||||
}
|
||||
|
||||
private static final Set<String> URIS = Collections.unmodifiableSet(new HashSet<String>( Arrays.asList( ProjectUri.Build.Extensions.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.configuration,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri,
|
||||
ProjectUri.Build.Plugins.xUri,
|
||||
ProjectUri.properties,
|
||||
ProjectUri.Build.Plugins.Plugin.configuration,
|
||||
ProjectUri.Reporting.Plugins.xUri,
|
||||
ProjectUri.Reporting.Plugins.Plugin.configuration,
|
||||
ProjectUri.Build.Plugins.Plugin.Dependencies.xUri,
|
||||
ProjectUri.Build.Resources.xUri,
|
||||
ProjectUri.Build.Resources.Resource.includes,
|
||||
ProjectUri.Build.Resources.Resource.excludes,
|
||||
ProjectUri.Build.TestResources.xUri,
|
||||
ProjectUri.Build.Filters.xUri,
|
||||
ProjectUri.CiManagement.Notifiers.xUri,
|
||||
ProjectUri.Contributors.xUri,
|
||||
ProjectUri.Dependencies.xUri,
|
||||
ProjectUri.DependencyManagement.Dependencies.xUri,
|
||||
ProjectUri.Developers.xUri,
|
||||
ProjectUri.Developers.Developer.roles,
|
||||
ProjectUri.Licenses.xUri,
|
||||
ProjectUri.MailingLists.xUri,
|
||||
ProjectUri.Modules.xUri,
|
||||
ProjectUri.PluginRepositories.xUri,
|
||||
ProjectUri.Profiles.xUri,
|
||||
ProjectUri.Profiles.Profile.Build.Plugins.xUri,
|
||||
ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Dependencies.xUri,
|
||||
ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.xUri,
|
||||
ProjectUri.Profiles.Profile.Build.Resources.xUri,
|
||||
ProjectUri.Profiles.Profile.Build.TestResources.xUri,
|
||||
ProjectUri.Profiles.Profile.Dependencies.xUri,
|
||||
ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.xUri,
|
||||
ProjectUri.Profiles.Profile.PluginRepositories.xUri,
|
||||
ProjectUri.Profiles.Profile.Reporting.Plugins.xUri,
|
||||
ProjectUri.Profiles.Profile.Repositories.xUri,
|
||||
ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.xUri,
|
||||
ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri,
|
||||
ProjectUri.Reporting.Plugins.xUri,
|
||||
ProjectUri.Repositories.xUri) ));
|
||||
|
||||
/**
|
||||
* Returns list of model properties transformed from the specified input stream.
|
||||
*
|
||||
* @param inputStream input stream containing the xml document. May not be null.
|
||||
* @param baseUri the base uri of every model property. May not be null or empty.
|
||||
* @param collections set of uris that are to be treated as a collection (multiple entries). May be null.
|
||||
* @return list of model properties transformed from the specified input stream.
|
||||
* @throws IOException if there was a problem doing the transform
|
||||
*/
|
||||
public static List<ModelProperty> marshallXmlToModelProperties( InputStream inputStream, String baseUri,
|
||||
Set<String> collections )
|
||||
throws IOException {
|
||||
if (inputStream == null) {
|
||||
throw new IllegalArgumentException("inputStream: null");
|
||||
}
|
||||
|
||||
if (baseUri == null || baseUri.trim().length() == 0) {
|
||||
throw new IllegalArgumentException("baseUri: null");
|
||||
}
|
||||
|
||||
if (collections == null) {
|
||||
collections = Collections.emptySet();
|
||||
}
|
||||
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
XMLInputFactory xmlInputFactory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
xmlInputFactory.setProperty(
|
||||
XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
|
||||
xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,
|
||||
Boolean.FALSE);
|
||||
|
||||
Uri uri = new Uri(baseUri);
|
||||
String tagName = baseUri;
|
||||
StringBuilder tagValue = new StringBuilder(256);
|
||||
|
||||
int depth = 0;
|
||||
int depthOfTagValue = depth;
|
||||
XMLStreamReader xmlStreamReader = null;
|
||||
try {
|
||||
xmlStreamReader = xmlInputFactory
|
||||
.createXMLStreamReader(inputStream);
|
||||
|
||||
Map<String, String> attributes = new HashMap<String, String>();
|
||||
for (;; xmlStreamReader.next()) {
|
||||
int type = xmlStreamReader.getEventType();
|
||||
switch (type) {
|
||||
|
||||
case XMLStreamConstants.CDATA:
|
||||
case XMLStreamConstants.CHARACTERS: {
|
||||
if (depth == depthOfTagValue) {
|
||||
tagValue.append(xmlStreamReader.getTextCharacters(),
|
||||
xmlStreamReader.getTextStart(), xmlStreamReader
|
||||
.getTextLength());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case XMLStreamConstants.START_ELEMENT: {
|
||||
if (!tagName.equals(baseUri)) {
|
||||
String value = null;
|
||||
if (depth < depthOfTagValue) {
|
||||
value = tagValue.toString().trim();
|
||||
}
|
||||
modelProperties.add(new ModelProperty(tagName, value));
|
||||
if (!attributes.isEmpty()) {
|
||||
for (Map.Entry<String, String> e : attributes
|
||||
.entrySet()) {
|
||||
modelProperties.add(new ModelProperty(e
|
||||
.getKey(), e.getValue()));
|
||||
}
|
||||
attributes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
depth++;
|
||||
tagName = uri.getUriFor(xmlStreamReader.getName()
|
||||
.getLocalPart(), depth);
|
||||
if (collections.contains(tagName + "#collection")) {
|
||||
tagName = tagName + "#collection";
|
||||
uri.addTag(xmlStreamReader.getName().getLocalPart()
|
||||
+ "#collection");
|
||||
} else if (collections.contains(tagName + "#set")) {
|
||||
tagName = tagName + "#set";
|
||||
uri.addTag(xmlStreamReader.getName().getLocalPart()
|
||||
+ "#set");
|
||||
} else {
|
||||
uri.addTag(xmlStreamReader.getName().getLocalPart());
|
||||
}
|
||||
tagValue.setLength(0);
|
||||
depthOfTagValue = depth;
|
||||
}
|
||||
case XMLStreamConstants.ATTRIBUTE: {
|
||||
for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++) {
|
||||
|
||||
attributes.put(tagName
|
||||
+ "#property/"
|
||||
+ xmlStreamReader.getAttributeName(i)
|
||||
.getLocalPart(), xmlStreamReader
|
||||
.getAttributeValue(i));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XMLStreamConstants.END_ELEMENT: {
|
||||
depth--;
|
||||
break;
|
||||
}
|
||||
case XMLStreamConstants.END_DOCUMENT: {
|
||||
modelProperties.add(new ModelProperty(tagName, tagValue
|
||||
.toString().trim()));
|
||||
if (!attributes.isEmpty()) {
|
||||
for (Map.Entry<String, String> e : attributes
|
||||
.entrySet()) {
|
||||
modelProperties.add(new ModelProperty(e.getKey(), e
|
||||
.getValue()));
|
||||
}
|
||||
attributes.clear();
|
||||
}
|
||||
return modelProperties;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (XMLStreamException e) {
|
||||
throw new IOException(":" + e.toString());
|
||||
} finally {
|
||||
if (xmlStreamReader != null) {
|
||||
try {
|
||||
xmlStreamReader.close();
|
||||
} catch (XMLStreamException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Class for storing information about URIs.
|
||||
*/
|
||||
private static class Uri
|
||||
{
|
||||
|
||||
List<String> uris;
|
||||
|
||||
Uri( String baseUri )
|
||||
{
|
||||
uris = new LinkedList<String>();
|
||||
uris.add( baseUri );
|
||||
}
|
||||
|
||||
String getUriFor( String tag, int depth )
|
||||
{
|
||||
setUrisToDepth( depth );
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for ( String tagName : uris )
|
||||
{
|
||||
sb.append( tagName ).append( "/" );
|
||||
}
|
||||
sb.append( tag );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
void addTag( String tag )
|
||||
{
|
||||
uris.add( tag );
|
||||
}
|
||||
|
||||
void setUrisToDepth( int depth )
|
||||
{
|
||||
uris = new LinkedList<String>( uris.subList( 0, depth ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -32,6 +32,7 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -47,13 +48,12 @@ import org.apache.maven.model.Resource;
|
|||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||
import org.apache.maven.project.builder.PomInterpolatorTag;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.shared.model.DomainModel;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.project.builder.interpolator.DomainModel;
|
||||
import org.apache.maven.project.builder.interpolator.InterpolatorProperty;
|
||||
import org.apache.maven.project.builder.interpolator.ModelProperty;
|
||||
import org.apache.maven.project.builder.interpolator.PomInterpolatorTag;
|
||||
import org.apache.maven.shared.model.ModelEventListener;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.ModelTransformerContext;
|
||||
import org.codehaus.plexus.util.WriterFactory;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
@ -136,7 +136,7 @@ public class ProcessorContext
|
|||
//TODO: Merge Dependency Management
|
||||
target.setDependencyManagement( depMng );
|
||||
|
||||
PomClassicDomainModel targetModel = convertToDomainModel( target, domainModel.isMostSpecialized());
|
||||
PomClassicDomainModel targetModel = new PomClassicDomainModel( target, domainModel.isMostSpecialized());
|
||||
targetModel.setParentFile(domainModel.getParentFile());
|
||||
targetModel.setProjectDirectory(domainModel.getProjectDirectory());
|
||||
return targetModel;
|
||||
|
@ -179,18 +179,9 @@ public class ProcessorContext
|
|||
}
|
||||
|
||||
}
|
||||
else {
|
||||
InputStream is = ( (PomClassicDomainModel) domainModel ).getInputStream();
|
||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
try
|
||||
{
|
||||
models.add( reader.read( is ) );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException( "model: null" );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -225,7 +216,7 @@ public class ProcessorContext
|
|||
new ContributorsProcessor(), new DevelopersProcessor(), new ProfilesProcessor() );
|
||||
Model target = processModelsForInheritance( convertDomainModelsToMavenModels( domainModels ), processors );
|
||||
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( convertToDomainModel( target, child.isMostSpecialized() ).getModelProperties(), child.isMostSpecialized() );
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( target, child.isMostSpecialized() );
|
||||
domainModel.setProjectDirectory(child.getProjectDirectory());
|
||||
domainModel.setParentFile(child.getParentFile());
|
||||
return domainModel;
|
||||
|
@ -298,32 +289,6 @@ public class ProcessorContext
|
|||
|
||||
}
|
||||
|
||||
private static PomClassicDomainModel convertToDomainModel( Model model, boolean isMostSpecialized )
|
||||
throws IOException
|
||||
{
|
||||
if ( model == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "model: null" );
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Writer out = null;
|
||||
MavenXpp3Writer writer = new MavenXpp3Writer();
|
||||
try
|
||||
{
|
||||
out = WriterFactory.newXmlWriter( baos );
|
||||
writer.write( out, model );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( out != null )
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
return new PomClassicDomainModel( new ByteArrayInputStream( baos.toByteArray() ), isMostSpecialized );
|
||||
}
|
||||
|
||||
private static final Map<String, String> aliases = new HashMap<String, String>();
|
||||
|
||||
private static void addProjectAlias( String element, boolean leaf )
|
||||
|
@ -355,156 +320,6 @@ public class ProcessorContext
|
|||
addProjectAlias( "ciManagement", false );
|
||||
}
|
||||
|
||||
public static void interpolateModelProperties( List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties, PomClassicDomainModel dm )
|
||||
throws IOException
|
||||
{
|
||||
|
||||
if(dm == null)
|
||||
{
|
||||
throw new IllegalArgumentException("dm: null");
|
||||
}
|
||||
if ( !containsProjectVersion( interpolatorProperties ) )
|
||||
{
|
||||
aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" );
|
||||
}
|
||||
|
||||
if("jar".equals( dm.getModel().getPackaging() ) )
|
||||
{
|
||||
modelProperties.add( new ModelProperty(ProjectUri.packaging, "jar") );
|
||||
}
|
||||
|
||||
List<ModelProperty> firstPassModelProperties = new ArrayList<ModelProperty>();
|
||||
List<ModelProperty> secondPassModelProperties = new ArrayList<ModelProperty>();
|
||||
|
||||
ModelProperty buildProperty = new ModelProperty( ProjectUri.Build.xUri, null );
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
if ( mp.getValue() != null && !mp.getUri().contains( "#property" ) && !mp.getUri().contains( "#collection" ) )
|
||||
{
|
||||
if ( ( !buildProperty.isParentOf( mp ) && !mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) || mp.getUri().equals(
|
||||
ProjectUri.Build.finalName ) ) )
|
||||
{
|
||||
firstPassModelProperties.add( mp );
|
||||
}
|
||||
else
|
||||
{
|
||||
secondPassModelProperties.add( mp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> standardInterpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
if ( dm.isPomInBuild() )
|
||||
{
|
||||
String basedir = dm.getProjectDirectory().getAbsolutePath();
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${project.basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
|
||||
String baseuri = dm.getProjectDirectory().toURI().toString();
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${project.baseUri}", baseuri,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.baseUri}", baseuri,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
}
|
||||
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null )
|
||||
{
|
||||
String uri = mp.getUri();
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty(
|
||||
"${"
|
||||
+ uri.substring(
|
||||
uri.lastIndexOf( "/" ) + 1,
|
||||
uri.length() ) + "}",
|
||||
mp.getValue(),
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
}
|
||||
}
|
||||
|
||||
// FIRST PASS - Withhold using build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips1 = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
ips1.addAll( standardInterpolatorProperties );
|
||||
ips1.addAll( ModelTransformerContext.createInterpolatorProperties(
|
||||
firstPassModelProperties,
|
||||
ProjectUri.baseUri,
|
||||
aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name(),
|
||||
false, false ) );
|
||||
Collections.sort( ips1, new Comparator<InterpolatorProperty>()
|
||||
{
|
||||
public int compare( InterpolatorProperty o, InterpolatorProperty o1 )
|
||||
{
|
||||
if ( o.getTag() == null || o1.getTag() == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) );
|
||||
}
|
||||
} );
|
||||
|
||||
ModelTransformerContext.interpolateModelProperties( modelProperties, ips1 );
|
||||
|
||||
// SECOND PASS - Set absolute paths on build directories
|
||||
|
||||
if ( dm.isPomInBuild() )
|
||||
{
|
||||
String basedir = dm.getProjectDirectory().getAbsolutePath();
|
||||
Map<ModelProperty, ModelProperty> buildDirectories = new HashMap<ModelProperty, ModelProperty>();
|
||||
for ( ModelProperty mp : secondPassModelProperties )
|
||||
{
|
||||
if ( mp.getUri().startsWith( ProjectUri.Build.xUri )
|
||||
|| mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) )
|
||||
{
|
||||
File file = new File( mp.getResolvedValue() );
|
||||
if ( !file.isAbsolute() && !mp.getResolvedValue().startsWith( "${project.build." )
|
||||
&& !mp.getResolvedValue().equals( "${project.basedir}" ) )
|
||||
{
|
||||
buildDirectories.put( mp,
|
||||
new ModelProperty( mp.getUri(),
|
||||
new File( basedir, file.getPath() ).getAbsolutePath() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( Map.Entry<ModelProperty, ModelProperty> e : buildDirectories.entrySet() )
|
||||
{
|
||||
secondPassModelProperties.remove( e.getKey() );
|
||||
secondPassModelProperties.add( e.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
// THIRD PASS - Use build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips2 = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
ips2.addAll( standardInterpolatorProperties );
|
||||
ips2.addAll( ModelTransformerContext.createInterpolatorProperties(
|
||||
secondPassModelProperties,
|
||||
ProjectUri.baseUri,
|
||||
aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name(),
|
||||
false, false ) );
|
||||
ips2.addAll( interpolatorProperties );
|
||||
Collections.sort( ips2, new Comparator<InterpolatorProperty>()
|
||||
{
|
||||
public int compare( InterpolatorProperty o, InterpolatorProperty o1 )
|
||||
{
|
||||
if ( o.getTag() == null || o1.getTag() == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) );
|
||||
}
|
||||
} );
|
||||
|
||||
ModelTransformerContext.interpolateModelProperties( modelProperties, ips2 );
|
||||
}
|
||||
|
||||
private static boolean containsProjectVersion( List<InterpolatorProperty> interpolatorProperties )
|
||||
{
|
||||
InterpolatorProperty versionInterpolatorProperty =
|
||||
|
@ -636,4 +451,408 @@ public class ProcessorContext
|
|||
return p;
|
||||
|
||||
}
|
||||
|
||||
public static PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, List<InterpolatorProperty> interpolatorProperties )
|
||||
throws IOException {
|
||||
|
||||
if (dm == null) {
|
||||
throw new IllegalArgumentException("dm: null");
|
||||
}
|
||||
if (!containsProjectVersion(interpolatorProperties)) {
|
||||
aliases.put("\\$\\{project.version\\}", "\\$\\{version\\}");
|
||||
}
|
||||
//TODO: Insert customized logic for parsing
|
||||
List<ModelProperty> modelProperties = dm.getModelProperties();
|
||||
|
||||
if ("jar".equals(dm.getModel().getPackaging())) {
|
||||
modelProperties.add(new ModelProperty(ProjectUri.packaging, "jar"));
|
||||
}
|
||||
|
||||
List<ModelProperty> firstPassModelProperties = new ArrayList<ModelProperty>();
|
||||
List<ModelProperty> secondPassModelProperties = new ArrayList<ModelProperty>();
|
||||
|
||||
ModelProperty buildProperty = new ModelProperty(ProjectUri.Build.xUri,
|
||||
null);
|
||||
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
if ( mp.getValue() != null && !mp.getUri().contains( "#property" ) && !mp.getUri().contains( "#collection" ) )
|
||||
{
|
||||
if ( ( !buildProperty.isParentOf( mp ) && !mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) || mp.getUri().equals(
|
||||
ProjectUri.Build.finalName ) ) )
|
||||
{
|
||||
firstPassModelProperties.add( mp );
|
||||
}
|
||||
else
|
||||
{
|
||||
secondPassModelProperties.add( mp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if ( !buildProperty.isParentOf(mp) && mp.getValue() != null && !mp.getUri().contains("#property")
|
||||
&& !mp.getUri().contains("#collection")) {
|
||||
if ((!mp.getUri().equals(
|
||||
ProjectUri.Reporting.outputDirectory) || mp
|
||||
.getUri().equals(ProjectUri.Build.finalName))) {
|
||||
firstPassModelProperties.add(mp);
|
||||
} else {
|
||||
secondPassModelProperties.add(mp);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
List<InterpolatorProperty> standardInterpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
if (dm.isPomInBuild()) {
|
||||
String basedir = dm.getProjectDirectory().getAbsolutePath();
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty(
|
||||
"${project.basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty(
|
||||
"${basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty(
|
||||
"${pom.basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
|
||||
String baseuri = dm.getProjectDirectory().toURI().toString();
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty(
|
||||
"${project.baseUri}", baseuri,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty(
|
||||
"${pom.baseUri}", baseuri,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
}
|
||||
|
||||
for (ModelProperty mp : modelProperties) {
|
||||
if (mp.getUri().startsWith(ProjectUri.properties)
|
||||
&& mp.getValue() != null) {
|
||||
String uri = mp.getUri();
|
||||
standardInterpolatorProperties.add(new InterpolatorProperty(
|
||||
"${"
|
||||
+ uri.substring(uri.lastIndexOf("/") + 1, uri
|
||||
.length()) + "}", mp.getValue(),
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
}
|
||||
}
|
||||
|
||||
// FIRST PASS - Withhold using build directories as interpolator
|
||||
// properties
|
||||
List<InterpolatorProperty> ips1 = new ArrayList<InterpolatorProperty>(
|
||||
interpolatorProperties);
|
||||
ips1.addAll(standardInterpolatorProperties);
|
||||
ips1.addAll(createInterpolatorProperties(
|
||||
firstPassModelProperties, ProjectUri.baseUri, aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
Collections.sort(ips1, new Comparator<InterpolatorProperty>() {
|
||||
public int compare(InterpolatorProperty o, InterpolatorProperty o1) {
|
||||
if (o.getTag() == null || o1.getTag() == null) {
|
||||
return 0;
|
||||
}
|
||||
return PomInterpolatorTag.valueOf(o.getTag()).compareTo(
|
||||
PomInterpolatorTag.valueOf(o1.getTag()));
|
||||
}
|
||||
});
|
||||
|
||||
interpolateModelProperties(modelProperties, ips1);
|
||||
|
||||
// SECOND PASS - Set absolute paths on build directories
|
||||
if (dm.isPomInBuild()) {
|
||||
String basedir = dm.getProjectDirectory().getAbsolutePath();
|
||||
Map<ModelProperty, ModelProperty> buildDirectories = new HashMap<ModelProperty, ModelProperty>();
|
||||
for (ModelProperty mp : secondPassModelProperties) {
|
||||
if (mp.getUri().startsWith(ProjectUri.Build.xUri)
|
||||
|| mp.getUri().equals(
|
||||
ProjectUri.Reporting.outputDirectory)) {
|
||||
File file = new File(mp.getResolvedValue());
|
||||
if (!file.isAbsolute()
|
||||
&& !mp.getResolvedValue().startsWith(
|
||||
"${project.build.")
|
||||
&& !mp.getResolvedValue().equals(
|
||||
"${project.basedir}")) {
|
||||
buildDirectories.put(mp, new ModelProperty(mp.getUri(),
|
||||
new File(basedir, file.getPath())
|
||||
.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<ModelProperty, ModelProperty> e : buildDirectories
|
||||
.entrySet()) {
|
||||
secondPassModelProperties.remove(e.getKey());
|
||||
secondPassModelProperties.add(e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// THIRD PASS - Use build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips2 = new ArrayList<InterpolatorProperty>(
|
||||
interpolatorProperties);
|
||||
ips2.addAll(standardInterpolatorProperties);
|
||||
ips2.addAll(createInterpolatorProperties(
|
||||
secondPassModelProperties, ProjectUri.baseUri, aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
ips2.addAll(interpolatorProperties);
|
||||
Collections.sort(ips2, new Comparator<InterpolatorProperty>() {
|
||||
public int compare(InterpolatorProperty o, InterpolatorProperty o1) {
|
||||
if (o.getTag() == null || o1.getTag() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return PomInterpolatorTag.valueOf(o.getTag()).compareTo(
|
||||
PomInterpolatorTag.valueOf(o1.getTag()));
|
||||
}
|
||||
});
|
||||
|
||||
interpolateModelProperties(modelProperties, ips2);
|
||||
|
||||
|
||||
|
||||
if ( dm.getProjectDirectory() != null )
|
||||
{
|
||||
modelProperties = ProcessorContext.alignPaths( modelProperties, dm.getProjectDirectory() );
|
||||
}
|
||||
try
|
||||
{
|
||||
String xml = unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
|
||||
return new PomClassicDomainModel( new ByteArrayInputStream ( xml.getBytes( "UTF-8" )));
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new IllegalStateException( "Unmarshalling of model properties failed", e );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
if((mp.getValue() != null) && !mp.getValue().equals(mp.getResolvedValue()))
|
||||
{
|
||||
if(mp.getUri().equals(ProjectUri.version))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public static void interpolateModelProperties(List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties )
|
||||
{
|
||||
if (modelProperties == null) {
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
|
||||
if (interpolatorProperties == null) {
|
||||
throw new IllegalArgumentException("interpolatorProperties: null");
|
||||
}
|
||||
|
||||
List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
|
||||
for (ModelProperty mp : modelProperties) {
|
||||
if (!mp.isResolved()) {
|
||||
unresolvedProperties.add(mp);
|
||||
}
|
||||
}
|
||||
|
||||
LinkedHashSet<InterpolatorProperty> ips = new LinkedHashSet<InterpolatorProperty>();
|
||||
ips.addAll(interpolatorProperties);
|
||||
boolean continueInterpolation = true;
|
||||
while (continueInterpolation) {
|
||||
continueInterpolation = false;
|
||||
for (InterpolatorProperty ip : ips) {
|
||||
for (ModelProperty mp : unresolvedProperties) {
|
||||
if (mp.resolveWith(ip) && !continueInterpolation) {
|
||||
continueInterpolation = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<InterpolatorProperty> createInterpolatorProperties(List<ModelProperty> modelProperties,
|
||||
String baseUriForModel,
|
||||
Map<String, String> aliases,
|
||||
String interpolatorTag)
|
||||
{
|
||||
if (modelProperties == null) {
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
|
||||
if (baseUriForModel == null) {
|
||||
throw new IllegalArgumentException("baseUriForModel: null");
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
for (ModelProperty mp : modelProperties) {
|
||||
InterpolatorProperty ip = mp
|
||||
.asInterpolatorProperty(baseUriForModel);
|
||||
if (ip != null) {
|
||||
ip.setTag(interpolatorTag);
|
||||
interpolatorProperties.add(ip);
|
||||
for (Map.Entry<String, String> a : aliases.entrySet()) {
|
||||
interpolatorProperties.add(new InterpolatorProperty(ip
|
||||
.getKey().replaceAll(a.getKey(), a.getValue()), ip
|
||||
.getValue().replaceAll(a.getKey(), a.getValue()),
|
||||
interpolatorTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>();
|
||||
for (InterpolatorProperty ip : interpolatorProperties) {
|
||||
if (!ips.contains(ip)) {
|
||||
ips.add(ip);
|
||||
}
|
||||
}
|
||||
return ips;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XML string unmarshalled from the specified list of model properties
|
||||
*
|
||||
* @param modelProperties the model properties to unmarshal. May not be null or empty
|
||||
* @param baseUri the base uri of every model property. May not be null or empty.
|
||||
* @return XML string unmarshalled from the specified list of model properties
|
||||
* @throws IOException if there was a problem with unmarshalling
|
||||
*/
|
||||
public static String unmarshalModelPropertiesToXml( List<ModelProperty> modelProperties, String baseUri )
|
||||
throws IOException
|
||||
{
|
||||
if ( modelProperties == null || modelProperties.isEmpty() )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelProperties: null or empty" );
|
||||
}
|
||||
|
||||
if ( baseUri == null || baseUri.trim().length() == 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "baseUri: null or empty" );
|
||||
}
|
||||
|
||||
final int basePosition = baseUri.length();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
List<String> lastUriTags = new ArrayList<String>();
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
String uri = mp.getUri();
|
||||
if ( uri.contains( "#property" ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//String val = (mp.getResolvedValue() != null) ? "\"" + mp.getResolvedValue() + "\"" : null;
|
||||
// System.out.println("new ModelProperty(\"" + mp.getUri() +"\" , " + val +"),");
|
||||
if ( !uri.startsWith( baseUri ) )
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"Passed in model property that does not match baseUri: Property URI = " + uri + ", Base URI = " +
|
||||
baseUri );
|
||||
}
|
||||
|
||||
List<String> tagNames = getTagNamesFromUri( basePosition, uri );
|
||||
|
||||
for ( int i = lastUriTags.size() - 1; i >= 0 && i >= tagNames.size() - 1; i-- )
|
||||
{
|
||||
sb.append( toEndTag( lastUriTags.get( i ) ) );
|
||||
}
|
||||
|
||||
String tag = tagNames.get( tagNames.size() - 1 );
|
||||
|
||||
List<ModelProperty> attributes = new ArrayList<ModelProperty>();
|
||||
for(int peekIndex = modelProperties.indexOf( mp ) + 1; peekIndex < modelProperties.size(); peekIndex++)
|
||||
{
|
||||
if ( peekIndex <= modelProperties.size() - 1 )
|
||||
{
|
||||
ModelProperty peekProperty = modelProperties.get( peekIndex );
|
||||
if ( peekProperty.getUri().contains( "#property" ) )
|
||||
{
|
||||
attributes.add(peekProperty);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( toStartTag( tag, attributes ) );
|
||||
|
||||
if ( mp.getResolvedValue() != null )
|
||||
{
|
||||
sb.append( mp.getResolvedValue() );
|
||||
}
|
||||
|
||||
lastUriTags = tagNames;
|
||||
}
|
||||
|
||||
for ( int i = lastUriTags.size() - 1; i >= 1; i-- )
|
||||
{
|
||||
sb.append( toEndTag( lastUriTags.get( i ) ) );
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of tag names parsed from the specified uri. All #collection parts of the tag are removed from the
|
||||
* tag names.
|
||||
*
|
||||
* @param basePosition the base position in the specified URI to start the parse
|
||||
* @param uri the uri to parse for tag names
|
||||
* @return list of tag names parsed from the specified uri
|
||||
*/
|
||||
private static List<String> getTagNamesFromUri( int basePosition, String uri )
|
||||
{
|
||||
return Arrays.asList( uri.substring( basePosition ).replaceAll( "#collection", "" )
|
||||
.replaceAll("#set", "").split( "/" ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XML formatted start tag for the specified value and the specified attribute.
|
||||
*
|
||||
* @param value the value to use for the start tag
|
||||
* @param attributes the attribute to use in constructing of start tag
|
||||
* @return the XML formatted start tag for the specified value and the specified attribute
|
||||
*/
|
||||
private static String toStartTag( String value, List<ModelProperty> attributes )
|
||||
{
|
||||
StringBuffer sb = new StringBuffer(); //TODO: Support more than one attribute
|
||||
sb.append( "\r\n<" ).append( value );
|
||||
if ( attributes != null )
|
||||
{
|
||||
for(ModelProperty attribute : attributes)
|
||||
{
|
||||
sb.append( " " ).append(
|
||||
attribute.getUri().substring( attribute.getUri().indexOf( "#property/" ) + 10 ) ).append( "=\"" )
|
||||
.append( attribute.getResolvedValue() ).append( "\" " );
|
||||
}
|
||||
}
|
||||
sb.append( ">" );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XML formatted end tag for the specified value.
|
||||
*
|
||||
* @param value the value to use for the end tag
|
||||
* @return xml formatted end tag for the specified value
|
||||
*/
|
||||
private static String toEndTag( String value )
|
||||
{
|
||||
if ( value.trim().length() == 0 )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append( "</" ).append( value ).append( ">" );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
import java.util.Properties;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.processor;
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -0,0 +1,13 @@
|
|||
package org.apache.maven.project.builder.interpolator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface DomainModel {
|
||||
|
||||
List<ModelProperty> getModelProperties() throws IOException;
|
||||
|
||||
boolean isMostSpecialized();
|
||||
|
||||
void setMostSpecialized(boolean isMostSpecialized);
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
package org.apache.maven.project.builder.interpolator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides interpolator property information.
|
||||
*/
|
||||
public final class InterpolatorProperty
|
||||
{
|
||||
/**
|
||||
* The key (or name) of the property
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* The value of the property
|
||||
*/
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* Metadata tag (general use)
|
||||
*/
|
||||
private String tag;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param key the key (or name) of the property. May not be null
|
||||
* @param value the value of the property. May not be null.
|
||||
*/
|
||||
public InterpolatorProperty( String key, String value )
|
||||
{
|
||||
this(key, value, null);
|
||||
}
|
||||
|
||||
public InterpolatorProperty( String key, String value, String tag )
|
||||
{
|
||||
if ( key == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "key: null" );
|
||||
}
|
||||
|
||||
if ( value == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "value: null" );
|
||||
}
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.tag = tag;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns key (or name) of property.
|
||||
*
|
||||
* @return key (or name) of property
|
||||
*/
|
||||
public String getKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of property.
|
||||
*
|
||||
* @return value of property
|
||||
*/
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getTag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag)
|
||||
{
|
||||
this.tag = tag;
|
||||
}
|
||||
public static List<InterpolatorProperty> toInterpolatorProperties( Map<String, String> properties, String tag )
|
||||
{
|
||||
if( properties == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "properties: null" );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
for ( Map.Entry<String, String> e : properties.entrySet() )
|
||||
{
|
||||
interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", e.getValue(), tag) );
|
||||
}
|
||||
return interpolatorProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if key values match, otherwise returns false.
|
||||
*
|
||||
* @param o interpolator property to compare
|
||||
* @return true if key values match, otherwise returns false
|
||||
*/
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
InterpolatorProperty that = (InterpolatorProperty) o;
|
||||
|
||||
if ( !key.equals( that.key ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns hash code of interpolator property key.
|
||||
*
|
||||
* @return hash code of interpolator property key
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return key.hashCode();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Key = " + key + ", Value = " + value + ", Hash = " +
|
||||
this.hashCode();
|
||||
}
|
||||
|
||||
public static List<InterpolatorProperty> toInterpolatorProperties( Properties properties, String tag )
|
||||
{
|
||||
if( properties == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "properties: null" );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
for ( Map.Entry<Object, Object> e : properties.entrySet() )
|
||||
{
|
||||
interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", (String) e.getValue(), tag) );
|
||||
}
|
||||
return interpolatorProperties;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,343 @@
|
|||
package org.apache.maven.project.builder.interpolator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
|
||||
public class ModelInterpolator {
|
||||
|
||||
private HashMap<String, String> values;
|
||||
|
||||
public ModelInterpolator()
|
||||
{
|
||||
values = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public static void interpolate(PomClassicDomainModel domainModel, List<InterpolatorProperty> interpolatorProperties ) throws IOException
|
||||
{
|
||||
List<ModelProperty> m = new ArrayList<ModelProperty>();
|
||||
|
||||
Model model = domainModel.getModel();
|
||||
|
||||
m.add(new ModelProperty(ProjectUri.groupId, model.getGroupId()));
|
||||
m.add(new ModelProperty(ProjectUri.artifactId, model.getArtifactId()));
|
||||
|
||||
interpolateModelProperties(m, interpolatorProperties, domainModel);
|
||||
//Set model properties on model
|
||||
|
||||
|
||||
|
||||
//InterpolatorProperty ip = new InterpolatorProperty();
|
||||
//ModelProperty mp;
|
||||
/*
|
||||
values.put("groupId", model.getGroupId());
|
||||
values.put("artifactId", model.getArtifactId());
|
||||
values.put("version", model.getVersion());
|
||||
values.put("packaging", model.getPackaging());
|
||||
values.put("name", model.getName());
|
||||
values.put("description", model.getDescription());
|
||||
|
||||
//Collect uninterpolated values
|
||||
HashMap<String, String> hm = new HashMap<String, String>();
|
||||
for(Map.Entry<String, String> entry : hm.entrySet())
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* addProjectAlias( "modelVersion", true );
|
||||
addProjectAlias( "groupId", true );
|
||||
addProjectAlias( "artifactId", true );
|
||||
addProjectAlias( "version", true );
|
||||
addProjectAlias( "packaging", true );
|
||||
addProjectAlias( "name", true );
|
||||
addProjectAlias( "description", true );
|
||||
addProjectAlias( "inceptionYear", true );
|
||||
addProjectAlias( "url", true );
|
||||
addProjectAlias( "parent", false );
|
||||
addProjectAlias( "prerequisites", false );
|
||||
addProjectAlias( "organization", false );
|
||||
addProjectAlias( "build", false );
|
||||
addProjectAlias( "reporting", false );
|
||||
addProjectAlias( "scm", false );
|
||||
addProjectAlias( "distributionManagement", false );
|
||||
addProjectAlias( "issueManagement", false );
|
||||
addProjectAlias( "ciManagement", false );
|
||||
*/
|
||||
|
||||
private static final Map<String, String> aliases = new HashMap<String, String>();
|
||||
|
||||
private static void addProjectAlias( String element, boolean leaf )
|
||||
{
|
||||
String suffix = leaf ? "\\}" : "\\.";
|
||||
aliases.put( "\\$\\{project\\." + element + suffix, "\\$\\{" + element + suffix );
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
aliases.put( "\\$\\{project\\.", "\\$\\{pom\\." );
|
||||
addProjectAlias( "modelVersion", true );
|
||||
addProjectAlias( "groupId", true );
|
||||
addProjectAlias( "artifactId", true );
|
||||
addProjectAlias( "version", true );
|
||||
addProjectAlias( "packaging", true );
|
||||
addProjectAlias( "name", true );
|
||||
addProjectAlias( "description", true );
|
||||
addProjectAlias( "inceptionYear", true );
|
||||
addProjectAlias( "url", true );
|
||||
addProjectAlias( "parent", false );
|
||||
addProjectAlias( "prerequisites", false );
|
||||
addProjectAlias( "organization", false );
|
||||
addProjectAlias( "build", false );
|
||||
addProjectAlias( "reporting", false );
|
||||
addProjectAlias( "scm", false );
|
||||
addProjectAlias( "distributionManagement", false );
|
||||
addProjectAlias( "issueManagement", false );
|
||||
addProjectAlias( "ciManagement", false );
|
||||
}
|
||||
|
||||
private static void interpolateModelProperties( List<ModelProperty> mps,
|
||||
List<InterpolatorProperty> interpolatorProperties,
|
||||
PomClassicDomainModel dm )
|
||||
throws IOException
|
||||
{
|
||||
|
||||
if(dm == null)
|
||||
{
|
||||
throw new IllegalArgumentException("dm: null");
|
||||
}
|
||||
if ( !containsProjectVersion( interpolatorProperties ) )
|
||||
{
|
||||
aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" );
|
||||
}
|
||||
|
||||
if("jar".equals( dm.getModel().getPackaging() ) )
|
||||
{
|
||||
mps.add( new ModelProperty(ProjectUri.packaging, "jar") );
|
||||
}
|
||||
|
||||
List<ModelProperty> firstPassModelProperties = new ArrayList<ModelProperty>();
|
||||
List<ModelProperty> secondPassModelProperties = new ArrayList<ModelProperty>();
|
||||
|
||||
ModelProperty buildProperty = new ModelProperty( ProjectUri.Build.xUri, null );
|
||||
for ( ModelProperty mp : mps )
|
||||
{
|
||||
if ( mp.getValue() != null )
|
||||
{
|
||||
//!buildProperty.isParentOf( mp ) &&
|
||||
if ( ( !mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) || mp.getUri().equals(
|
||||
ProjectUri.Build.finalName ) ) )
|
||||
{
|
||||
firstPassModelProperties.add( mp );
|
||||
}
|
||||
else
|
||||
{
|
||||
secondPassModelProperties.add( mp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> standardInterpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
if ( dm.isPomInBuild() )
|
||||
{
|
||||
String basedir = dm.getProjectDirectory().getAbsolutePath();
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${project.basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.basedir}", basedir,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
|
||||
String baseuri = dm.getProjectDirectory().toURI().toString();
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${project.baseUri}", baseuri,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.baseUri}", baseuri,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
}
|
||||
|
||||
for ( ModelProperty mp : mps )
|
||||
{
|
||||
if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null )
|
||||
{
|
||||
String uri = mp.getUri();
|
||||
standardInterpolatorProperties.add( new InterpolatorProperty(
|
||||
"${"
|
||||
+ uri.substring(
|
||||
uri.lastIndexOf( "/" ) + 1,
|
||||
uri.length() ) + "}",
|
||||
mp.getValue(),
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name() ) );
|
||||
}
|
||||
}
|
||||
|
||||
// FIRST PASS - Withhold using build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips1 = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
ips1.addAll( standardInterpolatorProperties );
|
||||
ips1.addAll(createInterpolatorProperties(firstPassModelProperties,
|
||||
ProjectUri.baseUri, aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
Collections.sort( ips1, new Comparator<InterpolatorProperty>()
|
||||
{
|
||||
public int compare( InterpolatorProperty o, InterpolatorProperty o1 )
|
||||
{
|
||||
if ( o.getTag() == null || o1.getTag() == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) );
|
||||
}
|
||||
} );
|
||||
|
||||
interpolateModelProperties( mps, ips1 );
|
||||
|
||||
// SECOND PASS - Set absolute paths on build directories
|
||||
|
||||
if ( dm.isPomInBuild() )
|
||||
{
|
||||
String basedir = dm.getProjectDirectory().getAbsolutePath();
|
||||
Map<ModelProperty, ModelProperty> buildDirectories = new HashMap<ModelProperty, ModelProperty>();
|
||||
for ( ModelProperty mp : secondPassModelProperties )
|
||||
{
|
||||
if ( mp.getUri().startsWith( ProjectUri.Build.xUri )
|
||||
|| mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) )
|
||||
{
|
||||
File file = new File( mp.getResolvedValue() );
|
||||
if ( !file.isAbsolute() && !mp.getResolvedValue().startsWith( "${project.build." )
|
||||
&& !mp.getResolvedValue().equals( "${project.basedir}" ) )
|
||||
{
|
||||
buildDirectories.put( mp,
|
||||
new ModelProperty( mp.getUri(),
|
||||
new File( basedir, file.getPath() ).getAbsolutePath() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( Map.Entry<ModelProperty, ModelProperty> e : buildDirectories.entrySet() )
|
||||
{
|
||||
secondPassModelProperties.remove( e.getKey() );
|
||||
secondPassModelProperties.add( e.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
// THIRD PASS - Use build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips2 = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
ips2.addAll( standardInterpolatorProperties );
|
||||
ips2.addAll(createInterpolatorProperties(secondPassModelProperties,
|
||||
ProjectUri.baseUri, aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
|
||||
ips2.addAll( interpolatorProperties );
|
||||
Collections.sort( ips2, new Comparator<InterpolatorProperty>()
|
||||
{
|
||||
public int compare( InterpolatorProperty o, InterpolatorProperty o1 )
|
||||
{
|
||||
if ( o.getTag() == null || o1.getTag() == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) );
|
||||
}
|
||||
} );
|
||||
|
||||
interpolateModelProperties( mps, ips2 );
|
||||
}
|
||||
|
||||
private static void interpolateModelProperties(
|
||||
List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties) {
|
||||
if (modelProperties == null) {
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
|
||||
if (interpolatorProperties == null) {
|
||||
throw new IllegalArgumentException("interpolatorProperties: null");
|
||||
}
|
||||
|
||||
List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
|
||||
for (ModelProperty mp : modelProperties) {
|
||||
if (!mp.isResolved()) {
|
||||
unresolvedProperties.add(mp);
|
||||
}
|
||||
}
|
||||
|
||||
LinkedHashSet<InterpolatorProperty> ips = new LinkedHashSet<InterpolatorProperty>();
|
||||
ips.addAll(interpolatorProperties);
|
||||
boolean continueInterpolation = true;
|
||||
while (continueInterpolation) {
|
||||
continueInterpolation = false;
|
||||
for (InterpolatorProperty ip : ips) {
|
||||
for (ModelProperty mp : unresolvedProperties) {
|
||||
if (mp.resolveWith(ip) && !continueInterpolation) {
|
||||
continueInterpolation = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<InterpolatorProperty> createInterpolatorProperties(List<ModelProperty> modelProperties,
|
||||
String baseUriForModel,
|
||||
Map<String, String> aliases,
|
||||
String interpolatorTag)
|
||||
{
|
||||
if (modelProperties == null) {
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
|
||||
if (baseUriForModel == null) {
|
||||
throw new IllegalArgumentException("baseUriForModel: null");
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
for (ModelProperty mp : modelProperties) {
|
||||
InterpolatorProperty ip = mp
|
||||
.asInterpolatorProperty(baseUriForModel);
|
||||
if (ip != null) {
|
||||
ip.setTag(interpolatorTag);
|
||||
interpolatorProperties.add(ip);
|
||||
for (Map.Entry<String, String> a : aliases.entrySet()) {
|
||||
interpolatorProperties.add(new InterpolatorProperty(ip
|
||||
.getKey().replaceAll(a.getKey(), a.getValue()), ip
|
||||
.getValue().replaceAll(a.getKey(), a.getValue()),
|
||||
interpolatorTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>();
|
||||
for (InterpolatorProperty ip : interpolatorProperties) {
|
||||
if (!ips.contains(ip)) {
|
||||
ips.add(ip);
|
||||
}
|
||||
}
|
||||
return ips;
|
||||
}
|
||||
|
||||
private static boolean containsProjectVersion( List<InterpolatorProperty> interpolatorProperties )
|
||||
{
|
||||
InterpolatorProperty versionInterpolatorProperty =
|
||||
new ModelProperty( ProjectUri.version, "" ).asInterpolatorProperty( ProjectUri.baseUri );
|
||||
for ( InterpolatorProperty ip : interpolatorProperties )
|
||||
{
|
||||
if ( ip.equals( versionInterpolatorProperty ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,254 @@
|
|||
package org.apache.maven.project.builder.interpolator;
|
||||
|
||||
/*
|
||||
* 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.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Maps a URI to a string value, which may be null. This class is immutable.
|
||||
*/
|
||||
public final class ModelProperty
|
||||
{
|
||||
|
||||
/**
|
||||
* A pattern used for finding pom, project and env properties
|
||||
*/
|
||||
private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom\\.|project\\.|env\\.)?([^}]+)\\}" );
|
||||
|
||||
/**
|
||||
* URI of the resource
|
||||
*/
|
||||
private final String uri;
|
||||
|
||||
/**
|
||||
* Value associated with the uri
|
||||
*/
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* The count of '/' within this model property's uri, which is the depth of its XML nodes.
|
||||
*/
|
||||
private final int depth;
|
||||
|
||||
/**
|
||||
* Value of this model property after interpolation
|
||||
*/
|
||||
private String resolvedValue;
|
||||
|
||||
/**
|
||||
* List of unresolved expressions within this model property's value
|
||||
*/
|
||||
private final List<String> unresolvedExpressions;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param uri URI of the resource. May not be null
|
||||
* @param value Value associated with specified uri. Value may be null if uri does not map to primitive type.
|
||||
*/
|
||||
public ModelProperty( String uri, String value )
|
||||
{
|
||||
if ( uri == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "uri" );
|
||||
}
|
||||
this.uri = uri;
|
||||
this.value = value;
|
||||
resolvedValue = value;
|
||||
|
||||
unresolvedExpressions = new ArrayList<String>();
|
||||
if ( value != null )
|
||||
{
|
||||
Matcher matcher = EXPRESSION_PATTERN.matcher( value );
|
||||
while ( matcher.find() )
|
||||
{
|
||||
unresolvedExpressions.add( matcher.group( 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
String uriWithoutProperty;
|
||||
int index = uri.lastIndexOf( "/" );
|
||||
if(index > -1) {
|
||||
uriWithoutProperty = uri.substring( 0, uri.lastIndexOf( "/" ) );
|
||||
if(uriWithoutProperty.endsWith("#property") || uriWithoutProperty.endsWith("combine.children") )
|
||||
{
|
||||
uriWithoutProperty = uriWithoutProperty.substring( 0, uriWithoutProperty.lastIndexOf( "/" ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uriWithoutProperty = uri;
|
||||
}
|
||||
|
||||
depth = uriWithoutProperty.split( "/" ).length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns URI key
|
||||
*
|
||||
* @return URI key
|
||||
*/
|
||||
public String getUri()
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value for the URI key. Value may be null.
|
||||
*
|
||||
* @return value for the URI key. Value may be null
|
||||
*/
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of this model property after interpolation. CDATA section will be added if needed.
|
||||
*
|
||||
* @return value of this model property after interpolation
|
||||
*/
|
||||
public String getResolvedValue()
|
||||
{
|
||||
if( !uri.contains("#property") && resolvedValue != null && !resolvedValue.startsWith ("<![CDATA[")
|
||||
&& (resolvedValue.contains( "=" ) || resolvedValue.contains( "<" ) || resolvedValue.contains( "&" )))
|
||||
{
|
||||
resolvedValue = "<![CDATA[" + resolvedValue + "]]>";
|
||||
}
|
||||
return resolvedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if model property is completely interpolated, otherwise returns false.
|
||||
*
|
||||
* @return true if model property is completely interpolated, otherwise returns false
|
||||
*/
|
||||
public boolean isResolved()
|
||||
{
|
||||
return unresolvedExpressions.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns copy of the uninterpolated model property
|
||||
*
|
||||
* @return copy of the uninterpolated model property
|
||||
*/
|
||||
public ModelProperty createCopyOfOriginal()
|
||||
{
|
||||
return new ModelProperty( uri, value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count of '/' within this model property's uri, which is the depth of its XML nodes.
|
||||
*
|
||||
* @return the count of '/' within this model property's uri, which is the depth of its XML nodes
|
||||
*/
|
||||
public int getDepth()
|
||||
{
|
||||
return depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this model property is a direct parent of the specified model property, otherwise returns false.
|
||||
*
|
||||
* @param modelProperty the model property
|
||||
* @return true if this model property is a direct parent of the specified model property, otherwise returns false
|
||||
*/
|
||||
public boolean isParentOf( ModelProperty modelProperty )
|
||||
{
|
||||
if ( Math.abs( depth - modelProperty.getDepth() ) > 1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( uri.equals( modelProperty.getUri() ) || uri.startsWith( modelProperty.getUri() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ( modelProperty.getUri().startsWith( uri ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this model property as an interpolator property, allowing the interpolation of model elements within
|
||||
* other model elements.
|
||||
*
|
||||
* @param baseUri the base uri of the model property
|
||||
* @return this model property as an interpolator property, allowing the interpolation of model elements within
|
||||
* other model elements
|
||||
*/
|
||||
public InterpolatorProperty asInterpolatorProperty( String baseUri )
|
||||
{
|
||||
if ( uri.contains( "#collection" ) || uri.contains("#set") || value == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String key = "${" + uri.replace( baseUri + "/", "" ).replace( "/", "." ) + "}";
|
||||
return new InterpolatorProperty( key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves any unresolved model property expressions using the specified interpolator property
|
||||
*
|
||||
* @param property the interpolator property used to resolve
|
||||
*/
|
||||
public boolean resolveWith( InterpolatorProperty property )
|
||||
{
|
||||
if ( property == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "property: null" );
|
||||
}
|
||||
if ( isResolved() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
boolean resolved = false;
|
||||
for ( String expression : unresolvedExpressions )
|
||||
{
|
||||
if ( property.getKey().equals( expression ) )
|
||||
{
|
||||
resolved = true;
|
||||
resolvedValue = resolvedValue.replace( property.getKey(), property.getValue() );
|
||||
unresolvedExpressions.clear();
|
||||
Matcher matcher = EXPRESSION_PATTERN.matcher( resolvedValue );
|
||||
while ( matcher.find() )
|
||||
{
|
||||
unresolvedExpressions.add( matcher.group( 0 ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
public String toCode() {
|
||||
String val = (value != null) ? "\"" + value + "\"" : null;
|
||||
return "mpz.add(new ModelProperty(\"" + uri + "\", " + val +"));";
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Uri = " + uri + ", Value = " + value + ", Resolved Value = " + resolvedValue + ", Hash = " +
|
||||
this.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.builder;
|
||||
package org.apache.maven.project.builder.interpolator;
|
||||
|
||||
|
||||
public enum PomInterpolatorTag
|
|
@ -1,44 +0,0 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
import org.apache.maven.shared.model.DomainModel;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.InputStreamDomainModel;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class DefaultDomainModel extends PomClassicDomainModel {
|
||||
|
||||
private List<ModelProperty> modelProperties;
|
||||
|
||||
public DefaultDomainModel(List<ModelProperty> modelProperties, boolean isMostSpecialized) {
|
||||
super( modelProperties, isMostSpecialized);
|
||||
this.modelProperties = modelProperties;
|
||||
}
|
||||
|
||||
public List<ModelProperty> getModelProperties() throws IOException {
|
||||
return modelProperties;
|
||||
}
|
||||
|
||||
public String getEventHistory() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setEventHistory(String s) {
|
||||
|
||||
}
|
||||
|
||||
public boolean isPomInBuild() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public File getProjectDirectory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
import org.apache.maven.shared.model.DomainModelFactory;
|
||||
import org.apache.maven.shared.model.DomainModel;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DefaultDomainModelFactory implements DomainModelFactory {
|
||||
public DomainModel createDomainModel(List<ModelProperty> modelProperties) throws IOException {
|
||||
return new DefaultDomainModel(modelProperties, false);
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
import org.apache.maven.shared.model.*;
|
||||
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class EnforcerPomTest
|
||||
{
|
||||
@org.junit.Test
|
||||
public void dependencyManagementWithScopeAndClassifier() throws IOException
|
||||
{
|
||||
List<ModelProperty> mp = new ArrayList<ModelProperty>();
|
||||
mp.add(new ModelProperty(ProjectUri.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.groupId, "gid"));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.artifactId, "aid"));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.version, "v1"));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.scope, "test"));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.classifier, "tests"));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.groupId, "gid"));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.artifactId, "aid"));
|
||||
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.version, "v1"));
|
||||
|
||||
List<ModelProperty> mp2 = new ArrayList<ModelProperty>();
|
||||
mp2.add(new ModelProperty(ProjectUri.xUri, null));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.xUri, null));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.xUri, null));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.groupId, "gid"));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.artifactId, "aid"));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.xUri, null));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.groupId, "gid"));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.artifactId, "aid"));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.classifier, "tests"));
|
||||
|
||||
DomainModel childModel = new DefaultDomainModel(mp2, true);
|
||||
DomainModel parentModel = new DefaultDomainModel(mp, false);
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS );
|
||||
|
||||
ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory());
|
||||
DomainModel domainModel = ctx.transform( Arrays.asList(childModel, parentModel), transformer, transformer );
|
||||
|
||||
DefaultModelDataSource source = new DefaultModelDataSource( domainModel.getModelProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES);
|
||||
|
||||
List<ModelContainer> containers = source.queryFor(ProjectUri.Dependencies.Dependency.xUri);
|
||||
assertTrue(containers.size() == 2 );
|
||||
|
||||
ModelContainer mc0 = containers.get(0);
|
||||
assertTrue(contains(ProjectUri.Dependencies.Dependency.version, "v1", mc0));
|
||||
assertFalse(contains(ProjectUri.Dependencies.Dependency.classifier, "tests", mc0));
|
||||
|
||||
ModelContainer mc1 = containers.get(1);
|
||||
assertTrue(contains(ProjectUri.Dependencies.Dependency.version, "v1", mc1));
|
||||
assertTrue(contains(ProjectUri.Dependencies.Dependency.classifier, "tests", mc1));
|
||||
}
|
||||
|
||||
private boolean contains(String name, String value, ModelContainer modelContainer) {
|
||||
for(ModelProperty mp : modelContainer.getProperties()) {
|
||||
if(mp.getUri().equals(name) && mp.getValue() != null && mp.getValue().equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.apache.maven.shared.model.*;
|
||||
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||
import org.apache.maven.project.builder.factories.PluginExecutionIdModelContainerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PluginSpecTest {
|
||||
|
||||
@org.junit.Test
|
||||
public void goalsInherited() throws IOException {
|
||||
|
||||
List<ModelProperty> mp0 = new ArrayList<ModelProperty>();
|
||||
mp0.add(new ModelProperty(ProjectUri.xUri, null));
|
||||
mp0.add(new ModelProperty(ProjectUri.Build.xUri, null));
|
||||
mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.xUri, null));
|
||||
mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.xUri, null));
|
||||
mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri, null));
|
||||
mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.groupId, "org.codehaus.modello"));
|
||||
mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.artifactId, "modello-maven-plugin"));
|
||||
mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.version, "v1"));
|
||||
|
||||
List<ModelProperty> mp = new ArrayList<ModelProperty>();
|
||||
mp.add(new ModelProperty(ProjectUri.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.groupId, "org.codehaus.modello"));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.artifactId, "modello-maven-plugin"));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.version, "v1"));
|
||||
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.id, "site-docs"));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.phase, "phase"));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xdoc"));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xsd"));
|
||||
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.id, "standard"));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, null));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xpp3-reader"));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xpp3-writer"));
|
||||
|
||||
DomainModel parentModel = new DefaultDomainModel(mp, false);
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS );
|
||||
|
||||
ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory());
|
||||
DomainModel domainModel = ctx.transform( Arrays.asList(parentModel, new DefaultDomainModel(mp0, true)), transformer, transformer );
|
||||
|
||||
|
||||
List<ModelContainerFactory> factories = new ArrayList<ModelContainerFactory>(PomTransformer.MODEL_CONTAINER_FACTORIES);
|
||||
factories.add(new PluginExecutionIdModelContainerFactory());
|
||||
DefaultModelDataSource source = new DefaultModelDataSource(domainModel.getModelProperties(), factories);
|
||||
|
||||
List<ModelContainer> containers = source.queryFor(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri);
|
||||
assertTrue(2 == containers.size());
|
||||
|
||||
int numberOfGoals = 0;
|
||||
for(ModelProperty x : containers.get(0).getProperties())
|
||||
{
|
||||
if(x.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal))
|
||||
{
|
||||
numberOfGoals++;
|
||||
}
|
||||
}
|
||||
assertTrue(numberOfGoals == 2);
|
||||
|
||||
numberOfGoals = 0;
|
||||
for(ModelProperty x : containers.get(1).getProperties())
|
||||
{
|
||||
if(x.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal))
|
||||
{
|
||||
numberOfGoals++;
|
||||
}
|
||||
}
|
||||
assertTrue(numberOfGoals == 2);
|
||||
|
||||
// System.out.println(ModelMarshaller.unmarshalModelPropertiesToXml(domainModel.getModelProperties(), ProjectUri.baseUri));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package org.apache.maven.project.builder.profile;
|
||||
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelContainerAction;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class DefaultModelContainer implements ModelContainer
|
||||
{
|
||||
|
||||
List<ModelProperty> modelProperties;
|
||||
|
||||
public DefaultModelContainer(List<ModelProperty> properties) {
|
||||
this.modelProperties = properties;
|
||||
}
|
||||
|
||||
public List<ModelProperty> getProperties() {
|
||||
return new ArrayList<ModelProperty>(modelProperties);
|
||||
}
|
||||
|
||||
public ModelContainerAction containerAction(ModelContainer modelContainer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ModelContainer createNewInstance(List<ModelProperty> modelProperties) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package org.apache.maven.project.builder.profile;
|
||||
|
||||
import org.apache.maven.project.builder.profile.FileMatcher;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FileMatcherTest {
|
||||
|
||||
private static String basedir = System.getProperty("basedir");
|
||||
|
||||
@org.junit.Test(expected=IllegalArgumentException.class)
|
||||
public void modelContainerIsNull() {
|
||||
FileMatcher matcher = new FileMatcher();
|
||||
matcher.isMatch(null, new ArrayList<InterpolatorProperty>());
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void fileExistActivationAndExists() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.exists ,
|
||||
new File(basedir, "src/test/resources/test.txt").getAbsolutePath()));
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
FileMatcher matcher = new FileMatcher();
|
||||
assertTrue(matcher.isMatch(modelContainer, new ArrayList<InterpolatorProperty>()));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void fileExistActivationButDoesNotExist() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.exists ,
|
||||
new File(basedir, "src/test/resources/bogus.txt").getAbsolutePath()));
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
FileMatcher matcher = new FileMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, new ArrayList<InterpolatorProperty>()));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void fileMissingActivationButExists() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.missing ,
|
||||
new File(basedir, "src/test/resources/test.txt").getAbsolutePath()));
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
FileMatcher matcher = new FileMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, new ArrayList<InterpolatorProperty>()));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void fileMissingActivationAndDoesNotExist() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.missing ,
|
||||
new File(basedir, "src/test/resources/bogus.txt").getAbsolutePath()));
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
FileMatcher matcher = new FileMatcher();
|
||||
assertTrue(matcher.isMatch(modelContainer, new ArrayList<InterpolatorProperty>()));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,228 +0,0 @@
|
|||
package org.apache.maven.project.builder.profile;
|
||||
|
||||
import org.apache.maven.project.builder.profile.JdkMatcher;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JdkMatcherTest {
|
||||
|
||||
@org.junit.Test(expected=IllegalArgumentException.class)
|
||||
public void modelContainerIsNull() {
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
matcher.isMatch(null, new ArrayList<InterpolatorProperty>());
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionMatches() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "1.5"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertTrue(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionPrefixMatches()
|
||||
{
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.jdk, "1.5" ) );
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer( modelProperties );
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add( new InterpolatorProperty( "${java.specification.version}", "1.5.2" ) );
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertTrue( matcher.isMatch( modelContainer, props ) );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionDoesNotMatchWithNotSymbol() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "!1.5"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertTrue(!matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionDoesMatchWithNotSymbol() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "!1.5"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.6"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertTrue(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionNotMatches() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "1.5"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.4"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionRange_ClosedEdge() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "[1.5,"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertTrue(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionRange_OpenEdge() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "(1.5,"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionRange_OpenEdge2() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "(1.4,"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertTrue(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionRange_OpenEdgeWithPadding() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "(1.5.0,"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionRange_OpenRightEdge() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , ", 1.6)"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertTrue(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionRange_OpenRightEdge2() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , ",1.5)"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionRange_OpenRightEdgeWithWhiteSpace() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , ", 1.5)"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void jdkVersionNotFound() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "1.5"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
JdkMatcher matcher = new JdkMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, new ArrayList<InterpolatorProperty>()));
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
package org.apache.maven.project.builder.profile;
|
||||
|
||||
import org.apache.maven.project.builder.profile.ProfileContext;
|
||||
import org.apache.maven.project.builder.PomTransformer;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.shared.model.DataSourceException;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ProfileContextTest {
|
||||
|
||||
@Test
|
||||
public void getActiveProfiles() throws DataSourceException {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.name , "foo"));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.value , "bar"));
|
||||
|
||||
DefaultModelDataSource dataSource = new DefaultModelDataSource(modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES );
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
interpolatorProperties.add(new InterpolatorProperty( "${foo}", "bar"));
|
||||
|
||||
ProfileContext ctx = new ProfileContext(dataSource, null, null, interpolatorProperties);
|
||||
|
||||
Collection<ModelContainer> profiles = ctx.getActiveProfiles();
|
||||
|
||||
assertTrue(profiles.size() == 1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getActiveProfilesById() throws DataSourceException {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.id , "test"));
|
||||
|
||||
DefaultModelDataSource dataSource = new DefaultModelDataSource(modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES );
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
ProfileContext ctx = new ProfileContext(dataSource, Arrays.asList("test"), null, interpolatorProperties);
|
||||
|
||||
Collection<ModelContainer> profiles = ctx.getActiveProfiles();
|
||||
|
||||
assertTrue(profiles.size() == 1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getActiveByDefaultProfilesOnlyActivatedIfNoOtherPomProfilesAreActive()
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add( new ModelProperty( ProjectUri.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.id, "default" ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.activeByDefault, "true" ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.id, "explicit" ) );
|
||||
|
||||
DefaultModelDataSource dataSource =
|
||||
new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES );
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
ProfileContext ctx = new ProfileContext( dataSource, Arrays.asList( "explicit" ), null, interpolatorProperties );
|
||||
|
||||
Collection<ModelContainer> profiles = ctx.getActiveProfiles();
|
||||
|
||||
assertEquals( 1, profiles.size() );
|
||||
assertProperty( profiles.iterator().next().getProperties(), ProjectUri.Profiles.Profile.id, "explicit" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDeactivateProfiles()
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add( new ModelProperty( ProjectUri.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.id, "default" ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.xUri, null ) );
|
||||
modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.activeByDefault, "true" ) );
|
||||
|
||||
DefaultModelDataSource dataSource =
|
||||
new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES );
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
ProfileContext ctx = new ProfileContext( dataSource, null, Arrays.asList( "default" ), interpolatorProperties );
|
||||
|
||||
Collection<ModelContainer> profiles = ctx.getActiveProfiles();
|
||||
|
||||
assertEquals( 0, profiles.size() );
|
||||
}
|
||||
|
||||
private void assertProperty( Collection<ModelProperty> properties, String uri, String value )
|
||||
{
|
||||
for ( ModelProperty property : properties )
|
||||
{
|
||||
if ( uri.equals( property.getUri() ) && value.equals( property.getValue() ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail( "missing model property " + uri + " = " + value );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package org.apache.maven.project.builder.profile;
|
||||
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PropertyMatcherTest {
|
||||
|
||||
@org.junit.Test
|
||||
public void propertyMatches() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.name , "foo"));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.value , "bar"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${foo}" , "bar"));
|
||||
|
||||
PropertyMatcher matcher = new PropertyMatcher();
|
||||
assertTrue(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void propertyDoesNotMatch() {
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.xUri , null));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.name , "foo"));
|
||||
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.value , "bars"));
|
||||
|
||||
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
|
||||
|
||||
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
|
||||
props.add(new InterpolatorProperty("${foo}" , "bar"));
|
||||
|
||||
PropertyMatcher matcher = new PropertyMatcher();
|
||||
assertFalse(matcher.isMatch(modelContainer, props));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package org.apache.maven.project.builder.rules;
|
||||
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.project.builder.ProjectUri;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ExecutionRuleTest {
|
||||
|
||||
@org.junit.Test
|
||||
public void execute() throws IOException
|
||||
{
|
||||
List<ModelProperty> modelProperties = Arrays.asList(
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri, null),
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI, null),
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "parent-a"),
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "merged"),
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "parent-b"),
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI, null),
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "child-b"),
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "merged"),
|
||||
new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "child-a"));
|
||||
|
||||
List<ModelProperty> mps = new ExecutionRule().execute(modelProperties);
|
||||
for(ModelProperty mp : mps) {
|
||||
//System.out.println(mp);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.model.Resource;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BuildProcessorTest extends TestCase
|
||||
{
|
||||
|
||||
public void testPluginManagementInheritance()
|
||||
{
|
||||
Model parent = new Model();
|
||||
|
||||
PluginManagement pm = new PluginManagement();
|
||||
Plugin p = new Plugin();
|
||||
p.setArtifactId( "aid" );
|
||||
pm.addPlugin( p );
|
||||
Build b = new Build();
|
||||
b.setPluginManagement( pm );
|
||||
parent.setBuild( b );
|
||||
|
||||
Model child = new Model();
|
||||
Model target = new Model();
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, true);
|
||||
|
||||
assertNotNull(target.getBuild());
|
||||
assertNotNull(target.getBuild().getPluginManagement());
|
||||
assertEquals(1, target.getBuild().getPluginManagement().getPlugins().size());
|
||||
}
|
||||
|
||||
public void testChild_FinalName()
|
||||
{
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().setFinalName( "name" );
|
||||
Model target = new Model();
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertEquals("name", target.getBuild().getFinalName());
|
||||
|
||||
child.getBuild().setFinalName( "name2" );
|
||||
assertEquals("name", target.getBuild().getFinalName());
|
||||
}
|
||||
|
||||
public void testParent_FinalName()
|
||||
{
|
||||
Model child = new Model();
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
parent.getBuild().setFinalName( "name" );
|
||||
Model target = new Model();
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals("name", target.getBuild().getFinalName());
|
||||
|
||||
//Immutable
|
||||
parent.getBuild().setFinalName( "name2" );
|
||||
assertEquals("name", target.getBuild().getFinalName());
|
||||
|
||||
}
|
||||
|
||||
public void testParent_Filters()
|
||||
{
|
||||
Model child = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
|
||||
parent.getBuild().getFilters().add( "filter1" );
|
||||
Model target = new Model();
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals(1, target.getBuild().getFilters().size());
|
||||
assertEquals("filter1", target.getBuild().getFilters().get( 0 ));
|
||||
|
||||
}
|
||||
|
||||
public void testChild_Filters()
|
||||
{
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().getFilters().add( "filter1" );
|
||||
Model target = new Model();
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertEquals(1, target.getBuild().getFilters().size());
|
||||
assertEquals("filter1", target.getBuild().getFilters().get( 0 ));
|
||||
|
||||
}
|
||||
public void testJoin_Filters()
|
||||
{
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().getFilters().add( "filter1" );
|
||||
Model target = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
|
||||
parent.getBuild().getFilters().add( "filter2" );
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals(2, target.getBuild().getFilters().size());
|
||||
|
||||
//ORDER
|
||||
assertEquals("filter1", target.getBuild().getFilters().get( 0 ));
|
||||
assertEquals("filter2", target.getBuild().getFilters().get( 1 ));
|
||||
}
|
||||
|
||||
public void testJoin_DuplicateFilters()
|
||||
{
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().getFilters().add( "filter" );
|
||||
Model target = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
|
||||
parent.getBuild().getFilters().add( "filter" );
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals(1, target.getBuild().getFilters().size());
|
||||
|
||||
assertEquals("filter", target.getBuild().getFilters().get( 0 ));
|
||||
}
|
||||
|
||||
public void testDoNotInheritParentIfChildExists_Resources()
|
||||
{
|
||||
Resource r = new Resource();
|
||||
r.setDirectory( "dir" );
|
||||
|
||||
Resource r1 = new Resource();
|
||||
r1.setDirectory( "dir1" );
|
||||
|
||||
Model child = new Model();
|
||||
child.setBuild( new Build() );
|
||||
child.getBuild().getResources().add( r );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setBuild( new Build() );
|
||||
|
||||
parent.getBuild().getResources().add( r1 );
|
||||
|
||||
BuildProcessor proc = new BuildProcessor(new ArrayList());
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals(1, target.getBuild().getResources().size());
|
||||
assertEquals("dir", target.getBuild().getResources().get( 0 ).getDirectory());
|
||||
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.maven.model.CiManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Notifier;
|
||||
|
||||
public class CiManagementProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testChildCopy()
|
||||
{
|
||||
CiManagement mng = new CiManagement();
|
||||
mng.setSystem( "system" );
|
||||
mng.setUrl( "uri" );
|
||||
|
||||
Notifier notifier = new Notifier();
|
||||
notifier.setAddress( "address" );
|
||||
notifier.setType( "type" );
|
||||
Properties prop = new Properties();
|
||||
prop.put( "key", "value" );
|
||||
notifier.setConfiguration( prop );
|
||||
mng.addNotifier( notifier );
|
||||
|
||||
Model child = new Model();
|
||||
child.setCiManagement( mng );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
CiManagementProcessor proc = new CiManagementProcessor();
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertEquals( "system", target.getCiManagement().getSystem() );
|
||||
assertEquals( "uri", target.getCiManagement().getUrl() );
|
||||
assertEquals( 1, target.getCiManagement().getNotifiers().size() );
|
||||
assertEquals( "address", target.getCiManagement().getNotifiers().get( 0 ).getAddress() );
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DependenciesProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testCopyChild()
|
||||
{
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "aid" );
|
||||
|
||||
List<Dependency> child = Arrays.asList( dependency );
|
||||
|
||||
List<Dependency> target = new ArrayList<Dependency>();
|
||||
|
||||
DependenciesProcessor processor = new DependenciesProcessor();
|
||||
processor.process( null, child, target, false );
|
||||
|
||||
assertEquals( 1, target.size() );
|
||||
assertEquals( "aid", target.get( 0 ).getArtifactId() );
|
||||
}
|
||||
|
||||
public void testParentCopy()
|
||||
{
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "aid" );
|
||||
|
||||
List<Dependency> child = new ArrayList<Dependency>();
|
||||
|
||||
List<Dependency> parent = Arrays.asList( dependency );
|
||||
|
||||
List<Dependency> target = new ArrayList<Dependency>();
|
||||
|
||||
DependenciesProcessor processor = new DependenciesProcessor();
|
||||
processor.process( parent, child, target, false );
|
||||
|
||||
assertEquals( 1, target.size() );
|
||||
assertEquals( "aid", target.get( 0 ).getArtifactId() );
|
||||
}
|
||||
/**FIX
|
||||
public void testDependencyOrder()
|
||||
{
|
||||
Dependency dependency1 = new Dependency();
|
||||
dependency1.setArtifactId( "aid1" );
|
||||
List<Dependency> child = Arrays.asList( dependency1 );
|
||||
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "aid" );
|
||||
List<Dependency> parent = Arrays.asList( dependency );
|
||||
|
||||
List<Dependency> target = new ArrayList<Dependency>();
|
||||
|
||||
DependenciesProcessor processor = new DependenciesProcessor();
|
||||
processor.process( parent, child, target, false );
|
||||
|
||||
assertEquals( 2, target.size() );
|
||||
assertEquals( "aid1", target.get( 0 ).getArtifactId() );
|
||||
assertEquals( "aid", target.get( 1 ).getArtifactId() );
|
||||
}
|
||||
*/
|
||||
public void testJoin_NullVersion()
|
||||
{
|
||||
Dependency dependency1 = new Dependency();
|
||||
dependency1.setArtifactId( "aid-c" );
|
||||
dependency1.setGroupId( "gid-c" );
|
||||
|
||||
List<Dependency> child = Arrays.asList( dependency1 );
|
||||
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "aid-c" );
|
||||
dependency.setGroupId( "gid-c" );
|
||||
dependency.setSystemPath( "sp" );
|
||||
|
||||
List<Dependency> parent= Arrays.asList( dependency );
|
||||
|
||||
List<Dependency> target = new ArrayList<Dependency>();
|
||||
|
||||
DependenciesProcessor processor = new DependenciesProcessor();
|
||||
processor.process( parent, child, target, false );
|
||||
|
||||
assertEquals( 1, target.size() );
|
||||
assertEquals( "sp", target.get( 0 ).getSystemPath() );
|
||||
}
|
||||
|
||||
public void testJoin_DefaultType()
|
||||
{
|
||||
Dependency dependency1 = new Dependency();
|
||||
dependency1.setArtifactId( "aid-c" );
|
||||
dependency1.setGroupId( "gid-c" );
|
||||
dependency1.setVersion( "1.0" );
|
||||
dependency1.setType( "jar" );
|
||||
List<Dependency> child = Arrays.asList( dependency1 );
|
||||
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "aid-c" );
|
||||
dependency.setGroupId( "gid-c" );
|
||||
dependency.setVersion( "1.0" );
|
||||
dependency.setSystemPath( "sp" );
|
||||
|
||||
List<Dependency> parent = Arrays.asList( dependency );
|
||||
|
||||
List<Dependency> target = new ArrayList<Dependency>();
|
||||
|
||||
DependenciesProcessor processor = new DependenciesProcessor();
|
||||
processor.process( parent, child, target, false );
|
||||
|
||||
assertEquals( 1, target.size() );
|
||||
assertEquals( "sp", target.get( 0 ).getSystemPath() );
|
||||
}
|
||||
|
||||
public void testJoin_DifferentClassifiers()
|
||||
{
|
||||
Dependency dependency1 = new Dependency();
|
||||
dependency1.setArtifactId( "aid-c" );
|
||||
dependency1.setGroupId( "gid-c" );
|
||||
dependency1.setVersion( "1.0" );
|
||||
dependency1.setClassifier( "c1" );
|
||||
|
||||
List<Dependency> child = Arrays.asList( dependency1 );
|
||||
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "aid-c" );
|
||||
dependency.setGroupId( "gid-c" );
|
||||
dependency.setVersion( "1.0" );
|
||||
dependency1.setClassifier( "c2" );
|
||||
|
||||
List<Dependency> parent = Arrays.asList( dependency );
|
||||
|
||||
List<Dependency> target = new ArrayList<Dependency>();
|
||||
|
||||
DependenciesProcessor processor = new DependenciesProcessor();
|
||||
processor.process( parent, child, target, false );
|
||||
|
||||
assertEquals( 2, target.size() );
|
||||
}
|
||||
|
||||
public void testJoin_DifferentVersions()
|
||||
{
|
||||
Dependency dependency1 = new Dependency();
|
||||
dependency1.setArtifactId( "aid-c" );
|
||||
dependency1.setGroupId( "gid-c" );
|
||||
dependency1.setVersion( "1.1" );
|
||||
|
||||
List<Dependency> child = Arrays.asList( dependency1 );
|
||||
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "aid-c" );
|
||||
dependency.setGroupId( "gid-c" );
|
||||
dependency.setVersion( "1.0" );
|
||||
|
||||
List<Dependency> parent = Arrays.asList( dependency );
|
||||
|
||||
List<Dependency> target = new ArrayList<Dependency>();
|
||||
|
||||
DependenciesProcessor processor = new DependenciesProcessor();
|
||||
processor.process( parent, child, target, false );
|
||||
|
||||
assertEquals( 1, target.size() );
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Exclusion;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DependencyProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testCopyChild()
|
||||
{
|
||||
DependencyProcessor processor = new DependencyProcessor();
|
||||
List<Dependency> dependencies = new ArrayList<Dependency>();
|
||||
Dependency child = new Dependency();
|
||||
child.setArtifactId( "aid" );
|
||||
|
||||
processor.process( null, child, dependencies, false );
|
||||
assertEquals( 1, dependencies.size() );
|
||||
|
||||
// Immutable
|
||||
child.setArtifactId( "aid2" );
|
||||
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
|
||||
}
|
||||
|
||||
public void testCopyParent()
|
||||
{
|
||||
DependencyProcessor processor = new DependencyProcessor();
|
||||
List<Dependency> dependencies = new ArrayList<Dependency>();
|
||||
Dependency parent = new Dependency();
|
||||
parent.setArtifactId( "aid" );
|
||||
|
||||
processor.process( parent, null, dependencies, false );
|
||||
assertEquals( 1, dependencies.size() );
|
||||
|
||||
// Immutable
|
||||
parent.setArtifactId( "aid2" );
|
||||
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
|
||||
}
|
||||
/**FIX
|
||||
public void testJoinChildOverridesParent()
|
||||
{
|
||||
DependencyProcessor processor = new DependencyProcessor();
|
||||
List<Dependency> dependencies = new ArrayList<Dependency>();
|
||||
Dependency child = new Dependency();
|
||||
child.setArtifactId( "aid" );
|
||||
|
||||
Dependency parent = new Dependency();
|
||||
parent.setArtifactId( "aid2" );
|
||||
|
||||
processor.process( parent, child, dependencies, false );
|
||||
assertEquals( 1, dependencies.size() );
|
||||
|
||||
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
|
||||
|
||||
// Immutable
|
||||
child.setArtifactId( "aid3" );
|
||||
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
|
||||
}
|
||||
*/
|
||||
public void testJoinElements()
|
||||
{
|
||||
DependencyProcessor processor = new DependencyProcessor();
|
||||
List<Dependency> dependencies = new ArrayList<Dependency>();
|
||||
Dependency child = new Dependency();
|
||||
child.setArtifactId( "aid" );
|
||||
|
||||
Dependency parent = new Dependency();
|
||||
parent.setGroupId( "gid" );
|
||||
|
||||
processor.process( parent, child, dependencies, false );
|
||||
assertEquals( 1, dependencies.size() );
|
||||
|
||||
assertEquals( "aid", dependencies.get( 0 ).getArtifactId() );
|
||||
assertEquals( "gid", dependencies.get( 0 ).getGroupId() );
|
||||
|
||||
}
|
||||
/*
|
||||
public void testExclusionJoin()
|
||||
{
|
||||
DependencyProcessor processor = new DependencyProcessor();
|
||||
List<Dependency> dependencies = new ArrayList<Dependency>();
|
||||
|
||||
Exclusion e = new Exclusion();
|
||||
e.setArtifactId( "aid" );
|
||||
e.setGroupId( "gid" );
|
||||
|
||||
Dependency child = new Dependency();
|
||||
child.addExclusion( e );
|
||||
|
||||
Exclusion e1 = new Exclusion();
|
||||
e1.setArtifactId( "aid1" );
|
||||
e1.setGroupId( "gid1" );
|
||||
Dependency parent = new Dependency();
|
||||
parent.addExclusion( e1 );
|
||||
|
||||
processor.process( parent, child, dependencies, false );
|
||||
assertEquals( 2, dependencies.get( 0 ).getExclusions().size() );
|
||||
assertEquals( "aid", dependencies.get( 0 ).getExclusions().get( 0 ).getArtifactId() );
|
||||
assertEquals( "aid1", dependencies.get( 0 ).getExclusions().get( 1 ).getArtifactId() );
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import org.apache.maven.model.IssueManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class IssueManagementProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testChildCopy()
|
||||
{
|
||||
IssueManagement mng = new IssueManagement();
|
||||
mng.setSystem( "system" );
|
||||
mng.setUrl( "http://url" );
|
||||
|
||||
Model child = new Model();
|
||||
child.setIssueManagement( mng );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
IssueManagementProcessor proc = new IssueManagementProcessor();
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertEquals( "system", target.getIssueManagement().getSystem() );
|
||||
assertEquals( "http://url", target.getIssueManagement().getUrl() );
|
||||
}
|
||||
|
||||
/**
|
||||
* If child does not have issue management node, then use parent.
|
||||
*/
|
||||
public void testParentCopy()
|
||||
{
|
||||
IssueManagement mng = new IssueManagement();
|
||||
mng.setSystem( "system" );
|
||||
mng.setUrl( "http://url" );
|
||||
|
||||
Model child = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
;
|
||||
parent.setIssueManagement( mng );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
IssueManagementProcessor proc = new IssueManagementProcessor();
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals( "system", target.getIssueManagement().getSystem() );
|
||||
assertEquals( "http://url", target.getIssueManagement().getUrl() );
|
||||
}
|
||||
|
||||
public void testChildCopy_DontInheritParent()
|
||||
{
|
||||
IssueManagement mng = new IssueManagement();
|
||||
mng.setSystem( "system" );
|
||||
mng.setUrl( "http://url" );
|
||||
|
||||
Model child = new Model();
|
||||
child.setIssueManagement( mng );
|
||||
|
||||
IssueManagement mng1 = new IssueManagement();
|
||||
Model parent = new Model();
|
||||
;
|
||||
mng1.setSystem( "system-1" );
|
||||
mng1.setUrl( "http://url-1" );
|
||||
parent.setIssueManagement( mng1 );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
IssueManagementProcessor proc = new IssueManagementProcessor();
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals( "system", target.getIssueManagement().getSystem() );
|
||||
assertEquals( "http://url", target.getIssueManagement().getUrl() );
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import org.apache.maven.model.MailingList;
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MailingListProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testChildCopy()
|
||||
{
|
||||
Model child = new Model();
|
||||
|
||||
MailingList list = new MailingList();
|
||||
list.setArchive( "archive" );
|
||||
list.setPost( "post" );
|
||||
|
||||
child.getMailingLists().add( list );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
MailingListProcessor proc = new MailingListProcessor();
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() );
|
||||
|
||||
list.setArchive( "aaa" );
|
||||
assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() );
|
||||
}
|
||||
|
||||
public void testParentCopy()
|
||||
{
|
||||
Model child = new Model();
|
||||
|
||||
Model parent = new Model();
|
||||
|
||||
MailingList list = new MailingList();
|
||||
list.setArchive( "archive" );
|
||||
list.setPost( "post" );
|
||||
|
||||
parent.getMailingLists().add( list );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
MailingListProcessor proc = new MailingListProcessor();
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() );
|
||||
|
||||
list.setArchive( "aaa" );
|
||||
assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() );
|
||||
}
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
|
||||
public class ModelProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testModelProcessorVersion()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setVersion( "1.0" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertEquals( "1.0", targetModel.getVersion() );
|
||||
}
|
||||
|
||||
public void testModelProcessorVersionFromParent()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
|
||||
Parent parent = new Parent();
|
||||
parent.setVersion( "1.0" );
|
||||
childModel.setParent( parent );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertEquals( "1.0", targetModel.getVersion() );
|
||||
}
|
||||
|
||||
public void testModelProcessorGroupId()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setGroupId( "gid" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertEquals( "gid", targetModel.getGroupId() );
|
||||
}
|
||||
|
||||
public void testModelProcessorGroupIdFromParent()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
|
||||
Parent parent = new Parent();
|
||||
parent.setGroupId( "gid" );
|
||||
childModel.setParent( parent );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertEquals( "gid", targetModel.getGroupId() );
|
||||
}
|
||||
|
||||
public void testModelVersion()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setModelVersion( "4.0" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertEquals( "4.0", targetModel.getModelVersion() );
|
||||
}
|
||||
|
||||
public void testPackaging()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setPackaging( "pom" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertEquals( "pom", targetModel.getPackaging() );
|
||||
}
|
||||
|
||||
public void testNameSpecialized()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setName( "name" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, true );
|
||||
assertEquals( "name", targetModel.getName() );
|
||||
}
|
||||
|
||||
public void testNameNotSpecialized()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setName( "name" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertNull( targetModel.getName() );
|
||||
}
|
||||
|
||||
public void testDescriptionSpecialized()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setDescription( "description" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, true );
|
||||
assertEquals( "description", targetModel.getDescription() );
|
||||
}
|
||||
|
||||
public void testInceptionYearFromChild()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setInceptionYear( "2000" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertEquals( "2000", targetModel.getInceptionYear() );
|
||||
|
||||
childModel.setInceptionYear( "2001" );
|
||||
assertEquals( "2000", targetModel.getInceptionYear() );
|
||||
}
|
||||
|
||||
public void testInceptionYearFromParent()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
|
||||
Model childModel = new Model();
|
||||
|
||||
Model parentModel = new Model();
|
||||
parentModel.setInceptionYear( "2000" );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( parentModel, childModel, targetModel, false );
|
||||
assertEquals( "2000", targetModel.getInceptionYear() );
|
||||
|
||||
parentModel.setInceptionYear( "2001" );
|
||||
assertEquals( "2000", targetModel.getInceptionYear() );
|
||||
}
|
||||
|
||||
public void testDependencyManagementChildCopy()
|
||||
{
|
||||
Model target= new Model();
|
||||
|
||||
Model child = new Model();
|
||||
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "aid" );
|
||||
|
||||
DependencyManagement mng = new DependencyManagement();
|
||||
mng.addDependency( dependency );
|
||||
|
||||
child.setDependencyManagement( mng );
|
||||
|
||||
ModelProcessor mp = new ModelProcessor( new ArrayList<Processor>() );
|
||||
mp.process( null, child, target, false );
|
||||
|
||||
assertNotNull(target.getDependencyManagement());
|
||||
|
||||
assertEquals(1, target.getDependencyManagement().getDependencies().size());
|
||||
assertEquals("aid", target.getDependencyManagement().getDependencies().get( 0 ).getArtifactId());
|
||||
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ModuleTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void testIsMostSpecialized()
|
||||
{
|
||||
ModuleProcessor proc = new ModuleProcessor();
|
||||
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setModules( Arrays.asList( "m1", "m2" ) );
|
||||
|
||||
proc.process( null, childModel, targetModel, true );
|
||||
|
||||
assertEquals( 2, targetModel.getModules().size() );
|
||||
assertEquals( "m1", targetModel.getModules().get( 0 ) );
|
||||
assertEquals( "m2", targetModel.getModules().get( 1 ) );
|
||||
}
|
||||
|
||||
public void testIsNotMostSpecialized()
|
||||
{
|
||||
ModuleProcessor proc = new ModuleProcessor();
|
||||
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setModules( Arrays.asList( "m1", "m2" ) );
|
||||
|
||||
proc.process( null, childModel, targetModel, false );
|
||||
|
||||
assertEquals( 0, targetModel.getModules().size() );
|
||||
}
|
||||
|
||||
public void testImmutable()
|
||||
{
|
||||
ModuleProcessor proc = new ModuleProcessor();
|
||||
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
childModel.setModules( Arrays.asList( "m1", "m2" ) );
|
||||
|
||||
proc.process( null, childModel, targetModel, true );
|
||||
|
||||
childModel.getModules().set( 0, "m0" );
|
||||
|
||||
assertEquals( "m1", targetModel.getModules().get( 0 ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Organization;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class OrganizationProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testChildCopy()
|
||||
{
|
||||
Model child = new Model();
|
||||
Organization org = new Organization();
|
||||
org.setName( "name" );
|
||||
org.setUrl( "url" );
|
||||
|
||||
child.setOrganization( org );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
OrganizationProcessor proc = new OrganizationProcessor();
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertNotNull( target.getOrganization() );
|
||||
assertEquals( "name", target.getOrganization().getName() );
|
||||
assertEquals( "url", target.getOrganization().getUrl() );
|
||||
|
||||
org.setName( "new" );
|
||||
assertEquals( "name", target.getOrganization().getName() );
|
||||
}
|
||||
|
||||
public void testParentCopy()
|
||||
{
|
||||
Model child = new Model();
|
||||
Organization org = new Organization();
|
||||
org.setName( "name" );
|
||||
org.setUrl( "url" );
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setOrganization( org );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
OrganizationProcessor proc = new OrganizationProcessor();
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertNotNull( target.getOrganization() );
|
||||
assertEquals( "name", target.getOrganization().getName() );
|
||||
assertEquals( "url", target.getOrganization().getUrl() );
|
||||
|
||||
org.setName( "new" );
|
||||
assertEquals( "name", target.getOrganization().getName() );
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ParentProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testVersion()
|
||||
{
|
||||
Model targetModel = new Model();
|
||||
Model childModel = new Model();
|
||||
Parent parent = new Parent();
|
||||
parent.setVersion( "1.0" );
|
||||
childModel.setParent( parent );
|
||||
|
||||
ParentProcessor mp = new ParentProcessor();
|
||||
mp.process( null, childModel, targetModel, false );
|
||||
assertEquals( "1.0", targetModel.getParent().getVersion() );
|
||||
}
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PluginProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPluginExecutionCopyOfGoals()
|
||||
{
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setArtifactId( "aid" );
|
||||
plugin.setGroupId( "gid" );
|
||||
plugin.setVersion( "1.0" );
|
||||
|
||||
PluginExecution ex = new PluginExecution();
|
||||
ex.setId( "id" );
|
||||
ex.setInherited( "true" );
|
||||
ex.setGoals( Arrays.asList("a", "b") );
|
||||
plugin.addExecution( ex );
|
||||
|
||||
Plugin plugin1 = new Plugin();
|
||||
plugin1.setArtifactId( "aid" );
|
||||
plugin1.setGroupId( "gid" );
|
||||
plugin1.setVersion( "1.0" );
|
||||
|
||||
PluginExecution ex1 = new PluginExecution();
|
||||
ex1.setId( "id" );
|
||||
ex1.setInherited( "true" );
|
||||
ex1.setGoals( Arrays.asList("b", "c") );
|
||||
plugin1.addExecution( ex1 );
|
||||
|
||||
List<Plugin> plugins = new ArrayList<Plugin>();
|
||||
|
||||
PluginProcessor proc = new PluginProcessor();
|
||||
proc.process( plugin1, plugin, plugins, false );
|
||||
|
||||
assertEquals(1, plugins.size());
|
||||
assertEquals(1, plugins.get( 0 ).getExecutions().size());
|
||||
assertEquals(3, plugins.get( 0 ).getExecutions().get( 0 ).getGoals().size());
|
||||
}
|
||||
|
||||
public void testPluginJoin_GroupId()
|
||||
{
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setArtifactId( "aid" );
|
||||
plugin.setGroupId( "gid" );
|
||||
plugin.setVersion( "1.0" );
|
||||
|
||||
Plugin plugin1 = new Plugin();
|
||||
plugin1.setArtifactId( "aid" );
|
||||
plugin1.setGroupId( "gid" );
|
||||
plugin1.setVersion( "1.0" );
|
||||
|
||||
|
||||
List<Plugin> plugins = new ArrayList<Plugin>();
|
||||
|
||||
PluginProcessor proc = new PluginProcessor();
|
||||
proc.process( plugin1, plugin, plugins, false );
|
||||
|
||||
assertEquals(1, plugins.size());
|
||||
assertEquals("gid", plugins.get( 0 ).getGroupId());
|
||||
}
|
||||
|
||||
public void testPluginExecutionJoin_Phase()
|
||||
{
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setArtifactId( "aid" );
|
||||
plugin.setGroupId( "gid" );
|
||||
plugin.setVersion( "1.0" );
|
||||
|
||||
PluginExecution ex = new PluginExecution();
|
||||
ex.setId( "id" );
|
||||
ex.setPhase( "p" );
|
||||
ex.setGoals( Arrays.asList("a", "b") );
|
||||
plugin.addExecution( ex );
|
||||
|
||||
Plugin plugin1 = new Plugin();
|
||||
plugin1.setArtifactId( "aid" );
|
||||
plugin1.setGroupId( "gid" );
|
||||
plugin1.setVersion( "1.0" );
|
||||
|
||||
PluginExecution ex1 = new PluginExecution();
|
||||
ex1.setId( "id" );
|
||||
ex1.setPhase( "p1" );
|
||||
ex1.setGoals( Arrays.asList("b", "c") );
|
||||
plugin1.addExecution( ex1 );
|
||||
|
||||
List<Plugin> plugins = new ArrayList<Plugin>();
|
||||
|
||||
PluginProcessor proc = new PluginProcessor();
|
||||
proc.process( plugin1, plugin, plugins, false );
|
||||
|
||||
assertEquals(1, plugins.size());
|
||||
assertEquals(1, plugins.get( 0 ).getExecutions().size());
|
||||
assertEquals("p", plugins.get( 0 ).getExecutions().get( 0 ).getPhase());
|
||||
}
|
||||
|
||||
|
||||
public void testPluginDependencyChildCopy_DependencyGroupId()
|
||||
{
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setGroupId( "gid" );
|
||||
|
||||
List<Plugin> target = new ArrayList<Plugin>();
|
||||
Plugin child = new Plugin();
|
||||
child.addDependency( dependency );
|
||||
|
||||
PluginProcessor proc = new PluginProcessor();
|
||||
proc.process( null, child, target, false );
|
||||
|
||||
assertEquals(1, target.size());
|
||||
assertEquals(1, target.get( 0 ).getDependencies().size());
|
||||
assertEquals("gid", target.get( 0 ).getDependencies().get( 0 ).getGroupId());
|
||||
}
|
||||
/*
|
||||
public void testPluginDependencyJoin()
|
||||
{
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setGroupId( "gid" );
|
||||
|
||||
List<Plugin> target = new ArrayList<Plugin>();
|
||||
|
||||
Plugin child = new Plugin();
|
||||
child.setArtifactId( "aid" );
|
||||
child.setGroupId( "gid" );
|
||||
child.setVersion( "1.0" );
|
||||
child.addDependency( dependency );
|
||||
|
||||
Plugin parent = new Plugin();
|
||||
parent.setGroupId( "gid" );
|
||||
parent.setArtifactId( "aid" );
|
||||
parent.setVersion( "1.0" );
|
||||
|
||||
Dependency dependency1 = new Dependency();
|
||||
dependency1.setGroupId( "gid1" );
|
||||
parent.addDependency( dependency1 );
|
||||
|
||||
PluginProcessor proc = new PluginProcessor();
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertEquals(1, target.size());
|
||||
assertEquals(2, target.get( 0 ).getDependencies().size());
|
||||
assertEquals("gid", target.get( 0 ).getDependencies().get( 0 ).getGroupId());
|
||||
assertEquals("gid1", target.get( 0 ).getDependencies().get( 1 ).getGroupId());
|
||||
}
|
||||
*/
|
||||
/*
|
||||
public void testMergeOfPluginConfiguration()
|
||||
{
|
||||
|
||||
List<Plugin> target = new ArrayList<Plugin>();
|
||||
|
||||
Xpp3Dom dom = new Xpp3Dom("a");
|
||||
Xpp3Dom dom2 = new Xpp3Dom("b");
|
||||
dom2.setValue( "test3" );
|
||||
dom.addChild( dom2 );
|
||||
|
||||
Plugin child = new Plugin();
|
||||
child.setArtifactId( "aid" );
|
||||
child.setGroupId( "gid" );
|
||||
child.setVersion( "1.0" );
|
||||
child.setConfiguration( dom );
|
||||
|
||||
Plugin parent = new Plugin();
|
||||
parent.setGroupId( "gid" );
|
||||
parent.setArtifactId( "aid" );
|
||||
parent.setVersion( "1.0" );
|
||||
|
||||
Xpp3Dom dom3 = new Xpp3Dom("a");
|
||||
Xpp3Dom dom4 = new Xpp3Dom("b");
|
||||
dom4.setValue( "test2" );
|
||||
dom.addChild( dom4 );
|
||||
|
||||
parent.setConfiguration( dom3 );
|
||||
|
||||
PluginProcessor proc = new PluginProcessor();
|
||||
proc.process( parent, child, target, false );
|
||||
|
||||
assertNotNull(target.get( 0 ).getConfiguration() );
|
||||
assertEquals( 2, ((Xpp3Dom) target.get( 0 ).getConfiguration()).getChildren( "b" ).length );
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PluginsManagementProcessorTest extends TestCase
|
||||
{
|
||||
public void testChildCopy_Dependencies()
|
||||
{
|
||||
PluginsManagementProcessor proc = new PluginsManagementProcessor();
|
||||
|
||||
Plugin p = new Plugin();
|
||||
p.setArtifactId( "aid" );
|
||||
p.setGroupId( "gid");
|
||||
p.setVersion( "1.0" );
|
||||
Dependency d = new Dependency();
|
||||
d.setArtifactId( "d-aid" );
|
||||
d.setGroupId( "gid" );
|
||||
|
||||
p.setDependencies( new ArrayList<Dependency>(Arrays.asList(d) ));
|
||||
|
||||
Plugin p1 = new Plugin();
|
||||
p1.setArtifactId( "aid" );
|
||||
p1.setGroupId( "gid");
|
||||
p1.setVersion( "1.0" );
|
||||
p1.setInherited( "true" );
|
||||
|
||||
Dependency d1 = new Dependency();
|
||||
d1.setArtifactId( "d1-aid" );
|
||||
d1.setGroupId( "gid" );
|
||||
|
||||
p1.setDependencies( Arrays.asList( d1 ) );
|
||||
|
||||
List<Plugin> plugins = new ArrayList<Plugin>();
|
||||
plugins.add(p);
|
||||
proc.process( null, Arrays.asList(p1), plugins , false);
|
||||
|
||||
assertEquals(1, plugins.size());
|
||||
assertEquals(2, plugins.get( 0 ).getDependencies().size());
|
||||
assertEquals("true", plugins.get( 0 ).getInherited());
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package org.apache.maven.project.processor;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Prerequisites;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PrerequisitesProcessorTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void testMaven()
|
||||
{
|
||||
Prerequisites prerequisites = new Prerequisites();
|
||||
prerequisites.setMaven( "2.1" );
|
||||
|
||||
Model child = new Model();
|
||||
child.setPrerequisites( prerequisites );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
PrerequisitesProcessor proc = new PrerequisitesProcessor();
|
||||
proc.process( null, child, target, true );
|
||||
|
||||
assertEquals( "2.1", target.getPrerequisites().getMaven() );
|
||||
|
||||
// Immutable
|
||||
prerequisites.setMaven( "2.2" );
|
||||
assertEquals( "2.1", target.getPrerequisites().getMaven() );
|
||||
|
||||
}
|
||||
|
||||
public void testMavenParent()
|
||||
{
|
||||
Prerequisites prerequisites = new Prerequisites();
|
||||
prerequisites.setMaven( "2.1" );
|
||||
|
||||
Model parent = new Model();
|
||||
parent.setPrerequisites( prerequisites );
|
||||
|
||||
Model target = new Model();
|
||||
|
||||
PrerequisitesProcessor proc = new PrerequisitesProcessor();
|
||||
proc.process( parent, new Model(), target, false );
|
||||
|
||||
assertEquals( null, target.getPrerequisites() );
|
||||
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue