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.jpa.mojo;
017
018import java.util.ArrayList;
019import java.util.HashMap;
020import java.util.List;
021import java.util.Map;
022
023import org.apache.maven.plugin.MojoExecutionException;
024import org.apache.maven.plugin.MojoFailureException;
025import org.apache.maven.project.MavenProject;
026import org.kuali.student.common.mojo.AbstractKSMojo;
027import org.kuali.student.contract.model.ServiceContractModel;
028import org.kuali.student.contract.model.util.ServicesFilter;
029import org.kuali.student.contract.model.util.ServicesFilterByKeys;
030import org.slf4j.Logger;
031import org.slf4j.LoggerFactory;
032
033/**
034 *
035 * @author nwright
036 * 
037 *  @goal ks-create-jpa-impl
038 *  @phase site
039 *  @requiresProject true
040 */
041public class KSCreateJpaImplMojo extends AbstractKSMojo {
042
043    private static final Logger log = LoggerFactory.getLogger(KSCreateJpaImplMojo.class);
044    
045    public KSCreateJpaImplMojo() {
046    }
047 
048    private String targetDir;
049
050    public String getTargetDir() {
051        return targetDir;
052    }
053
054    public void setTargetDir(String targetDir) {
055        this.targetDir = targetDir;
056    }
057    
058    
059    
060    @Override
061        public void execute() throws MojoExecutionException, MojoFailureException {
062        ServiceContractModel model = getModel();
063        validate(model);
064        if (targetDir == null) {
065            targetDir = "target/generated-jpa-impls";
066        }
067        List<String> servKeys = new ArrayList<String>();
068//        servKeys.add ("Atp");
069//        ServicesFilter filter = new ServicesFilterByKeys (servKeys);
070        ServicesFilter filter = null;
071        boolean isR1 = false;
072        JpaImplWriter instance =
073                new JpaImplWriter(model,
074                targetDir,
075                JpaImplWriter.ROOT_PACKAGE,
076                filter,
077                isR1);
078        instance.write();
079
080    }
081    
082    
083    
084    private static final String CORE_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-core-api/src/main";
085    // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
086    private static final String COMMON_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-common-api/src/main/java";
087    private static final String ENROLL_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-enroll-api/src/main/java";
088    private static final String LUM_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-lum-api/src/main/java";
089    private static final String RICE_CORE_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/core/api/src/main/java";
090    private static final String RICE_KIM_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/kim/kim-api/src/main/java";
091    private static final String RICE_KRMS_API_DIRECTORY = "D:/svn/rice/rice-2.2.0/krms/api/src/main/java";
092    private static final String TEST_SOURCE_DIRECTORY =
093            "src/test/java/org/kuali/student/contract/model/test/source";
094    private static final String TARGET_GENERATED_SOURCES = "target/generated-sources";
095    private static final String STANDALONE_MAIN_DIRECTORY = "D:/svn/ks/ks-standalone-admin-app/src/main";
096    private static final String SERVICES_ENROLL_IMPL = "D:/svn/ks/services/ks-enroll/ks-enroll-impl/src/main/java";
097    private static final String CM_CORE_API = "D:/svn/ks/CM-2.0/ks-api/ks-core-api/src/main/java";
098    private static final String TRUNK_CORE_IMPL = "D:/svn/ks/trunk/ks-core/ks-core-impl/src/main/java";
099    private static final String TRUNK_ENROLL_IMPL = "D:/svn/ks/trunk/ks-enroll/ks-enroll-impl/src/main/java";
100    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";
101                                                   
102
103    public static void main(String[] args) {
104        log.info("execute");
105        List<String> srcDirs = new ArrayList<String>();
106        srcDirs.add(COMMON_DIRECTORY);
107        srcDirs.add(CORE_DIRECTORY);
108        srcDirs.add(LUM_DIRECTORY);
109        srcDirs.add(ENROLL_DIRECTORY);
110//        srcDirs.add(RICE_KIM_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        KSCreateJpaImplMojo instance = new KSCreateJpaImplMojo();
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.setTargetDir(SERVICES_ENROLL_IMPL);
121//        instance.setTargetDir(CM_CORE_API);
122        instance.setTargetDir(TRUNK_ENROLL_IMPL);
123        try {
124            instance.execute();
125            //        assertTrue(new File(instance.getOutputDirectory() + "/" + "ks-LprInfo-dictionary.xml").exists());  
126        } catch (MojoExecutionException ex) {
127            throw new RuntimeException(ex);
128        } catch (MojoFailureException ex) {
129            throw new RuntimeException(ex);
130        }
131    }
132}