From 1a9ef5d0e0aa5c802a300671e2c073818fde9250 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Fri, 14 Nov 2008 19:18:09 +0000 Subject: [PATCH] Added in Project Event Listeners. Still need to hook up a plexus component and a model container factory for configuring listeners. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@714109 13f79535-47bb-0310-9956-ffa450edef68 --- .../builder/PomClassicTransformer.java | 23 +++++++++++++++++-- .../builder/ProjectEventListeners.java | 4 ++++ .../builder/impl/DefaultProjectBuilder.java | 3 ++- .../shared/model/ModelEventListener.java | 13 +++++++++++ .../maven/shared/model/ModelTransformer.java | 2 +- .../shared/model/ModelTransformerContext.java | 20 ++++++++++++---- 6 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 maven-project/src/main/java/org/apache/maven/project/builder/ProjectEventListeners.java create mode 100644 maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelEventListener.java diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java index 6279905334..8187c5270e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java @@ -115,9 +115,9 @@ public final class PomClassicTransformer } /** - * @see ModelTransformer#transformToDomainModel(java.util.List) + * @see ModelTransformer#transformToDomainModel(java.util.List, java.util.List) */ - public DomainModel transformToDomainModel( List properties ) + public DomainModel transformToDomainModel( List properties, List eventListeners) throws IOException { if ( properties == null ) @@ -125,6 +125,15 @@ public final class PomClassicTransformer throw new IllegalArgumentException( "properties: null" ); } + if( eventListeners == null ) + { + eventListeners = new ArrayList(); + } + else + { + eventListeners = new ArrayList(eventListeners); + } + List props = new ArrayList( properties ); //dependency management @@ -226,6 +235,16 @@ public final class PomClassicTransformer } props.removeAll( removeProperties ); + for(ModelEventListener listener : eventListeners) + { + ModelDataSource ds = new DefaultModelDataSource(); + ds.init( props, listener.getModelContainerFactories() ); + for(String uri : listener.getUris() ) + { + listener.fire(ds.queryFor(uri)); + } + } + String xml = null; try { diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectEventListeners.java b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectEventListeners.java new file mode 100644 index 0000000000..bc3609caa9 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectEventListeners.java @@ -0,0 +1,4 @@ +package org.apache.maven.project.builder; + +public class ProjectEventListeners { +} diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java index f1b56a6184..540f009399 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java @@ -177,7 +177,8 @@ public final class DefaultProjectBuilder transformer, transformer, importModels, - properties ) ); + properties, + null) ); try { MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory, diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelEventListener.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelEventListener.java new file mode 100644 index 0000000000..d068e8e5c5 --- /dev/null +++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelEventListener.java @@ -0,0 +1,13 @@ +package org.apache.maven.shared.model; + +import java.util.List; +import java.util.Collection; + +public interface ModelEventListener { + + public void fire(List modelContainers); + + List getUris(); + + Collection getModelContainerFactories(); +} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java index acd05ca3a9..b48ab598c6 100644 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java +++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java @@ -39,7 +39,7 @@ public interface ModelTransformer * @param properties list of model properties to transform into domain model. List may not be null. * @return domain model */ - DomainModel transformToDomainModel( List properties ) + DomainModel transformToDomainModel( List properties, List eventListeners) throws IOException; /** diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java index 282d1ab908..900ce0c0c3 100644 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java +++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java @@ -213,12 +213,24 @@ public final class ModelTransformerContext * @param interpolatorProperties properties to use during interpolation. @return processed domain model * @throws IOException if there was a problem with the transform */ - public DomainModel transform(List domainModels, ModelTransformer fromModelTransformer, + public DomainModel transform(List domainModels, + ModelTransformer fromModelTransformer, ModelTransformer toModelTransformer, - Collection importModels, List interpolatorProperties) + Collection importModels, + List interpolatorProperties, + List eventListeners) throws IOException { + if( eventListeners == null ) + { + eventListeners = new ArrayList(); + } + else + { + eventListeners = new ArrayList(eventListeners); + } + List transformedProperties = importModelProperties(importModels, fromModelTransformer.transformToModelProperties( domainModels)); @@ -290,7 +302,7 @@ public final class ModelTransformerContext try { - DomainModel domainModel = toModelTransformer.transformToDomainModel( mps ); + DomainModel domainModel = toModelTransformer.transformToDomainModel( mps, eventListeners ); domainModel.setEventHistory(modelDataSource.getEventHistory()); return domainModel; } @@ -316,7 +328,7 @@ public final class ModelTransformerContext ModelTransformer toModelTransformer ) throws IOException { - return this.transform( domainModels, fromModelTransformer, toModelTransformer, null, systemInterpolatorProperties ); + return this.transform( domainModels, fromModelTransformer, toModelTransformer, null, systemInterpolatorProperties, null ); } private static List importModelProperties(Collection importModels,