o Added new IT plugin to verify multi goal executions scenarios

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@722525 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2008-12-02 17:05:12 +00:00
parent be10f64e2c
commit 3015a143c7
6 changed files with 369 additions and 0 deletions

View File

@ -0,0 +1,52 @@
<?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 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>
<parent>
<artifactId>maven-it-plugins</artifactId>
<groupId>org.apache.maven.its.plugins</groupId>
<version>2.1-SNAPSHOT</version>
</parent>
<artifactId>maven-it-plugin-log-file</artifactId>
<packaging>maven-plugin</packaging>
<name>Maven Integration Test Plugin :: Log File</name>
<description>
A test plugin that appends lines to a UTF-8 encoded log file. Apparently, the order of log lines allows to check
the order in which the plugin's goals were executed.
</description>
<inceptionYear>2008</inceptionYear>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,153 @@
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.plugin.MojoExecutionException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
/**
* Provides common services for the mojos of this plugin.
*
* @author Benjamin Bentmann
* @version $Id$
*/
public abstract class AbstractLogMojo
extends AbstractMojo
{
/**
* The project's base directory, used for manual path translation.
*
* @parameter default-value="${basedir}"
* @readonly
*/
private File basedir;
/**
* The path to the output file, relative to the current working directory.
*
* @parameter expression="${log.logFile}" default-value="target/it.log" alias="outputFile"
*/
private File logFile;
/**
* The character encoding of the log file.
*/
private String encoding = "UTF-8";
/**
* Gets the absolute path to the log file.
*
* @return The absolute path to the log file, never <code>null</code>.
*/
private File getLogFile()
{
/*
* NOTE: We don't want to test path translation here.
*/
return logFile.isAbsolute() ? logFile : new File( basedir, logFile.getPath() );
}
/**
* Appends the string representation of the specified object to the log file. Logging <code>null</code> has no other
* effect than touching the file. For each value different from <code>null</code>, a line terminator will be
* appended to the value's string representation.
*
* @param value The object to log, may be <code>null</code>.
* @throws MojoExecutionException If the log file could not be updated.
*/
protected void append( Object value )
throws MojoExecutionException
{
File file = getLogFile();
getLog().info( "[MAVEN-CORE-IT-LOG] Updating log file: " + file );
getLog().info( "[MAVEN-CORE-IT-LOG] " + value );
try
{
file.getParentFile().mkdirs();
OutputStream out = new FileOutputStream( file, true );
try
{
BufferedWriter writer = new BufferedWriter( new OutputStreamWriter( out, encoding ) );
if ( value != null )
{
writer.write( value.toString() );
writer.newLine();
writer.flush();
}
}
finally
{
try
{
out.close();
}
catch ( IOException e )
{
// just ignore, we tried our best to clean up
}
}
}
catch ( IOException e )
{
throw new MojoExecutionException( "Failed to update log file " + logFile, e );
}
}
/**
* Clears the contents of the log file by creating a new empty log file.
*
* @throws MojoExecutionException If the log file could not be reset.
*/
protected void reset()
throws MojoExecutionException
{
File file = getLogFile();
getLog().info( "[MAVEN-CORE-IT-LOG] Resetting log file: " + file );
try
{
/*
* NOTE: Intentionally don't delete the file but create a new empty one to check the plugin was executed.
*/
file.getParentFile().mkdirs();
OutputStream out = new FileOutputStream( file );
try
{
out.close();
}
catch ( IOException e )
{
// just ignore, we tried our best to clean up
}
}
catch ( IOException e )
{
throw new MojoExecutionException( "Failed to reset log file " + logFile, e );
}
}
}

View File

@ -0,0 +1,60 @@
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.MojoExecutionException;
/**
* Appends a separator line to the log file.
*
* @goal log-separator
* @phase initialize
*
* @author Benjamin Bentmann
* @version $Id$
*/
public class LogSeparatorMojo
extends AbstractLogMojo
{
/**
* The length of the separator line.
*
* @parameter expression="${log.length}" default-value="80"
*/
private int length;
/**
* Runs this mojo.
*
* @throws MojoExecutionException If the output file could not be created.
*/
public void execute()
throws MojoExecutionException
{
StringBuffer buffer = new StringBuffer( length );
for ( int i = 0; i < length; i++ )
{
buffer.append( '-' );
}
append( buffer.toString() );
}
}

View File

@ -0,0 +1,55 @@
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.MojoExecutionException;
/**
* Appends a string to the log file.
*
* @goal log-string
* @phase initialize
*
* @author Benjamin Bentmann
* @version $Id$
*/
public class LogStringMojo
extends AbstractLogMojo
{
/**
* The string to append to the log file.
*
* @parameter expression="${log.string}"
*/
private String string;
/**
* Runs this mojo.
*
* @throws MojoExecutionException If the output file could not be created.
*/
public void execute()
throws MojoExecutionException
{
append( string );
}
}

View File

@ -0,0 +1,48 @@
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.MojoExecutionException;
/**
* Appends a string to the log file.
*
* @goal reset
* @phase initialize
*
* @author Benjamin Bentmann
* @version $Id$
*/
public class ResetMojo
extends AbstractLogMojo
{
/**
* Runs this mojo.
*
* @throws MojoExecutionException If the output file could not be created.
*/
public void execute()
throws MojoExecutionException
{
reset();
}
}

View File

@ -44,6 +44,7 @@ under the License.
<module>maven-it-plugin-expression</module>
<module>maven-it-plugin-file</module>
<module>maven-it-plugin-fork</module>
<module>maven-it-plugin-log-file</module>
<module>maven-it-plugin-no-project</module>
<module>maven-it-plugin-packaging</module>
<module>maven-it-plugin-parameter-implementation</module>