This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to annotated tag maven-invoker-plugin-1.1 in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit 14816a55c03831a43fdc4a0f86747f655761e8aa Author: Oliver Lamy <ol...@apache.org> AuthorDate: Thu Nov 22 23:03:30 2007 +0000 [MINVOKER-9] Interpolate goal files with project and new properties field git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-invoker-plugin@597507 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/plugin/invoker/CompositeMap.java | 176 +++++++++++++++++++++ .../apache/maven/plugin/invoker/InvokerMojo.java | 53 +++++-- .../plugin/invoker/ExtendedMavenProjectStub.java | 43 +++++ .../maven/plugin/invoker/InterpolationTest.java | 80 ++++++++++ .../maven/plugin/invoker/InvokerMojoTest.java | 2 - src/test/resources/unit/interpolation/goals.txt | 2 + 6 files changed, 340 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/apache/maven/plugin/invoker/CompositeMap.java b/src/main/java/org/apache/maven/plugin/invoker/CompositeMap.java new file mode 100755 index 0000000..7792946 --- /dev/null +++ b/src/main/java/org/apache/maven/plugin/invoker/CompositeMap.java @@ -0,0 +1,176 @@ +/* + * 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. + */ +package org.apache.maven.plugin.invoker; + +import java.util.Collection; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; + +/** + * @author <a href="mailto:ol...@apache.org">olamy</a> + * @since 22 nov. 07 + * @version $Id$ + */ +class CompositeMap + implements Map +{ + + private MavenProject mavenProject; + + private Properties properties; + + protected CompositeMap(MavenProject mavenProject, Properties properties) + { + this.mavenProject = mavenProject; + this.properties = properties == null ? new Properties() : properties; + } + + /** + * @see java.util.Map#clear() + */ + public void clear() + { + // nothing here + + } + + /** + * @see java.util.Map#containsKey(java.lang.Object) + */ + public boolean containsKey( Object key ) + { + if ( key == null ) + { + return false; + } + try + { + Object evaluated = ReflectionValueExtractor.evaluate( (String) key, this.mavenProject ); + return evaluated == null; + } + catch ( Exception e ) + { + // uhm do we have to throw a RuntimeException here ? + } + return properties.containsKey( key ); + } + + /** + * @see java.util.Map#containsValue(java.lang.Object) + */ + public boolean containsValue( Object value ) + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Map#entrySet() + */ + public Set entrySet() + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Map#get(java.lang.Object) + */ + public Object get( Object key ) + { + if ( key == null ) + { + return null; + } + try + { + Object evaluated = ReflectionValueExtractor.evaluate( (String) key, this.mavenProject ); + if ( evaluated != null ) + { + return evaluated; + } + } + catch ( Exception e ) + { + // uhm do we have to throw a RuntimeException here ? + } + return properties.get( key ); + } + + /** + * @see java.util.Map#isEmpty() + */ + public boolean isEmpty() + { + return this.mavenProject == null && this.properties.isEmpty(); + } + + /** + * @see java.util.Map#keySet() + */ + public Set keySet() + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Map#put(java.lang.Object, java.lang.Object) + */ + public Object put( Object key, Object value ) + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Map#putAll(java.util.Map) + */ + public void putAll( Map t ) + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Map#remove(java.lang.Object) + */ + public Object remove( Object key ) + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Map#size() + */ + public int size() + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Map#values() + */ + public Collection values() + { + throw new UnsupportedOperationException(); + } + + + +} diff --git a/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java b/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java index 3c5d486..1444404 100644 --- a/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java +++ b/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java @@ -19,9 +19,25 @@ package org.apache.maven.plugin.invoker; * under the License. */ +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; import org.apache.maven.shared.invoker.CommandLineConfigurationException; import org.apache.maven.shared.invoker.DefaultInvocationRequest; import org.apache.maven.shared.invoker.InvocationRequest; @@ -33,21 +49,9 @@ import org.apache.maven.shared.model.fileset.FileSet; import org.apache.maven.shared.model.fileset.util.FileSetManager; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.InterpolationFilterReader; import org.codehaus.plexus.util.cli.CommandLineException; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; -import java.util.StringTokenizer; - import bsh.EvalError; import bsh.Interpreter; @@ -202,10 +206,29 @@ public class InvokerMojo /** * List of profileId's to explicitly trigger in the build. + * * @parameter * @since 1.1 */ private List profiles; + + /** + * List properties which will be used to interpolate goal files. + * + * @parameter + * @since 1.1 + */ + private Properties interpolationsProperties; + + /** + * The Maven Project Object + * + * @parameter expression="${project}" + * @required + * @readonly + * @since 1.1 + */ + private MavenProject project; public void execute() throws MojoExecutionException, MojoFailureException @@ -824,7 +847,9 @@ public class InvokerMojo try { - reader = new BufferedReader( new FileReader( projectGoalList ) ); + Map composite = new CompositeMap(this.project, this.interpolationsProperties); + reader = new BufferedReader( new InterpolationFilterReader( new FileReader( projectGoalList ), composite ) ); + /// new BufferedReader( new FileReader( projectGoalList ) ); result = new ArrayList(); diff --git a/src/test/java/org/apache/maven/plugin/invoker/ExtendedMavenProjectStub.java b/src/test/java/org/apache/maven/plugin/invoker/ExtendedMavenProjectStub.java new file mode 100755 index 0000000..c598b94 --- /dev/null +++ b/src/test/java/org/apache/maven/plugin/invoker/ExtendedMavenProjectStub.java @@ -0,0 +1,43 @@ +/* + * 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. + */ +package org.apache.maven.plugin.invoker; + +import org.apache.maven.model.Scm; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; + +/** + * @author <a href="mailto:ol...@apache.org">olamy</a> + * @since 22 nov. 07 + * @version $Id$ + */ +public class ExtendedMavenProjectStub + extends MavenProjectStub +{ + private Scm scm; + + public Scm getScm() + { + return scm; + } + + public void setScm( Scm scm ) + { + this.scm = scm; + } +} diff --git a/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java b/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java new file mode 100755 index 0000000..0a4ec44 --- /dev/null +++ b/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java @@ -0,0 +1,80 @@ +/* + * 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. + */ +package org.apache.maven.plugin.invoker; + +import java.io.File; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.model.Scm; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; + +/** + * @author <a href="mailto:ol...@apache.org">olamy</a> + * @since 22 nov. 07 + * @version $Id$ + */ +public class InterpolationTest + extends AbstractMojoTestCase +{ + + protected MavenProjectStub buildMavenProjectStub() + { + ExtendedMavenProjectStub project = new ExtendedMavenProjectStub(); + project.setVersion( "1.0-SNAPSHOT" ); + project.setArtifactId( "foo" ); + project.setGroupId( "bar" ); + Scm scm = new Scm(); + scm.setConnection( "http://blabla" ); + project.setScm( scm ); + return project; + } + + public void testCompositeMap() + throws Exception + { + + Properties properties = new Properties(); + properties.put( "foo", "bar" ); + properties.put( "version", "2.0-SNAPSHOT" ); + CompositeMap compositeMap = new CompositeMap( buildMavenProjectStub(), properties ); + assertEquals( "1.0-SNAPSHOT", compositeMap.get( "pom.version" ) ); + assertEquals( "bar", compositeMap.get( "foo" ) ); + assertEquals( "bar", compositeMap.get( "pom.groupId" ) ); + assertEquals( "http://blabla", compositeMap.get( "pom.scm.connection" ) ); + } + + public void testInterpolationGoalsFile() + throws Exception + { + InvokerMojo invokerMojo = new InvokerMojo(); + setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" ); + setVariableValueToObject( invokerMojo, "project", buildMavenProjectStub() ); + Properties properties = new Properties(); + properties.put( "cleanProps", "clean" ); + properties.put( "version", "2.0-SNAPSHOT" ); + setVariableValueToObject( invokerMojo, "interpolationsProperties", properties ); + String dirPath = getBasedir() + "/src/test/resources/unit/interpolation/"; + List goals = invokerMojo.getGoals( new File( dirPath ) ); + assertEquals( goals.toString(), 2, goals.size() ); + assertEquals( "clean", goals.get( 0 ) ); + assertEquals( "bar:foo:1.0-SNAPSHOT:mygoal", goals.get( 1 ) ); + } +} diff --git a/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java b/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java index 068a761..b676f2b 100644 --- a/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java @@ -21,9 +21,7 @@ package org.apache.maven.plugin.invoker; import java.io.File; import java.util.ArrayList; -import java.util.Enumeration; import java.util.List; -import java.util.Properties; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.shared.invoker.Invoker; diff --git a/src/test/resources/unit/interpolation/goals.txt b/src/test/resources/unit/interpolation/goals.txt new file mode 100755 index 0000000..b9d46e8 --- /dev/null +++ b/src/test/resources/unit/interpolation/goals.txt @@ -0,0 +1,2 @@ +${cleanProps} +${pom.groupId}:${pom.artifactId}:${pom.version}:mygoal \ No newline at end of file -- To stop receiving notification emails like this one, please contact "commits@maven.apache.org" <commits@maven.apache.org>.