You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/05/25 19:50:33 UTC

[GitHub] [maven-integration-testing] michael-o commented on a diff in pull request #165: [MNG-7468] Check unsupported plugins parameters in configuration

michael-o commented on code in PR #165:
URL: https://github.com/apache/maven-integration-testing/pull/165#discussion_r882053370


##########
core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/TouchMojo.java:
##########
@@ -0,0 +1,82 @@
+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.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * simple Touch Mojo
+ *
+ * @author Slawomir Jaranowski
+ */
+@Mojo( name = "touch", defaultPhase = LifecyclePhase.VALIDATE )
+public class TouchMojo
+    extends AbstractMojo
+{
+    @Parameter( defaultValue = "${project.build.directory}" )
+    private File outputDirectory;
+
+    @Parameter( alias = "validParameterAlias" )
+    private String validParameter;
+
+    public void execute()
+        throws MojoExecutionException
+    {
+
+        getLog().info( "[MAVEN-CORE-IT-LOG] Using output directory " + outputDirectory );
+        touch( outputDirectory, "touch.txt" );
+
+    }
+
+    static void touch( File dir, String file )
+        throws MojoExecutionException
+    {
+        try
+        {
+            if ( !dir.exists() )
+            {
+                dir.mkdirs();
+            }
+
+            File touch = new File( dir, file );
+
+            try ( OutputStreamWriter w = new OutputStreamWriter(
+                new FileOutputStream( touch, true ), StandardCharsets.UTF_8 ) )
+            {
+                w.write( file );

Review Comment:
   A `touch` produces a zero byte file, this one don't.



##########
core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7468UnsupportedPluginsParametersTest.java:
##########
@@ -0,0 +1,183 @@
+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.regex.Pattern;
+
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * Test for
+ * <a href="https://issues.apache.org/jira/browse/MNG-7468">MNG-7468</a>
+ *
+ * @author Slawomir Jaranowski
+ */
+public class MavenITmng7468UnsupportedPluginsParametersTest extends AbstractMavenIntegrationTestCase
+{
+    public MavenITmng7468UnsupportedPluginsParametersTest()
+    {
+        super( "[4.0.0-alpha-1,)" );
+    }
+
+    /**
+     * Test that ensures that warning is not printed for empty configuration
+     */
+    public void testNoConfiguration() throws Exception
+    {
+        List<String> warnLines = performTest( "no-config" );
+        assertTrue( "Unwanted warnings: " + warnLines, warnLines.isEmpty() );
+    }
+
+    /**
+     * Test that ensures that warning is not printed for valid parameters
+     */
+    public void testValidParameter() throws Exception
+    {
+        List<String> warnLines = performTest( "valid-parameter" );
+        assertTrue( "Unwanted warnings: " + warnLines, warnLines.isEmpty() );
+    }
+
+    /**
+     * Test that ensures that warning is not printed for valid parameters
+     */
+    public void testValidParameterAlias() throws Exception
+    {
+        List<String> warnLines = performTest( "valid-parameter-alias" );
+        assertTrue( "Unwanted warnings: " + warnLines, warnLines.isEmpty() );
+    }
+
+    /**
+     * Test that ensures that warning is not printed for valid parameters
+     */
+    public void testValidParameterForOtherGoal() throws Exception
+    {
+        List<String> warnLines = performTest( "valid-parameter-other-goal" );
+        assertTrue( "Unwanted warnings: " + warnLines, warnLines.isEmpty() );
+    }
+
+    /**
+     * Test that ensures that warning is printed for configuration
+     */
+    public void testInBuildPlugin() throws Exception
+    {
+        List<String> warnLines = performTest( "config-build-plugin" );
+        assertWarningPresents( warnLines );
+    }
+
+    /**
+     * Test that ensures that warning is printed for configuration
+     */
+    public void testInBuildExecution() throws Exception
+    {
+        List<String> warnLines = performTest( "config-build-execution" );
+        assertWarningPresents( warnLines );
+    }
+
+    /**
+     * Test that ensures that warning is printed for configuration
+     */
+    public void testInBuildMixed() throws Exception
+    {
+        List<String> warnLines = performTest( "config-build-mixed" );
+        assertWarningPresents( warnLines );
+    }
+
+    /**
+     * Test that ensures that warning is printed for configuration
+     */
+    public void testInPluginManagement() throws Exception
+    {
+        List<String> warnLines = performTest( "config-plugin-management" );
+        assertWarningPresents( warnLines );
+    }
+
+    /**
+     * Test that ensures that warning is printed for configuration
+     */
+    public void testInPluginManagementParent() throws Exception
+    {
+        List<String> warnLines = performTest( "config-plugin-management-parent" );
+        assertWarningPresents( warnLines );
+    }
+
+    /**
+     * Test that ensures that warning is printed for configuration
+     */
+    public void testWithForkedGoalExecution() throws Exception
+    {
+        List<String> warnLines = performTest( "config-with-fork-goal" );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'invalidXml' is unknown for plugin: 'maven-it-plugin-fork:2.1-SNAPSHOT:fork-goal (fork)" ) );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'invalidValue' is unknown for plugin: 'maven-it-plugin-fork:2.1-SNAPSHOT:fork-goal (fork)" ) );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'invalidXml' is unknown for plugin: 'maven-it-plugin-fork:2.1-SNAPSHOT:touch (touch)" ) );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'invalidValue' is unknown for plugin: 'maven-it-plugin-fork:2.1-SNAPSHOT:touch (touch)" ) );
+
+        assertTrue( "Not verified line: " + warnLines, warnLines.isEmpty() );
+    }
+
+    private List<String> performTest( String project ) throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-7468-unsupported-params" );
+
+        Verifier verifier = newVerifier( new File( testDir, project ).getAbsolutePath() );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        List<String> logLines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+        return findUnknownWarning( logLines );
+    }
+
+    private void assertWarningPresents( List<String> warnLines )

Review Comment:
   Rather `assertWarningContains`, no?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org