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.datadictionary.mojo;
017    
018    import java.io.File;
019    import java.util.Collection;
020    import java.util.List;
021    
022    import org.apache.maven.plugin.AbstractMojo;
023    import org.apache.maven.plugin.MojoExecutionException;
024    
025    import org.kuali.student.common.mojo.AbstractKSMojo;
026    import org.kuali.student.contract.model.ServiceContractModel;
027    import org.kuali.student.contract.model.impl.ServiceContractModelCache;
028    import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
029    import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
030    import org.kuali.student.contract.writer.service.EachMethodServiceWriter;
031    
032    /**
033     * The plugin entrypoint which is used to generate a java interface file for each
034     * service method in the source files based on the contract definition
035     * @phase generate-sources
036     * @goal kseachmethodservicegenerator
037     */
038    public class KSEachMethodServiceGeneratorrMojo extends AbstractKSMojo {
039    
040        /**
041         * @parameter property="outputDirectory" default-value="${project.build.directory}/generated-sources"
042         */
043        private File outputDirectory;
044    
045        public File getOutputDirectory() {
046            return outputDirectory;
047        }
048    
049       
050        public void setOutputDirectory(File htmlDirectory) {
051            this.outputDirectory = htmlDirectory;
052        }
053    
054           /**
055         * @parameter property="rootPackage" default-value="org.kuali.student.enrollment"
056         */
057        private String rootPackage;
058    
059        public String getRootPackage() {
060            return rootPackage;
061        }
062    
063        public void setRootPackage(String rootPackage) {
064            this.rootPackage = rootPackage;
065        }
066    
067        
068        
069    
070        @Override
071        public void execute() throws MojoExecutionException {
072            getLog().info("generating separate java interface files for each method in the service contracts");
073            ServiceContractModel model = this.getModel();
074            this.validate(model);
075            if (!outputDirectory.exists()) {
076                if (!outputDirectory.mkdirs()) {
077    //                throw new MojoExecutionException("Could not create directory "
078                    throw new IllegalArgumentException("Could not create directory "
079                            + this.outputDirectory.getPath());
080                }
081            }
082            String targetDirectory = this.outputDirectory.toString();
083            EachMethodServiceWriter instance =
084                    new EachMethodServiceWriter(model,
085                    targetDirectory,
086                    rootPackage,
087                    null);
088            instance.write();
089    
090        }
091    }