MNG-5640: IT that verifies that lifecycle participant afterSessionEnd is invoked even with build failure

Signed-off-by: Jason van Zyl <jason@tesla.io>
This commit is contained in:
Tamas Cservenak 2014-06-02 15:41:19 +02:00 committed by Jason van Zyl
parent 84b9a832e9
commit 9a128aa7c1
6 changed files with 271 additions and 0 deletions

View File

@ -106,6 +106,7 @@ public class IntegrationTestSuite
// -------------------------------------------------------------------------------------------------------------
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
suite.addTestSuite( MavenITmng5640LifecycleParticipantAfterSessionEnd.class );
suite.addTestSuite( MavenITmng5608ProfileActivationWarningTest.class );
suite.addTestSuite( MavenITmng5591WorkspaceReader.class );
suite.addTestSuite( MavenITmng5581LifecycleMappingDelegate.class );

View File

@ -0,0 +1,66 @@
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 org.apache.maven.it.util.ResourceExtractor;
/**
* IT that verifies that lifecycle participant afterSessionEnd
* method is invoked even with build failure.
*/
public class MavenITmng5640LifecycleParticipantAfterSessionEnd
extends AbstractMavenIntegrationTestCase
{
public MavenITmng5640LifecycleParticipantAfterSessionEnd()
{
super( "[3.2.2,)" );
}
public void test()
throws Exception
{
File testDir =
ResourceExtractor.simpleExtractResources( getClass(), "/mng-5640-lifecycleParticipant-afterSession" );
File extensionDir = new File( testDir, "extension" );
File projectDir = new File( testDir, "basic" );
Verifier verifier;
// install the test plugin
verifier = newVerifier( extensionDir.getAbsolutePath(), "remote" );
verifier.executeGoal( "install" );
verifier.resetStreams();
verifier.verifyErrorFreeLog();
// build the test project
verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
try {
verifier.executeGoal("package");
} catch (VerificationException e) {
// expected, as the build will fail due to always failing UT
}
verifier.resetStreams();
verifier.verifyTextInLog("testApp(org.apache.maven.its.mng5640.FailingTest)");
verifier.assertFilePresent( "target/afterSessionEnd.txt" );
}
}

View File

@ -0,0 +1,48 @@
<?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>
<groupId>org.apache.maven.its.mng5640.lifecycleParticipantAfterSession</groupId>
<artifactId>mng-5640-lifecycleParticipant-afterSession-basic</artifactId>
<version>0.1</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.its.mng5640.lifecycleParticipantAfterSession</groupId>
<artifactId>mng-5640-lifecycleParticipant-afterSession-extension</artifactId>
<version>0.1</version>
</extension>
</extensions>
</build>
</project>

View File

@ -0,0 +1,18 @@
package org.apache.maven.its.mng5640;
import junit.framework.TestCase;
/**
* Always failing UT.
*/
public class FailingTest
extends TestCase
{
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( false );
}
}

View File

@ -0,0 +1,69 @@
<?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>
<groupId>org.apache.maven.its.mng5640.lifecycleParticipantAfterSession</groupId>
<artifactId>mng-5640-lifecycleParticipant-afterSession-extension</artifactId>
<version>0.1</version>
<properties>
<maven-version>3.2.1</maven-version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven-version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>main-index</goal>
<goal>test-index</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,69 @@
package org.apache.maven.its.mng5640.lifecycleParticipantAfterSession;
/*
* 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 javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.Logger;
@Named
@Singleton
public class LifecycleParticipantImpl
extends AbstractMavenLifecycleParticipant
{
private final Logger log;
@Inject
public LifecycleParticipantImpl( Logger log )
{
this.log = log;
}
@Override
public void afterSessionEnd( MavenSession session )
{
MavenProject project = session.getProjects().get( 0 );
File target = new File( project.getBuild().getDirectory() );
File marker = new File( target, "afterSessionEnd.txt" );
if ( !target.exists() && !target.getParentFile().mkdirs() )
{
log.error( "Could not create directory " + target );
}
try
{
new FileOutputStream( marker ).close();
}
catch ( IOException e )
{
log.error( "Could not create marker file " + marker, e );
}
}
}