1 package org.kuali.student.datadictionary.mojo;
2
3 import java.io.File;
4 import java.util.Collection;
5 import java.util.List;
6
7 import org.apache.maven.plugin.AbstractMojo;
8 import org.apache.maven.plugin.MojoExecutionException;
9
10 import org.kuali.student.contract.model.ServiceContractModel;
11 import org.kuali.student.contract.model.impl.ServiceContractModelCache;
12 import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
13 import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
14 import org.kuali.student.contract.writer.service.EachMethodServiceWriter;
15
16
17
18
19
20
21
22 public class EachMethodServiceGeneratorrMojo extends AbstractMojo {
23
24
25
26
27 private List<String> sourceDirs;
28
29
30
31 private File outputDirectory;
32
33 public File getOutputDirectory() {
34 return outputDirectory;
35 }
36
37 public List<String> getSourceDirs() {
38 return sourceDirs;
39 }
40
41 public void setOutputDirectory(File htmlDirectory) {
42 this.outputDirectory = htmlDirectory;
43 }
44
45 public void setSourceDirs(List<String> sourceDirs) {
46 this.sourceDirs = sourceDirs;
47 }
48
49
50
51 private String rootPackage;
52
53 public String getRootPackage() {
54 return rootPackage;
55 }
56
57 public void setRootPackage(String rootPackage) {
58 this.rootPackage = rootPackage;
59 }
60
61 private ServiceContractModel getModel() {
62 ServiceContractModel instance = new ServiceContractModelQDoxLoader(
63 sourceDirs);
64 return new ServiceContractModelCache(instance);
65 }
66
67 private boolean validate(ServiceContractModel model) {
68 Collection<String> errors = new ServiceContractModelValidator(model).validate();
69 if (errors.size() > 0) {
70 StringBuilder buf = new StringBuilder();
71 buf.append(errors.size()).append(" errors found while validating the data.");
72 return false;
73 }
74 return true;
75 }
76
77 @Override
78 public void execute() throws MojoExecutionException {
79 getLog().info("generating separate java interface files for each method in the service contracts");
80 ServiceContractModel model = this.getModel();
81 this.validate(model);
82 if (!outputDirectory.exists()) {
83 if (!outputDirectory.mkdirs()) {
84
85 throw new IllegalArgumentException("Could not create directory "
86 + this.outputDirectory.getPath());
87 }
88 }
89 String targetDirectory = this.outputDirectory.toString();
90 EachMethodServiceWriter instance =
91 new EachMethodServiceWriter(model,
92 targetDirectory,
93 rootPackage,
94 null);
95 instance.write();
96
97 }
98 }