mirror of https://github.com/apache/archiva.git
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:
parent
df909125ed
commit
6114332b91
|
@ -36,7 +36,6 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.maven.archiva</groupId>
|
||||
<artifactId>archiva-model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.archiva</groupId>
|
||||
|
@ -64,20 +63,6 @@
|
|||
<version>1.0-alpha-2-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</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>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
|
@ -89,6 +74,13 @@
|
|||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>descriptor</id>
|
||||
<goals>
|
||||
<goal>descriptor</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<!--
|
||||
<execution>
|
||||
<id>merge</id>
|
||||
<goals>
|
||||
|
@ -101,6 +93,7 @@
|
|||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
-->
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @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 );
|
||||
}
|
|
@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @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 )
|
|
@ -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>
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @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" );
|
|
@ -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() );
|
||||
|
|
Loading…
Reference in New Issue