001 package org.kuali.student.contract.mojo; 002 003 import java.io.File; 004 import java.net.MalformedURLException; 005 import java.net.URL; 006 import java.net.URLClassLoader; 007 import java.util.Collection; 008 import java.util.List; 009 010 import org.apache.maven.artifact.DependencyResolutionRequiredException; 011 import org.apache.maven.model.Dependency; 012 import org.apache.maven.plugin.AbstractMojo; 013 import org.apache.maven.plugin.MojoExecutionException; 014 import org.apache.maven.project.MavenProject; 015 import org.joda.time.DateTime; 016 import org.kuali.student.contract.model.ServiceContractModel; 017 import org.kuali.student.contract.model.impl.ServiceContractModelCache; 018 import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader; 019 import org.kuali.student.contract.model.util.DateUtility; 020 import org.kuali.student.contract.model.util.HtmlContractWriter; 021 import org.kuali.student.contract.model.validation.ServiceContractModelValidator; 022 023 /** 024 * The plugin entrypoint which is used to generate the html wiki doc of the service interface. 025 * @goal kscontractdoc 026 * @phase site 027 * @requiresProject true 028 */ 029 public class KSContractDocMojo extends AbstractMojo { 030 031 /** 032 * @parameter 033 **/ 034 private List<String> sourceDirs; 035 /** 036 * @parameter expression="${htmlDirectory}" default-value="${project.build.directory}/site/services/contractdocs" 037 */ 038 private File htmlDirectory; 039 040 public File getHtmlDirectory() { 041 return htmlDirectory; 042 } 043 044 public List<String> getSourceDirs() { 045 return sourceDirs; 046 } 047 048 public void setHtmlDirectory(File htmlDirectory) { 049 this.htmlDirectory = htmlDirectory; 050 } 051 052 public void setSourceDirs(List<String> sourceDirs) { 053 this.sourceDirs = sourceDirs; 054 } 055 056 private ServiceContractModel getModel() { 057 058 059 ServiceContractModel instance = new ServiceContractModelQDoxLoader( 060 sourceDirs); 061 return new ServiceContractModelCache(instance); 062 063 } 064 065 private boolean validate(ServiceContractModel model) { 066 Collection<String> errors = new ServiceContractModelValidator(model).validate(); 067 if (errors.size() > 0) { 068 StringBuilder buf = new StringBuilder(); 069 buf.append(errors.size()).append(" errors found while validating the data."); 070 return false; 071 072 073 } 074 return true; 075 } 076 077 @Override 078 public void execute() throws MojoExecutionException { 079 080 MavenProject project = (MavenProject) getPluginContext().get("project"); 081 082 String formattedDate = DateUtility.asYMDHMInEasternTimeZone(new DateTime()); 083 084 ServiceContractModel model = null; 085 HtmlContractWriter writer = null; 086 getLog().info("publishing wiki contracts"); 087 model = this.getModel(); 088 this.validate(model); 089 getLog().info("publishing to = " + this.htmlDirectory.toString()); 090 writer = new HtmlContractWriter(htmlDirectory.toString(), model); 091 writer.write(project.getVersion(), formattedDate); 092 093 094 } 095 }