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 */
016package org.kuali.student.contract.mojo;
017
018import java.io.File;
019import java.util.ArrayList;
020import java.util.HashMap;
021import java.util.List;
022import java.util.Map;
023
024import org.apache.maven.plugin.MojoExecutionException;
025import org.apache.maven.plugin.MojoFailureException;
026import org.apache.maven.project.MavenProject;
027import org.joda.time.DateTime;
028import org.kuali.student.common.mojo.AbstractKSMojo;
029import org.kuali.student.contract.model.ServiceContractModel;
030import org.kuali.student.contract.model.util.DateUtility;
031import org.kuali.student.contract.model.util.HtmlContractWriter;
032import org.slf4j.Logger;
033import 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 */
041public 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/services/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/services/ks-api/ks-common-api/src/main/java";
081    private static final String ENROLL_DIRECTORY = "D:/svn/ks/services/ks-api/ks-enroll-api/src/main/java";
082    private static final String LUM_DIRECTORY = "D:/svn/ks/services/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(KSA_DIRECTORY);
105        srcDirs.add(COMMON_DIRECTORY);
106        srcDirs.add(CORE_DIRECTORY);
107        srcDirs.add(LUM_DIRECTORY);
108        srcDirs.add(ENROLL_DIRECTORY);        
109//        srcDirs.add(RICE_KIM_API_DIRECTORY);     
110//        srcDirs.add(KSAP_API_DIRECTORY);    
111//        srcDirs.add(KME_API_DIRECTORY);
112//        srcDirs.add(RICE_CORE_API_DIRECTORY);
113//        srcDirs.add(RICE_KRMS_API_DIRECTORY);
114//        srcDirs.add(TRUNK_ENROLL_IMPL_KRMS_API);
115        KSContractDocMojo instance = new KSContractDocMojo();
116        Map pluginContext = new HashMap();
117        MavenProject project = new MavenProject();
118        pluginContext.put("project", project);
119        instance.setPluginContext(pluginContext);
120        instance.setSourceDirs(srcDirs);
121        instance.setHtmlDirectory(new File (TARGET_GENERATED_SOURCES));
122        try {
123            instance.execute();
124        } catch (MojoExecutionException ex) {
125            throw new RuntimeException(ex);
126        } catch (MojoFailureException ex) {
127            throw new RuntimeException(ex);
128        }
129    }
130    
131}