]> source.dussan.org Git - archiva.git/commitdiff
Correcting project model filters.
authorJoakim Erdfelt <joakime@apache.org>
Thu, 5 Apr 2007 21:26:44 +0000 (21:26 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Thu, 5 Apr 2007 21:26:44 +0000 (21:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@525966 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-repository-layer/pom.xml
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelFilter.java
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilder.java [deleted file]
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilter.java [new file with mode: 0644]
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpander.java [deleted file]
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionFilter.java [new file with mode: 0644]
archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components.xml [deleted file]
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/AllTests.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilderTest.java [deleted file]
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java [new file with mode: 0644]
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java

index 33b2aaee9b0d6fa271f2eda366c7e18ca67491b7..5561d5948a427fbbd83d51c549a88436984da35b 100644 (file)
@@ -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>
       <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>
         <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>
               </descriptors>
             </configuration>
           </execution>
+            -->
         </executions>
       </plugin>
     </plugins>
index e00943360b114eee2a2ad604853d408574828aaa..fe23970d430ee278956adc9da4263bf458c3026c 100644 (file)
@@ -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-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilder.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilder.java
deleted file mode 100644 (file)
index 549c049..0000000
+++ /dev/null
@@ -1,269 +0,0 @@
-package org.apache.maven.archiva.repository.project.filters;
-
-/*
- * 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.
- */
-
-import org.apache.commons.lang.StringUtils;
-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.model.VersionedReference;
-import org.apache.maven.archiva.repository.project.ProjectModelException;
-import org.apache.maven.archiva.repository.project.ProjectModelMerge;
-import org.apache.maven.archiva.repository.project.ProjectModelResolver;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Builder for the Effective Project Model.  
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class EffectiveProjectModelBuilder
-{
-    private List projectModelResolvers;
-
-    public EffectiveProjectModelBuilder()
-    {
-        projectModelResolvers = new ArrayList();
-    }
-
-    public void addProjectModelResolver( ProjectModelResolver resolver )
-    {
-        if ( resolver == null )
-        {
-            return;
-        }
-
-        this.projectModelResolvers.add( resolver );
-    }
-
-    /**
-     * Take the provided {@link ArchivaProjectModel} and build the effective {@link ArchivaProjectModel}.
-     * 
-     * Steps:
-     * 1) Expand any expressions / properties.
-     * 2) Walk the parent project references and merge.
-     * 3) Apply dependency management settings.
-     * 
-     * @param project the project to create the effective {@link ArchivaProjectModel} from.
-     * @return a the effective {@link ArchivaProjectModel}.
-     * @throws ProjectModelException if there was a problem building the effective pom.
-     */
-    public ArchivaProjectModel buildEffectiveProjectModel( ArchivaProjectModel project )
-        throws ProjectModelException
-    {
-        if ( project == null )
-        {
-            return null;
-        }
-
-        if ( this.projectModelResolvers.isEmpty() )
-        {
-            throw new IllegalStateException( "Unable to build effective pom with no project model resolvers defined." );
-        }
-
-        // Clone submitted project (so that we don't mess with it) 
-        ArchivaProjectModel effectiveProject = ArchivaModelCloner.clone( project );
-
-        // Setup Expression Evaluation pieces.
-        ProjectModelExpressionExpander.evaluateExpressions( effectiveProject );
-
-        debug( "Starting build of effective with: " + effectiveProject );
-
-        // Merge in all the parent poms.
-        effectiveProject = mergeParent( effectiveProject );
-
-        // Resolve dependency versions from dependency management.
-        applyDependencyManagement( effectiveProject );
-
-        // Return what we got.
-        return effectiveProject;
-    }
-
-    public void removeResolver( ProjectModelResolver resolver )
-    {
-        this.projectModelResolvers.remove( resolver );
-    }
-
-    private void applyDependencyManagement( ArchivaProjectModel pom )
-    {
-        if ( ( pom.getDependencyManagement() == null ) || ( pom.getDependencies() == null ) )
-        {
-            // Nothing to do. All done!
-            return;
-        }
-        
-        if ( pom.getDependencyManagement().isEmpty() || pom.getDependencies().isEmpty() )
-        {
-            // Nothing to do. All done!
-            return;
-        }
-
-        Map managedDependencies = createDependencyMap( pom.getDependencyManagement() );
-        Iterator it = pom.getDependencies().iterator();
-        while ( it.hasNext() )
-        {
-            Dependency dep = (Dependency) it.next();
-            String key = toVersionlessDependencyKey( dep );
-
-            // Do we need to do anything?
-            if ( managedDependencies.containsKey( key ) )
-            {
-                Dependency mgmtDep = (Dependency) managedDependencies.get( key );
-
-                dep.setVersion( mgmtDep.getVersion() );
-                dep.setScope( mgmtDep.getScope() );
-                dep.setExclusions( ProjectModelMerge.mergeExclusions( dep.getExclusions(), mgmtDep.getExclusions() ) );
-            }
-        }
-    }
-
-    private void debug( String msg )
-    {
-        System.out.println( "## " + msg );
-    }
-
-    private ArchivaProjectModel findProject( VersionedReference projectRef )
-    {
-        debug( "Trying to find project: " + projectRef );
-        Iterator it = this.projectModelResolvers.iterator();
-
-        while ( it.hasNext() )
-        {
-            ProjectModelResolver resolver = (ProjectModelResolver) it.next();
-
-            try
-            {
-                debug( "Trying to find in " + resolver.getClass().getName() );
-                ArchivaProjectModel model = resolver.resolveProjectModel( projectRef );
-
-                if ( model != null )
-                {
-                    debug( "Found it!: " + model );
-                    return model;
-                }
-                debug( "Not found." );
-            }
-            catch ( ProjectModelException e )
-            {
-                // TODO: trigger notifier of problem?
-                e.printStackTrace();
-            }
-        }
-
-        // TODO: Document that project was not found. (Use monitor?)
-
-        return null;
-    }
-
-    private ArchivaProjectModel mergeParent( ArchivaProjectModel pom )
-        throws ProjectModelException
-    {
-        ArchivaProjectModel mixedProject;
-
-        debug( "Parent: " + pom.getParentProject() );
-
-        if ( pom.getParentProject() != null )
-        {
-            // Use parent reference.
-            VersionedReference parentRef = pom.getParentProject();
-
-            debug( "Has parent: " + parentRef );
-
-            // Find parent using resolvers.
-            ArchivaProjectModel parentProject = findProject( parentRef );
-
-            if ( parentProject != null )
-            {
-                ProjectModelExpressionExpander.evaluateExpressions( parentProject );
-                parentProject = mergeParent( parentProject );
-                mixedProject = ProjectModelMerge.merge( pom, parentProject );
-            }
-            else
-            {
-                // Shortcircuit due to missing parent pom.
-                // TODO: Document this via monitor.
-                mixedProject = mixinSuperPom( pom );
-            }
-        }
-        else
-        {
-            debug( "No parent found" );
-
-            /* Mix in the super-pom.
-             * 
-             * Super POM from maven/components contains many things.
-             * However, for purposes of archiva, only the <repositories>
-             * and <pluginRepositories> sections are of any value.
-             */
-
-            mixedProject = mixinSuperPom( pom );
-        }
-
-        return mixedProject;
-    }
-
-    /**
-     * Super POM from maven/components contains many things.
-     * However, for purposes of archiva, only the <repositories>
-     * and <pluginRepositories> sections are of any value.
-     * 
-     * @param pom
-     * @return
-     */
-    private ArchivaProjectModel mixinSuperPom( ArchivaProjectModel pom )
-    {
-        // TODO: add super pom repositories.
-        debug( "Mix in Super POM: " + pom );
-
-        return pom;
-    }
-
-    private static Map createDependencyMap( List dependencies )
-    {
-        Map ret = new HashMap();
-
-        Iterator it = dependencies.iterator();
-        while ( it.hasNext() )
-        {
-            Dependency dep = (Dependency) it.next();
-            String key = toVersionlessDependencyKey( dep );
-            ret.put( key, dep );
-        }
-
-        return ret;
-    }
-
-    private static String toVersionlessDependencyKey( Dependency dep )
-    {
-        StringBuffer key = new StringBuffer();
-
-        key.append( dep.getGroupId() ).append( ":" ).append( dep.getArtifactId() );
-        key.append( StringUtils.defaultString( dep.getClassifier() ) ).append( ":" );
-        key.append( dep.getType() );
-
-        return key.toString();
-    }
-}
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilter.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilter.java
new file mode 100644 (file)
index 0000000..3308376
--- /dev/null
@@ -0,0 +1,278 @@
+package org.apache.maven.archiva.repository.project.filters;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.lang.StringUtils;
+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.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;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Builder for the Effective Project Model.  
+ *
+ * @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 EffectiveProjectModelFilter implements ProjectModelFilter
+{
+    /**
+     * @plexus.requirement role-hint="expression"
+     */
+    private ProjectModelFilter expressionFilter;
+    
+    private List projectModelResolvers;
+    
+    public EffectiveProjectModelFilter()
+    {
+        projectModelResolvers = new ArrayList();
+    }
+
+    public void addProjectModelResolver( ProjectModelResolver resolver )
+    {
+        if ( resolver == null )
+        {
+            return;
+        }
+
+        this.projectModelResolvers.add( resolver );
+    }
+
+    /**
+     * Take the provided {@link ArchivaProjectModel} and build the effective {@link ArchivaProjectModel}.
+     * 
+     * Steps:
+     * 1) Expand any expressions / properties.
+     * 2) Walk the parent project references and merge.
+     * 3) Apply dependency management settings.
+     * 
+     * @param project the project to create the effective {@link ArchivaProjectModel} from.
+     * @return a the effective {@link ArchivaProjectModel}.
+     * @throws ProjectModelException if there was a problem building the effective pom.
+     */
+    public ArchivaProjectModel filter( final ArchivaProjectModel project )
+        throws ProjectModelException
+    {
+        if ( project == null )
+        {
+            return null;
+        }
+
+        if ( this.projectModelResolvers.isEmpty() )
+        {
+            throw new IllegalStateException( "Unable to build effective pom with no project model resolvers defined." );
+        }
+
+        // Clone submitted project (so that we don't mess with it) 
+        ArchivaProjectModel effectiveProject = ArchivaModelCloner.clone( project );
+
+        // Setup Expression Evaluation pieces.
+        effectiveProject = expressionFilter.filter( effectiveProject );
+
+        debug( "Starting build of effective with: " + effectiveProject );
+
+        // Merge in all the parent poms.
+        effectiveProject = mergeParent( effectiveProject );
+
+        // Resolve dependency versions from dependency management.
+        applyDependencyManagement( effectiveProject );
+
+        // Return what we got.
+        return effectiveProject;
+    }
+
+    public void removeResolver( ProjectModelResolver resolver )
+    {
+        this.projectModelResolvers.remove( resolver );
+    }
+
+    private void applyDependencyManagement( ArchivaProjectModel pom )
+    {
+        if ( ( pom.getDependencyManagement() == null ) || ( pom.getDependencies() == null ) )
+        {
+            // Nothing to do. All done!
+            return;
+        }
+        
+        if ( pom.getDependencyManagement().isEmpty() || pom.getDependencies().isEmpty() )
+        {
+            // Nothing to do. All done!
+            return;
+        }
+
+        Map managedDependencies = createDependencyMap( pom.getDependencyManagement() );
+        Iterator it = pom.getDependencies().iterator();
+        while ( it.hasNext() )
+        {
+            Dependency dep = (Dependency) it.next();
+            String key = toVersionlessDependencyKey( dep );
+
+            // Do we need to do anything?
+            if ( managedDependencies.containsKey( key ) )
+            {
+                Dependency mgmtDep = (Dependency) managedDependencies.get( key );
+
+                dep.setVersion( mgmtDep.getVersion() );
+                dep.setScope( mgmtDep.getScope() );
+                dep.setExclusions( ProjectModelMerge.mergeExclusions( dep.getExclusions(), mgmtDep.getExclusions() ) );
+            }
+        }
+    }
+
+    private void debug( String msg )
+    {
+        System.out.println( "## " + msg );
+    }
+
+    private ArchivaProjectModel findProject( VersionedReference projectRef )
+    {
+        debug( "Trying to find project: " + projectRef );
+        Iterator it = this.projectModelResolvers.iterator();
+
+        while ( it.hasNext() )
+        {
+            ProjectModelResolver resolver = (ProjectModelResolver) it.next();
+
+            try
+            {
+                debug( "Trying to find in " + resolver.getClass().getName() );
+                ArchivaProjectModel model = resolver.resolveProjectModel( projectRef );
+
+                if ( model != null )
+                {
+                    debug( "Found it!: " + model );
+                    return model;
+                }
+                debug( "Not found." );
+            }
+            catch ( ProjectModelException e )
+            {
+                // TODO: trigger notifier of problem?
+                e.printStackTrace();
+            }
+        }
+
+        // TODO: Document that project was not found. (Use monitor?)
+
+        return null;
+    }
+
+    private ArchivaProjectModel mergeParent( ArchivaProjectModel pom )
+        throws ProjectModelException
+    {
+        ArchivaProjectModel mixedProject;
+
+        debug( "Parent: " + pom.getParentProject() );
+
+        if ( pom.getParentProject() != null )
+        {
+            // Use parent reference.
+            VersionedReference parentRef = pom.getParentProject();
+
+            debug( "Has parent: " + parentRef );
+
+            // Find parent using resolvers.
+            ArchivaProjectModel parentProject = findProject( parentRef );
+
+            if ( parentProject != null )
+            {
+                parentProject = expressionFilter.filter( parentProject );
+                parentProject = mergeParent( parentProject );
+                mixedProject = ProjectModelMerge.merge( pom, parentProject );
+            }
+            else
+            {
+                // Shortcircuit due to missing parent pom.
+                // TODO: Document this via monitor.
+                mixedProject = mixinSuperPom( pom );
+            }
+        }
+        else
+        {
+            debug( "No parent found" );
+
+            /* Mix in the super-pom.
+             * 
+             * Super POM from maven/components contains many things.
+             * However, for purposes of archiva, only the <repositories>
+             * and <pluginRepositories> sections are of any value.
+             */
+
+            mixedProject = mixinSuperPom( pom );
+        }
+
+        return mixedProject;
+    }
+
+    /**
+     * Super POM from maven/components contains many things.
+     * However, for purposes of archiva, only the <repositories>
+     * and <pluginRepositories> sections are of any value.
+     * 
+     * @param pom
+     * @return
+     */
+    private ArchivaProjectModel mixinSuperPom( ArchivaProjectModel pom )
+    {
+        // TODO: add super pom repositories.
+        debug( "Mix in Super POM: " + pom );
+
+        return pom;
+    }
+
+    private static Map createDependencyMap( List dependencies )
+    {
+        Map ret = new HashMap();
+
+        Iterator it = dependencies.iterator();
+        while ( it.hasNext() )
+        {
+            Dependency dep = (Dependency) it.next();
+            String key = toVersionlessDependencyKey( dep );
+            ret.put( key, dep );
+        }
+
+        return ret;
+    }
+
+    private static String toVersionlessDependencyKey( Dependency dep )
+    {
+        StringBuffer key = new StringBuffer();
+
+        key.append( dep.getGroupId() ).append( ":" ).append( dep.getArtifactId() );
+        key.append( StringUtils.defaultString( dep.getClassifier() ) ).append( ":" );
+        key.append( dep.getType() );
+
+        return key.toString();
+    }
+}
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpander.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpander.java
deleted file mode 100644 (file)
index 764c730..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.apache.maven.archiva.repository.project.filters;
-
-/*
- * 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.
- */
-
-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.codehaus.plexus.evaluator.EvaluatorException;
-import org.codehaus.plexus.evaluator.ExpressionEvaluator;
-import org.codehaus.plexus.evaluator.sources.PropertiesExpressionSource;
-import org.codehaus.plexus.evaluator.sources.SystemPropertyExpressionSource;
-
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * ProjectModelExpressionExpander 
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelExpressionExpander"
- */
-public class ProjectModelExpressionExpander
-{
-    /**
-     * Find and Evaluate the Expressions present in the model.
-     * 
-     * @param model the model to correct.
-     */
-    public static void evaluateExpressions( ArchivaProjectModel model )
-        throws ProjectModelException
-    {
-        ExpressionEvaluator evaluator = new DefaultExpressionEvaluator();
-
-        if ( model.getProperties() != null )
-        {
-            PropertiesExpressionSource propsSource = new PropertiesExpressionSource();
-            propsSource.setProperties( model.getProperties() );
-            evaluator.addExpressionSource( propsSource );
-        }
-
-        evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
-
-        try
-        {
-            model.setVersion( evaluator.expand( model.getVersion() ) );
-            model.setGroupId( evaluator.expand( model.getGroupId() ) );
-
-            evaluateExpressionsInDependencyList( evaluator, model.getDependencies() );
-            evaluateExpressionsInDependencyList( evaluator, model.getDependencyManagement() );
-        }
-        catch ( EvaluatorException e )
-        {
-            throw new ProjectModelException( "Unable to evaluate expression in model: " + e.getMessage(), e );
-        }
-    }
-
-    private static void evaluateExpressionsInDependencyList( ExpressionEvaluator evaluator, List dependencies )
-        throws EvaluatorException
-    {
-        if ( dependencies == null )
-        {
-            return;
-        }
-
-        Iterator it = dependencies.iterator();
-        while ( it.hasNext() )
-        {
-            Dependency dependency = (Dependency) it.next();
-            dependency.setGroupId( evaluator.expand( dependency.getGroupId() ) );
-            dependency.setVersion( evaluator.expand( dependency.getVersion() ) );
-        }
-    }
-}
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionFilter.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionFilter.java
new file mode 100644 (file)
index 0000000..6dd44b9
--- /dev/null
@@ -0,0 +1,103 @@
+package org.apache.maven.archiva.repository.project.filters;
+
+/*
+ * 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.
+ */
+
+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.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;
+import org.codehaus.plexus.evaluator.sources.SystemPropertyExpressionSource;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * ProjectModelExpressionFilter 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelFilter"
+ *                   role-hint="expression" 
+ *                   instantiation-strategy="per-lookup"
+ */
+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 ArchivaProjectModel filter( final ArchivaProjectModel model )
+        throws ProjectModelException
+    {
+        if ( model.getProperties() != null )
+        {
+            PropertiesExpressionSource propsSource = new PropertiesExpressionSource();
+            propsSource.setProperties( model.getProperties() );
+            evaluator.addExpressionSource( propsSource );
+        }
+
+        evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
+
+        ArchivaProjectModel ret = ArchivaModelCloner.clone( model );
+
+        try
+        {
+            ret.setVersion( evaluator.expand( ret.getVersion() ) );
+            ret.setGroupId( evaluator.expand( ret.getGroupId() ) );
+
+            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 )
+        throws EvaluatorException
+    {
+        if ( dependencies == null )
+        {
+            return;
+        }
+
+        Iterator it = dependencies.iterator();
+        while ( it.hasNext() )
+        {
+            Dependency dependency = (Dependency) it.next();
+            dependency.setGroupId( evaluator.expand( dependency.getGroupId() ) );
+            dependency.setVersion( evaluator.expand( dependency.getVersion() ) );
+        }
+    }
+}
diff --git a/archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components.xml b/archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644 (file)
index c2ee003..0000000
+++ /dev/null
@@ -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>
index a4bf59f9688e38bb9a7674ca3ce2b15634ad8c10..f004a0ad8f6e906c6f4d3ab2b997e758d7dbe7a5 100644 (file)
@@ -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-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilderTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilderTest.java
deleted file mode 100644 (file)
index fd82b34..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-package org.apache.maven.archiva.repository.project.filters;
-
-/*
- * 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.
- */
-
-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.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.readers.ProjectModel400Reader;
-import org.apache.maven.archiva.repository.project.resolvers.RepositoryProjectResolver;
-import org.codehaus.plexus.PlexusTestCase;
-
-import java.io.File;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * EffectiveProjectModelBuilderTest 
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class EffectiveProjectModelBuilderTest
-    extends PlexusTestCase
-{
-    private static final String DEFAULT_REPOSITORY = "src/test/repositories/default-repository";
-
-    private ArchivaProjectModel createArchivaProjectModel( String path )
-        throws ProjectModelException
-    {
-        ProjectModelReader reader = new ProjectModel400Reader();
-
-        File pomFile = new File( getBasedir(), path );
-
-        return reader.read( pomFile );
-    }
-
-    private ProjectModelResolver createDefaultRepositoryResolver()
-    {
-        File defaultRepoDir = new File( getBasedir(), DEFAULT_REPOSITORY );
-
-        ArchivaRepository repo = new ArchivaRepository( "defaultTestRepo", "Default Test Repo", "file://"
-            + defaultRepoDir.getAbsolutePath() );
-
-        RepositoryProjectResolver resolver = new RepositoryProjectResolver( repo );
-
-        return resolver;
-    }
-
-    public void testBuildEffectiveProject()
-        throws Exception
-    {
-        EffectiveProjectModelBuilder builder = new EffectiveProjectModelBuilder();
-        builder.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 expectedModel = createArchivaProjectModel( "src/test/effective-poms/"
-            + "/archiva-model-effective.pom" );
-
-        assertModel( expectedModel, effectiveModel );
-    }
-
-    private void assertModel( ArchivaProjectModel expectedModel, ArchivaProjectModel effectiveModel )
-    {
-        assertEquals( "Equivalent Models", expectedModel, effectiveModel );
-
-        assertContainsSame( "Individuals", expectedModel.getIndividuals(), effectiveModel.getIndividuals() );
-        dumpDependencyList( "Expected", expectedModel.getDependencies() );
-        dumpDependencyList( "Effective", effectiveModel.getDependencies() );
-        assertContainsSame( "Dependencies", expectedModel.getDependencies(), effectiveModel.getDependencies() );
-        assertContainsSame( "DependencyManagement", expectedModel.getDependencyManagement(), effectiveModel
-            .getDependencyManagement() );
-    }
-    
-    private void dumpDependencyList( String type, List deps )
-    {
-        System.out.println( ".\\ [" + type + "] Dependency List (size:" + deps.size() + ") \\.________________" );
-        Iterator it = deps.iterator();
-        while ( it.hasNext() )
-        {
-            Dependency dep = (Dependency) it.next();
-            System.out.println( "  " + toDependencyKey( dep ) );
-        }
-        System.out.println( "" );
-    }
-    
-    private String toDependencyKey( Dependency dep )
-    {
-        return "[" + dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion() + ":" + dep.getClassifier()
-            + ":" + dep.getType() + "]";
-    }
-
-    private void assertContainsSame( String listId, List expectedList, List effectiveList )
-    {
-        if ( ( expectedList == null ) && ( effectiveList == null ) )
-        {
-            return;
-        }
-
-        if ( ( expectedList == null ) && ( effectiveList != null ) )
-        {
-            fail( "Effective [" + listId + "] List is instantiated, while expected List is null." );
-        }
-
-        if ( ( expectedList != null ) && ( effectiveList == null ) )
-        {
-            fail( "Effective [" + listId + "] List is null, while expected List is instantiated." );
-        }
-
-        assertEquals( "[" + listId + "] List Size", expectedList.size(), expectedList.size() );
-
-        Iterator it = expectedList.iterator();
-        while ( it.hasNext() )
-        {
-            Object o = it.next();
-            assertTrue( "Should exist in Effective [" + listId + "] list: " + o, effectiveList.contains( o ) );
-        }
-    }
-}
diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java
new file mode 100644 (file)
index 0000000..6a2d976
--- /dev/null
@@ -0,0 +1,150 @@
+package org.apache.maven.archiva.repository.project.filters;
+
+/*
+ * 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.
+ */
+
+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.EffectiveProjectModelFilter;
+import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
+import org.apache.maven.archiva.repository.project.resolvers.RepositoryProjectResolver;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * EffectiveProjectModelFilterTest 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+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
+    {
+        ProjectModelReader reader = new ProjectModel400Reader();
+
+        File pomFile = new File( getBasedir(), path );
+
+        return reader.read( pomFile );
+    }
+
+    private ProjectModelResolver createDefaultRepositoryResolver()
+    {
+        File defaultRepoDir = new File( getBasedir(), DEFAULT_REPOSITORY );
+
+        ArchivaRepository repo = new ArchivaRepository( "defaultTestRepo", "Default Test Repo", "file://"
+            + defaultRepoDir.getAbsolutePath() );
+
+        RepositoryProjectResolver resolver = new RepositoryProjectResolver( repo );
+
+        return resolver;
+    }
+
+    public void testBuildEffectiveProject()
+        throws Exception
+    {
+        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 = filter.filter( startModel );
+
+        ArchivaProjectModel expectedModel = createArchivaProjectModel( "src/test/effective-poms/"
+            + "/archiva-model-effective.pom" );
+
+        assertModel( expectedModel, effectiveModel );
+    }
+
+    private void assertModel( ArchivaProjectModel expectedModel, ArchivaProjectModel effectiveModel )
+    {
+        assertEquals( "Equivalent Models", expectedModel, effectiveModel );
+
+        assertContainsSame( "Individuals", expectedModel.getIndividuals(), effectiveModel.getIndividuals() );
+        dumpDependencyList( "Expected", expectedModel.getDependencies() );
+        dumpDependencyList( "Effective", effectiveModel.getDependencies() );
+        assertContainsSame( "Dependencies", expectedModel.getDependencies(), effectiveModel.getDependencies() );
+        assertContainsSame( "DependencyManagement", expectedModel.getDependencyManagement(), effectiveModel
+            .getDependencyManagement() );
+    }
+    
+    private void dumpDependencyList( String type, List deps )
+    {
+        System.out.println( ".\\ [" + type + "] Dependency List (size:" + deps.size() + ") \\.________________" );
+        Iterator it = deps.iterator();
+        while ( it.hasNext() )
+        {
+            Dependency dep = (Dependency) it.next();
+            System.out.println( "  " + toDependencyKey( dep ) );
+        }
+        System.out.println( "" );
+    }
+    
+    private String toDependencyKey( Dependency dep )
+    {
+        return "[" + dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion() + ":" + dep.getClassifier()
+            + ":" + dep.getType() + "]";
+    }
+
+    private void assertContainsSame( String listId, List expectedList, List effectiveList )
+    {
+        if ( ( expectedList == null ) && ( effectiveList == null ) )
+        {
+            return;
+        }
+
+        if ( ( expectedList == null ) && ( effectiveList != null ) )
+        {
+            fail( "Effective [" + listId + "] List is instantiated, while expected List is null." );
+        }
+
+        if ( ( expectedList != null ) && ( effectiveList == null ) )
+        {
+            fail( "Effective [" + listId + "] List is null, while expected List is instantiated." );
+        }
+
+        assertEquals( "[" + listId + "] List Size", expectedList.size(), expectedList.size() );
+
+        Iterator it = expectedList.iterator();
+        while ( it.hasNext() )
+        {
+            Object o = it.next();
+            assertTrue( "Should exist in Effective [" + listId + "] list: " + o, effectiveList.contains( o ) );
+        }
+    }
+}
index ed06ac95a1aca306b933492a58f4d9112f6eea21..911b789c432553c35220e3a53b0b8b9a05a01af1 100644 (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.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() );