MNG-5640: IT that verifies that lifecycle participant afterSessionEnd is invoked even with build failure
Signed-off-by: Jason van Zyl <ja...@tesla.io> Project: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/commit/3483c6e1 Tree: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/tree/3483c6e1 Diff: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/diff/3483c6e1 Branch: refs/heads/master Commit: 3483c6e1ec499f11becc7899d0a40672b06088b7 Parents: 637d7ad Author: Tamas Cservenak <ta...@cservenak.net> Authored: Mon Jun 2 15:41:19 2014 +0200 Committer: Jason van Zyl <ja...@tesla.io> Committed: Tue Jun 10 07:21:25 2014 -0400 ---------------------------------------------------------------------- .../apache/maven/it/IntegrationTestSuite.java | 1 + ...5640LifecycleParticipantAfterSessionEnd.java | 66 +++++++++++++++++++ .../basic/pom.xml | 48 ++++++++++++++ .../apache/maven/its/mng5640/FailingTest.java | 18 +++++ .../extension/pom.xml | 69 ++++++++++++++++++++ .../LifecycleParticipantImpl.java | 69 ++++++++++++++++++++ 6 files changed, 271 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/3483c6e1/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java ---------------------------------------------------------------------- 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 72bc030..b229581 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 // ------------------------------------------------------------------------------------------------------------- // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137 + suite.addTestSuite( MavenITmng5640LifecycleParticipantAfterSessionEnd.class ); suite.addTestSuite( MavenITmng5608ProfileActivationWarningTest.class ); suite.addTestSuite( MavenITmng5591WorkspaceReader.class ); suite.addTestSuite( MavenITmng5581LifecycleMappingDelegate.class ); http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/3483c6e1/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5640LifecycleParticipantAfterSessionEnd.java ---------------------------------------------------------------------- diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5640LifecycleParticipantAfterSessionEnd.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5640LifecycleParticipantAfterSessionEnd.java new file mode 100644 index 0000000..d0151cd --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5640LifecycleParticipantAfterSessionEnd.java @@ -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" ); + } +} http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/3483c6e1/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/pom.xml ---------------------------------------------------------------------- diff --git a/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/pom.xml b/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/pom.xml new file mode 100644 index 0000000..fea98e0 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/pom.xml @@ -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> http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/3483c6e1/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/src/test/java/org/apache/maven/its/mng5640/FailingTest.java ---------------------------------------------------------------------- diff --git a/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/src/test/java/org/apache/maven/its/mng5640/FailingTest.java b/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/src/test/java/org/apache/maven/its/mng5640/FailingTest.java new file mode 100644 index 0000000..3f2dd98 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/src/test/java/org/apache/maven/its/mng5640/FailingTest.java @@ -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 ); + } +} http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/3483c6e1/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/pom.xml ---------------------------------------------------------------------- diff --git a/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/pom.xml b/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/pom.xml new file mode 100644 index 0000000..ec97934 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/pom.xml @@ -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> http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/3483c6e1/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/src/main/java/org/apache/maven/its/mng5640/lifecycleParticipantAfterSession/LifecycleParticipantImpl.java ---------------------------------------------------------------------- diff --git a/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/src/main/java/org/apache/maven/its/mng5640/lifecycleParticipantAfterSession/LifecycleParticipantImpl.java b/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/src/main/java/org/apache/maven/its/mng5640/lifecycleParticipantAfterSession/LifecycleParticipantImpl.java new file mode 100644 index 0000000..1dabb2e --- /dev/null +++ b/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/src/main/java/org/apache/maven/its/mng5640/lifecycleParticipantAfterSession/LifecycleParticipantImpl.java @@ -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 ); + } + } +}