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.tasks;
21
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.MojoFailureException;
24 import org.codehaus.mojo.cobertura.configuration.ConfigCheck;
25 import org.codehaus.mojo.cobertura.configuration.Regex;
26 import org.codehaus.plexus.util.StringUtils;
27
28
29
30
31
32
33 public class CheckTask
34 extends AbstractTask
35 {
36 private ConfigCheck config;
37
38 private String dataFile;
39
40
41
42
43 public CheckTask()
44 {
45 super( net.sourceforge.cobertura.check.CheckCoverageMain.class.getName() );
46 }
47
48
49
50
51 public void execute()
52 throws MojoExecutionException, MojoFailureException
53 {
54 if ( dataFile != null )
55 {
56 cmdLineArgs.addArg( "--datafile", dataFile );
57 }
58
59 if ( StringUtils.isNotEmpty( config.getBranchRate() ) )
60 {
61 cmdLineArgs.addArg( "--branch", config.getBranchRate() );
62 }
63
64 if ( StringUtils.isNotEmpty( config.getLineRate() ) )
65 {
66 cmdLineArgs.addArg( "--line", config.getLineRate() );
67 }
68
69 if ( StringUtils.isNotEmpty( config.getTotalBranchRate() ) )
70 {
71 cmdLineArgs.addArg( "--totalbranch", config.getTotalBranchRate() );
72 }
73
74 if ( StringUtils.isNotEmpty( config.getTotalLineRate() ) )
75 {
76 cmdLineArgs.addArg( "--totalline", config.getTotalLineRate() );
77 }
78
79 if ( StringUtils.isNotEmpty( config.getPackageBranchRate() ) )
80 {
81 cmdLineArgs.addArg( "--packagebranch", config.getPackageBranchRate() );
82 }
83
84 if ( StringUtils.isNotEmpty( config.getPackageLineRate() ) )
85 {
86 cmdLineArgs.addArg( "--packageline", config.getPackageLineRate() );
87 }
88
89 if ( StringUtils.isNotEmpty( config.getMaxmem() ) )
90 {
91 this.setMaxmem( config.getMaxmem() );
92 }
93
94 for ( Regex regex : config.getRegexes() )
95 {
96 cmdLineArgs.addArg( "--regex", regex.toString() );
97 }
98
99 int returnCode = executeJava();
100
101
102 if ( returnCode == 0 )
103 {
104 getLog().info( "All checks passed." );
105 }
106 else
107 {
108 if ( config.isHaltOnFailure() )
109 {
110 throw new MojoFailureException( "Coverage check failed. See messages above." );
111 }
112 else
113 {
114 getLog().error( "Coverage check failed. See messages above." );
115 }
116 }
117 }
118
119
120
121
122 public ConfigCheck getConfig()
123 {
124 return config;
125 }
126
127
128
129
130 public String getDataFile()
131 {
132 return dataFile;
133 }
134
135
136
137
138
139
140 public void setConfig( ConfigCheck config )
141 {
142 this.config = config;
143 }
144
145
146
147
148 public void setDataFile( String dataFile )
149 {
150 this.dataFile = dataFile;
151 }
152
153 }