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.APIFilter;
28  import net.sf.jour.signature.ExportClasses;
29  import net.sf.jour.signature.SignatureImport;
30  
31  import org.apache.maven.artifact.Artifact;
32  import org.apache.maven.plugin.AbstractMojo;
33  import org.apache.maven.plugin.MojoExecutionException;
34  import org.apache.maven.plugin.MojoFailureException;
35  import org.apache.maven.plugin.logging.Log;
36  import org.apache.maven.project.MavenProject;
37  
38  import com.pyx4j.log4j.MavenLogAppender;
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  public class GenerateMojo extends AbstractMojo {
52  
53  	
54  
55  
56  
57  
58  
59  	private File output;
60  
61  	
62  
63  
64  
65  
66  
67  	private File signature;
68  
69  	
70  
71  
72  
73  
74  
75  
76  
77  	private boolean useSystemClassPath;
78  
79  	
80  
81  
82  
83  
84  	private String classVersion;
85  
86  	
87  
88  
89  
90  
91  	private String level;
92  
93  	
94  
95  
96  
97  
98  	private String packages;
99  
100 	
101 
102 
103 
104 
105 
106 	private String stubException;
107 
108 	
109 
110 
111 
112 
113 	private String stubExceptionMessage;
114 
115 	
116 
117 
118 
119 
120 
121 
122 
123 
124 	protected MavenProject mavenProject;
125 
126 	
127 
128 
129 
130 
131 	public void execute() throws MojoExecutionException, MojoFailureException {
132 		Log log = getLog();
133 		MavenLogAppender.startPluginLog(this);
134 		log.info("use signature: " + signature);
135 		log.debug("packages: " + packages + " level:" + level);
136 
137 		StringBuffer supportingJars = new StringBuffer();
138 
139 		List dependancy = this.mavenProject.getTestArtifacts();
140 		for (Iterator i = dependancy.iterator(); i.hasNext();) {
141 			Artifact artifact = (Artifact) i.next();
142 			File file = InstrumentationMojo.getClasspathElement(artifact, mavenProject);
143 			log.debug("dependancy:" + file.toString());
144 			if (supportingJars.length() < 0) {
145 				supportingJars.append(File.pathSeparatorChar);
146 			}
147 			supportingJars.append(file.toString());
148 		}
149 
150 		SignatureImport im = new SignatureImport(useSystemClassPath, (supportingJars.length() > 0) ? supportingJars
151 				.toString() : null);
152 
153 		im.setStubException(stubException);
154 		im.setStubExceptionMessage(stubExceptionMessage);
155 
156 		APIFilter apiFilter = new APIFilter(level, packages);
157 
158 		im.load(signature.getAbsolutePath(), apiFilter);
159 
160 		log.debug("loaded " + im.getClassNames().size() + " classe(s)");
161 
162 		log.debug("output: " + output.getAbsolutePath());
163 
164 		int count = ExportClasses.export(output.getAbsolutePath(), im.getClasses(), classVersion);
165 		log.info("Created " + count + " classe(s)");
166 	}
167 
168 }