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/07/14 12:42:35 UTC

svn commit: r793842 - in /maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model: building/ profile/activation/

Author: bentmann
Date: Tue Jul 14 10:42:34 2009
New Revision: 793842

URL: http://svn.apache.org/viewvc?rev=793842&view=rev
Log:
o Introduced model building listener

Added:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/AbstractModelBuildingListener.java   (with props)
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java   (with props)
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEvent.java   (with props)
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingListener.java   (with props)
Modified:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java

Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/AbstractModelBuildingListener.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/AbstractModelBuildingListener.java?rev=793842&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/AbstractModelBuildingListener.java (added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/AbstractModelBuildingListener.java Tue Jul 14 10:42:34 2009
@@ -0,0 +1,37 @@
+package org.apache.maven.model.building;
+
+/*
+ * 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 a skeleton implementation for model building listeners. The methods of this class are empty.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class AbstractModelBuildingListener
+    implements ModelBuildingListener
+{
+
+    public void buildExtensionsAssembled( ModelBuildingEvent event )
+        throws Exception
+    {
+        // default does nothing
+    }
+
+}

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

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

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java?rev=793842&r1=793841&r2=793842&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java Tue Jul 14 10:42:34 2009
@@ -180,6 +180,8 @@
 
         pluginManagementInjector.injectBasicManagement( resultModel, request );
 
+        fireBuildExtensionsAssembled( resultModel, request, problems );
+
         if ( request.isProcessPlugins() )
         {
             lifecycleBindingsInjector.injectLifecycleBindings( resultModel );
@@ -226,18 +228,6 @@
         return result;
     }
 
-    private ProfileActivationContext getProfileActivationContext( File pomFile, ModelBuildingRequest request )
-    {
-        ProfileActivationContext context = new DefaultProfileActivationContext();
-
-        context.setActiveProfileIds( request.getActiveProfileIds() );
-        context.setInactiveProfileIds( request.getInactiveProfileIds() );
-        context.setExecutionProperties( request.getExecutionProperties() );
-        context.setProjectDirectory( ( pomFile != null ) ? pomFile.getParentFile() : null );
-
-        return context;
-    }
-
     private Model readModel( ModelSource modelSource, File pomFile, ModelBuildingRequest request,
                              List<ModelProblem> problems )
         throws ModelBuildingException
@@ -310,6 +300,18 @@
         }
     }
 
+    private ProfileActivationContext getProfileActivationContext( File pomFile, ModelBuildingRequest request )
+    {
+        ProfileActivationContext context = new DefaultProfileActivationContext();
+
+        context.setActiveProfileIds( request.getActiveProfileIds() );
+        context.setInactiveProfileIds( request.getInactiveProfileIds() );
+        context.setExecutionProperties( request.getExecutionProperties() );
+        context.setProjectDirectory( ( pomFile != null ) ? pomFile.getParentFile() : null );
+
+        return context;
+    }
+
     private List<Profile> getActiveExternalProfiles( ModelBuildingRequest request, ProfileActivationContext context,
                                                      List<ModelProblem> problems )
     {
@@ -509,6 +511,30 @@
         return ModelUtils.cloneModel( superPomProvider.getSuperModel( "4.0.0" ) );
     }
 
+    private void fireBuildExtensionsAssembled( Model model, ModelBuildingRequest request, List<ModelProblem> problems )
+        throws ModelBuildingException
+    {
+        if ( request.getModelBuildingListeners().isEmpty() )
+        {
+            return;
+        }
+
+        ModelBuildingEvent event = new DefaultModelBuildingEvent( model, request );
+
+        for ( ModelBuildingListener listener : request.getModelBuildingListeners() )
+        {
+            try
+            {
+                listener.buildExtensionsAssembled( event );
+            }
+            catch ( Exception e )
+            {
+                problems.add( new ModelProblem( "Invalid build extensions: " + e.getMessage(),
+                                                ModelProblem.Severity.ERROR, toSourceHint( model ), e ) );
+            }
+        }
+    }
+
     private String toSourceHint( Model model )
     {
         StringBuilder buffer = new StringBuilder( 128 );

Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java?rev=793842&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java (added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java Tue Jul 14 10:42:34 2009
@@ -0,0 +1,53 @@
+package org.apache.maven.model.building;
+
+/*
+ * 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;
+
+/**
+ * Holds data relevant for a model building event.
+ * 
+ * @author Benjamin Bentmann
+ */
+class DefaultModelBuildingEvent
+    implements ModelBuildingEvent
+{
+
+    private Model model;
+
+    private ModelBuildingRequest request;
+
+    public DefaultModelBuildingEvent( Model model, ModelBuildingRequest request )
+    {
+        this.model = model;
+        this.request = request;
+    }
+
+    public Model getModel()
+    {
+        return model;
+    }
+
+    public ModelBuildingRequest getRequest()
+    {
+        return request;
+    }
+
+}

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

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

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java?rev=793842&r1=793841&r2=793842&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java Tue Jul 14 10:42:34 2009
@@ -52,6 +52,8 @@
 
     private ModelResolver modelResolver;
 
+    private List<ModelBuildingListener> modelBuildingListeners;
+
     public int getValidationLevel()
     {
         return validationLevel;
@@ -197,4 +199,28 @@
         return this;
     }
 
+    public List<ModelBuildingListener> getModelBuildingListeners()
+    {
+        if ( modelBuildingListeners == null )
+        {
+            modelBuildingListeners = new ArrayList<ModelBuildingListener>();
+        }
+
+        return modelBuildingListeners;
+    }
+
+    public ModelBuildingRequest setModelBuildingListeners( List<? extends ModelBuildingListener> modelBuildingListeners )
+    {
+        if ( modelBuildingListeners != null )
+        {
+            this.modelBuildingListeners = new ArrayList<ModelBuildingListener>( modelBuildingListeners );
+        }
+        else
+        {
+            this.modelBuildingListeners = null;
+        }
+
+        return this;
+    }
+
 }

Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEvent.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEvent.java?rev=793842&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEvent.java (added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEvent.java Tue Jul 14 10:42:34 2009
@@ -0,0 +1,46 @@
+package org.apache.maven.model.building;
+
+/*
+ * 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;
+
+/**
+ * Holds data relevant for a model building event.
+ * 
+ * @author Benjamin Bentmann
+ */
+public interface ModelBuildingEvent
+{
+
+    /**
+     * The model being built. The precise state of this model depends on the event being fired.
+     * 
+     * @return The model being built, never {@code null}.
+     */
+    Model getModel();
+
+    /**
+     * The model building request being processed.
+     * 
+     * @return The model building request being processed, never {@code null}.
+     */
+    ModelBuildingRequest getRequest();
+
+}

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

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

Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingListener.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingListener.java?rev=793842&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingListener.java (added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingListener.java Tue Jul 14 10:42:34 2009
@@ -0,0 +1,41 @@
+package org.apache.maven.model.building;
+
+/*
+ * 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.
+ */
+
+/**
+ * Defines events that the model builder fires during construction of the effective model. Unless otherwise noted, an
+ * exception thrown by the listener during processing of the event will be treated as a fatal error and aborts building
+ * of the corresponding model.
+ * 
+ * @author Benjamin Bentmann
+ */
+public interface ModelBuildingListener
+{
+
+    /**
+     * Notifies the listener that the model has been constructed to the extent where build extensions can be processed.
+     * 
+     * @param event The details about the event.
+     * @throws Exception If the listener encountered an error.
+     */
+    void buildExtensionsAssembled( ModelBuildingEvent event )
+        throws Exception;
+
+}

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

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

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java?rev=793842&r1=793841&r2=793842&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java Tue Jul 14 10:42:34 2009
@@ -188,4 +188,19 @@
      */
     ModelBuildingRequest setModelResolver( ModelResolver modelResolver );
 
+    /**
+     * Gets the model building listeners to notify during the build process.
+     * 
+     * @return The model building listeners to notify, never {@code null}.
+     */
+    List<ModelBuildingListener> getModelBuildingListeners();
+
+    /**
+     * Sets the model building listeners to notify during the build process.
+     * 
+     * @param modelBuildingListeners The model building listeners to notify, may be {@code null}.
+     * @return This request, never {@code null}.
+     */
+    ModelBuildingRequest setModelBuildingListeners( List<? extends ModelBuildingListener> modelBuildingListeners );
+
 }

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java?rev=793842&r1=793841&r2=793842&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java Tue Jul 14 10:42:34 2009
@@ -109,7 +109,7 @@
         addZeroTokens( valueTokens, max );
         addZeroTokens( rangeValueTokens, max );
 
-        if ( value.equals( rangeValue.value ) )
+        if ( value.equals( rangeValue.getValue() ) )
         {
             if ( !rangeValue.isClosed() )
             {