maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r982993 - in /maven/core-integration-testing/trunk: core-it-suite/src/test/java/org/apache/maven/it/ core-it-suite/src/test/resources/mng-4615/ core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plu...
Date Fri, 06 Aug 2010 14:38:43 GMT
Author: bentmann
Date: Fri Aug  6 14:38:43 2010
New Revision: 982993

URL: http://svn.apache.org/viewvc?rev=982993&view=rev
Log:
[MNG-4615] [regression] @required plugin parameters are not validated

o Added IT

Added:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4615ValidateRequiredPluginParameterTest.java
  (with props)
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4615/
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4615/pom.xml
  (with props)
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/RequiredConfigMojo.java
  (with props)
Modified:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java?rev=982993&r1=982992&r2=982993&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
(original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
Fri Aug  6 14:38:43 2010
@@ -98,6 +98,7 @@ public class IntegrationTestSuite
         suite.addTestSuite( MavenITmng4629NoPomValidationErrorUponMissingSystemDepTest.class
);
         suite.addTestSuite( MavenITmng4625SettingsXmlInterpolationWithXmlMarkupTest.class
);
         suite.addTestSuite( MavenITmng4618AggregatorBuiltAfterModulesTest.class );
+        suite.addTestSuite( MavenITmng4615ValidateRequiredPluginParameterTest.class );
         suite.addTestSuite( MavenITmng4600DependencyOptionalFlagManagementTest.class );
         suite.addTestSuite( MavenITmng4590ImportedPomUsesSystemPropertiesTest.class );
         suite.addTestSuite( MavenITmng4586PluginPrefixResolutionFromVersionlessPluginMngtTest.class
);

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4615ValidateRequiredPluginParameterTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4615ValidateRequiredPluginParameterTest.java?rev=982993&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4615ValidateRequiredPluginParameterTest.java
(added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4615ValidateRequiredPluginParameterTest.java
Fri Aug  6 14:38:43 2010
@@ -0,0 +1,86 @@
+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 org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4615">MNG-4615</a>.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class MavenITmng4615ValidateRequiredPluginParameterTest
+    extends AbstractMavenIntegrationTestCase
+{
+
+    public MavenITmng4615ValidateRequiredPluginParameterTest()
+    {
+        super( "[2.0.3,3.0-alpha-1),[3.0-beta-2,)" );
+    }
+
+    /**
+     * Verify that Maven validates required mojo parameters (and doesn't just have the plugins
die with NPEs).
+     */
+    public void testit()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4615"
);
+
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        try
+        {
+            verifier.executeGoal( "validate" );
+            verifier.verifyErrorFreeLog();
+            fail( "Build did not fail despite required plugin parameter missing" );
+        }
+        catch ( VerificationException e )
+        {
+            // expected
+        }
+
+        // sanity check that adding the param makes it work
+
+        verifier.setLogFileName( "log-2.txt" );
+        verifier.getCliOptions().add( "-Pmng4615" );
+        verifier.deleteDirectory( "target" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        Properties props = verifier.loadProperties( "target/config.properties" );
+        assertEquals( "PROFILE", props.get( "requiredParam" ) );
+
+        verifier.setLogFileName( "log-3.txt" );
+        verifier.getCliOptions().remove( "-Pmng4615" );
+        verifier.setSystemProperty( "config.requiredParam", "CLI" );
+        verifier.deleteDirectory( "target" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        props = verifier.loadProperties( "target/config.properties" );
+        assertEquals( "CLI", props.get( "requiredParam" ) );
+
+        verifier.resetStreams();
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4615ValidateRequiredPluginParameterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4615ValidateRequiredPluginParameterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4615/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4615/pom.xml?rev=982993&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4615/pom.xml
(added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4615/pom.xml
Fri Aug  6 14:38:43 2010
@@ -0,0 +1,73 @@
+<?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.mng4615</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: MNG-4615</name>
+  <description>
+    Verify that Maven validates required mojo parameters (and doesn't just have the plugins
die with NPEs).
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.its.plugins</groupId>
+        <artifactId>maven-it-plugin-configuration</artifactId>
+        <version>2.1-SNAPSHOT</version>
+        <configuration>
+          <propertiesFile>target/config.properties</propertiesFile>
+        </configuration>
+        <executions>
+          <execution>
+            <id>test</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>required-config</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>mng4615</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.its.plugins</groupId>
+            <artifactId>maven-it-plugin-configuration</artifactId>
+            <configuration>
+              <requiredParam>PROFILE</requiredParam>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4615/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4615/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/RequiredConfigMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/RequiredConfigMojo.java?rev=982993&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/RequiredConfigMojo.java
(added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/RequiredConfigMojo.java
Fri Aug  6 14:38:43 2010
@@ -0,0 +1,113 @@
+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 required-config
+ * @phase validate
+ * 
+ * @author Benjamin Bentmann
+ */
+public class RequiredConfigMojo
+    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 expression="${config.propertiesFile}"
+     */
+    private File propertiesFile;
+
+    /**
+     * A required parameter.
+     * 
+     * @parameter expression="${config.requiredParam}"
+     * @required
+     */
+    private String requiredParam;
+
+    /**
+     * A required parameter that is actually backed by default value from the POM.
+     * 
+     * @parameter default-value="${project.artifactId}"
+     * @required
+     */
+    private String requiredParamWithDefault;
+
+    /**
+     * 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>.
+     */
+    private void dumpConfiguration( Properties props )
+    {
+        PropertiesUtil.serialize( props, "requiredParam", requiredParam );
+        PropertiesUtil.serialize( props, "requiredParamWithDefault", requiredParamWithDefault
);
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/RequiredConfigMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/RequiredConfigMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message