From 9fd6f2696d375084db6e0d562fbd8af51c605284 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 5 Apr 2007 21:26:44 +0000 Subject: [PATCH] Correcting project model filters. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@525966 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-repository-layer/pom.xml | 23 ++++------ .../project/ProjectModelFilter.java | 3 +- ....java => EffectiveProjectModelFilter.java} | 21 ++++++--- ...java => ProjectModelExpressionFilter.java} | 33 +++++++++----- .../resources/META-INF/plexus/components.xml | 43 ------------------- .../repository/project/filters/AllTests.java | 2 +- ...a => EffectiveProjectModelFilterTest.java} | 19 +++++--- .../ProjectModelExpressionExpanderTest.java | 19 +++++--- 8 files changed, 73 insertions(+), 90 deletions(-) rename archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/{EffectiveProjectModelBuilder.java => EffectiveProjectModelFilter.java} (92%) rename archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/{ProjectModelExpressionExpander.java => ProjectModelExpressionFilter.java} (75%) delete mode 100644 archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components.xml rename archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/{EffectiveProjectModelBuilderTest.java => EffectiveProjectModelFilterTest.java} (90%) diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/pom.xml b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/pom.xml index 33b2aaee9..5561d5948 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/pom.xml +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/pom.xml @@ -36,7 +36,6 @@ org.apache.maven.archiva archiva-model - 1.0-SNAPSHOT org.apache.maven.archiva @@ -64,20 +63,6 @@ 1.0-alpha-2-SNAPSHOT compile - org.slf4j slf4j-log4j12 @@ -89,6 +74,13 @@ org.codehaus.plexus plexus-maven-plugin + + descriptor + + descriptor + + + diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelFilter.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelFilter.java index e00943360..fe23970d4 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelFilter.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelFilter.java @@ -34,6 +34,7 @@ public interface ProjectModelFilter * * @param model the model to filter. * @return a new model representing the filtered state of the model. + * @throws ProjectModelException if there was a problem executing the filter. */ - public ArchivaProjectModel filter( final ArchivaProjectModel model ); + public ArchivaProjectModel filter( final ArchivaProjectModel model ) throws ProjectModelException; } diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilder.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilter.java similarity index 92% rename from archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilder.java rename to archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilter.java index 549c049a0..33083768b 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilder.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilter.java @@ -25,6 +25,7 @@ import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.Dependency; import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.project.ProjectModelException; +import org.apache.maven.archiva.repository.project.ProjectModelFilter; import org.apache.maven.archiva.repository.project.ProjectModelMerge; import org.apache.maven.archiva.repository.project.ProjectModelResolver; @@ -39,12 +40,20 @@ import java.util.Map; * * @author Joakim Erdfelt * @version $Id$ + * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelFilter" + * role-hint="effective" + * instantiation-strategy="per-lookup" */ -public class EffectiveProjectModelBuilder +public class EffectiveProjectModelFilter implements ProjectModelFilter { + /** + * @plexus.requirement role-hint="expression" + */ + private ProjectModelFilter expressionFilter; + private List projectModelResolvers; - - public EffectiveProjectModelBuilder() + + public EffectiveProjectModelFilter() { projectModelResolvers = new ArrayList(); } @@ -71,7 +80,7 @@ public class EffectiveProjectModelBuilder * @return a the effective {@link ArchivaProjectModel}. * @throws ProjectModelException if there was a problem building the effective pom. */ - public ArchivaProjectModel buildEffectiveProjectModel( ArchivaProjectModel project ) + public ArchivaProjectModel filter( final ArchivaProjectModel project ) throws ProjectModelException { if ( project == null ) @@ -88,7 +97,7 @@ public class EffectiveProjectModelBuilder ArchivaProjectModel effectiveProject = ArchivaModelCloner.clone( project ); // Setup Expression Evaluation pieces. - ProjectModelExpressionExpander.evaluateExpressions( effectiveProject ); + effectiveProject = expressionFilter.filter( effectiveProject ); debug( "Starting build of effective with: " + effectiveProject ); @@ -197,7 +206,7 @@ public class EffectiveProjectModelBuilder if ( parentProject != null ) { - ProjectModelExpressionExpander.evaluateExpressions( parentProject ); + parentProject = expressionFilter.filter( parentProject ); parentProject = mergeParent( parentProject ); mixedProject = ProjectModelMerge.merge( pom, parentProject ); } diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpander.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionFilter.java similarity index 75% rename from archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpander.java rename to archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionFilter.java index 764c7302e..6dd44b9a4 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpander.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionFilter.java @@ -19,10 +19,11 @@ package org.apache.maven.archiva.repository.project.filters; * under the License. */ +import org.apache.maven.archiva.model.ArchivaModelCloner; import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.Dependency; import org.apache.maven.archiva.repository.project.ProjectModelException; -import org.codehaus.plexus.evaluator.DefaultExpressionEvaluator; +import org.apache.maven.archiva.repository.project.ProjectModelFilter; import org.codehaus.plexus.evaluator.EvaluatorException; import org.codehaus.plexus.evaluator.ExpressionEvaluator; import org.codehaus.plexus.evaluator.sources.PropertiesExpressionSource; @@ -32,24 +33,30 @@ import java.util.Iterator; import java.util.List; /** - * ProjectModelExpressionExpander + * ProjectModelExpressionFilter * * @author Joakim Erdfelt * @version $Id$ - * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelExpressionExpander" + * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelFilter" + * role-hint="expression" + * instantiation-strategy="per-lookup" */ -public class ProjectModelExpressionExpander +public class ProjectModelExpressionFilter + implements ProjectModelFilter { + /** + * @plexus.requirement + */ + private ExpressionEvaluator evaluator; + /** * Find and Evaluate the Expressions present in the model. * * @param model the model to correct. */ - public static void evaluateExpressions( ArchivaProjectModel model ) + public ArchivaProjectModel filter( final ArchivaProjectModel model ) throws ProjectModelException { - ExpressionEvaluator evaluator = new DefaultExpressionEvaluator(); - if ( model.getProperties() != null ) { PropertiesExpressionSource propsSource = new PropertiesExpressionSource(); @@ -59,18 +66,22 @@ public class ProjectModelExpressionExpander evaluator.addExpressionSource( new SystemPropertyExpressionSource() ); + ArchivaProjectModel ret = ArchivaModelCloner.clone( model ); + try { - model.setVersion( evaluator.expand( model.getVersion() ) ); - model.setGroupId( evaluator.expand( model.getGroupId() ) ); + ret.setVersion( evaluator.expand( ret.getVersion() ) ); + ret.setGroupId( evaluator.expand( ret.getGroupId() ) ); - evaluateExpressionsInDependencyList( evaluator, model.getDependencies() ); - evaluateExpressionsInDependencyList( evaluator, model.getDependencyManagement() ); + evaluateExpressionsInDependencyList( evaluator, ret.getDependencies() ); + evaluateExpressionsInDependencyList( evaluator, ret.getDependencyManagement() ); } catch ( EvaluatorException e ) { throw new ProjectModelException( "Unable to evaluate expression in model: " + e.getMessage(), e ); } + + return ret; } private static void evaluateExpressionsInDependencyList( ExpressionEvaluator evaluator, List dependencies ) diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components.xml b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index c2ee003f5..000000000 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - org.codehaus.plexus.cache.Cache - repository-query - org.codehaus.plexus.cache.ehcache.EhcacheCache - EhcacheCache - - 600 - true - ${java.io.tmpdir}/ehcache/repo-query - false - 1000 - LRU - repository-query - false - 600 - 300 - - - - diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/AllTests.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/AllTests.java index a4bf59f96..f004a0ad8 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/AllTests.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/AllTests.java @@ -36,7 +36,7 @@ public class AllTests TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.repository.project.filters" ); //$JUnit-BEGIN$ suite.addTestSuite( ProjectModelExpressionExpanderTest.class ); - suite.addTestSuite( EffectiveProjectModelBuilderTest.class ); + suite.addTestSuite( EffectiveProjectModelFilterTest.class ); //$JUnit-END$ return suite; } diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilderTest.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java similarity index 90% rename from archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilderTest.java rename to archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java index fd82b345a..6a2d976e6 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilderTest.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java @@ -23,9 +23,10 @@ import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.Dependency; import org.apache.maven.archiva.repository.project.ProjectModelException; +import org.apache.maven.archiva.repository.project.ProjectModelFilter; import org.apache.maven.archiva.repository.project.ProjectModelReader; import org.apache.maven.archiva.repository.project.ProjectModelResolver; -import org.apache.maven.archiva.repository.project.filters.EffectiveProjectModelBuilder; +import org.apache.maven.archiva.repository.project.filters.EffectiveProjectModelFilter; import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader; import org.apache.maven.archiva.repository.project.resolvers.RepositoryProjectResolver; import org.codehaus.plexus.PlexusTestCase; @@ -35,15 +36,20 @@ import java.util.Iterator; import java.util.List; /** - * EffectiveProjectModelBuilderTest + * EffectiveProjectModelFilterTest * * @author Joakim Erdfelt * @version $Id$ */ -public class EffectiveProjectModelBuilderTest +public class EffectiveProjectModelFilterTest extends PlexusTestCase { private static final String DEFAULT_REPOSITORY = "src/test/repositories/default-repository"; + + private EffectiveProjectModelFilter lookupEffective() throws Exception + { + return (EffectiveProjectModelFilter) lookup( ProjectModelFilter.class, "effective" ); + } private ArchivaProjectModel createArchivaProjectModel( String path ) throws ProjectModelException @@ -70,13 +76,14 @@ public class EffectiveProjectModelBuilderTest public void testBuildEffectiveProject() throws Exception { - EffectiveProjectModelBuilder builder = new EffectiveProjectModelBuilder(); - builder.addProjectModelResolver( createDefaultRepositoryResolver() ); + EffectiveProjectModelFilter filter = lookupEffective(); + + filter.addProjectModelResolver( createDefaultRepositoryResolver() ); ArchivaProjectModel startModel = createArchivaProjectModel( DEFAULT_REPOSITORY + "/org/apache/maven/archiva/archiva-model/1.0-SNAPSHOT/archiva-model-1.0-SNAPSHOT.pom" ); - ArchivaProjectModel effectiveModel = builder.buildEffectiveProjectModel( startModel ); + ArchivaProjectModel effectiveModel = filter.filter( startModel ); ArchivaProjectModel expectedModel = createArchivaProjectModel( "src/test/effective-poms/" + "/archiva-model-effective.pom" ); diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java index ed06ac95a..911b789c4 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java @@ -21,13 +21,11 @@ package org.apache.maven.archiva.repository.project.filters; import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.Dependency; -import org.apache.maven.archiva.repository.project.ProjectModelException; -import org.apache.maven.archiva.repository.project.filters.ProjectModelExpressionExpander; +import org.apache.maven.archiva.repository.project.ProjectModelFilter; +import org.codehaus.plexus.PlexusTestCase; import java.util.Iterator; -import junit.framework.TestCase; - /** * ProjectModelExpressionExpanderTest * @@ -35,10 +33,15 @@ import junit.framework.TestCase; * @version $Id$ */ public class ProjectModelExpressionExpanderTest - extends TestCase + extends PlexusTestCase { + private ProjectModelExpressionFilter lookupExpression() throws Exception + { + return (ProjectModelExpressionFilter) lookup( ProjectModelFilter.class, "expression" ); + } + public void testExpressionEvaluation() - throws ProjectModelException + throws Exception { ArchivaProjectModel model = new ArchivaProjectModel(); model.setGroupId( "org.apache.maven.archiva" ); @@ -51,7 +54,9 @@ public class ProjectModelExpressionExpanderTest model.addProperty( "archiva.version", "1.0-SNAPSHOT" ); - ProjectModelExpressionExpander.evaluateExpressions( model ); + ProjectModelExpressionFilter filter = lookupExpression(); + + model = filter.filter( model ); assertNotNull( model ); assertEquals( "Group ID", "org.apache.maven.archiva", model.getGroupId() ); -- 2.39.5