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.mock.mojo; 017 018 import org.apache.maven.plugin.MojoExecutionException; 019 import org.apache.maven.plugin.MojoFailureException; 020 import org.apache.maven.project.MavenProject; 021 import org.kuali.student.common.mojo.AbstractKSMojo; 022 import org.kuali.student.contract.model.ServiceContractModel; 023 import org.kuali.student.contract.model.impl.ServiceContractModelPescXsdLoader; 024 import org.slf4j.Logger; 025 import org.slf4j.LoggerFactory; 026 027 import java.util.ArrayList; 028 import java.util.HashMap; 029 import java.util.List; 030 import java.util.Map; 031 032 /** 033 * This class associates a mojo to create the conformance tests. 034 * 035 * @goal kscreateconftest 036 * @phase site 037 * @requiresProject true 038 * @author Mezba Mahtab (mezba.mahtab@utoronto.ca) 039 */ 040 public class KSCreateConformanceTestMojo extends AbstractKSMojo { 041 042 private static Logger log = LoggerFactory.getLogger(KSCreateConformanceTestMojo.class); 043 044 /////////////////////////// 045 // Data Variables 046 /////////////////////////// 047 048 private String targetDir; 049 050 /////////////////////////// 051 // Getters and Setters 052 /////////////////////////// 053 054 public String getTargetDir() { 055 return targetDir; 056 } 057 058 public void setTargetDir(String targetDir) { 059 this.targetDir = targetDir; 060 } 061 062 /////////////////////////// 063 // Constructor 064 /////////////////////////// 065 066 public KSCreateConformanceTestMojo() {} 067 068 //////////////////////////// 069 // Functional Methods 070 //////////////////////////// 071 072 @Override 073 public void execute() throws MojoExecutionException, MojoFailureException { 074 075 ServiceContractModel model = getModel(); 076 validate(model); 077 if (targetDir == null) { 078 targetDir = "target/generated-conf-tests"; 079 } 080 boolean isR1 = false; 081 ConformanceTestWriter instance = 082 new ConformanceTestWriter(model, 083 targetDir, 084 MockImplWriter.ROOT_PACKAGE, 085 null, 086 isR1); 087 instance.write(); 088 } 089 090 public static void main (String [] args) { 091 log.info("execute"); 092 List<String> srcDirs = new ArrayList<String>(); 093 srcDirs.add("D:/svn/ks/ks-api/ks-common-api/src/main/java"); // common 094 srcDirs.add("D:/svn/ks/ks-api/ks-core-api/src/main"); // core 095 srcDirs.add("D:/svn/ks/ks-api/ks-lum-api/src/main/java"); // lum 096 srcDirs.add("D:/svn/ks/ks-api/ks-enroll-api/src/main/java"); // enroll 097 KSCreateConformanceTestMojo instance = new KSCreateConformanceTestMojo(); 098 Map pluginContext = new HashMap(); 099 MavenProject project = new MavenProject(); 100 pluginContext.put("project", project); 101 instance.setPluginContext(pluginContext); 102 instance.setSourceDirs(srcDirs); 103 instance.setTargetDir("D:/svn/ks/ks-api//target/generated-conf-tests"); 104 try { 105 instance.execute(); 106 // assertTrue(new File(instance.getOutputDirectory() + "/" + "ks-LprInfo-dictionary.xml").exists()); 107 } catch (MojoExecutionException ex) { 108 throw new RuntimeException(ex); 109 } catch (MojoFailureException ex) { 110 throw new RuntimeException(ex); 111 } 112 113 } 114 115 116 }