001    /*
002     * Copyright 2009 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.osedu.org/licenses/ECL-2.0
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.admin.ui.mojo;
017    
018    import java.util.ArrayList;
019    import java.util.HashMap;
020    import java.util.List;
021    import java.util.Map;
022    
023    import org.apache.maven.plugin.MojoExecutionException;
024    import org.apache.maven.plugin.MojoFailureException;
025    import org.apache.maven.project.MavenProject;
026    import org.kuali.student.common.mojo.AbstractKSMojo;
027    import org.kuali.student.contract.model.ServiceContractModel;
028    import org.kuali.student.contract.model.util.ServicesFilterByKeys;
029    import org.slf4j.Logger;
030    import org.slf4j.LoggerFactory;
031    
032    /**
033     *
034     * @author nwright
035     *
036     * @goal kscreateadminui
037     * @phase none
038     * @requiresProject true
039     */
040    public class KSCreateAdminUiMojo extends AbstractKSMojo {
041    
042        private static final Logger log = LoggerFactory.getLogger(KSCreateAdminUiMojo.class);
043        
044        public KSCreateAdminUiMojo() {
045        }
046        public String targetDir;
047    
048        public String getTargetDir() {
049            return targetDir;
050        }
051    
052        public void setTargetDir(String targetDir) {
053            this.targetDir = targetDir;
054        }
055    
056        @Override
057        public void execute() throws MojoExecutionException, MojoFailureException {
058            ServiceContractModel model = getModel();
059            validate(model);
060            if (targetDir == null) {
061                targetDir = "target/generated-sources/admin-ui";
062            }
063    //        ServicesFilterKualiStudentOnly filter = new ServicesFilterKualiStudentOnly ();
064            List<String> servKeys = new ArrayList<String>();
065            servKeys.add("Atp");
066            servKeys.add("Type");
067            servKeys.add("State");
068            servKeys.add("LRC");
069            ServicesFilterByKeys filter = new ServicesFilterByKeys(servKeys);
070    
071            AdminUiWriter instance =
072                    new AdminUiWriter(model,
073                    targetDir,
074                    AdminUiWriter.DEFAULT_ROOT_PACKAGE,
075                    // TODO: inject filters as part of the Mojo parameters
076                    filter);
077            instance.write();
078    
079        }
080        private static final String CORE_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-core-api/src/main";
081        // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
082        private static final String COMMON_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-common-api/src/main/java";
083        private static final String ENROLL_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-enroll-api/src/main/java";
084        private static final String LUM_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-lum-api/src/main/java";
085        private static final String RICE_CORE_API_DIRECTORY = "D:/svn/rice/rice-2.2.0-M3/core/api/src/main/java";
086        private static final String RICE_KIM_API_DIRECTORY = "D:/svn/rice/rice-2.2.0-M3/kim/kim-api/src/main/java";
087        private static final String TEST_SOURCE_DIRECTORY =
088                "src/test/java/org/kuali/student/contract/model/test/source";
089        private static final String TARGET_GENERATED_SOURCES = "target/generated-sources";
090        private static final String STANDALONE_MAIN_DIRECTORY = "D:/svn/ks/ks-standalone-admin-app/src/main";
091    
092        public static void main(String[] args) {
093            log.info("execute");
094            List<String> srcDirs = new ArrayList<String>();
095            srcDirs.add(COMMON_DIRECTORY);
096            srcDirs.add(CORE_DIRECTORY);
097            srcDirs.add(LUM_DIRECTORY);
098            srcDirs.add(ENROLL_DIRECTORY);
099    //        srcDirs.add(RICE_KIM_API_DIRECTORY);
100    //        srcDirs.add(RICE_CORE_API_DIRECTORY);
101            KSCreateAdminUiMojo instance = new KSCreateAdminUiMojo();
102            Map pluginContext = new HashMap();
103            MavenProject project = new MavenProject();
104            pluginContext.put("project", project);
105            instance.setPluginContext(pluginContext);
106            instance.setSourceDirs(srcDirs);
107            instance.setTargetDir(STANDALONE_MAIN_DIRECTORY);
108            try {
109                instance.execute();
110                //        assertTrue(new File(instance.getOutputDirectory() + "/" + "ks-LprInfo-dictionary.xml").exists());  
111            } catch (MojoExecutionException ex) {
112                throw new RuntimeException(ex);
113            } catch (MojoFailureException ex) {
114                throw new RuntimeException(ex);
115            }
116        }
117    }