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