1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
32
33
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
66
67
68
69
70
71
72
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 }