View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.contract.mojo;
17  
18  import java.io.File;
19  import java.net.MalformedURLException;
20  import java.net.URL;
21  import java.net.URLClassLoader;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  import org.apache.maven.artifact.DependencyResolutionRequiredException;
29  import org.apache.maven.model.Dependency;
30  import org.apache.maven.plugin.AbstractMojo;
31  import org.apache.maven.plugin.MojoExecutionException;
32  import org.apache.maven.plugin.MojoFailureException;
33  import org.apache.maven.project.MavenProject;
34  import org.joda.time.DateTime;
35  import org.kuali.student.admin.ui.mojo.KSCreateAdminUiMojo;
36  import org.kuali.student.common.mojo.AbstractKSMojo;
37  import org.kuali.student.contract.model.ServiceContractModel;
38  import org.kuali.student.contract.model.impl.ServiceContractModelCache;
39  import org.kuali.student.contract.model.impl.ServiceContractModelPescXsdLoader;
40  import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
41  import org.kuali.student.contract.model.util.DateUtility;
42  import org.kuali.student.contract.model.util.HtmlContractWriter;
43  import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
44  import org.slf4j.Logger;
45  import org.slf4j.LoggerFactory;
46  
47  /**
48   * The plugin entrypoint which is used to generate the html wiki doc of the service interface.
49   * @goal kscontractdoc
50   * @phase site
51   * @requiresProject true
52   */
53  public class KSContractDocMojo extends AbstractKSMojo {
54      
55      private static Logger log = LoggerFactory.getLogger(KSContractDocMojo.class);
56  
57      /**
58       * @parameter property="htmlDirectory" default-value="${project.build.directory}/site/services/contractdocs"
59       */
60      private File htmlDirectory;
61  
62      public File getHtmlDirectory() {
63          return htmlDirectory;
64      }
65    
66      public void setHtmlDirectory(File htmlDirectory) {
67          this.htmlDirectory = htmlDirectory;
68      }
69  
70      @Override
71      public void execute() throws MojoExecutionException, MojoFailureException {
72      	
73      	MavenProject project = (MavenProject) getPluginContext().get("project");
74      	
75      	String formattedDate = DateUtility.asYMDHMInEasternTimeZone(new DateTime());
76      	
77          ServiceContractModel model = null;
78          HtmlContractWriter writer = null;
79          getLog().info("publishing wiki contracts");
80          model = this.getModel();
81          this.validate(model);
82          getLog().info("publishing to = " + this.htmlDirectory.toString());
83          writer = new HtmlContractWriter(htmlDirectory.toString(), model);
84          writer.write(project.getVersion(), formattedDate);
85  
86  
87      }
88      
89      
90      private static final String CORE_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-core-api/src/main";
91      // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
92      private static final String COMMON_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-common-api/src/main/java";
93      private static final String ENROLL_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-enroll-api/src/main/java";
94      private static final String LUM_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-lum-api/src/main/java";
95      private static final String KSA_DIRECTORY = "D:/svn/ks/ksa/ksa-core/src/main/java";
96      private static final String TEST_SOURCE_DIRECTORY =
97              "src/test/java/org/kuali/student/contract/model/test/source";
98      private static final String TARGET_GENERATED_SOURCES = "target/generated-sources";
99      private static final String STANDALONE_MAIN_DIRECTORY = "D:/svn/ks/ks-standalone-admin-app/src/main";
100 
101     private static final String RICE_CORE_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/core/api/src/main/java";
102     private static final String RICE_KIM_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/kim/kim-api/src/main/java";
103     private static final String RICE_KRMS_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/krms/api/src/main/java";
104     
105     
106     private static final String TRUNK_CORE_IMPL = "D:/svn/ks/trunk/ks-core/ks-core-impl/src/main/java";
107     private static final String TRUNK_ENROLL_IMPL = "D:/svn/ks/trunk/ks-core/ks-core-impl/src/main/java";
108     private static final String TRUNK_ENROLL_IMPL_KRMS_API = "D:/svn/ks/trunk/ks-enroll/ks-enroll-impl/src/main/java/org/kuali/rice/krms/api";
109                                                    
110     
111     public static void main(String[] args) {
112         log.info("execute");
113         List<String> srcDirs = new ArrayList<String>();
114 //        srcDirs.add(COMMON_DIRECTORY);
115 //        srcDirs.add(CORE_DIRECTORY);
116 //        srcDirs.add(LUM_DIRECTORY);
117 //        srcDirs.add(ENROLL_DIRECTORY);        
118 //        srcDirs.add(RICE_KIM_API_DIRECTORY);     
119         srcDirs.add(KSA_DIRECTORY);
120 //        srcDirs.add(RICE_CORE_API_DIRECTORY);
121 //        srcDirs.add(RICE_KRMS_API_DIRECTORY);
122 //        srcDirs.add(TRUNK_ENROLL_IMPL_KRMS_API);
123         KSContractDocMojo instance = new KSContractDocMojo();
124         Map pluginContext = new HashMap();
125         MavenProject project = new MavenProject();
126         pluginContext.put("project", project);
127         instance.setPluginContext(pluginContext);
128         instance.setSourceDirs(srcDirs);
129         instance.setHtmlDirectory(new File (TARGET_GENERATED_SOURCES));
130         try {
131             instance.execute();
132         } catch (MojoExecutionException ex) {
133             throw new RuntimeException(ex);
134         } catch (MojoFailureException ex) {
135             throw new RuntimeException(ex);
136         }
137     }
138     
139 }