Repository: maven-surefire Updated Branches: refs/heads/master ac6cf3c9b -> 7b8b2ede6
[SUREFIRE-1053] Suppress warning message if file.encoding is set using argLine Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/7b8b2ede Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/7b8b2ede Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/7b8b2ede Branch: refs/heads/master Commit: 7b8b2ede633ec6d0ed4ad3111d17eefe69c922ba Parents: ac6cf3c Author: tibordigana <tibo...@lycos.com> Authored: Wed Oct 29 11:49:56 2014 +0100 Committer: tibordigana <tibo...@lycos.com> Committed: Wed Oct 29 11:55:47 2014 +0100 ---------------------------------------------------------------------- .../plugin/surefire/AbstractSurefireMojo.java | 46 +++++++++---- .../surefire/its/fixture/SurefireLauncher.java | 6 ++ .../jiras/Surefire1053SystemPropertiesIT.java | 59 ++++++++++++++++ .../surefire-1053-system-properties/pom.xml | 72 ++++++++++++++++++++ .../src/test/java/jiras/surefire1053/ATest.java | 32 +++++++++ 5 files changed, 202 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7b8b2ede/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index bf1b9cd..5820a62 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -930,11 +931,22 @@ public abstract class AbstractSurefireMojo result.setProperty( "basedir", getBasedir().getAbsolutePath() ); result.setProperty( "user.dir", getWorkingDirectory().getAbsolutePath() ); result.setProperty( "localRepository", getLocalRepository().getBasedir() ); - - for ( Object o : result.propertiesThatCannotBeSetASystemProperties() ) + if ( isForking() ) { - getLog().warn( o + " cannot be set as system property, use <argLine>-D" + o + "=...<argLine> instead" ); - + for ( Object o : result.propertiesThatCannotBeSetASystemProperties() ) + { + if ( getArgLine() == null || !getArgLine().contains( "-D" + o + "=" ) ) + { + getLog().warn( o + " cannot be set as system property, use <argLine>-D" + + o + "=...<argLine> instead" ); + } + } + for ( Object systemPropertyMatchingArgLine : systemPropertiesMatchingArgLine( result ) ) + { + getLog().warn( "The system property " + systemPropertyMatchingArgLine + " is configured twice! " + + "The property appears in <argLine/> and any of <systemPropertyVariables/>, " + + "<systemProperties/> or user property." ); + } } if ( getLog().isDebugEnabled() ) { @@ -943,6 +955,22 @@ public abstract class AbstractSurefireMojo return result; } + private Set<Object> systemPropertiesMatchingArgLine( SurefireProperties result ) + { + Set<Object> intersection = new HashSet<Object>(); + if ( StringUtils.isNotBlank( getArgLine() ) ) + { + for ( Object systemProperty : result.getStringKeySet() ) + { + if ( getArgLine().contains( "-D" + systemProperty + "=" ) ) + { + intersection.add( systemProperty ); + } + } + } + return intersection; + } + public void showToLog( SurefireProperties props, org.apache.maven.plugin.logging.Log log, String setting ) { for ( Object key : props.getStringKeySet() ) @@ -1847,15 +1875,7 @@ public abstract class AbstractSurefireMojo { double multiplier = Double.parseDouble( trimmed.substring( 0, trimmed.length() - 1 ) ); double calculated = multiplier * ( (double) Runtime.getRuntime().availableProcessors() ); - - if ( calculated > 0d ) - { - return Math.max( (int) calculated, 1 ); - } - else - { - return 0; - } + return calculated > 0d ? Math.max( (int) calculated, 1 ) : 0; } else { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7b8b2ede/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java index 149adcc..2cd69ff 100755 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java @@ -405,6 +405,12 @@ public class SurefireLauncher return this; } + public SurefireLauncher argLine( String value ) + { + mavenLauncher.sysProp( "argLine", value ); + return this; + } + public SurefireLauncher sysProp( String variable, String value ) { mavenLauncher.sysProp( variable, value ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7b8b2ede/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1053SystemPropertiesIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1053SystemPropertiesIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1053SystemPropertiesIT.java new file mode 100644 index 0000000..09c1d6c --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1053SystemPropertiesIT.java @@ -0,0 +1,59 @@ +package org.apache.maven.surefire.its.jiras; + +/* + * 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.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.apache.maven.surefire.its.fixture.SurefireLauncher; +import org.junit.Test; + +/** + * @author <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> + * @see {@linkplain https://jira.codehaus.org/browse/SUREFIRE-1053} + * @since 2.18 + */ +public class Surefire1053SystemPropertiesIT + extends SurefireJUnit4IntegrationTestCase +{ + @Test + public void checkWarningsFileEncoding() + { + unpack().sysProp( "file.encoding", "ISO-8859-1" ) + .executeTest() + .verifyErrorFree( 1 ) + .verifyTextInLog( "file.encoding cannot be set as system property, use <argLine>-D" + + "file.encoding=...<argLine> instead" ); + } + @Test + public void checkWarningsSysPropTwice() + { + unpack().argLine( "-DmyArg=myVal2" ) + .executeTest() + .verifyErrorFree( 1 ) + .verifyTextInLog( "The system property myArg is configured twice! " + + "The property appears in <argLine/> and any of <systemPropertyVariables/>, " + + "<systemProperties/> or user property." ); + + } + + private SurefireLauncher unpack() + { + return unpack( "surefire-1053-system-properties" ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7b8b2ede/surefire-integration-tests/src/test/resources/surefire-1053-system-properties/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-1053-system-properties/pom.xml b/surefire-integration-tests/src/test/resources/surefire-1053-system-properties/pom.xml new file mode 100644 index 0000000..eeb446b --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-1053-system-properties/pom.xml @@ -0,0 +1,72 @@ +<?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> + <parent> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>it-parent</artifactId> + <version>1.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>jiras-surefire-1053</artifactId> + <version>1.0</version> + <url>http://maven.apache.org</url> + <developers> + <developer> + <id>tibordigana</id> + <name>Tibor DigaÅa (tibor17)</name> + <email>tibordig...@apache.org</email> + <roles> + <role>Committer</role> + </roles> + <timezone>Europe/Bratislava</timezone> + </developer> + </developers> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkMode>once</forkMode> + <systemPropertyVariables> + <myArg>myVal1</myArg> + </systemPropertyVariables> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7b8b2ede/surefire-integration-tests/src/test/resources/surefire-1053-system-properties/src/test/java/jiras/surefire1053/ATest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-1053-system-properties/src/test/java/jiras/surefire1053/ATest.java b/surefire-integration-tests/src/test/resources/surefire-1053-system-properties/src/test/java/jiras/surefire1053/ATest.java new file mode 100644 index 0000000..367adc5 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-1053-system-properties/src/test/java/jiras/surefire1053/ATest.java @@ -0,0 +1,32 @@ +package jiras.surefire1053; + +/* + * 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.junit.Test; + +public final class ATest { + + @Test + public void someMethod() throws InterruptedException { + System.out.println( "file.encoding=" + System.getProperty( "file.encoding" ) ); + System.out.println( "myArg=" + System.getProperty( "myArg" ) ); + } + +}