From dd635ca490bae271442d7b69eafdf595a627cafd Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 25 Jun 2009 10:00:21 +0000 Subject: [PATCH] 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 --- .../maven/model/DefaultModelBuilder.java | 23 ++---- .../superpom/DefaultSuperPomProvider.java | 76 +++++++++++++++++++ .../model/superpom/SuperPomProvider.java | 42 ++++++++++ 3 files changed, 123 insertions(+), 18 deletions(-) create mode 100644 maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java create mode 100644 maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java index 4a560c7e6d..786e492acb 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java @@ -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 ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java b/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java new file mode 100644 index 0000000000..5dcd53558c --- /dev/null +++ b/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java @@ -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; + } + +} diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java b/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java new file mode 100644 index 0000000000..46d807fadc --- /dev/null +++ b/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java @@ -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 ); + +}