o Refactored code

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@805332 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-18 09:36:45 +00:00
parent 6499386f49
commit 7cae21ebf5
2 changed files with 58 additions and 10 deletions

View File

@ -217,7 +217,7 @@ public class DefaultModelBuilder
pluginManagementInjector.injectBasicManagement( resultModel, request, problems );
fireBuildExtensionsAssembled( resultModel, request, problems );
fireEvent( resultModel, request, problems, ModelBuildingEventCatapult.BUILD_EXTENSIONS_ASSEMBLED );
if ( request.isProcessPlugins() )
{
@ -663,19 +663,20 @@ public class DefaultModelBuilder
return null;
}
private void fireBuildExtensionsAssembled( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
private void fireEvent( Model model, ModelBuildingRequest request, ModelProblemCollector problems,
ModelBuildingEventCatapult catapult )
throws ModelBuildingException
{
if ( request.getModelBuildingListeners().isEmpty() )
{
return;
}
List<ModelBuildingListener> listeners = request.getModelBuildingListeners();
ModelBuildingEvent event = new DefaultModelBuildingEvent( model, request, problems );
for ( ModelBuildingListener listener : request.getModelBuildingListeners() )
if ( !listeners.isEmpty() )
{
listener.buildExtensionsAssembled( event );
ModelBuildingEvent event = new DefaultModelBuildingEvent( model, request, problems );
for ( ModelBuildingListener listener : listeners )
{
catapult.fire( listener, event );
}
}
}

View File

@ -0,0 +1,47 @@
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.
*/
/**
* Assists in firing events from a generic method by abstracting from the actual callback method to be called on the
* listener.
*
* @author Benjamin Bentmann
*/
interface ModelBuildingEventCatapult
{
/**
* Notifies the specified listener of the given event.
*
* @param listener The listener to notify, must not be {@code null}.
* @param event The event to fire, must not be {@code null}.
*/
void fire( ModelBuildingListener listener, ModelBuildingEvent event );
static final ModelBuildingEventCatapult BUILD_EXTENSIONS_ASSEMBLED = new ModelBuildingEventCatapult()
{
public void fire( ModelBuildingListener listener, ModelBuildingEvent event )
{
listener.buildExtensionsAssembled( event );
}
};
}