o Moved super POM retrieval into dedicated component to provide an extension point for integrators like Tycho that need different/further values in the super model

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@788309 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-25 10:00:21 +00:00
parent 5a8e3f08c2
commit dd635ca490
3 changed files with 123 additions and 18 deletions

View File

@ -21,7 +21,6 @@ package org.apache.maven.model;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -46,6 +45,7 @@ import org.apache.maven.model.profile.ProfileSelector;
import org.apache.maven.model.resolution.InvalidRepositoryException;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.model.superpom.SuperPomProvider;
import org.apache.maven.model.validation.ModelValidationResult;
import org.apache.maven.model.validation.ModelValidator;
import org.codehaus.plexus.component.annotations.Component;
@ -59,8 +59,6 @@ public class DefaultModelBuilder
implements ModelBuilder
{
private Model superModel;
@Requirement
private ModelReader modelReader;
@ -76,6 +74,9 @@ public class DefaultModelBuilder
@Requirement
private ModelPathTranslator modelPathTranslator;
@Requirement
private SuperPomProvider superPomProvider;
@Requirement
private InheritanceAssembler inheritanceAssembler;
@ -460,21 +461,7 @@ public class DefaultModelBuilder
private Model getSuperModel()
{
if ( superModel == null )
{
InputStream is = getClass().getResourceAsStream( "/org/apache/maven/model/pom-4.0.0.xml" );
try
{
superModel = modelReader.read( is, null );
}
catch ( IOException e )
{
throw new IllegalStateException( "The super POM is damaged"
+ ", please verify the integrity of your Maven installation", e );
}
}
return ModelUtils.cloneModel( superModel );
return ModelUtils.cloneModel( superPomProvider.getSuperModel( "4.0.0" ) );
}
private String toSourceHint( Model model )

View File

@ -0,0 +1,76 @@
package org.apache.maven.model.superpom;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.IOException;
import java.io.InputStream;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.ModelReader;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
/**
* Provides the super POM that all models implicitly inherit from.
*
* @author Benjamin Bentmann
*/
@Component( role = SuperPomProvider.class )
public class DefaultSuperPomProvider
implements SuperPomProvider
{
/**
* The cached super POM, lazily created.
*/
private Model superModel;
@Requirement
private ModelReader modelReader;
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
{
superModel = modelReader.read( is, null );
}
catch ( IOException e )
{
throw new IllegalStateException( "The super POM " + resource + " is damaged"
+ ", please verify the integrity of your Maven installation", e );
}
}
return superModel;
}
}

View File

@ -0,0 +1,42 @@
package org.apache.maven.model.superpom;
/*
* 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;
/**
* Provides the super POM that all models implicitly inherit from.
*
* @author Benjamin Bentmann
*/
public interface SuperPomProvider
{
/**
* Gets the super POM for the specified model version. The returned model is supposed to be read-only, i.e. if the
* caller intends to make updates to the model the return value must be cloned before updating to ensure the
* modifications don't affect future retrievals of the super POM.
*
* @param version The model version to retrieve the super POM for (e.g. "4.0.0"), must not be {@code null}.
* @return The super POM, never {@code null}.
*/
Model getSuperModel( String version );
}