Author: gboue Date: Sun Jun 11 18:10:40 2017 New Revision: 1798389 URL: http://svn.apache.org/viewvc?rev=1798389&view=rev Log: [MANTRUN-204] antrun loops the backing map of java.util.Properties withouth checking type safety
Avoid blind casts to String when copying Ant project properties to Maven properties. Added: maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/ maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/invoker.properties (with props) maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/pom.xml (with props) Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java Added: maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/invoker.properties?rev=1798389&view=auto ============================================================================== --- maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/invoker.properties (added) +++ maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/invoker.properties Sun Jun 11 18:10:40 2017 @@ -0,0 +1,18 @@ +# 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. + +invoker.goals = clean validate Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/invoker.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/invoker.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/pom.xml?rev=1798389&view=auto ============================================================================== --- maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/pom.xml (added) +++ maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/pom.xml Sun Jun 11 18:10:40 2017 @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins.antrun</groupId> + <artifactId>export-ant-propertie</artifactId> + <packaging>pom</packaging> + <version>1.0</version> + <description>Checks that exportAntProperties correctly generates the Maven properties</description> + <properties> + <prop1>val1-from-maven</prop1> + </properties> + <build> + <plugins> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <version>@pom.version@</version> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <target> + <property name="prop2" value="val2-from-ant" /> + </target> + <exportAntProperties>true</exportAntProperties> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-enforcer-plugin</artifactId> + <version>1.4.1</version> + <executions> + <execution> + <id>enforce-properties</id> + <goals> + <goal>enforce</goal> + </goals> + <phase>validate</phase> + <configuration> + <rules> + <requireProperty> + <property>prop1</property> + <regex>val1-from-maven</regex> + </requireProperty> + <requireProperty> + <property>prop2</property> + <regex>val2-from-ant</regex> + </requireProperty> + </rules> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/export-ant-properties/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java?rev=1798389&r1=1798388&r2=1798389&view=diff ============================================================================== --- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java (original) +++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java Sun Jun 11 18:10:40 2017 @@ -25,6 +25,7 @@ import java.io.LineNumberReader; import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; +import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Properties; @@ -495,12 +496,12 @@ public class AntRunMojo } getLog().debug( "Propagated Ant properties to Maven properties" ); - Map<?, ?> antProps = antProject.getProperties(); + Hashtable<String, Object> antProps = antProject.getProperties(); Properties mavenProperties = mavenProject.getProperties(); - for ( Map.Entry<?, ?> entry : antProps.entrySet() ) + for ( Map.Entry<String, Object> entry : antProps.entrySet() ) { - String key = (String) entry.getKey(); + String key = entry.getKey(); if ( mavenProperties.getProperty( key ) != null ) { getLog().debug( "Ant property '" + key + "=" + mavenProperties.getProperty( key ) @@ -508,7 +509,8 @@ public class AntRunMojo + "SKIPPING this Ant property propagation." ); continue; } - mavenProperties.setProperty( key, (String) entry.getValue() ); + // it is safe to call toString directly since the value cannot be null in Hashtable + mavenProperties.setProperty( key, entry.getValue().toString() ); } }