You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/04/01 21:34:38 UTC
[maven-integration-testing] 01/01: [MNG-5222] IT test - warn about deprecated plugin params
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch MNG-5222
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git
commit cdf69e7075a3ba293a9901d2c67f5a302bb2780f
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Fri Apr 1 23:33:42 2022 +0200
[MNG-5222] IT test - warn about deprecated plugin params
---
.../org/apache/maven/it/IntegrationTestSuite.java | 1 +
.../it/MavenITmng5222MojoDeprectaeParamsTest.java | 152 +++++++++++++++++++++
.../mng-5222-mojo-deprecated-params/pom.xml | 75 ++++++++++
.../maven/plugin/coreit/DeprecatedConfigMojo.java | 136 ++++++++++++++++++
4 files changed, 364 insertions(+)
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index a7de66a..f15bcdb 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -190,6 +190,7 @@ public class IntegrationTestSuite
suite.addTestSuite( MavenITmng5280SettingsProfilesRepositoriesOrderTest.class );
suite.addTestSuite( MavenITmng5230MakeReactorWithExcludesTest.class );
suite.addTestSuite( MavenITmng5224InjectedSettings.class );
+ suite.addTestSuite( MavenITmng5222MojoDeprectaeParamsTest.class );
suite.addTestSuite( MavenITmng5214DontMapWsdlToJar.class );
//suite.addTestSuite( MavenITmng5208EventSpyParallelTest.class );
suite.addTestSuite( MavenITmng5175WagonHttpTest.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5222MojoDeprectaeParamsTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5222MojoDeprectaeParamsTest.java
new file mode 100644
index 0000000..630131c
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5222MojoDeprectaeParamsTest.java
@@ -0,0 +1,152 @@
+package org.apache.maven.it;
+
+/*
+ * 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 java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import org.apache.maven.it.util.ResourceExtractor;
+
+public class MavenITmng5222MojoDeprectaeParamsTest
+ extends AbstractMavenIntegrationTestCase
+{
+ public MavenITmng5222MojoDeprectaeParamsTest()
+ {
+ super( "[4.0.0-alpha-1,)" );
+ }
+
+ /**
+ * Test that ensures that deprecation is not printed for empty and default value
+ *
+ * @throws Exception in case of failure
+ */
+ public void testEmptyConfiguration()
+ throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5222-mojo-deprecated-params" );
+
+ Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+ verifier.setAutoclean( false );
+ verifier.deleteDirectory( "target" );
+ verifier.executeGoal( "validate" );
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+
+ List<String> logLines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+ List<String> warnLines = findDeprecationWarning( logLines );
+ assertTrue( "Log contains warnings: " + warnLines, warnLines.isEmpty() );
+
+ Properties configProps = verifier.loadProperties( "target/config.properties" );
+ assertNull( configProps.getProperty( "deprecatedParam" ) );
+ assertNull( configProps.getProperty( "deprecatedParam2" ) );
+ assertEquals( "testValue", configProps.getProperty( "deprecatedParamWithDefaultConstant" ) );
+ assertEquals( "https://www.test.org", configProps.getProperty( "deprecatedParamWithDefaultEvaluate" ) );
+ }
+
+ /**
+ * Test that ensures that deprecation is printed for deprecated parameter set by property
+ *
+ * @throws Exception in case of failure
+ */
+ public void testDeprecatedProperty()
+ throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5222-mojo-deprecated-params" );
+
+ Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+ verifier.addCliOption( "-Dconfig.deprecatedParam2=deprecatedValueInProps" );
+ verifier.setAutoclean( false );
+ verifier.deleteDirectory( "target" );
+ verifier.executeGoal( "validate" );
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+
+ List<String> logLines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+ List<String> warnLines = findDeprecationWarning( logLines );
+ assertEquals( 1, warnLines.size() );
+ assertEquals(
+ "[WARNING] Parameter 'deprecatedParam2' (User Property 'config.deprecatedParam2') is deprecated. No reason given",
+ warnLines.get( 0 ) );
+
+ Properties configProps = verifier.loadProperties( "target/config.properties" );
+ assertNull( configProps.getProperty( "deprecatedParam" ) );
+ assertEquals( "deprecatedValueInProps", configProps.getProperty( "deprecatedParam2" ) );
+ assertEquals( "testValue", configProps.getProperty( "deprecatedParamWithDefaultConstant" ) );
+ assertEquals( "https://www.test.org", configProps.getProperty( "deprecatedParamWithDefaultEvaluate" ) );
+ }
+
+ /**
+ * Test that ensures that deprecation is printed for deprecated parameter set by plugin configuration.
+ *
+ * @throws Exception in case of failure
+ */
+ public void testDeprecatedConfig()
+ throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5222-mojo-deprecated-params" );
+
+ Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+ verifier.addCliOption( "-Pconfig-values" );
+ verifier.setAutoclean( false );
+ verifier.deleteDirectory( "target" );
+ verifier.executeGoal( "validate" );
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+
+ List<String> logLines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+ List<String> warnLines = findDeprecationWarning( logLines );
+ assertEquals( 4, warnLines.size() );
+
+ assertTrue( warnLines.contains(
+ "[WARNING] Parameter 'deprecatedParam' is deprecated. I'm deprecated param" ) );
+
+ assertTrue( warnLines.contains(
+ "[WARNING] Parameter 'deprecatedParam2' (User Property 'config.deprecatedParam2') is deprecated. No reason given" ) );
+
+ assertTrue( warnLines.contains(
+ "[WARNING] Parameter 'deprecatedParamWithDefaultConstant' is deprecated. deprecated with constant value" ) );
+
+ assertTrue( warnLines.contains(
+ "[WARNING] Parameter 'deprecatedParamWithDefaultEvaluate' is deprecated. deprecated with evaluate value" ) );
+
+ Properties configProps = verifier.loadProperties( "target/config.properties" );
+ assertEquals( "value1", configProps.getProperty( "deprecatedParam" ) );
+ assertEquals( "value2", configProps.getProperty( "deprecatedParam2" ) );
+ assertEquals( "value3", configProps.getProperty( "deprecatedParamWithDefaultConstant" ) );
+ assertEquals( "value4", configProps.getProperty( "deprecatedParamWithDefaultEvaluate" ) );
+ }
+
+ private List<String> findDeprecationWarning( List<String> logLines )
+ {
+ Pattern pattern = Pattern.compile( "\\[WARNING] {3}Parameter .* is deprecated\\..*" );
+ List<String> result = new ArrayList<>();
+ for ( String line : logLines )
+ {
+ if ( pattern.matcher( line ).matches() )
+ {
+ result.add( line );
+ }
+ }
+ return result;
+ }
+}
diff --git a/core-it-suite/src/test/resources/mng-5222-mojo-deprecated-params/pom.xml b/core-it-suite/src/test/resources/mng-5222-mojo-deprecated-params/pom.xml
new file mode 100644
index 0000000..f33b18e
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5222-mojo-deprecated-params/pom.xml
@@ -0,0 +1,75 @@
+<?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>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.mng5222</groupId>
+ <artifactId>maven-it-mng5222</artifactId>
+ <version>1.0</version>
+
+ <name>Maven Integration Test :: mng5222</name>
+ <description>
+ Test that ensures that warning about deprecated mojo params are generated.
+ </description>
+
+ <url>https://www.test.org</url>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.plugins</groupId>
+ <artifactId>maven-it-plugin-configuration</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>deprecated-config</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>config-values</id>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.plugins</groupId>
+ <artifactId>maven-it-plugin-configuration</artifactId>
+ <configuration>
+ <deprecatedParam>value1</deprecatedParam>
+ <deprecatedParam2>value2</deprecatedParam2>
+ <deprecatedParamWithDefaultConstant>value3</deprecatedParamWithDefaultConstant>
+ <deprecatedParamWithDefaultEvaluate>value4</deprecatedParamWithDefaultEvaluate>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/DeprecatedConfigMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/DeprecatedConfigMojo.java
new file mode 100644
index 0000000..447c841
--- /dev/null
+++ b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/DeprecatedConfigMojo.java
@@ -0,0 +1,136 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * 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 java.io.File;
+import java.util.Properties;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Dumps this mojo's configuration into a properties file.
+ *
+ * @goal deprecated-config
+ * @phase validate
+ *
+ * @author Slawomir Jaranowski
+ */
+public class DeprecatedConfigMojo
+ extends AbstractMojo
+{
+
+ /**
+ * The current project's base directory, used for path alignment.
+ *
+ * @parameter default-value="${basedir}"
+ * @readonly
+ */
+ private File basedir;
+
+ /**
+ * The path to the properties file into which to save the mojo configuration.
+ *
+ * @parameter default-value="${project.build.directory}/config.properties"
+ */
+ private File propertiesFile;
+
+ /**
+ * A deprecated parameter to be set via plugin configuration in POM.
+ *
+ * @parameter
+ * @deprecated I'm deprecated param
+ */
+ @Deprecated
+ private String deprecatedParam;
+
+ /**
+ * A deprecated parameter without message to be set via plugin configuration in POM.
+ *
+ * @parameter property="config.deprecatedParam2"
+ * @deprecated
+ */
+ @Deprecated
+ private String deprecatedParam2;
+
+ /**
+ * A deprecated parameter that defaults to a non-mandatory value from the POM.
+ *
+ * @parameter default-value="testValue"
+ * @deprecated deprecated with constant value
+ */
+ @Deprecated
+ private String deprecatedParamWithDefaultConstant;
+
+ /**
+ * A deprecated parameter that defaults to a non-mandatory value from the POM.
+ *
+ * @parameter default-value="${project.url}"
+ * @deprecated deprecated with evaluate value
+ */
+ @Deprecated
+ private String deprecatedParamWithDefaultEvaluate;
+
+ /**
+ * Runs this mojo.
+ *
+ * @throws MojoExecutionException If the output file could not be created.
+ */
+ public void execute()
+ throws MojoExecutionException
+ {
+ getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + propertiesFile );
+
+ if ( propertiesFile == null )
+ {
+ throw new MojoExecutionException( "Path name for output file has not been specified" );
+ }
+
+ if ( !propertiesFile.isAbsolute() )
+ {
+ propertiesFile = new File( basedir, propertiesFile.getPath() ).getAbsoluteFile();
+ }
+
+ Properties configProps = new Properties();
+
+ dumpConfiguration( configProps );
+
+ getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + propertiesFile );
+
+ PropertiesUtil.write( propertiesFile, configProps );
+
+ getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + propertiesFile );
+ }
+
+ /**
+ * Dumps the mojo configuration into the specified properties.
+ *
+ * @param props The properties to dump the configuration into, must not be <code>null</code>.
+ */
+ @SuppressWarnings( "deprecation" )
+ private void dumpConfiguration( Properties props )
+ {
+ PropertiesUtil.serialize( props, "deprecatedParam", deprecatedParam );
+ PropertiesUtil.serialize( props, "deprecatedParam2", deprecatedParam2 );
+ PropertiesUtil.serialize( props, "deprecatedParamWithDefaultConstant", deprecatedParamWithDefaultConstant );
+ PropertiesUtil.serialize( props, "deprecatedParamWithDefaultEvaluate", deprecatedParamWithDefaultEvaluate );
+ }
+
+}