001    /**
002     * Copyright 2004-2014 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.student.contract.mojo;
017    
018    import java.io.File;
019    import java.util.ArrayList;
020    import java.util.HashMap;
021    import java.util.List;
022    import java.util.Map;
023    
024    import org.apache.maven.plugin.MojoExecutionException;
025    import org.apache.maven.plugin.MojoFailureException;
026    import org.apache.maven.project.MavenProject;
027    import org.joda.time.DateTime;
028    import org.kuali.student.common.mojo.AbstractKSMojo;
029    import org.kuali.student.contract.model.ServiceContractModel;
030    import org.kuali.student.contract.model.util.DateUtility;
031    import org.kuali.student.contract.model.util.HtmlContractWriter;
032    import org.slf4j.Logger;
033    import org.slf4j.LoggerFactory;
034    
035    /**
036     * The plugin entrypoint which is used to generate the html wiki doc of the service interface.
037     * @goal kscontractdoc
038     * @phase site
039     * @requiresProject true
040     */
041    public class KSContractDocMojo extends AbstractKSMojo {
042        
043        private static Logger log = LoggerFactory.getLogger(KSContractDocMojo.class);
044    
045        /**
046         * @parameter property="htmlDirectory" default-value="${project.build.directory}/site/services/contractdocs"
047         */
048        private File htmlDirectory;
049    
050        public File getHtmlDirectory() {
051            return htmlDirectory;
052        }
053      
054        public void setHtmlDirectory(File htmlDirectory) {
055            this.htmlDirectory = htmlDirectory;
056        }
057    
058        @Override
059        public void execute() throws MojoExecutionException, MojoFailureException {
060            
061            MavenProject project = (MavenProject) getPluginContext().get("project");
062            
063            String formattedDate = DateUtility.asYMDHMInEasternTimeZone(new DateTime());
064            
065            ServiceContractModel model = null;
066            HtmlContractWriter writer = null;
067            getLog().info("publishing wiki contracts");
068            model = this.getModel();
069            this.validate(model);
070            getLog().info("publishing to = " + this.htmlDirectory.toString());
071            writer = new HtmlContractWriter(htmlDirectory.toString(), model);
072            writer.write(project.getVersion(), formattedDate);
073    
074    
075        }
076        
077        
078        private static final String CORE_DIRECTORY = "D:/svn/ks/ks-api/ks-core-api/src/main";
079        // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
080        private static final String COMMON_DIRECTORY = "D:/svn/ks/ks-api/ks-common-api/src/main/java";
081        private static final String ENROLL_DIRECTORY = "D:/svn/ks/ks-api/ks-enroll-api/src/main/java";
082        private static final String LUM_DIRECTORY = "D:/svn/ks/ks-api/ks-lum-api/src/main/java";
083        private static final String KSAP_API_DIRECTORY = "D:\\svn\\ks\\trunk\\ks-api\\ks-ap-api\\src\\main\\java";
084        private static final String KME_API_DIRECTORY = "D:\\svn\\kplus2\\kme\\bulletin\\api\\src\\main\\java\\org\\kuali\\mobility\\bulletin";
085        private static final String KSA_DIRECTORY = "D:/svn/ks/ksa/ksa-core/src/main/java";
086        private static final String TEST_SOURCE_DIRECTORY =
087                "src/test/java/org/kuali/student/contract/model/test/source";
088        private static final String TARGET_GENERATED_SOURCES = "target/generated-sources";
089        private static final String STANDALONE_MAIN_DIRECTORY = "D:/svn/ks/ks-standalone-admin-app/src/main";
090    
091        private static final String RICE_CORE_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/core/api/src/main/java";
092        private static final String RICE_KIM_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/kim/kim-api/src/main/java";
093        private static final String RICE_KRMS_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/krms/api/src/main/java";
094        
095        
096        private static final String TRUNK_CORE_IMPL = "D:/svn/ks/trunk/ks-core/ks-core-impl/src/main/java";
097        private static final String TRUNK_ENROLL_IMPL = "D:/svn/ks/trunk/ks-core/ks-core-impl/src/main/java";
098        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";
099                                                       
100        
101        public static void main(String[] args) {
102            log.info("execute");
103            List<String> srcDirs = new ArrayList<String>();
104            srcDirs.add(COMMON_DIRECTORY);
105            srcDirs.add(CORE_DIRECTORY);
106            srcDirs.add(LUM_DIRECTORY);
107            srcDirs.add(ENROLL_DIRECTORY);        
108    //        srcDirs.add(RICE_KIM_API_DIRECTORY);     
109            srcDirs.add(KSAP_API_DIRECTORY);    
110    //        srcDirs.add(KME_API_DIRECTORY);
111            srcDirs.add(RICE_CORE_API_DIRECTORY);
112            srcDirs.add(RICE_KRMS_API_DIRECTORY);
113    //        srcDirs.add(TRUNK_ENROLL_IMPL_KRMS_API);
114            KSContractDocMojo instance = new KSContractDocMojo();
115            Map pluginContext = new HashMap();
116            MavenProject project = new MavenProject();
117            pluginContext.put("project", project);
118            instance.setPluginContext(pluginContext);
119            instance.setSourceDirs(srcDirs);
120            instance.setHtmlDirectory(new File (TARGET_GENERATED_SOURCES));
121            try {
122                instance.execute();
123            } catch (MojoExecutionException ex) {
124                throw new RuntimeException(ex);
125            } catch (MojoFailureException ex) {
126                throw new RuntimeException(ex);
127            }
128        }
129        
130    }