1 package org.apache.maven.archiva.repository.project.filters;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.model.ArchivaProjectModel;
23 import org.apache.maven.archiva.model.Dependency;
24 import org.apache.maven.archiva.repository.project.ProjectModelException;
25 import org.codehaus.plexus.evaluator.DefaultExpressionEvaluator;
26 import org.codehaus.plexus.evaluator.EvaluatorException;
27 import org.codehaus.plexus.evaluator.ExpressionEvaluator;
28 import org.codehaus.plexus.evaluator.sources.PropertiesExpressionSource;
29 import org.codehaus.plexus.evaluator.sources.SystemPropertyExpressionSource;
31 import java.util.Iterator;
32 import java.util.List;
35 * ProjectModelExpressionExpander
37 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
39 * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelExpressionExpander"
41 public class ProjectModelExpressionExpander
44 * Find and Evaluate the Expressions present in the model.
46 * @param model the model to correct.
48 public static void evaluateExpressions( ArchivaProjectModel model )
49 throws ProjectModelException
51 ExpressionEvaluator evaluator = new DefaultExpressionEvaluator();
53 if ( model.getProperties() != null )
55 PropertiesExpressionSource propsSource = new PropertiesExpressionSource();
56 propsSource.setProperties( model.getProperties() );
57 evaluator.addExpressionSource( propsSource );
60 evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
64 model.setVersion( evaluator.expand( model.getVersion() ) );
65 model.setGroupId( evaluator.expand( model.getGroupId() ) );
67 evaluateExpressionsInDependencyList( evaluator, model.getDependencies() );
68 evaluateExpressionsInDependencyList( evaluator, model.getDependencyManagement() );
70 catch ( EvaluatorException e )
72 throw new ProjectModelException( "Unable to evaluate expression in model: " + e.getMessage(), e );
76 private static void evaluateExpressionsInDependencyList( ExpressionEvaluator evaluator, List dependencies )
77 throws EvaluatorException
79 if ( dependencies == null )
84 Iterator it = dependencies.iterator();
85 while ( it.hasNext() )
87 Dependency dependency = (Dependency) it.next();
88 dependency.setGroupId( evaluator.expand( dependency.getGroupId() ) );
89 dependency.setVersion( evaluator.expand( dependency.getVersion() ) );