View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.datadictionary.mojo;
17  
18  import java.io.File;
19  import java.util.Collection;
20  import java.util.List;
21  
22  import org.apache.maven.plugin.AbstractMojo;
23  import org.apache.maven.plugin.MojoExecutionException;
24  
25  import org.kuali.student.common.mojo.AbstractKSMojo;
26  import org.kuali.student.contract.model.ServiceContractModel;
27  import org.kuali.student.contract.model.impl.ServiceContractModelCache;
28  import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
29  import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
30  import org.kuali.student.contract.writer.service.EachMethodServiceWriter;
31  
32  /**
33   * The plugin entrypoint which is used to generate a java interface file for each
34   * service method in the source files based on the contract definition
35   * @phase generate-sources
36   * @goal kseachmethodservicegenerator
37   */
38  public class KSEachMethodServiceGeneratorrMojo extends AbstractKSMojo {
39  
40      /**
41       * @parameter property="outputDirectory" default-value="${project.build.directory}/generated-sources"
42       */
43      private File outputDirectory;
44  
45      public File getOutputDirectory() {
46          return outputDirectory;
47      }
48  
49     
50      public void setOutputDirectory(File htmlDirectory) {
51          this.outputDirectory = htmlDirectory;
52      }
53  
54         /**
55       * @parameter property="rootPackage" default-value="org.kuali.student.enrollment"
56       */
57      private String rootPackage;
58  
59      public String getRootPackage() {
60          return rootPackage;
61      }
62  
63      public void setRootPackage(String rootPackage) {
64          this.rootPackage = rootPackage;
65      }
66  
67      
68      
69  
70      @Override
71      public void execute() throws MojoExecutionException {
72          getLog().info("generating separate java interface files for each method in the service contracts");
73          ServiceContractModel model = this.getModel();
74          this.validate(model);
75          if (!outputDirectory.exists()) {
76              if (!outputDirectory.mkdirs()) {
77  //                throw new MojoExecutionException("Could not create directory "
78                  throw new IllegalArgumentException("Could not create directory "
79                          + this.outputDirectory.getPath());
80              }
81          }
82          String targetDirectory = this.outputDirectory.toString();
83          EachMethodServiceWriter instance =
84                  new EachMethodServiceWriter(model,
85                  targetDirectory,
86                  rootPackage,
87                  null);
88          instance.write();
89  
90      }
91  }