o Introduced model building listener

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@793842 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-07-14 10:42:34 +00:00
parent d8ff78d643
commit faa082995e
8 changed files with 257 additions and 13 deletions

View File

@ -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
}
}

View File

@ -180,6 +180,8 @@ public class DefaultModelBuilder
pluginManagementInjector.injectBasicManagement( resultModel, request ); pluginManagementInjector.injectBasicManagement( resultModel, request );
fireBuildExtensionsAssembled( resultModel, request, problems );
if ( request.isProcessPlugins() ) if ( request.isProcessPlugins() )
{ {
lifecycleBindingsInjector.injectLifecycleBindings( resultModel ); lifecycleBindingsInjector.injectLifecycleBindings( resultModel );
@ -226,18 +228,6 @@ public class DefaultModelBuilder
return result; 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, private Model readModel( ModelSource modelSource, File pomFile, ModelBuildingRequest request,
List<ModelProblem> problems ) List<ModelProblem> problems )
throws ModelBuildingException throws ModelBuildingException
@ -310,6 +300,18 @@ public class DefaultModelBuilder
} }
} }
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, private List<Profile> getActiveExternalProfiles( ModelBuildingRequest request, ProfileActivationContext context,
List<ModelProblem> problems ) List<ModelProblem> problems )
{ {
@ -509,6 +511,30 @@ public class DefaultModelBuilder
return ModelUtils.cloneModel( superPomProvider.getSuperModel( "4.0.0" ) ); 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 ) private String toSourceHint( Model model )
{ {
StringBuilder buffer = new StringBuilder( 128 ); StringBuilder buffer = new StringBuilder( 128 );

View File

@ -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;
}
}

View File

@ -52,6 +52,8 @@ public class DefaultModelBuildingRequest
private ModelResolver modelResolver; private ModelResolver modelResolver;
private List<ModelBuildingListener> modelBuildingListeners;
public int getValidationLevel() public int getValidationLevel()
{ {
return validationLevel; return validationLevel;
@ -197,4 +199,28 @@ public class DefaultModelBuildingRequest
return this; 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;
}
} }

View File

@ -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();
}

View File

@ -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;
}

View File

@ -188,4 +188,19 @@ public interface ModelBuildingRequest
*/ */
ModelBuildingRequest setModelResolver( ModelResolver modelResolver ); 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 );
} }

View File

@ -109,7 +109,7 @@ public class JdkVersionProfileActivator
addZeroTokens( valueTokens, max ); addZeroTokens( valueTokens, max );
addZeroTokens( rangeValueTokens, max ); addZeroTokens( rangeValueTokens, max );
if ( value.equals( rangeValue.value ) ) if ( value.equals( rangeValue.getValue() ) )
{ {
if ( !rangeValue.isClosed() ) if ( !rangeValue.isClosed() )
{ {