Correcting project model filters.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@525966 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-04-05 21:26:44 +00:00
parent df909125ed
commit 6114332b91
8 changed files with 73 additions and 90 deletions

View File

@ -36,7 +36,6 @@
<dependency> <dependency>
<groupId>org.apache.maven.archiva</groupId> <groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-model</artifactId> <artifactId>archiva-model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.maven.archiva</groupId> <groupId>org.apache.maven.archiva</groupId>
@ -64,20 +63,6 @@
<version>1.0-alpha-2-SNAPSHOT</version> <version>1.0-alpha-2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!--
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
</dependency>
-->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
@ -89,6 +74,13 @@
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId> <artifactId>plexus-maven-plugin</artifactId>
<executions> <executions>
<execution>
<id>descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
<!--
<execution> <execution>
<id>merge</id> <id>merge</id>
<goals> <goals>
@ -101,6 +93,7 @@
</descriptors> </descriptors>
</configuration> </configuration>
</execution> </execution>
-->
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -34,6 +34,7 @@ public interface ProjectModelFilter
* *
* @param model the model to filter. * @param model the model to filter.
* @return a new model representing the filtered state of the model. * @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;
} }

View File

@ -25,6 +25,7 @@ import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.Dependency; import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.project.ProjectModelException; 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.ProjectModelMerge;
import org.apache.maven.archiva.repository.project.ProjectModelResolver; import org.apache.maven.archiva.repository.project.ProjectModelResolver;
@ -39,12 +40,20 @@ import java.util.Map;
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$ * @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; private List projectModelResolvers;
public EffectiveProjectModelBuilder() public EffectiveProjectModelFilter()
{ {
projectModelResolvers = new ArrayList(); projectModelResolvers = new ArrayList();
} }
@ -71,7 +80,7 @@ public class EffectiveProjectModelBuilder
* @return a the effective {@link ArchivaProjectModel}. * @return a the effective {@link ArchivaProjectModel}.
* @throws ProjectModelException if there was a problem building the effective pom. * @throws ProjectModelException if there was a problem building the effective pom.
*/ */
public ArchivaProjectModel buildEffectiveProjectModel( ArchivaProjectModel project ) public ArchivaProjectModel filter( final ArchivaProjectModel project )
throws ProjectModelException throws ProjectModelException
{ {
if ( project == null ) if ( project == null )
@ -88,7 +97,7 @@ public class EffectiveProjectModelBuilder
ArchivaProjectModel effectiveProject = ArchivaModelCloner.clone( project ); ArchivaProjectModel effectiveProject = ArchivaModelCloner.clone( project );
// Setup Expression Evaluation pieces. // Setup Expression Evaluation pieces.
ProjectModelExpressionExpander.evaluateExpressions( effectiveProject ); effectiveProject = expressionFilter.filter( effectiveProject );
debug( "Starting build of effective with: " + effectiveProject ); debug( "Starting build of effective with: " + effectiveProject );
@ -197,7 +206,7 @@ public class EffectiveProjectModelBuilder
if ( parentProject != null ) if ( parentProject != null )
{ {
ProjectModelExpressionExpander.evaluateExpressions( parentProject ); parentProject = expressionFilter.filter( parentProject );
parentProject = mergeParent( parentProject ); parentProject = mergeParent( parentProject );
mixedProject = ProjectModelMerge.merge( pom, parentProject ); mixedProject = ProjectModelMerge.merge( pom, parentProject );
} }

View File

@ -19,10 +19,11 @@ package org.apache.maven.archiva.repository.project.filters;
* under the License. * under the License.
*/ */
import org.apache.maven.archiva.model.ArchivaModelCloner;
import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.Dependency; import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.repository.project.ProjectModelException; 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.EvaluatorException;
import org.codehaus.plexus.evaluator.ExpressionEvaluator; import org.codehaus.plexus.evaluator.ExpressionEvaluator;
import org.codehaus.plexus.evaluator.sources.PropertiesExpressionSource; import org.codehaus.plexus.evaluator.sources.PropertiesExpressionSource;
@ -32,24 +33,30 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* ProjectModelExpressionExpander * ProjectModelExpressionFilter
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$ * @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. * Find and Evaluate the Expressions present in the model.
* *
* @param model the model to correct. * @param model the model to correct.
*/ */
public static void evaluateExpressions( ArchivaProjectModel model ) public ArchivaProjectModel filter( final ArchivaProjectModel model )
throws ProjectModelException throws ProjectModelException
{ {
ExpressionEvaluator evaluator = new DefaultExpressionEvaluator();
if ( model.getProperties() != null ) if ( model.getProperties() != null )
{ {
PropertiesExpressionSource propsSource = new PropertiesExpressionSource(); PropertiesExpressionSource propsSource = new PropertiesExpressionSource();
@ -59,18 +66,22 @@ public class ProjectModelExpressionExpander
evaluator.addExpressionSource( new SystemPropertyExpressionSource() ); evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
ArchivaProjectModel ret = ArchivaModelCloner.clone( model );
try try
{ {
model.setVersion( evaluator.expand( model.getVersion() ) ); ret.setVersion( evaluator.expand( ret.getVersion() ) );
model.setGroupId( evaluator.expand( model.getGroupId() ) ); ret.setGroupId( evaluator.expand( ret.getGroupId() ) );
evaluateExpressionsInDependencyList( evaluator, model.getDependencies() ); evaluateExpressionsInDependencyList( evaluator, ret.getDependencies() );
evaluateExpressionsInDependencyList( evaluator, model.getDependencyManagement() ); evaluateExpressionsInDependencyList( evaluator, ret.getDependencyManagement() );
} }
catch ( EvaluatorException e ) catch ( EvaluatorException e )
{ {
throw new ProjectModelException( "Unable to evaluate expression in model: " + e.getMessage(), e ); throw new ProjectModelException( "Unable to evaluate expression in model: " + e.getMessage(), e );
} }
return ret;
} }
private static void evaluateExpressionsInDependencyList( ExpressionEvaluator evaluator, List dependencies ) private static void evaluateExpressionsInDependencyList( ExpressionEvaluator evaluator, List dependencies )

View File

@ -1,43 +0,0 @@
<?xml version="1.0" ?>
<!--
~ 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.
-->
<component-set>
<components>
<component>
<role>org.codehaus.plexus.cache.Cache</role>
<role-hint>repository-query</role-hint>
<implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
<description>EhcacheCache</description>
<configuration>
<disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
<disk-persistent>true</disk-persistent>
<disk-store-path>${java.io.tmpdir}/ehcache/repo-query</disk-store-path>
<eternal>false</eternal>
<max-elements-in-memory>1000</max-elements-in-memory>
<memory-eviction-policy>LRU</memory-eviction-policy>
<name>repository-query</name>
<overflow-to-disk>false</overflow-to-disk>
<time-to-idle-seconds>600</time-to-idle-seconds>
<time-to-live-seconds>300</time-to-live-seconds>
</configuration>
</component>
</components>
</component-set>

View File

@ -36,7 +36,7 @@ public class AllTests
TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.repository.project.filters" ); TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.repository.project.filters" );
//$JUnit-BEGIN$ //$JUnit-BEGIN$
suite.addTestSuite( ProjectModelExpressionExpanderTest.class ); suite.addTestSuite( ProjectModelExpressionExpanderTest.class );
suite.addTestSuite( EffectiveProjectModelBuilderTest.class ); suite.addTestSuite( EffectiveProjectModelFilterTest.class );
//$JUnit-END$ //$JUnit-END$
return suite; return suite;
} }

View File

@ -23,9 +23,10 @@ import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.Dependency; import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.repository.project.ProjectModelException; 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.ProjectModelReader;
import org.apache.maven.archiva.repository.project.ProjectModelResolver; 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.readers.ProjectModel400Reader;
import org.apache.maven.archiva.repository.project.resolvers.RepositoryProjectResolver; import org.apache.maven.archiva.repository.project.resolvers.RepositoryProjectResolver;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
@ -35,16 +36,21 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* EffectiveProjectModelBuilderTest * EffectiveProjectModelFilterTest
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$ * @version $Id$
*/ */
public class EffectiveProjectModelBuilderTest public class EffectiveProjectModelFilterTest
extends PlexusTestCase extends PlexusTestCase
{ {
private static final String DEFAULT_REPOSITORY = "src/test/repositories/default-repository"; 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 ) private ArchivaProjectModel createArchivaProjectModel( String path )
throws ProjectModelException throws ProjectModelException
{ {
@ -70,13 +76,14 @@ public class EffectiveProjectModelBuilderTest
public void testBuildEffectiveProject() public void testBuildEffectiveProject()
throws Exception throws Exception
{ {
EffectiveProjectModelBuilder builder = new EffectiveProjectModelBuilder(); EffectiveProjectModelFilter filter = lookupEffective();
builder.addProjectModelResolver( createDefaultRepositoryResolver() );
filter.addProjectModelResolver( createDefaultRepositoryResolver() );
ArchivaProjectModel startModel = createArchivaProjectModel( DEFAULT_REPOSITORY ArchivaProjectModel startModel = createArchivaProjectModel( DEFAULT_REPOSITORY
+ "/org/apache/maven/archiva/archiva-model/1.0-SNAPSHOT/archiva-model-1.0-SNAPSHOT.pom" ); + "/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/" ArchivaProjectModel expectedModel = createArchivaProjectModel( "src/test/effective-poms/"
+ "/archiva-model-effective.pom" ); + "/archiva-model-effective.pom" );

View File

@ -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.ArchivaProjectModel;
import org.apache.maven.archiva.model.Dependency; 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.filters.ProjectModelExpressionExpander; import org.codehaus.plexus.PlexusTestCase;
import java.util.Iterator; import java.util.Iterator;
import junit.framework.TestCase;
/** /**
* ProjectModelExpressionExpanderTest * ProjectModelExpressionExpanderTest
* *
@ -35,10 +33,15 @@ import junit.framework.TestCase;
* @version $Id$ * @version $Id$
*/ */
public class ProjectModelExpressionExpanderTest public class ProjectModelExpressionExpanderTest
extends TestCase extends PlexusTestCase
{ {
private ProjectModelExpressionFilter lookupExpression() throws Exception
{
return (ProjectModelExpressionFilter) lookup( ProjectModelFilter.class, "expression" );
}
public void testExpressionEvaluation() public void testExpressionEvaluation()
throws ProjectModelException throws Exception
{ {
ArchivaProjectModel model = new ArchivaProjectModel(); ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( "org.apache.maven.archiva" ); model.setGroupId( "org.apache.maven.archiva" );
@ -51,7 +54,9 @@ public class ProjectModelExpressionExpanderTest
model.addProperty( "archiva.version", "1.0-SNAPSHOT" ); model.addProperty( "archiva.version", "1.0-SNAPSHOT" );
ProjectModelExpressionExpander.evaluateExpressions( model ); ProjectModelExpressionFilter filter = lookupExpression();
model = filter.filter( model );
assertNotNull( model ); assertNotNull( model );
assertEquals( "Group ID", "org.apache.maven.archiva", model.getGroupId() ); assertEquals( "Group ID", "org.apache.maven.archiva", model.getGroupId() );