Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit d8310c3

Browse files
author
Guillaume Boué
committed
[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. git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1798389 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5bccd01 commit d8310c3

3 files changed

Lines changed: 105 additions & 4 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals = clean validate
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
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
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
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
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
25+
<modelVersion>4.0.0</modelVersion>
26+
<groupId>org.apache.maven.plugins.antrun</groupId>
27+
<artifactId>export-ant-propertie</artifactId>
28+
<packaging>pom</packaging>
29+
<version>1.0</version>
30+
<description>Checks that exportAntProperties correctly generates the Maven properties</description>
31+
<properties>
32+
<prop1>val1-from-maven</prop1>
33+
</properties>
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<artifactId>maven-antrun-plugin</artifactId>
38+
<version>@pom.version@</version>
39+
<executions>
40+
<execution>
41+
<phase>validate</phase>
42+
<goals>
43+
<goal>run</goal>
44+
</goals>
45+
<configuration>
46+
<target>
47+
<property name="prop2" value="val2-from-ant" />
48+
</target>
49+
<exportAntProperties>true</exportAntProperties>
50+
</configuration>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
<plugin>
55+
<artifactId>maven-enforcer-plugin</artifactId>
56+
<version>1.4.1</version>
57+
<executions>
58+
<execution>
59+
<id>enforce-properties</id>
60+
<goals>
61+
<goal>enforce</goal>
62+
</goals>
63+
<phase>validate</phase>
64+
<configuration>
65+
<rules>
66+
<requireProperty>
67+
<property>prop1</property>
68+
<regex>val1-from-maven</regex>
69+
</requireProperty>
70+
<requireProperty>
71+
<property>prop2</property>
72+
<regex>val2-from-ant</regex>
73+
</requireProperty>
74+
</rules>
75+
</configuration>
76+
</execution>
77+
</executions>
78+
</plugin>
79+
</plugins>
80+
</build>
81+
</project>

maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.StringWriter;
2626
import java.util.ArrayList;
2727
import java.util.Collection;
28+
import java.util.Hashtable;
2829
import java.util.List;
2930
import java.util.Map;
3031
import java.util.Properties;
@@ -495,20 +496,21 @@ public void copyProperties( Project antProject, MavenProject mavenProject )
495496
}
496497

497498
getLog().debug( "Propagated Ant properties to Maven properties" );
498-
Map<?, ?> antProps = antProject.getProperties();
499+
Hashtable<String, Object> antProps = antProject.getProperties();
499500
Properties mavenProperties = mavenProject.getProperties();
500501

501-
for ( Map.Entry<?, ?> entry : antProps.entrySet() )
502+
for ( Map.Entry<String, Object> entry : antProps.entrySet() )
502503
{
503-
String key = (String) entry.getKey();
504+
String key = entry.getKey();
504505
if ( mavenProperties.getProperty( key ) != null )
505506
{
506507
getLog().debug( "Ant property '" + key + "=" + mavenProperties.getProperty( key )
507508
+ "' clashs with an existing Maven property, "
508509
+ "SKIPPING this Ant property propagation." );
509510
continue;
510511
}
511-
mavenProperties.setProperty( key, (String) entry.getValue() );
512+
// it is safe to call toString directly since the value cannot be null in Hashtable
513+
mavenProperties.setProperty( key, entry.getValue().toString() );
512514
}
513515
}
514516

0 commit comments

Comments
 (0)