You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/06/25 12:00:21 UTC

svn commit: r788309 - in /maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model: DefaultModelBuilder.java superpom/ superpom/DefaultSuperPomProvider.java superpom/SuperPomProvider.java

Author: bentmann
Date: Thu Jun 25 10:00:21 2009
New Revision: 788309

URL: http://svn.apache.org/viewvc?rev=788309&view=rev
Log:
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 

Added:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/   (with props)
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java   (with props)
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java   (with props)
Modified:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java?rev=788309&r1=788308&r2=788309&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java Thu Jun 25 10:00:21 2009
@@ -21,7 +21,6 @@
 
 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.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 @@
     implements ModelBuilder
 {
 
-    private Model superModel;
-
     @Requirement
     private ModelReader modelReader;
 
@@ -77,6 +75,9 @@
     private ModelPathTranslator modelPathTranslator;
 
     @Requirement
+    private SuperPomProvider superPomProvider;
+
+    @Requirement
     private InheritanceAssembler inheritanceAssembler;
 
     @Requirement
@@ -460,21 +461,7 @@
 
     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 )

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/
------------------------------------------------------------------------------
    bugtraq:label = Enter issue ID:

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/
------------------------------------------------------------------------------
    bugtraq:message = Issue id: %BUGID%

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/
------------------------------------------------------------------------------
    bugtraq:number = false

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java?rev=788309&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java (added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java Thu Jun 25 10:00:21 2009
@@ -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;
+    }
+
+}

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java?rev=788309&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java (added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java Thu Jun 25 10:00:21 2009
@@ -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 );
+
+}

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/superpom/SuperPomProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision