Author: vmassol Date: Fri May 19 04:11:59 2006 New Revision: 407771 URL: http://svn.apache.org/viewvc?rev=407771&view=rev Log: MCLOVER-36: Plugin should locate clover artifact based on groupId+artifactId and not only on artifactId
Added: maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojoTest.java (with props) Modified: maven/plugins/trunk/maven-clover-plugin/pom.xml maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java Modified: maven/plugins/trunk/maven-clover-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/pom.xml?rev=407771&r1=407770&r2=407771&view=diff ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-clover-plugin/pom.xml Fri May 19 04:11:59 2006 @@ -32,12 +32,6 @@ </developers> <dependencies> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-compiler-api</artifactId> <version>1.5.2</version> @@ -48,12 +42,6 @@ <version>2.0</version> </dependency> <dependency> - <groupId>jmock</groupId> - <artifactId>jmock</artifactId> - <version>1.0.1</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>2.0</version> @@ -77,6 +65,18 @@ <groupId>com.cenqua.clover</groupId> <artifactId>clover</artifactId> <version>1.3.12</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>jmock</groupId> + <artifactId>jmock</artifactId> + <version>1.0.1</version> + <scope>test</scope> </dependency> </dependencies> </project> Modified: maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml?rev=407771&r1=407770&r2=407771&view=diff ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml (original) +++ maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml Fri May 19 04:11:59 2006 @@ -49,15 +49,6 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clover-plugin</artifactId> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - </dependency> - </dependencies> - <configuration> <targetPercentage>1%</targetPercentage> Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java?rev=407771&r1=407770&r2=407771&view=diff ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java (original) +++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java Fri May 19 04:11:59 2006 @@ -282,23 +282,32 @@ return resolvedArtifacts; } - private void addCloverDependencyToCompileClasspath() - throws MojoExecutionException + protected Artifact findCloverArtifact(List pluginArtifacts) { Artifact cloverArtifact = null; - Iterator artifacts = this.pluginArtifacts.iterator(); + Iterator artifacts = pluginArtifacts.iterator(); while ( artifacts.hasNext() && cloverArtifact == null ) { Artifact artifact = (Artifact) artifacts.next(); - if ( "clover".equalsIgnoreCase( artifact.getArtifactId() ) ) + + // We identify the clover JAR by checking the groupId and artifactId. + if ( "com.cenqua.clover".equals( artifact.getGroupId() ) + && "clover".equals( artifact.getArtifactId() ) ) { cloverArtifact = artifact; } } + return cloverArtifact; + } + private void addCloverDependencyToCompileClasspath() + throws MojoExecutionException + { + Artifact cloverArtifact = findCloverArtifact(this.pluginArtifacts); if ( cloverArtifact == null ) { - throw new MojoExecutionException( "Couldn't find 'clover' artifact in plugin dependencies" ); + throw new MojoExecutionException( + "Couldn't find [com.cenqua.cover:clover] artifact in plugin dependencies" ); } cloverArtifact = artifactFactory.createArtifact( cloverArtifact.getGroupId(), cloverArtifact.getArtifactId(), Added: maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojoTest.java?rev=407771&view=auto ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojoTest.java (added) +++ maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojoTest.java Fri May 19 04:11:59 2006 @@ -0,0 +1,55 @@ +/* + * Copyright 2006 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. + */ +package org.apache.maven.plugin.clover; + +import org.jmock.MockObjectTestCase; +import org.jmock.Mock; +import org.apache.maven.artifact.Artifact; + +import java.util.Collections; + +/** + * Unit tests for [EMAIL PROTECTED] org.apache.maven.plugin.clover.CloverInstrumentInternalMojo}. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * @version $Id$ + */ +public class CloverInstrumentInternalMojoTest extends MockObjectTestCase +{ + public void testFindCloverArtifactWithCorrectArtifactIdButWrongGroupId() + { + Mock mockArtifact = mock(Artifact.class); + mockArtifact.stubs().method( "getArtifactId" ).will( returnValue( "clover" ) ); + mockArtifact.stubs().method( "getGroupId" ).will( returnValue( "notcenquaid" ) ); + + CloverInstrumentInternalMojo mojo = new CloverInstrumentInternalMojo(); + Artifact clover = mojo.findCloverArtifact( Collections.singletonList( mockArtifact.proxy() ) ); + + assertNull( "Clover artifact should not have been found!", clover ); + } + + public void testFindCloverArtifactWhenCorrectIds() + { + Mock mockArtifact = mock(Artifact.class); + mockArtifact.stubs().method( "getArtifactId" ).will( returnValue( "clover" ) ); + mockArtifact.stubs().method( "getGroupId" ).will( returnValue( "com.cenqua.clover" ) ); + + CloverInstrumentInternalMojo mojo = new CloverInstrumentInternalMojo(); + Artifact clover = mojo.findCloverArtifact( Collections.singletonList( mockArtifact.proxy() ) ); + + assertNotNull( "Clover artifact should have been found!", clover ); + } +} Propchange: maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojoTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojoTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision