mirror of https://github.com/apache/maven.git
[MNG-3684] Adding integration test to verify fix, and surrounding report configuration/instantiation with calls to make the project build section concrete, then restore it to dynamic mode after the report is ready to go. The execution of a plugin that uses these reports will trigger the calculation of the project's concrete state again, but we don't want to leave the project in this state in the meantime.
git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@679892 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8fe8821672
commit
f2cf5ce658
|
@ -65,6 +65,7 @@ public class IntegrationTestSuite
|
||||||
* a fail fast technique as well.
|
* a fail fast technique as well.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
suite.addTestSuite( MavenITmng3684BuildPluginParameterTest.class );
|
||||||
suite.addTestSuite( MavenITmng3680InvalidDependencyPOMTest.class );
|
suite.addTestSuite( MavenITmng3680InvalidDependencyPOMTest.class );
|
||||||
suite.addTestSuite( MavenITmng3679PluginExecIdInterpolationTest.class );
|
suite.addTestSuite( MavenITmng3679PluginExecIdInterpolationTest.class );
|
||||||
suite.addTestSuite( MavenITmng3671PluginLevelDepInterpolationTest.class );
|
suite.addTestSuite( MavenITmng3671PluginLevelDepInterpolationTest.class );
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package org.apache.maven.integrationtests;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
|
import org.apache.maven.it.Verifier;
|
||||||
|
import org.apache.maven.it.util.ResourceExtractor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify that the Build instance injected as a plugin parameter contains
|
||||||
|
* interpolated values for things like the various build paths, etc.
|
||||||
|
*
|
||||||
|
* @author jdcasey
|
||||||
|
*/
|
||||||
|
public class MavenITmng3684BuildPluginParameterTest
|
||||||
|
extends AbstractMavenIntegrationTestCase
|
||||||
|
{
|
||||||
|
public MavenITmng3684BuildPluginParameterTest()
|
||||||
|
throws InvalidVersionSpecificationException
|
||||||
|
{
|
||||||
|
super( "(2.0.9,)" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testitMNG3684 ()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3684-buildPluginParameter" );
|
||||||
|
File pluginDir = new File( testDir, "maven-mng3684-plugin" );
|
||||||
|
File projectDir = new File( testDir, "project" );
|
||||||
|
|
||||||
|
Verifier verifier = new Verifier( pluginDir.getAbsolutePath() );
|
||||||
|
verifier.executeGoal( "install" );
|
||||||
|
|
||||||
|
verifier.verifyErrorFreeLog();
|
||||||
|
verifier.resetStreams();
|
||||||
|
|
||||||
|
verifier = new Verifier( projectDir.getAbsolutePath() );
|
||||||
|
verifier.executeGoal( "validate" );
|
||||||
|
|
||||||
|
verifier.verifyErrorFreeLog();
|
||||||
|
verifier.resetStreams();
|
||||||
|
|
||||||
|
File logFile = new File( projectDir, "log.txt" );
|
||||||
|
logFile.renameTo( new File( projectDir, "log-validate.txt" ) );
|
||||||
|
|
||||||
|
verifier.executeGoal( "site" );
|
||||||
|
|
||||||
|
verifier.verifyErrorFreeLog();
|
||||||
|
verifier.resetStreams();
|
||||||
|
|
||||||
|
logFile.renameTo( new File( projectDir, "log-site.txt" ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
<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>
|
||||||
|
<groupId>org.apache.maven.its.mng3684</groupId>
|
||||||
|
<artifactId>maven-mng3684-plugin</artifactId>
|
||||||
|
<packaging>maven-plugin</packaging>
|
||||||
|
<version>1</version>
|
||||||
|
<name>maven-mng3684-plugin Maven Mojo</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-plugin-api</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-project</artifactId>
|
||||||
|
<version>2.0.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.reporting</groupId>
|
||||||
|
<artifactId>maven-reporting-api</artifactId>
|
||||||
|
<version>2.0.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.reporting</groupId>
|
||||||
|
<artifactId>maven-reporting-impl</artifactId>
|
||||||
|
<version>2.0.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,122 @@
|
||||||
|
package plugin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensed 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.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.maven.model.Build;
|
||||||
|
import org.apache.maven.model.Resource;
|
||||||
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @goal check
|
||||||
|
*/
|
||||||
|
public class MyMojo
|
||||||
|
extends AbstractMojo
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @parameter default-value="${project.build}"
|
||||||
|
* @required
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
private Build build;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @parameter default-value="${project}"
|
||||||
|
* @required
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
private MavenProject project;
|
||||||
|
|
||||||
|
public void execute()
|
||||||
|
throws MojoExecutionException
|
||||||
|
{
|
||||||
|
Build projectBuild = project.getBuild();
|
||||||
|
|
||||||
|
Map failedComparisons = new HashMap();
|
||||||
|
|
||||||
|
check( "project.build.directory", projectBuild.getDirectory(), build.getDirectory(), failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.outputDirectory", projectBuild.getOutputDirectory(), build.getOutputDirectory(),
|
||||||
|
failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.sourceDirectory", projectBuild.getSourceDirectory(), build.getSourceDirectory(),
|
||||||
|
failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.testSourceDirectory", projectBuild.getTestSourceDirectory(),
|
||||||
|
build.getTestSourceDirectory(), failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.scriptSourceDirectory", projectBuild.getScriptSourceDirectory(),
|
||||||
|
build.getScriptSourceDirectory(), failedComparisons );
|
||||||
|
|
||||||
|
List projectResources = projectBuild.getResources();
|
||||||
|
List buildResources = build.getResources();
|
||||||
|
|
||||||
|
if ( projectResources != null )
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < projectResources.size(); i++ )
|
||||||
|
{
|
||||||
|
Resource projectRes = (Resource) projectResources.get( i );
|
||||||
|
Resource buildRes = (Resource) buildResources.get( i );
|
||||||
|
|
||||||
|
check( "project.build.resources[" + i + "].directory", projectRes.getDirectory(),
|
||||||
|
buildRes.getDirectory(), failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.resources[" + i + "].targetPath", projectRes.getTargetPath(),
|
||||||
|
buildRes.getTargetPath(), failedComparisons );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !failedComparisons.isEmpty() )
|
||||||
|
{
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
|
buffer.append( "One or more build-section values were not interpolated correctly"
|
||||||
|
+ "\nbefore the build instance was injected as a plugin parameter:\n" );
|
||||||
|
|
||||||
|
for ( Iterator it = failedComparisons.entrySet().iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
Map.Entry entry = (Map.Entry) it.next();
|
||||||
|
String key = (String) entry.getKey();
|
||||||
|
String[] value = (String[]) entry.getValue();
|
||||||
|
|
||||||
|
buffer.append( "\n- " ).append( key );
|
||||||
|
buffer.append( "\n\tShould be: \'" ).append( value[0] );
|
||||||
|
buffer.append( "\'\n\t Was: \'" ).append( value[1] ).append( "\'\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new MojoExecutionException( buffer.toString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void check( String description, String projectValue, String buildValue, Map failedComparisons )
|
||||||
|
{
|
||||||
|
if ( projectValue == null && buildValue != null )
|
||||||
|
{
|
||||||
|
failedComparisons.put( description, new String[] { projectValue, buildValue } );
|
||||||
|
}
|
||||||
|
else if ( projectValue != null && !projectValue.equals( buildValue ) )
|
||||||
|
{
|
||||||
|
failedComparisons.put( description, new String[] { projectValue, buildValue } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,160 @@
|
||||||
|
package plugin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensed 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.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.maven.doxia.siterenderer.Renderer;
|
||||||
|
import org.apache.maven.model.Build;
|
||||||
|
import org.apache.maven.model.Resource;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.reporting.AbstractMavenReport;
|
||||||
|
import org.apache.maven.reporting.MavenReportException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @goal check-report
|
||||||
|
*/
|
||||||
|
public class MyReport
|
||||||
|
extends AbstractMavenReport
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @parameter default-value="${project.build}"
|
||||||
|
* @required
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
private Build build;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @parameter default-value="${project}"
|
||||||
|
* @required
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
private MavenProject project;
|
||||||
|
|
||||||
|
private void runChecks()
|
||||||
|
throws MavenReportException
|
||||||
|
{
|
||||||
|
Build projectBuild = project.getBuild();
|
||||||
|
|
||||||
|
Map failedComparisons = new HashMap();
|
||||||
|
|
||||||
|
check( "project.build.directory", projectBuild.getDirectory(), build.getDirectory(), failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.outputDirectory", projectBuild.getOutputDirectory(), build.getOutputDirectory(),
|
||||||
|
failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.sourceDirectory", projectBuild.getSourceDirectory(), build.getSourceDirectory(),
|
||||||
|
failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.testSourceDirectory", projectBuild.getTestSourceDirectory(),
|
||||||
|
build.getTestSourceDirectory(), failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.scriptSourceDirectory", projectBuild.getScriptSourceDirectory(),
|
||||||
|
build.getScriptSourceDirectory(), failedComparisons );
|
||||||
|
|
||||||
|
List projectResources = projectBuild.getResources();
|
||||||
|
List buildResources = build.getResources();
|
||||||
|
|
||||||
|
if ( projectResources != null )
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < projectResources.size(); i++ )
|
||||||
|
{
|
||||||
|
Resource projectRes = (Resource) projectResources.get( i );
|
||||||
|
Resource buildRes = (Resource) buildResources.get( i );
|
||||||
|
|
||||||
|
check( "project.build.resources[" + i + "].directory", projectRes.getDirectory(),
|
||||||
|
buildRes.getDirectory(), failedComparisons );
|
||||||
|
|
||||||
|
check( "project.build.resources[" + i + "].targetPath", projectRes.getTargetPath(),
|
||||||
|
buildRes.getTargetPath(), failedComparisons );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !failedComparisons.isEmpty() )
|
||||||
|
{
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
|
buffer.append( "One or more build-section values were not interpolated correctly"
|
||||||
|
+ "\nbefore the build instance was injected as a plugin parameter:\n" );
|
||||||
|
|
||||||
|
for ( Iterator it = failedComparisons.entrySet().iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
Map.Entry entry = (Map.Entry) it.next();
|
||||||
|
String key = (String) entry.getKey();
|
||||||
|
String[] value = (String[]) entry.getValue();
|
||||||
|
|
||||||
|
buffer.append( "\n- " ).append( key );
|
||||||
|
buffer.append( "\n\tShould be: \'" ).append( value[0] );
|
||||||
|
buffer.append( "\'\n\t Was: \'" ).append( value[1] ).append( "\'\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new MavenReportException( buffer.toString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void check( String description, String projectValue, String buildValue, Map failedComparisons )
|
||||||
|
{
|
||||||
|
if ( projectValue == null && buildValue != null )
|
||||||
|
{
|
||||||
|
failedComparisons.put( description, new String[] { projectValue, buildValue } );
|
||||||
|
}
|
||||||
|
else if ( projectValue != null && !projectValue.equals( buildValue ) )
|
||||||
|
{
|
||||||
|
failedComparisons.put( description, new String[] { projectValue, buildValue } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void executeReport( Locale locale )
|
||||||
|
throws MavenReportException
|
||||||
|
{
|
||||||
|
runChecks();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getOutputDirectory()
|
||||||
|
{
|
||||||
|
return project.getReporting().getOutputDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MavenProject getProject()
|
||||||
|
{
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Renderer getSiteRenderer()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription( Locale locale )
|
||||||
|
{
|
||||||
|
return "test";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName( Locale locale )
|
||||||
|
{
|
||||||
|
return "test";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOutputName()
|
||||||
|
{
|
||||||
|
return "test";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
<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>
|
||||||
|
<groupId>org.apache.maven.its.mng3684</groupId>
|
||||||
|
<artifactId>mng3684-project</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1</version>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.its.mng3684</groupId>
|
||||||
|
<artifactId>maven-mng3684-plugin</artifactId>
|
||||||
|
<version>1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>check</id>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.its.mng3684</groupId>
|
||||||
|
<artifactId>maven-mng3684-plugin</artifactId>
|
||||||
|
<version>1</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
</project>
|
Loading…
Reference in New Issue