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/28 19:53:16 UTC

[maven-integration-testing] branch MNG-7464 created (now 557663219)

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a change to branch MNG-7464
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git


      at 557663219 [MNG-7464] Warn about using read-only parameters for Mojo in configuration

This branch includes the following new commits:

     new 557663219 [MNG-7464] Warn about using read-only parameters for Mojo in configuration

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-integration-testing] 01/01: [MNG-7464] Warn about using read-only parameters for Mojo in configuration

Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MNG-7464
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit 557663219bb50b5be8f9ccd4de5581e041a83abb
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Thu Apr 28 21:41:02 2022 +0200

    [MNG-7464] Warn about using read-only parameters for Mojo in configuration
---
 .../org/apache/maven/it/IntegrationTestSuite.java  |   1 +
 ...ITmng7464ReadOnlyMojoParametersWarningTest.java | 138 +++++++++++++++++++++
 .../mng-7464-mojo-read-only-params/pom.xml         |  79 ++++++++++++
 .../maven/plugin/coreit/ReadOnlyConfigMojo.java    |  58 +++++++++
 4 files changed, 276 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 48b58dec6..69b9c906d 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
@@ -106,6 +106,7 @@ public class IntegrationTestSuite
         // Tests that don't run stable and need to be fixed
         // -------------------------------------------------------------------------------------------------------------
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
+        suite.addTestSuite( MavenITmng7464ReadOnlyMojoParametersWarningTest.class );
         suite.addTestSuite( MavenITmng7404IgnorePrefixlessExpressionsTest.class );
         suite.addTestSuite( MavenITmng5222MojoDeprecatedTest.class );
         suite.addTestSuite( MavenITmng7390SelectModuleOutsideCwdTest.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7464ReadOnlyMojoParametersWarningTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7464ReadOnlyMojoParametersWarningTest.java
new file mode 100644
index 000000000..259e07249
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7464ReadOnlyMojoParametersWarningTest.java
@@ -0,0 +1,138 @@
+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-7464">MNG-7464</a>
+ *
+ * @author Slawomir Jaranowski
+ */
+public class MavenITmng7464ReadOnlyMojoParametersWarningTest extends AbstractMavenIntegrationTestCase
+{
+    public MavenITmng7464ReadOnlyMojoParametersWarningTest()
+    {
+        super( "4.0.0-alpha-1,)" );
+    }
+
+    /**
+     * Test that ensures that warning is not printed for empty and default value
+     */
+    public void testEmptyConfiguration() throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-7464-mojo-read-only-params" );
+
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.setLogFileName( "log-empty-configuration.txt" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        List<String> logLines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+        List<String> warnLines = findReadOnlyWarning( logLines );
+
+        assertTrue( "Unwanted warnings: " + warnLines, warnLines.isEmpty() );
+    }
+
+    /**
+     * Test that ensures that warning is printed for read-only parameter set by property
+     */
+    public void testDeprecatedProperty()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-7464-mojo-read-only-params" );
+
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.addCliOption( "-Duser.property=value" );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.setLogFileName( "log-read-only-property.txt" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        List<String> logLines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+        List<String> warnLines = findReadOnlyWarning( logLines );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'readOnlyWithUserProperty' (user property 'user.property') is read-only, should not be used in configuration" ) );
+
+        assertTrue( "Not verified line: " + warnLines, warnLines.isEmpty() );
+    }
+
+    /**
+     * Test that ensures that warning is printed for read-only parameter set by plugin configuration.
+     */
+    public void testReadOnlyConfig() throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-7464-mojo-read-only-params" );
+
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.setLogFileName( "log-read-only-configuration.txt" );
+        verifier.addCliOption( "-Pconfig-values" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        List<String> logLines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+        List<String> warnLines = findReadOnlyWarning( logLines );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'readOnlyWithDefault' is read-only, should not be used in configuration" ) );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'readOnlyWithOutDefaults' is read-only, should not be used in configuration" ) );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'readOnlyWithProperty' (user property 'project.version') is read-only, should not be used in configuration" ) );
+
+        assertTrue( warnLines.remove(
+            "[WARNING] Parameter 'readOnlyWithUserProperty' (user property 'user.property') is read-only, should not be used in configuration" ) );
+
+        assertTrue( "Not verified line: " + warnLines, warnLines.isEmpty() );
+
+    }
+
+    private List<String> findReadOnlyWarning( List<String> logLines )
+    {
+        Pattern pattern = Pattern.compile( "\\[WARNING] Parameter .* is read-only.*" );
+        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-7464-mojo-read-only-params/pom.xml b/core-it-suite/src/test/resources/mng-7464-mojo-read-only-params/pom.xml
new file mode 100644
index 000000000..5278a3e98
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7464-mojo-read-only-params/pom.xml
@@ -0,0 +1,79 @@
+<?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.mng7464</groupId>
+  <artifactId>maven-it-mng7464</artifactId>
+  <version>1.0</version>
+
+  <name>Maven Integration Test :: mng7464</name>
+  <description>
+    Test that ensures that warning about read-only mojo params are generated.
+  </description>
+
+  <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>read-only-config</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>config-values</id>
+    <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>read-only-config</goal>
+              </goals>
+            </execution>
+          </executions>
+          <configuration>
+            <readOnlyWithDefault>value1</readOnlyWithDefault>
+            <readOnlyWithOutDefaults>value2</readOnlyWithOutDefaults>
+            <readOnlyWithProperty>value3</readOnlyWithProperty>
+            <readOnlyWithUserProperty>value4</readOnlyWithUserProperty>
+          </configuration>
+        </plugin>
+      </plugins>
+    </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/ReadOnlyConfigMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ReadOnlyConfigMojo.java
new file mode 100644
index 000000000..5b7405e63
--- /dev/null
+++ b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ReadOnlyConfigMojo.java
@@ -0,0 +1,58 @@
+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 org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Mojo for testing read-only parameters.
+ *
+ * @author Slawomir Jaranowski
+ */
+@Mojo( name = "read-only-config", defaultPhase = LifecyclePhase.VALIDATE )
+public class ReadOnlyConfigMojo extends AbstractMojo
+{
+    /**
+     * Only such has sense ...
+     */
+    @Parameter( defaultValue = "${project.version}", readonly = true )
+    String readOnlyWithDefault;
+
+    /**
+     * strange definition ... but possible
+     */
+    @Parameter( readonly = true )
+    private String readOnlyWithOutDefaults;
+
+    @Parameter( property = "project.version", readonly = true )
+    String readOnlyWithProperty;
+
+    @Parameter( property = "user.property", readonly = true )
+    String readOnlyWithUserProperty;
+
+    @Override
+    public void execute()
+    {
+        getLog().info( "[MAVEN-CORE-IT-LOG]" );
+    }
+}