Author: vmassol Date: Sat Dec 2 16:55:45 2006 New Revision: 481679 URL: http://svn.apache.org/viewvc?view=rev&rev=481679 Log: Refactoring: use the Plexus Resources component to locate the Clover license specified by the user (using the licenseLocation configuration element). Added a functional test to prove it works.
Added: maven/plugins/trunk/maven-clover-plugin/src/it/license/ maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/ maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/pom.xml maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/src/ maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/src/main/ maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/src/main/resources/ maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/src/main/resources/myclover.license maven/plugins/trunk/maven-clover-plugin/src/it/license/pom.xml maven/plugins/trunk/maven-clover-plugin/src/it/license/project/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/pom.xml maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/main/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/main/java/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/main/java/org/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/main/java/org/apache/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/main/java/org/apache/maven/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/main/java/org/apache/maven/plugin/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/main/java/org/apache/maven/plugin/clover/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/main/java/org/apache/maven/plugin/clover/samples/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/test/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/test/java/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/test/java/org/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/test/java/org/apache/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/test/java/org/apache/maven/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/test/java/org/apache/maven/plugin/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/test/java/org/apache/maven/plugin/clover/ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/src/test/java/org/apache/maven/plugin/clover/samples/ Removed: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/internal/DefaultLocator.java maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/internal/Locator.java Modified: maven/plugins/trunk/maven-clover-plugin/pom.xml maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/internal/AbstractCloverMojo.java maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/internal/CloverMojoTest.java Modified: maven/plugins/trunk/maven-clover-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/pom.xml?view=diff&rev=481679&r1=481678&r2=481679 ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-clover-plugin/pom.xml Sat Dec 2 16:55:45 2006 @@ -87,6 +87,11 @@ <version>1.5.2</version> </dependency> <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-resources</artifactId> + <version>1.0-alpha-4-SNAPSHOT</version> + </dependency> + <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-project</artifactId> <version>2.0</version> Added: maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/pom.xml?view=auto&rev=481679 ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/pom.xml (added) +++ maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/pom.xml Sat Dec 2 16:55:45 2006 @@ -0,0 +1,13 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-clover-plugin-sample-license</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>maven-clover-plugin-sample-license-build-tools</artifactId> + <packaging>jar</packaging> + <name>Maven Clover Plugin Build Tools License Sample</name> + <description>Maven Clover Plugin Build Tools License Sample</description> + <version>1.0-SNAPSHOT</version> +</project> Added: maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/src/main/resources/myclover.license URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/src/main/resources/myclover.license?view=auto&rev=481679 ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/src/main/resources/myclover.license (added) +++ maven/plugins/trunk/maven-clover-plugin/src/it/license/build-tools/src/main/resources/myclover.license Sat Dec 2 16:55:45 2006 @@ -0,0 +1,103 @@ +Product: Clover +License: Maven License, 0.x, 1.x +Issued: Sun Feb 20 2005 16:07:54 CST +Expiry: Tue Jan 30 2007 00:00:00 CST +Key: cb1bdacca8bc16c87e3a54ba8 +Name: Vincent Massol +Org: Maven +Certificate: AAACSW+Ow8B7/zEbxOMqqKwwrdpP+b9RI3QpJp1t7GEdsHEZ1bTfFsNcI +BFgt6wjtrbhk5osqpdgk/yEZJj3job+JBdaXy0D57q4LR5IvOBFb4CejKlB7R0tBLMtZB1 +z8E40a4RpZPEs1unqS5oRKOLDDsuZMK6fVZK9RnYiEzfIO6UjDvImCYDyjkq8SSYBJdTpP +KHHttTJZrrTOMq/onTG48fHvG9PJns/HPb08BUDW+OhGX392JfAVPEJPR3tJ3kJbsdNe3K +DbyXxMdbmpVPTFD/p1UWP4Cm+zU6apE12fkU37zazJkv0Q1mB4tJSu103bmrK83fzu+OQj +HD73nDmuu84w+7Wz6BkTwZ3Pgbru/ZBE0Kq+kRj6NrNxlW/DiEd4zB+AW7+Qy14jzsO+S3 +W1eBP1QQz88lSku5Vsdlezr9RI3QpYckovj9d43Rdl/GKLKVBMQFrzvg86OLtkp4kqZRa0 +6P9INP30s+9c1JaZikH7732AANCtuALXuLGyoNd9hstErAhNgwvwAI1cpY7IeAvn/XgW5R +9MvPLTNa0La7aN4umT2tlUWLJULQ5XfI5TYO5m1S8TVgIbN74fPLj/snfZ+/CNJ79v2SOt +pGR/T1bZCZ8f+G79hUWSK2zZmbvzsrGEekROxW3ZH4QOsMYdDKWbDO2PJPp9ErbWTnoywC +fr3+03UmSok12cAN7xTm5Pl3jLQmT4Z1VoEc8RGrbvVHt6abF3h72zjPGov0xmP/XxKNjD +Dl2cUDIupIJHlit5kJn5pLN0UT6cmt3yzrO+BX3scmXzeu17h1HJLOQy9q0o7miSCEcOEH +LjJ1P78PDE3rjL5NC2IROehYovQkUBV6sLclEk9vAKS+dEAlnzKMur44hl0A8VXYIg4xUQ +y9EfblF3m8BcH5d9ggEI168IblSrBoovsoeDoKnL9iqcl2afQabsFPXk2g9 +License Agreement: CENQUA CLOVER EVALUATION SOFTWARE LICENSE AGREEMENT + +CENQUA IS WILLING TO LICENSE CLOVER AND ACCOMPANYING DOCUMENTATION +(THE "SOFTWARE") TO YOU (THE "EVALUATOR") FOR EVALUATION PURPOSES ONLY +UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS OF THIS LICENSE +AGREEMENT. PLEASE READ THESE TERMS CAREFULLY BEFORE INSTALLING OR +USING THE SOFTWARE. BY INSTALLING OR USING THE SOFTWARE, YOU ARE +CONSENTING TO BE BOUND BY AND ARE BECOMING A PARTY TO THIS AGREEMENT. + +1. Software: The licensed Software is "Clover Evaluation Edition". + +2. Grant of License: Cortex eBusiness Pty Ltd ("Cenqua") hereby + grants to Evaluator, for 30 days (the "Evaluation Period") + following the execution of this Agreement (the "Agreement"), a + limited, nontransferable, nonexclusive, nonsublicensable, + revocable, worldwide license to use the Software for the purposes + of internal evaluation and testing for suitability for commercial + licensing ("Evaluation") by Evaluator. Title to the Software shall + remain with Cenqua at all times. + +3. Exclusions: Evaluator shall not: a. copy any part of the Software + except to make one copy for back-up purposes only; b. reverse + compile or reverse assemble any portion of the Software where the + source code is not freely accessible; c. distribute, disclose, + market, rent, lease, or transfer the Software; d. export the + Software; or e. allow others to make or obtain copies of the + Software. + +4. Support: Cenqua may, during the Evaluation Period, make + available updates, enhancements, and/or modifications to the + Software and may provide such updates to Evaluator, but is under no + obligation to do so. The provision by Cenqua to Evaluator of + such updates, enhancements, and/or modifications to the Software + shall be subject to all terms and conditions of this Agreement and + shall expire at the end of the Evaluation Period. + +5. Specific Disclaimer of Warranty and Limitation of Liability: + +THE SOFTWARE IS PROVIDED WITHOUT WARRANTY OF ANY KIND. CENQUA +DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE. CENQUA WILL NOT BE LIABLE FOR ANY DAMAGES +ASSOCIATED WITH THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ORDINARY, +INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING +BUT NOT LIMITED TO DAMAGES RELATING TO LOST DATA OR LOST PROFITS, EVEN +IF CENQUA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +6. Termination: Evaluator's license to use the Software shall + terminate on the earlier of (i) written notice by either Cenqua + or Evaluator, or (ii) expiration of the Evaluation Period. Upon + termination of the license as provided above, Evaluator shall + promptly destroy the Software and any back-up copy of the Software + made during the Evaluation Period. Evaluator shall also promptly + return all materials provided by Cenqua in connection with the + Software. + +7. Warranties and Representations; Indemnification. Evaluator warrants + and represents that Evaluator's actions with regard to the Software + will be in compliance with all applicable laws; and Evaluator will + indemnify, defend, and hold Cenqua harmless from and against any + and all liabilities, damages, losses, claims, costs, and expenses + (including legal fees) arising out of or resulting from Evaluator's + failure to observe the use restrictions set forth herein. + +8. Governing Law: This Agreement shall be governed by the laws of New + South Wales, Australia. + +9.Independent Contractors; Assignment: The parties are independent + contractors with respect to each other, and nothing in this + Agreement shall be construed as creating an employer-employee + relationship, a partnership, agency relationship or a joint venture + between the parties. This Agreement is not assignable or + transferable by Evaluator. + +10.Entire Agreement: This Agreement constitutes the entire agreement + between the parties concerning Evaluator's use of the + Software. This Agreement supersedes any prior verbal understanding + between the parties and any Evaluator purchase order or other + ordering document, regardless of whether such document is received + by Cenqua before or after execution of this Agreement. This + Agreement may be amended only in writing by Cenqua. + Added: maven/plugins/trunk/maven-clover-plugin/src/it/license/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/it/license/pom.xml?view=auto&rev=481679 ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/it/license/pom.xml (added) +++ maven/plugins/trunk/maven-clover-plugin/src/it/license/pom.xml Sat Dec 2 16:55:45 2006 @@ -0,0 +1,14 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-clover-plugin-sample-license</artifactId> + <packaging>pom</packaging> + <name>Maven Clover Plugin License Sample</name> + <description>Maven Clover Plugin License Sample</description> + <version>1.0-SNAPSHOT</version> + <modules> + <module>build-tools</module> + <module>project</module> + </modules> +</project> + \ No newline at end of file Added: maven/plugins/trunk/maven-clover-plugin/src/it/license/project/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/it/license/project/pom.xml?view=auto&rev=481679 ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/it/license/project/pom.xml (added) +++ maven/plugins/trunk/maven-clover-plugin/src/it/license/project/pom.xml Sat Dec 2 16:55:45 2006 @@ -0,0 +1,47 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-clover-plugin-sample-license</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>maven-clover-plugin-sample-license-project</artifactId> + <packaging>jar</packaging> + <name>Maven Clover Plugin Project License Sample</name> + <description>Maven Clover Plugin Project License Sample</description> + <version>1.0-SNAPSHOT</version> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-clover-plugin</artifactId> + <dependencies> + <dependency> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-clover-plugin-sample-license-build-tools</artifactId> + <version>${version}</version> + </dependency> + </dependencies> + <configuration> + <licenseLocation>myclover.license</licenseLocation> + </configuration> + <executions> + <execution> + <phase>verify</phase> + <goals> + <goal>instrument</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java?view=diff&rev=481679&r1=481678&r2=481679 ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java (original) +++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java Sat Dec 2 16:55:45 2006 @@ -43,6 +43,5 @@ public void execute() throws MojoExecutionException { - super.execute(); } } Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/internal/AbstractCloverMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/internal/AbstractCloverMojo.java?view=diff&rev=481679&r1=481678&r2=481679 ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/internal/AbstractCloverMojo.java (original) +++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/internal/AbstractCloverMojo.java Sat Dec 2 16:55:45 2006 @@ -20,8 +20,8 @@ import org.apache.maven.project.MavenProject; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Taskdef; +import org.codehaus.plexus.resource.ResourceManager; -import java.io.IOException; import java.io.File; /** @@ -113,9 +113,10 @@ private MavenProject project; /** - * Resource locator. + * Resource manager used to locate any Clover license file provided by the user. + * @component */ - private Locator locator; + private ResourceManager resourceManager; /** * [EMAIL PROTECTED] @@ -123,22 +124,17 @@ */ public void execute() throws MojoExecutionException { - if (this.locator == null) - { - this.locator = new DefaultLocator( getLog(), new File( this.project.getBuild().getDirectory() ) ); - } - registerLicenseFile(); } - public void setLocator(Locator locator) + public void setResourceManager(ResourceManager resourceManager) { - this.locator = locator; + this.resourceManager = resourceManager; } - public Locator getLocator() + public ResourceManager getResourceManager() { - return this.locator; + return this.resourceManager; } /** @@ -158,11 +154,12 @@ { try { - license = getLocator().resolveLocation(this.licenseLocation, "clover.license").getPath(); + license = getResourceManager().getResourceAsFile(this.licenseLocation).getPath(); + getLog().debug("Loading license from classpath [" + license + "]"); } - catch (IOException e) + catch (Exception e) { - throw new MojoExecutionException("Failed to load license file", e); + throw new MojoExecutionException("Failed to load license file [" + this.licenseLocation + "]", e); } } else if (this.licenseFile != null) @@ -175,6 +172,7 @@ license = getClass().getResource("/clover.license").getFile(); } + getLog().debug("Using license file [" + license + "]"); System.setProperty("clover.license.path", license); } Modified: maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/internal/CloverMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/internal/CloverMojoTest.java?view=diff&rev=481679&r1=481678&r2=481679 ============================================================================== --- maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/internal/CloverMojoTest.java (original) +++ maven/plugins/trunk/maven-clover-plugin/src/test/java/org/apache/maven/plugin/clover/internal/CloverMojoTest.java Sat Dec 2 16:55:45 2006 @@ -16,10 +16,10 @@ package org.apache.maven.plugin.clover.internal; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.clover.internal.Locator; import org.apache.maven.plugin.clover.internal.AbstractCloverMojo; import org.jmock.MockObjectTestCase; import org.jmock.Mock; +import org.codehaus.plexus.resource.ResourceManager; import java.io.File; @@ -43,15 +43,15 @@ { TestableAbstractCloverMojo mojo = new TestableAbstractCloverMojo(); - Mock mockLocator = mock( Locator.class ); - mojo.setLocator( (Locator) mockLocator.proxy() ); + Mock mockResourceManager = mock( ResourceManager.class ); + mojo.setResourceManager( (ResourceManager) mockResourceManager.proxy() ); // Ensure that the system property is not already set System.setProperty( "clover.license.path", "" ); mojo.setLicenseLocation( "build-tools/clover.license" ); - mockLocator.expects( once() ).method( "resolveLocation" ) - .with( eq( "build-tools/clover.license" ), eq( "clover.license" ) ) + mockResourceManager.expects( once() ).method( "getResourceAsFile" ) + .with( eq( "build-tools/clover.license" ) ) .will( returnValue( new File( "targetFile" ) ) ); mojo.registerLicenseFile();