概述
public Model getSuperModel( String version )
{
if ( superModel == null )
{
String resource = "/org/apache/maven/model/pom-" + version + ".xml";
InputStream is = getClass().getResourceAsStream( resource );
if ( is == null )
{
throw new IllegalStateException( "The super POM " + resource + " was not found"
+ ", please verify the integrity of your Maven installation" );
}
try
{
Map<String, String> options = new HashMap<String, String>();
options.put( "xml:4.0.0", "xml:4.0.0" );
superModel = modelProcessor.read( is, options );
}
catch ( IOException e )
{
throw new IllegalStateException( "The super POM " + resource + " is damaged"
+ ", please verify the integrity of your Maven installation", e );
}
}
return superModel;
}
加载supermodle的目录是:/org/apache/maven/model/pom-*.xml
maven解析pom文件的代码
:
for ( ModelData currentData = resultData; currentData != null; )
{
lineage.add( currentData );
Model tmpModel = currentData.getModel();
Model rawModel = tmpModel.clone();
currentData.setRawModel( rawModel );
problems.setSource( tmpModel );
modelNormalizer.mergeDuplicates( tmpModel, request, problems );
profileActivationContext.setProjectProperties( tmpModel.getProperties() );
List<Profile> activePomProfiles =
profileSelector.getActiveProfiles( rawModel.getProfiles(), profileActivationContext, problems );
currentData.setActiveProfiles( activePomProfiles );
for ( Profile activeProfile : activePomProfiles )
{
profileInjector.injectProfile( tmpModel, activeProfile, request, problems );
}
if ( currentData == resultData )
{
for ( Profile activeProfile : activeExternalProfiles )
{
profileInjector.injectProfile( tmpModel, activeProfile, request, problems );
}
}
if ( currentData == superData )
{
break;
}
configureResolver( request.getModelResolver(), tmpModel, problems );
currentData = readParent( tmpModel, currentData.getSource(), request, problems );
if ( currentData == null )
{
currentData = superData;
}
else if ( !parentIds.add( currentData.getId() ) )
{
String message = "The parents form a cycle: ";
for ( String modelId : parentIds )
{
message += modelId + " -> ";
}
message += currentData.getId();
problems.add( new ModelProblemCollectorRequest( ModelProblem.Severity.FATAL, ModelProblem.Version.BASE ).setMessage( message ) );
throw problems.newModelBuildingException();
}
}
从这里可以说明,pom的文件内容是先整合当前pom内容,然后整合parent最后整合superpom文件内容
最后
以上就是悦耳蜻蜓为你收集整理的maven 代码解析的全部内容,希望文章能够帮你解决maven 代码解析所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复