|  1 |     | 
   package org.apache.torque.mojo;  | 
  |  2 |     | 
     | 
  |  3 |     | 
   import java.io.File;  | 
  |  4 |     | 
   import java.io.IOException;  | 
  |  5 |     | 
     | 
  |  6 |     | 
   import org.apache.commons.configuration.PropertiesConfiguration;  | 
  |  7 |     | 
   import org.apache.commons.io.FileUtils;  | 
  |  8 |     | 
   import org.apache.maven.plugin.MojoExecutionException;  | 
  |  9 |     | 
   import org.apache.torque.task.TorqueDataModelTask;  | 
  |  10 |     | 
   import org.kuali.core.db.torque.Utils;  | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
     | 
  |  18 |    0 |    public class DataDtdMojo extends DataModelTaskMojo { | 
  |  19 |     | 
         | 
  |  20 |     | 
       public static final String PROJECT_CONTEXT_PROPERTY = "project";  | 
  |  21 |     | 
     | 
  |  22 |     | 
         | 
  |  23 |     | 
     | 
  |  24 |     | 
     | 
  |  25 |     | 
       boolean antCompatibilityMode;  | 
  |  26 |     | 
     | 
  |  27 |     | 
         | 
  |  28 |     | 
     | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
       String copyToFile;  | 
  |  33 |     | 
     | 
  |  34 |     | 
         | 
  |  35 |     | 
     | 
  |  36 |     | 
     | 
  |  37 |     | 
     | 
  |  38 |     | 
     | 
  |  39 |     | 
       String artifactId;  | 
  |  40 |     | 
     | 
  |  41 |     | 
         | 
  |  42 |     | 
     | 
  |  43 |     | 
     | 
  |  44 |     | 
     | 
  |  45 |     | 
     | 
  |  46 |     | 
     | 
  |  47 |     | 
       @SuppressWarnings("unused") | 
  |  48 |     | 
       private String dummy1;  | 
  |  49 |     | 
     | 
  |  50 |     | 
         | 
  |  51 |     | 
     | 
  |  52 |     | 
     | 
  |  53 |     | 
     | 
  |  54 |     | 
     | 
  |  55 |     | 
     | 
  |  56 |     | 
       @SuppressWarnings("unused") | 
  |  57 |     | 
       private String dummy2;  | 
  |  58 |     | 
     | 
  |  59 |     | 
         | 
  |  60 |     | 
     | 
  |  61 |     | 
     | 
  |  62 |     | 
     | 
  |  63 |     | 
     | 
  |  64 |     | 
     | 
  |  65 |     | 
       @SuppressWarnings("unused") | 
  |  66 |     | 
       private String dummy3;  | 
  |  67 |     | 
     | 
  |  68 |     | 
         | 
  |  69 |     | 
     | 
  |  70 |     | 
     | 
  |  71 |     | 
     | 
  |  72 |     | 
     | 
  |  73 |     | 
       private String projectName;  | 
  |  74 |     | 
     | 
  |  75 |     | 
         | 
  |  76 |     | 
     | 
  |  77 |     | 
     | 
  |  78 |     | 
     | 
  |  79 |     | 
     | 
  |  80 |     | 
     | 
  |  81 |     | 
     | 
  |  82 |     | 
       private String schemaXMLFile;  | 
  |  83 |     | 
     | 
  |  84 |     | 
         | 
  |  85 |     | 
     | 
  |  86 |     | 
     | 
  |  87 |     | 
     | 
  |  88 |     | 
     | 
  |  89 |     | 
       @Override  | 
  |  90 |     | 
       protected PropertiesConfiguration getMojoContextProperties() { | 
  |  91 |    0 |            PropertiesConfiguration configuration = new PropertiesConfiguration();  | 
  |  92 |    0 |            configuration.addProperty(PROJECT_CONTEXT_PROPERTY, getProjectName());  | 
  |  93 |    0 |            configuration.addProperty("version", getProject().getVersion()); | 
  |  94 |    0 |            return configuration;  | 
  |  95 |     | 
       }  | 
  |  96 |     | 
     | 
  |  97 |     | 
       protected void showConfig() { | 
  |  98 |    0 |            getLog().info("Schema XML File: " + schemaXMLFile); | 
  |  99 |    0 |            getLog().info("Ant Compatibility Mode: " + antCompatibilityMode); | 
  |  100 |    0 |            getLog().info("Output Directory: " + getOutputDir()); | 
  |  101 |    0 |        }  | 
  |  102 |     | 
     | 
  |  103 |     | 
         | 
  |  104 |     | 
     | 
  |  105 |     | 
     | 
  |  106 |     | 
       @Override  | 
  |  107 |     | 
       protected void configureTask() throws MojoExecutionException { | 
  |  108 |    0 |            TorqueDataModelTask task = new TorqueDataModelTask();  | 
  |  109 |    0 |            setAntTask(task);  | 
  |  110 |    0 |            super.configureTask();  | 
  |  111 |    0 |            boolean exists = new Utils().isFileOrResource(getSchemaXMLFile());  | 
  |  112 |    0 |            if (!exists) { | 
  |  113 |    0 |                throw new MojoExecutionException("Unable to locate: " + getSchemaXMLFile()); | 
  |  114 |     | 
           }  | 
  |  115 |    0 |            task.setXmlFile(getSchemaXMLFile());  | 
  |  116 |     | 
     | 
  |  117 |    0 |        }  | 
  |  118 |     | 
     | 
  |  119 |     | 
         | 
  |  120 |     | 
     | 
  |  121 |     | 
     | 
  |  122 |     | 
     | 
  |  123 |     | 
     | 
  |  124 |     | 
       @Override  | 
  |  125 |     | 
       protected String getControlTemplate() { | 
  |  126 |    0 |            return "data/Control.vm";  | 
  |  127 |     | 
       }  | 
  |  128 |     | 
     | 
  |  129 |     | 
         | 
  |  130 |     | 
     | 
  |  131 |     | 
     | 
  |  132 |     | 
     | 
  |  133 |     | 
     | 
  |  134 |     | 
       public String getProjectName() { | 
  |  135 |    0 |            return projectName;  | 
  |  136 |     | 
       }  | 
  |  137 |     | 
     | 
  |  138 |     | 
         | 
  |  139 |     | 
     | 
  |  140 |     | 
     | 
  |  141 |     | 
     | 
  |  142 |     | 
     | 
  |  143 |     | 
     | 
  |  144 |     | 
       public void setProjectName(final String projectName) { | 
  |  145 |    0 |            this.projectName = projectName;  | 
  |  146 |    0 |        }  | 
  |  147 |     | 
     | 
  |  148 |     | 
         | 
  |  149 |     | 
     | 
  |  150 |     | 
     | 
  |  151 |     | 
     | 
  |  152 |     | 
     | 
  |  153 |     | 
       public String getSchemaXMLFile() { | 
  |  154 |    0 |            return schemaXMLFile;  | 
  |  155 |     | 
       }  | 
  |  156 |     | 
     | 
  |  157 |     | 
         | 
  |  158 |     | 
     | 
  |  159 |     | 
     | 
  |  160 |     | 
     | 
  |  161 |     | 
     | 
  |  162 |     | 
     | 
  |  163 |     | 
       public void setSchemaXMLFile(final String xmlFile) { | 
  |  164 |    0 |            this.schemaXMLFile = xmlFile;  | 
  |  165 |    0 |        }  | 
  |  166 |     | 
     | 
  |  167 |     | 
       @Override  | 
  |  168 |     | 
       public void executeMojo() throws MojoExecutionException { | 
  |  169 |    0 |            getLog().info("------------------------------------------------------------------------"); | 
  |  170 |    0 |            getLog().info("Generating database DTD"); | 
  |  171 |    0 |            getLog().info("------------------------------------------------------------------------"); | 
  |  172 |    0 |            showConfig();  | 
  |  173 |    0 |            super.executeMojo();  | 
  |  174 |    0 |            if (antCompatibilityMode) { | 
  |  175 |    0 |                File srcFile = new File(getOutputDir() + FS + getArtifactId() + ".dtd");  | 
  |  176 |    0 |                File dstFile = new File(copyToFile);  | 
  |  177 |    0 |                getLog().info("Creating " + dstFile.getAbsolutePath() + " for Ant compatibility mode"); | 
  |  178 |     | 
               try { | 
  |  179 |    0 |                    FileUtils.copyFile(srcFile, dstFile);  | 
  |  180 |    0 |                } catch (IOException e) { | 
  |  181 |    0 |                    throw new MojoExecutionException("Error copying file", e); | 
  |  182 |    0 |                }  | 
  |  183 |     | 
           }  | 
  |  184 |    0 |        }  | 
  |  185 |     | 
     | 
  |  186 |     | 
       public boolean isAntCompatibilityMode() { | 
  |  187 |    0 |            return antCompatibilityMode;  | 
  |  188 |     | 
       }  | 
  |  189 |     | 
     | 
  |  190 |     | 
       public void setAntCompatibilityMode(final boolean antCompatibilityMode) { | 
  |  191 |    0 |            this.antCompatibilityMode = antCompatibilityMode;  | 
  |  192 |    0 |        }  | 
  |  193 |     | 
     | 
  |  194 |     | 
       public String getCopyToFile() { | 
  |  195 |    0 |            return copyToFile;  | 
  |  196 |     | 
       }  | 
  |  197 |     | 
     | 
  |  198 |     | 
       public void setCopyToFile(final String copyToFile) { | 
  |  199 |    0 |            this.copyToFile = copyToFile;  | 
  |  200 |    0 |        }  | 
  |  201 |     | 
     | 
  |  202 |     | 
       public String getArtifactId() { | 
  |  203 |    0 |            return artifactId;  | 
  |  204 |     | 
       }  | 
  |  205 |     | 
     | 
  |  206 |     | 
       public void setArtifactId(final String artifactId) { | 
  |  207 |    0 |            this.artifactId = artifactId;  | 
  |  208 |    0 |        }  | 
  |  209 |     | 
   }  |