View Javadoc
1   /*
2    * #%L
3    * Mojo's Maven plugin for Cobertura
4    * %%
5    * Copyright (C) 2005 - 2013 Codehaus
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package org.codehaus.mojo.cobertura;
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
24  import org.codehaus.mojo.cobertura.stubs.ArtifactStub;
25  
26  import java.io.File;
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * Base TestCase for all Cobertura Tests.
32   *
33   * @author Joakim Erdfelt
34   */
35  public abstract class AbstractCoberturaTestCase
36      extends AbstractMojoTestCase
37  {
38      protected void assertArtifactExists( Artifact artifact )
39      {
40          if ( artifact == null )
41          {
42              fail( "Artifact is null." );
43          }
44  
45          if ( artifact.getFile() == null )
46          {
47              fail( "Artifact.file is not defined for " + artifact );
48          }
49  
50          if ( !artifact.getFile().exists() )
51          {
52              fail( "Artifact " + artifact.getFile().getAbsolutePath() + " file does not exist." );
53          }
54      }
55  
56      protected List getPluginClasspath()
57          throws Exception
58      {
59          String localRepository = System.getProperty( "localRepository" );
60  
61          assertNotNull( "System.property(localRepository) should not be null.", localRepository );
62  
63          List pluginClasspath = new ArrayList();
64  
65          // Artifact artifact;
66          // artifact = new ArtifactStub();
67          // artifact.setFile( new File( PlexusTestCase.getBasedir() + "/target/classes" ) );
68          // assertArtifactExists( artifact );
69          // pluginClasspath.add( artifact );
70  
71          // Specify dependencies, that must match whatever is in the Cobertura version being used
72          // @todo We need to find a way to not have to repeat this info here
73  
74          String asmVersion = "5.0.1";
75          String coberturaVersion = "2.1.1";
76  
77          pluginClasspath.add( createArtifact( "net.sourceforge.cobertura", "cobertura", coberturaVersion, "jar", localRepository ) );
78  
79          pluginClasspath.add( createArtifact( "ch.qos.logback", "logback-classic", "1.0.13", "jar", localRepository ) );
80          pluginClasspath.add( createArtifact( "ch.qos.logback", "logback-core", "1.0.13", "jar", localRepository ) );
81  
82          pluginClasspath.add( createArtifact( "org.apache.ant", "ant", "1.8.3", "jar", localRepository ) );
83          pluginClasspath.add( createArtifact( "org.apache.ant", "ant-launcher", "1.8.3", "jar", localRepository ) );
84  
85          pluginClasspath.add( createArtifact( "org.apache.commons", "commons-lang3", "3.3.2", "jar", localRepository ) );
86  
87          pluginClasspath.add( createArtifact( "org.ow2.asm", "asm", asmVersion, "jar", localRepository ) );
88          pluginClasspath.add( createArtifact( "org.ow2.asm", "asm-analysis", asmVersion, "jar", localRepository ) );
89          pluginClasspath.add( createArtifact( "org.ow2.asm", "asm-commons", asmVersion, "jar", localRepository ) );
90          pluginClasspath.add( createArtifact( "org.ow2.asm", "asm-tree", asmVersion, "jar", localRepository ) );
91          pluginClasspath.add( createArtifact( "org.ow2.asm", "asm-util", asmVersion, "jar", localRepository ) );
92  
93          pluginClasspath.add( createArtifact( "oro", "oro", "2.0.8", "jar", localRepository ) );
94  
95          pluginClasspath.add( createArtifact( "org.slf4j", "slf4j-api", "1.7.5", "jar", localRepository ) );
96  
97          pluginClasspath.add( createArtifact( "net.sourceforge.cobertura", "cobertura-runtime", coberturaVersion, "pom", localRepository ) );
98  
99          return pluginClasspath;
100     }
101 
102     private Artifact createArtifact( String groupId, String artifactId, String version, String type, String localRepository ) {
103         Artifact artifact;
104         artifact = new ArtifactStub();
105         artifact.setGroupId( groupId );
106         artifact.setArtifactId( artifactId );
107         artifact.setVersion( version );
108         artifact.setFile( new File( localRepository + "/" + groupId.replace( ".", "/" ) + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "." + type ) );
109         assertArtifactExists( artifact );
110         return artifact;
111     }
112 }