From: Joakim Erdfelt Date: Thu, 5 Apr 2007 21:26:44 +0000 (+0000) Subject: Correcting project model filters. X-Git-Tag: archiva-1.0-alpha-1~113^2~86 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6114332b911dea3003c7cbcd24f9579a65c5a280;p=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 --- diff --git a/archiva-base/archiva-repository-layer/pom.xml b/archiva-base/archiva-repository-layer/pom.xml index 33b2aaee9..5561d5948 100644 --- a/archiva-base/archiva-repository-layer/pom.xml +++ b/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-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelFilter.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelFilter.java index e00943360..fe23970d4 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelFilter.java +++ b/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-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 index 549c049a0..000000000 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilder.java +++ /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 Joakim Erdfelt - * @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 - * and 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 - * and 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 index 000000000..33083768b --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilter.java @@ -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 Joakim Erdfelt + * @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 + * and 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 + * and 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 index 764c7302e..000000000 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpander.java +++ /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 Joakim Erdfelt - * @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 index 000000000..6dd44b9a4 --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionFilter.java @@ -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 Joakim Erdfelt + * @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 index c2ee003f5..000000000 --- a/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-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/AllTests.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/AllTests.java index a4bf59f96..f004a0ad8 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/AllTests.java +++ b/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-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 index fd82b345a..000000000 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelBuilderTest.java +++ /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 Joakim Erdfelt - * @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 index 000000000..6a2d976e6 --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java @@ -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 Joakim Erdfelt + * @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 ) ); + } + } +} diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java index ed06ac95a..911b789c4 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java +++ b/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() );