View Javadoc

1   package org.apache.torque.generator.maven;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.FileInputStream;
24  import java.io.FileNotFoundException;
25  import java.io.IOException;
26  import java.util.ArrayList;
27  import java.util.HashMap;
28  import java.util.List;
29  import java.util.Map;
30  import java.util.Properties;
31  import java.util.Set;
32  
33  import org.apache.maven.model.Resource;
34  import org.apache.maven.plugin.AbstractMojo;
35  import org.apache.maven.plugin.Mojo;
36  import org.apache.maven.plugin.MojoExecutionException;
37  import org.apache.maven.project.MavenProject;
38  import org.apache.torque.generator.configuration.ConfigurationException;
39  import org.apache.torque.generator.configuration.UnitDescriptor;
40  import org.apache.torque.generator.configuration.UnitDescriptor.Packaging;
41  import org.apache.torque.generator.configuration.controller.Loglevel;
42  import org.apache.torque.generator.configuration.option.MapOptionsConfiguration;
43  import org.apache.torque.generator.configuration.option.OptionsConfiguration;
44  import org.apache.torque.generator.configuration.paths.CustomProjectPaths;
45  import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths;
46  import org.apache.torque.generator.configuration.paths.Maven2DirectoryProjectPaths;
47  import org.apache.torque.generator.configuration.paths.Maven2JarProjectPaths;
48  import org.apache.torque.generator.configuration.paths.Maven2ProjectPaths;
49  import org.apache.torque.generator.configuration.paths.ProjectPaths;
50  import org.apache.torque.generator.control.Controller;
51  import org.apache.torque.generator.file.Fileset;
52  import org.apache.torque.generator.source.stream.FileSourceProvider;
53  
54  /**
55   * Executes a unit of generation within the torque generator.
56   *
57   * $Id: TorqueGeneratorMojo.java 1388679 2012-09-21 21:03:11Z tfischer $
58   *
59   * @goal generate
60   */
61  public class TorqueGeneratorMojo extends AbstractMojo implements Mojo
62  {
63      /** Possible usages for generator output directories. */
64      private enum OutputDirUsage
65      {
66          /**
67           * The output dir will be added to the maven project's
68           * compileSourceRoot.
69           */
70          COMPILE("compile"),
71          /**
72           * The output dir will be added to the maven project's
73           * testCompileSourceRoot.
74           */
75          TEST_COMPILE("test-compile"),
76          /**
77           * The output dir will be added to the maven project's resources.
78           */
79          RESOURCE("resource"),
80          /**
81           * The output dir will be added to the maven project's test resources.
82           */
83          TEST_RESOURCE("test-resource"),
84          /**
85           * The target dir will not be used in the maven build.
86           */
87          NONE("none");
88  
89          /** The usage key. */
90          private final String key;
91  
92          /**
93           * Constructor.
94           *
95           * @param key the key for the enum.
96           */
97          private OutputDirUsage(String key)
98          {
99              this.key = key;
100         }
101 
102         @Override
103         public String toString()
104         {
105             return key;
106         }
107 
108         /**
109          * Returns the key of the Usage.
110          *
111          * @return the key, not null.
112          */
113         public String getKey()
114         {
115             return key;
116         }
117 
118         public static OutputDirUsage get(String key)
119             throws MojoExecutionException
120         {
121             for (OutputDirUsage candidate : values())
122             {
123                 if (candidate.getKey().equals(key))
124                 {
125                     return candidate;
126                 }
127             }
128             StringBuilder errorMessage = new StringBuilder()
129                 .append("targetDirUsage contains illegal value: ")
130                 .append(key)
131                 .append(". Possible values are :");
132             for (OutputDirUsage targetDirUsage : values())
133             {
134                 errorMessage.append(" ").append(targetDirUsage.getKey());
135             }
136             throw new MojoExecutionException(errorMessage.toString());
137         }
138     }
139 
140     /**
141      * The packaging type of the generation unit, either "directory" , "jar"
142      * or "classpath".
143      *
144      * @parameter expression="directory"
145      * @required
146      */
147     private String packaging;
148 
149     /**
150      * The root directory of the project.
151      * Has no effect if packaging is "classpath".
152      *
153      * @parameter expression="${basedir}"
154      * @required
155      */
156     private File projectRootDir;
157 
158     /**
159      * The configuration directory of the generation unit.
160      * Has no effect if packaging is "classpath".
161      *
162      * @parameter
163      */
164     private File configDir;
165 
166     /**
167      * The configuration package of the generation unit.
168      * Has only effect if packaging is "classpath".
169      *
170      * @parameter
171      */
172     private String configPackage;
173 
174     /**
175      * The directory where the source files reside.
176      *
177      * @parameter
178      */
179     private File sourceDir;
180 
181     /**
182      * Include patterns for the source files.
183      * If set, the include and exclude patterns from the templates
184      * are overridden.
185      * If not set, then the include patterns from the templates are used.
186      * The patterns are case sensitive, wildcards are * and ?.
187      *
188      * @parameter
189      */
190     private Set<String> sourceIncludes;
191 
192     /**
193      * Exclude patterns for the source files.
194      * If set, the include and exclude patterns from the templates
195      * are overridden.
196      * If not set, then the include patterns from the templates are used.
197      * The patterns are case sensitive, wildcards are * and ?.
198      *
199      * @parameter
200      */
201     private Set<String> sourceExcludes;
202 
203     /**
204      * Whether all source files should be combined into one source tree.
205      * If false, each source file will be read in its own source tree
206      * and start a new generation run.
207      * If true, a single source tree with the following structure will be
208      * built from all source files:
209      * &lt;source&gt;
210      *   &lt;file path="path/to/file1"&gt;
211      *      &lt;rootOfFile1&gt;
212      *        ...
213      *      &lt;/rootOfFile1&gt;
214      *   &lt;/file&gt;
215      *   &lt;file path="path/to/file2"&gt;
216      *      &lt;rootOfFile2&gt;
217      *        ...
218      *      &lt;/rootOfFile2&gt;
219      *   &lt;/file&gt;
220      *   ...
221      * &lt;/source&gt;
222      * If not set, the settings from the templates will be used.
223      *
224      * @parameter
225      */
226     private Boolean combineFiles;
227 
228     /**
229      * The default base output directory for the generated files.
230      * Whether the configured templates use this directory or not,
231      * is up to the templates; check the template documentation.
232      *
233      * @parameter expression="${project.build.directory}/generated-sources"
234      * @required
235      */
236     private File defaultOutputDir;
237 
238     /**
239      * The target directories for the generated files, keyed by the
240      * output directory keys.
241      * If output directory keys are used by the output
242      * (and if yes, which output directory keys),
243      * is up to the templates; check the template documentation.
244      * Default is to map the key "modifiable" to
245      * ${project.build.directory}/src/main/generated-java
246      *
247      * @parameter
248      */
249     private Map<String, String> outputDirMap = new HashMap<String, String>();
250 
251     /**
252      * The work directory for e.g. merge sources.
253      *
254      * @parameter expression="${basedir}/src/main/torque-gen/work"
255      */
256     private File workDir;
257 
258     /**
259      * The filename of the jar file of the generation unit.
260      * Has only effect if packaging is "jar".
261      *
262      * @parameter
263      */
264     private String jarFile;
265 
266     /**
267      * What to do with the generated files in the default output directory.
268      * Possible values are:
269      * <ul>
270      *   <li>
271      *     compile: The generated files are treated as compileable sources.
272      *     In maven-speak, this means the newFileTargetDir will be added as
273      *     compileSourceRoot of the maven project.
274      *   </li>
275      *   <li>
276      *     test-compile: The generated files are treated as compileable
277      *     test sources.
278      *     In maven-speak, this means the newFileTargetDir will be added as
279      *     testCompileSourceRoot of the maven project.
280      *   </li>
281      *   <li>
282      *     resource: The generated files are treated as resource.
283      *     This means the newFileTargetDir will be added to the
284      *     resources of the maven project.
285      *   </li>
286      *   <li>
287      *     test-resource: The generated files are treated as test resource.
288      *     This means the newFileTargetDir will be added to the
289      *     test resources of the maven project.
290      *   </li>
291      *   <li>
292      *     none: The generated files are not used in the maven build.
293      *   </li>
294      *
295      * @parameter expression="compile"
296      * @required
297      */
298     private String defaultOutputDirUsage;
299 
300     /**
301      * What to do with the generated files for the output directories
302      * defined in outputDirMap. The map uses the same keys as outputDirMap.
303      * Possible values are:
304      * <ul>
305      *   <li>
306      *     compile: The generated files are treated as compileable sources.
307      *     In maven-speak, this means the modifiedFileTargetDir will be added
308      *     as compileSourceRoot of the maven project.
309      *   </li>
310      *   <li>
311      *     test-compile: The generated files are treated as compileable
312      *     test sources.
313      *     In maven-speak, this means the modifiedFileTargetDir will be added
314      *     as testCompileSourceRoot of the maven project.
315      *   </li>
316      *   <li>
317      *     resource: The generated files are treated as resource.
318      *     This means the modifiedFileTargetDir will be added to the
319      *     resources of the maven project.
320      *   </li>
321      *   <li>
322      *     test-resource: The generated files are treated as test resource.
323      *     This means the modifiedFileTargetDir will be added to the
324      *     test resources of the maven project.
325      *   </li>
326      *   <li>
327      *     none: The generated files are not used in the maven build.
328      *   </li>
329      * Default is to map the key "modifiable" to compile
330      *
331      * @parameter
332      */
333     private Map<String, String> outputDirUsageMap
334             = new HashMap<String, String>();
335 
336     /**
337      * The config directory of the project overriding the settings.
338      * If set, the settings of this directory are used as "child"
339      * and the "normal" settings are used as "parent".
340      *
341      * @parameter
342      */
343     private File overrideConfigDir;
344 
345     /**
346      * The config package of the project overriding the settings.
347      * If set, the settings of this directory are used as "child"
348      * and the "normal" settings are used as "parent".
349      *
350      * @parameter
351      */
352     private String overrideConfigPackage;
353 
354     /**
355      * The Loglevel to use in the generation process. Must be one of
356      * trace, debug, info, warn or error.
357      *
358      * @parameter
359      */
360     private String loglevel;
361 
362     /**
363      * Additional options which can be added to the generation process.
364      * This overrides both the options set in the templates
365      * and the options in optionsFile.
366      *
367      * @parameter
368      */
369     private Map<String, String> options;
370 
371     /**
372      * Properties file which contains the options which can be added
373      * to the generation process.
374      * This overrides the options set in the templates, but not the
375      * options set by the parameter <code>options</code>.
376      *
377      * @parameter
378      */
379     private File optionsFile;
380 
381     /**
382      * The encoding which should be used for the files which do not have an
383      * output encoding set in the templates.
384      * If not set, the property project.build.sourceEncoding from the
385      * maven pom is used.
386      * If that is also not set, the generator default is used
387      * (which is the platform default encoding).
388      *
389      * @parameter
390      */
391     private String defaultOutputEncoding;
392 
393     /**
394      * The Maven project this plugin runs in.
395      *
396      * @parameter expression="${project}"
397      * @required
398      * @readonly
399      */
400     private MavenProject project;
401 
402     /**
403      * Configures and runs the Torque generator.
404      */
405     public void execute() throws MojoExecutionException
406     {
407         Controller controller = new Controller();
408         List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
409 
410         // Do conversion here so illegal values are discovered before generation
411         OutputDirUsage defaultOutputDirUsageConverted
412                 = OutputDirUsage.get(defaultOutputDirUsage);
413         Map<String, OutputDirUsage> outputDirUsageConvertedMap
414                 = new HashMap<String, OutputDirUsage>();
415         for (Map.Entry<String, String> outputDirUsageEntry
416                 : outputDirUsageMap.entrySet())
417         {
418             outputDirUsageConvertedMap.put(
419                     outputDirUsageEntry.getKey(),
420                     OutputDirUsage.get(outputDirUsageEntry.getValue()));
421         }
422 
423         UnitDescriptor.Packaging packaging;
424         if ("jar".equals(this.packaging))
425         {
426             packaging = UnitDescriptor.Packaging.JAR;
427         }
428         else if ("directory".equals(this.packaging))
429         {
430             packaging = UnitDescriptor.Packaging.DIRECTORY;
431         }
432         else if ("classpath".equals(this.packaging))
433         {
434             packaging = UnitDescriptor.Packaging.CLASSPATH;
435         }
436         else
437         {
438             throw new IllegalArgumentException(
439                     "Unknown packaging " + this.packaging
440                         + ", must be jar, directory or classpath");
441         }
442         getLog().debug("Packaging is " + packaging);
443 
444         ProjectPaths defaultProjectPaths;
445         if (UnitDescriptor.Packaging.JAR == packaging)
446         {
447             defaultProjectPaths
448                     = new Maven2JarProjectPaths(projectRootDir, jarFile);
449         }
450         else if (UnitDescriptor.Packaging.DIRECTORY == packaging)
451         {
452             defaultProjectPaths
453                     = new Maven2DirectoryProjectPaths(projectRootDir);
454         }
455         else if (UnitDescriptor.Packaging.CLASSPATH == packaging)
456         {
457             defaultProjectPaths
458                     = new Maven2DirectoryProjectPaths(projectRootDir);
459         }
460         else
461         {
462              throw new IllegalStateException("Unknown packaging" + packaging);
463         }
464 
465         CustomProjectPaths projectPaths
466                 = new CustomProjectPaths(defaultProjectPaths);
467 
468         if (UnitDescriptor.Packaging.CLASSPATH == packaging)
469         {
470             if (configPackage == null)
471             {
472                 throw new MojoExecutionException(
473                     "configPackage must be set for packaging =\"classpath\"");
474             }
475             projectPaths.setConfigurationPackage(configPackage);
476             projectPaths.setConfigurationDir(null);
477         }
478         else
479         {
480             if (configDir != null)
481             {
482                 projectPaths.setConfigurationDir(configDir);
483                 getLog().debug("Setting config dir to " + configDir.toString());
484             }
485         }
486 
487         if (sourceDir != null)
488         {
489             projectPaths.setSourceDir(sourceDir);
490             getLog().debug("Setting source dir to " + sourceDir.toString());
491         }
492 
493         FileSourceProvider fileSourceProvider = null;
494         if (sourceIncludes != null || sourceExcludes != null)
495         {
496             Fileset sourceFileset
497                     = new Fileset(
498                             projectPaths.getDefaultSourcePath(),
499                             sourceIncludes,
500                             sourceExcludes);
501             getLog().debug("Setting source includes to "
502                     + sourceIncludes);
503             getLog().debug("Setting source excludes to "
504                     + sourceExcludes);
505             try
506             {
507                 fileSourceProvider = new FileSourceProvider(
508                         null,
509                         sourceFileset,
510                         combineFiles);
511             }
512             catch (ConfigurationException e)
513             {
514                 throw new MojoExecutionException(
515                         "The source provider cannot be instantiated", e);
516             }
517         }
518 
519         projectPaths.setOutputDirectory(null, defaultOutputDir);
520         getLog().debug("Setting defaultOutputDir to "
521                 + defaultOutputDir.toString());
522         if (outputDirMap != null)
523         {
524             if (outputDirMap.get(Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR_KEY)
525                     == null)
526             {
527                 outputDirMap.put(
528                         Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR_KEY,
529                         project.getBasedir()
530                                 + "/"
531                                 + Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR);
532             }
533             for (Map.Entry<String, String> outputDirMapEntry
534                     : outputDirMap.entrySet())
535             {
536                 projectPaths.setOutputDirectory(
537                         outputDirMapEntry.getKey(),
538                         new File(outputDirMapEntry.getValue()));
539                 getLog().debug("Setting output directory with key "
540                         + outputDirMapEntry.getKey()
541                         + " to "
542                         + outputDirMapEntry.getValue());
543             }
544         }
545         if (workDir != null)
546         {
547             projectPaths.setWorkDir(workDir);
548             getLog().debug("Setting workDir to "
549                     + workDir.toString());
550         }
551         getLog().debug("ProjectPaths = " + projectPaths);
552 
553         OptionsConfiguration optionConfiguration = null;
554         if (options != null || optionsFile != null)
555         {
556             if (options == null)
557             {
558                 options = new HashMap<String, String>();
559             }
560             if (optionsFile != null)
561             {
562                 Properties optionProperties = new Properties();
563                 FileInputStream optionsFileInputStream = null;
564                 try
565                 {
566                     optionsFileInputStream = new FileInputStream(optionsFile);
567                     optionProperties.load(optionsFileInputStream);
568                 }
569                 catch (FileNotFoundException e)
570                 {
571                     getLog().error(e);
572                     throw new MojoExecutionException(e.getMessage());
573                 }
574                 catch (IOException e)
575                 {
576                     getLog().error(e);
577                     throw new MojoExecutionException(e.getMessage());
578                 }
579                 finally
580                 {
581                     if (optionsFileInputStream != null)
582                     {
583                         try
584                         {
585                             optionsFileInputStream.close();
586                         }
587                         catch (IOException e)
588                         {
589                             getLog().error(e);
590                         }
591                     }
592                 }
593                 getLog().debug("loaded options file from "
594                         + optionsFile.getAbsolutePath() + ", contents: "
595                         + optionProperties);
596                 for (Map.Entry<Object, Object> propertiesEntry
597                         : optionProperties.entrySet())
598                 {
599                     if (!options.containsKey(propertiesEntry.getKey()))
600                     {
601                         options.put(
602                                 (String) propertiesEntry.getKey(),
603                                 (String) propertiesEntry.getValue());
604                     }
605                 }
606             }
607             getLog().debug("options = " + options);
608             optionConfiguration = new MapOptionsConfiguration(options);
609         }
610         Loglevel convertedLoglevel = null;
611         if (this.loglevel != null)
612         {
613             convertedLoglevel = Loglevel.getByKey(loglevel);
614         }
615         String encoding = defaultOutputEncoding;
616         if (encoding == null)
617         {
618             encoding = project.getProperties().getProperty(
619                     "project.build.sourceEncoding");
620         }
621         UnitDescriptor unitDescriptor = new UnitDescriptor(
622                 packaging,
623                 projectPaths,
624                 new DefaultTorqueGeneratorPaths());
625         unitDescriptor.setOverrideSourceProvider(fileSourceProvider);
626         unitDescriptor.setOverrideOptions(optionConfiguration);
627         unitDescriptor.setLoglevel(convertedLoglevel);
628         unitDescriptor.setDefaultOutputEncoding(encoding);
629         getLog().debug("unit descriptor created");
630         if (overrideConfigDir != null)
631         {
632             CustomProjectPaths childProjectPaths
633                 = new CustomProjectPaths(projectPaths);
634             childProjectPaths.setConfigurationDir(overrideConfigDir);
635 
636             UnitDescriptor parentUnitDescriptor = new UnitDescriptor(
637                     Packaging.DIRECTORY,
638                     childProjectPaths,
639                     new DefaultTorqueGeneratorPaths());
640             parentUnitDescriptor.setInheritsFrom(unitDescriptor);
641             parentUnitDescriptor.setOverrideSourceProvider(fileSourceProvider);
642             parentUnitDescriptor.setOverrideOptions(optionConfiguration);
643             parentUnitDescriptor.setLoglevel(convertedLoglevel);
644             parentUnitDescriptor.setDefaultOutputEncoding(encoding);
645             getLog().debug("child unit descriptor created from directory");
646             unitDescriptor = parentUnitDescriptor;
647         }
648         else if (overrideConfigPackage != null)
649         {
650             CustomProjectPaths childProjectPaths
651                 = new CustomProjectPaths(projectPaths);
652             childProjectPaths.setConfigurationPackage(overrideConfigPackage);
653 
654             UnitDescriptor parentUnitDescriptor = new UnitDescriptor(
655                     Packaging.CLASSPATH,
656                     childProjectPaths,
657                     new DefaultTorqueGeneratorPaths());
658             parentUnitDescriptor.setInheritsFrom(unitDescriptor);
659             parentUnitDescriptor.setOverrideSourceProvider(fileSourceProvider);
660             parentUnitDescriptor.setOverrideOptions(optionConfiguration);
661             parentUnitDescriptor.setLoglevel(convertedLoglevel);
662             parentUnitDescriptor.setDefaultOutputEncoding(encoding);
663             getLog().debug("child unit descriptor created from package");
664             unitDescriptor = parentUnitDescriptor;
665         }
666         unitDescriptors.add(unitDescriptor);
667         try
668         {
669             getLog().debug("Generation started");
670             controller.run(unitDescriptors);
671             getLog().info("Generation successful");
672         }
673         catch (Exception e)
674         {
675             getLog().error(e);
676             throw new MojoExecutionException(e.getMessage());
677         }
678 
679         File defaultOutputDirPath = projectPaths.getOutputDirectory(null);
680         if (defaultOutputDirPath.exists())
681         {
682             switch (defaultOutputDirUsageConverted)
683             {
684             case COMPILE:
685                 project.addCompileSourceRoot(
686                         defaultOutputDirPath.toString());
687                 getLog().debug("Added "
688                         + defaultOutputDirPath.toString()
689                         + " as compile source root");
690                 break;
691             case TEST_COMPILE:
692                 project.addTestCompileSourceRoot(
693                         defaultOutputDirPath.toString());
694                 getLog().debug("Added "
695                         + defaultOutputDirPath.toString()
696                         + " as test compile source root");
697                 break;
698             case RESOURCE:
699                 Resource resource = new Resource();
700                 resource.setDirectory(defaultOutputDirPath.toString());
701                 project.addResource(resource);
702                 getLog().debug("Added "
703                         + defaultOutputDirPath.toString()
704                         + " to the project resources");
705                 break;
706             case TEST_RESOURCE:
707                 resource = new Resource();
708                 resource.setDirectory(defaultOutputDirPath.toString());
709                 project.addTestResource(resource);
710                 getLog().debug("Added "
711                         + defaultOutputDirPath.toString()
712                         + " to the project test resources");
713                 break;
714             case NONE:
715             default:
716             }
717         }
718         else
719         {
720             getLog().info("defaultOutputDirPath "
721                 + defaultOutputDirPath.getAbsolutePath()
722                 + " does not exist, not applying defaultOutputDirUsage");
723         }
724 
725         if (outputDirUsageConvertedMap.get(
726                 Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR_KEY)
727                   == null
728             && outputDirMap.get(
729                 Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR_KEY)
730                     != null)
731         {
732             outputDirUsageConvertedMap.put(
733                     Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR_KEY,
734                     OutputDirUsage.COMPILE);
735         }
736         for (Map.Entry<String, OutputDirUsage> usageEntry
737                 : outputDirUsageConvertedMap.entrySet())
738         {
739             String outputDirPath = outputDirMap.get(usageEntry.getKey());
740             if (outputDirPath == null)
741             {
742                 getLog().info("outputDirPath set for key "
743                         + usageEntry.getKey()
744                         + " ignoring this outputDirUsageMap entry");
745                 continue;
746             }
747 
748             File outputDirFile = new File(outputDirPath);
749             if (!outputDirFile.exists())
750             {
751                 getLog().info("outputDirPath "
752                         + outputDirFile.getAbsolutePath()
753                         + " for outputDirUsageMap with key "
754                         + usageEntry.getKey()
755                         + " does not exist,"
756                         + " ignoring this outputDirUsageMap entry");
757                 continue;
758             }
759             switch (usageEntry.getValue())
760             {
761             case COMPILE:
762                 project.addCompileSourceRoot(outputDirPath.toString());
763                 getLog().debug("Added "
764                         + outputDirPath.toString()
765                         + " as compile source root");
766                 break;
767             case TEST_COMPILE:
768                 project.addTestCompileSourceRoot(
769                         outputDirPath.toString());
770                 getLog().debug("Added "
771                         + outputDirPath.toString()
772                         + " as test compile source root");
773                 break;
774             case RESOURCE:
775                 Resource resource = new Resource();
776                 resource.setDirectory(outputDirPath.toString());
777                 project.addResource(resource);
778                 getLog().debug("Added "
779                         + outputDirPath.toString()
780                         + " to the project resources");
781                 break;
782             case TEST_RESOURCE:
783                 resource = new Resource();
784                 resource.setDirectory(outputDirPath.toString());
785                 project.addTestResource(resource);
786                 getLog().debug("Added "
787                         + outputDirPath.toString()
788                         + " to the project test resources");
789                 break;
790             case NONE:
791             default:
792             }
793         }
794     }
795 
796     /**
797      * Sets the packaging.
798      *
799      * @param packaging the packaging, either "jar" or "directory"
800      */
801     public void setPackaging(String packaging)
802     {
803         this.packaging = packaging;
804     }
805 
806     /**
807      * Sets the root directory of the project.
808      *
809      * @param projectRootDir the project root Directory.
810      */
811     public void setProjectRootDir(File projectRootDir)
812     {
813         this.projectRootDir = projectRootDir;
814     }
815 
816     public void setConfigDir(File configDir)
817     {
818         this.configDir = configDir;
819     }
820 
821     public void setConfigPackage(String configPackage)
822     {
823         this.configPackage = configPackage;
824     }
825 
826     /**
827      * Sets the default output directory for generated files.
828      *
829      * @param outputDir the default output directory, not null.
830      */
831     public void setDefaultOutputDir(File outputDir)
832     {
833         this.defaultOutputDir = outputDir;
834     }
835 
836     /**
837      * Sets the target directory for files which are not generated
838      * each time anew.
839      *
840      * @param targetDir the target directory, or null to use the default.
841      */
842     public void setOutputDir(String outputDirKey, String outputDir)
843     {
844         this.outputDirMap.put(outputDirKey, outputDir);
845     }
846 
847     /**
848      * The path to the jar file to use.
849      *
850      * @param jarFile the jar file, or null.
851      */
852     public void setJarFile(String jarFile)
853     {
854         this.jarFile = jarFile;
855     }
856 
857     /**
858      * Sets the maven project this mojo runs in.
859      *
860      * @param project the maven project this mojo runs in.
861      */
862     public void setProject(MavenProject project)
863     {
864         this.project = project;
865     }
866 
867     /**
868      * Sets the usage for the default output dir.
869      *
870      * @param defaultOutputDirUsage the new usage, not null.
871      */
872     public void setDefaultOutputDirUsage(String defaultOutputDirUsage)
873     {
874         if (defaultOutputDirUsage == null)
875         {
876             throw new NullPointerException(
877                     "defaultOutputDirUsage must not be null");
878         }
879         this.defaultOutputDirUsage = defaultOutputDirUsage;
880     }
881 
882     /**
883      * Sets the usage for an output directory.
884      *
885      * @param outputDirKey key for the output directory, not null.
886      * @param outputDirUsage the new usage, not null.
887      */
888     public void setOutputDirUsage(
889             String outputDirKey,
890             String outputDirUsage)
891     {
892         if (outputDirKey == null)
893         {
894             throw new NullPointerException(
895                     "outputDirKey must not be null");
896         }
897         if (outputDirUsage == null)
898         {
899             throw new NullPointerException(
900                     "modifiedFileTargetDirUsage must not be null");
901         }
902         this.outputDirUsageMap.put(outputDirKey, outputDirUsage);
903     }
904 
905     /**
906      * Sets the directory in which the source files are located.
907      *
908      * @param sourceDir the directory in which the source files are located.
909      */
910     public void setSourceDir(File sourceDir)
911     {
912         this.sourceDir = sourceDir;
913     }
914 
915     /**
916      * Sets the pattern which files are included in the generation process.
917      *
918      * @param sourceIncludes a list containing the include patterns, or null
919      *        if no include pattern should be used.
920      */
921     public void setSourceIncludes(Set<String> sourceIncludes)
922     {
923         this.sourceIncludes = sourceIncludes;
924     }
925 
926     /**
927      * Sets the pattern which files are excluded in the generation process.
928      *
929      * @param sourceExcludes a list containing the exclude patterns, or null
930      *        if no exclude pattern should be used.
931      */
932     public void setSourceExcludes(Set<String> sourceExcludes)
933     {
934         this.sourceExcludes = sourceExcludes;
935     }
936 
937     /**
938      * Sets the config directory overriding the template settings.
939      * If set, the settings of this directory are used as "child"
940      * and the "normal" settings are used as "parent".
941      *
942      * @parameter the config directory overriding the template settings,
943      *            or null if the template settings will not be overridden.
944      */
945     public void setOverrideConfigDir(File overrideConfigDir)
946     {
947         this.overrideConfigDir = overrideConfigDir;
948     }
949 
950     /**
951      * Sets the Loglevel to use in the generation process.
952      *
953      * @param loglevel the loglevel, must be one of trace, debug, info, warn
954      *        or error, or null if the loglevel defined in the templates
955      *        should be used.
956      */
957     public void setLoglevel(String loglevel)
958     {
959         this.loglevel = loglevel;
960     }
961 
962     /**
963      * Sets the encoding which should be used for the files which do not have
964      * an output encoding set in the templates.
965      *
966      * @param defaultOutputEncoding the default output encoding,
967      *        or null to use the generator default
968      *        (the platform default encoding).
969      */
970     public void setDefaultOutputEncoding(String defaultOutputEncoding)
971     {
972         this.defaultOutputEncoding = defaultOutputEncoding;
973     }
974 
975     /**
976      * Sets additional options which can be added to the generation process.
977      * These options overrides existing options in the templates.
978      *
979      * @param options the overriding options, or null if no options
980      *        should be overridden.
981      */
982     public void setOptions(Map<String, String> options)
983     {
984         this.options = options;
985     }
986 
987     /**
988      * Sets whether all source files should be combined into one single graph-
989      *
990      * @param combineFiles whether the source file should be combined.
991      */
992     public void setCombineFiles(Boolean combineFiles)
993     {
994         this.combineFiles = combineFiles;
995     }
996 
997     /**
998      * Sets the work dir for e.g. merging sources.
999      *
1000      * @param workDir the new workdir.
1001      */
1002     public void setWorkDir(File workDir)
1003     {
1004         this.workDir = workDir;
1005     }
1006 
1007     /**
1008      * Sets a options file by which generation parameters can be set.
1009      *
1010      * @param optionsFile the path to the file containing the generation
1011      *        options.
1012      */
1013     public void setOptionsFile(File optionsFile)
1014     {
1015         this.optionsFile = optionsFile;
1016     }
1017 
1018 
1019 }