1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  package net.sf.jour.maven;
22  
23  import java.io.File;
24  import java.util.Iterator;
25  import java.util.List;
26  
27  import net.sf.jour.signature.APICompare;
28  import net.sf.jour.signature.APICompareConfig;
29  import net.sf.jour.signature.APIFilter;
30  import net.sf.jour.signature.ChangeDetectedException;
31  
32  import org.apache.maven.artifact.Artifact;
33  import org.apache.maven.plugin.AbstractMojo;
34  import org.apache.maven.plugin.MojoExecutionException;
35  import org.apache.maven.plugin.MojoFailureException;
36  import org.apache.maven.plugin.logging.Log;
37  import org.apache.maven.project.MavenProject;
38  
39  import com.pyx4j.log4j.MavenLogAppender;
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  public class SignatureVerifyMojo extends AbstractMojo {
55  
56  	
57  
58  
59  
60  
61  
62  	private File signature;
63  
64  	
65  
66  
67  
68  
69  
70  	private File classes;
71  
72  	
73  
74  
75  
76  
77  
78  
79  
80  	private boolean useSystemClassPath;
81  
82  	
83  
84  
85  
86  
87  
88  	private boolean allowAPIextension;
89  
90  	
91  
92  
93  
94  
95  
96  	private boolean allowThrowsLess;
97  
98  	
99  
100 
101 
102 
103 	private String level;
104 
105 	
106 
107 
108 
109 
110 	private String packages;
111 
112 	
113 
114 
115 
116 
117 
118 
119 
120 
121 	protected MavenProject mavenProject;
122 
123 	public void execute() throws MojoExecutionException, MojoFailureException {
124 		Log log = getLog();
125 		MavenLogAppender.startPluginLog(this);
126 		log.info("use signature: " + signature);
127 
128 		APICompareConfig config = new APICompareConfig();
129 
130 		config.allowAPIextension = allowAPIextension;
131 		config.allowThrowsLess = allowThrowsLess;
132 
133 		config.packages = packages;
134 		config.apiLevel = APIFilter.getAPILevel(level);
135 
136 		StringBuffer supportingJars = new StringBuffer();
137 
138 		List dependancy = this.mavenProject.getTestArtifacts();
139 		for (Iterator i = dependancy.iterator(); i.hasNext();) {
140 			Artifact artifact = (Artifact) i.next();
141 			File file = InstrumentationMojo.getClasspathElement(artifact, mavenProject);
142 			log.debug("dependancy:" + file.toString());
143 			if (supportingJars.length() < 0) {
144 				supportingJars.append(File.pathSeparatorChar);
145 			}
146 			supportingJars.append(file.toString());
147 		}
148 
149 		try {
150 			APICompare.compare(classes.getAbsolutePath(), signature.getAbsolutePath(), config, useSystemClassPath,
151 					(supportingJars.length() > 0) ? supportingJars.toString() : null);
152 		} catch (ChangeDetectedException e) {
153 			log.error("API compare FAILED, processed " + APICompare.getClassesCount() + " classes");
154 			log.error(e.getMessage());
155 			throw new MojoExecutionException("API compare FAILED", e);
156 		}
157 		log.info("API compare PASSED in " + APICompare.getClassesCount() + " classes");
158 	}
159 
160 }