/**
* Configures and runs the Torque generator.
*/
public void execute() throws MojoExecutionException
{
Controller controller = new Controller();
List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
// Do conversion here so illegal values are discovered before generation
OutputDirUsage defaultOutputDirUsageConverted
= OutputDirUsage.get(defaultOutputDirUsage);
Map<String, OutputDirUsage> outputDirUsageConvertedMap
= new HashMap<String, OutputDirUsage>();
for (Map.Entry<String, String> outputDirUsageEntry
: outputDirUsageMap.entrySet())
{
outputDirUsageConvertedMap.put(
outputDirUsageEntry.getKey(),
OutputDirUsage.get(outputDirUsageEntry.getValue()));
}
UnitDescriptor.Packaging packaging;
if ("jar".equals(this.packaging))
{
packaging = UnitDescriptor.Packaging.JAR;
}
else if ("directory".equals(this.packaging))
{
packaging = UnitDescriptor.Packaging.DIRECTORY;
}
else if ("classpath".equals(this.packaging))
{
packaging = UnitDescriptor.Packaging.CLASSPATH;
}
else
{
throw new IllegalArgumentException(
"Unknown packaging " + this.packaging
+ ", must be jar, directory or classpath");
}
getLog().debug("Packaging is " + packaging);
ProjectPaths defaultProjectPaths;
if (UnitDescriptor.Packaging.JAR == packaging)
{
defaultProjectPaths
= new Maven2JarProjectPaths(projectRootDir, jarFile);
}
else if (UnitDescriptor.Packaging.DIRECTORY == packaging)
{
defaultProjectPaths
= new Maven2DirectoryProjectPaths(projectRootDir);
}
else if (UnitDescriptor.Packaging.CLASSPATH == packaging)
{
defaultProjectPaths
= new Maven2DirectoryProjectPaths(projectRootDir);
}
else
{
throw new IllegalStateException("Unknown packaging" + packaging);
}
CustomProjectPaths projectPaths
= new CustomProjectPaths(defaultProjectPaths);
if (UnitDescriptor.Packaging.CLASSPATH == packaging)
{
if (configPackage == null)
{
throw new MojoExecutionException(
"configPackage must be set for packaging =\"classpath\"");
}
projectPaths.setConfigurationPackage(configPackage);
projectPaths.setConfigurationDir(null);
}
else
{
if (configDir != null)
{
projectPaths.setConfigurationDir(configDir);
getLog().debug("Setting config dir to " + configDir.toString());
}
}
if (sourceDir != null)
{
projectPaths.setSourceDir(sourceDir);
getLog().debug("Setting source dir to " + sourceDir.toString());
}
FileSourceProvider fileSourceProvider = null;
if (sourceIncludes != null || sourceExcludes != null)
{
Fileset sourceFileset
= new Fileset(
projectPaths.getDefaultSourcePath(),
sourceIncludes,
sourceExcludes);
getLog().debug("Setting source includes to "
+ sourceIncludes);
getLog().debug("Setting source excludes to "
+ sourceExcludes);
try
{
fileSourceProvider = new FileSourceProvider(
null,
sourceFileset,
combineFiles);
}
catch (ConfigurationException e)
{
throw new MojoExecutionException(
"The source provider cannot be instantiated", e);
}
}
projectPaths.setOutputDirectory(null, defaultOutputDir);
getLog().debug("Setting defaultOutputDir to "
+ defaultOutputDir.toString());
if (outputDirMap != null)
{
if (outputDirMap.get(Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR_KEY)
== null)
{
outputDirMap.put(
Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR_KEY,
project.getBasedir()
+ "/"
+ Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR);
}
for (Map.Entry<String, String> outputDirMapEntry
: outputDirMap.entrySet())
{
projectPaths.setOutputDirectory(
outputDirMapEntry.getKey(),
new File(outputDirMapEntry.getValue()));
getLog().debug("Setting output directory with key "
+ outputDirMapEntry.getKey()
+ " to "
+ outputDirMapEntry.getValue());
}
}
if (workDir != null)
{
projectPaths.setWorkDir(workDir);
getLog().debug("Setting workDir to "
+ workDir.toString());
}
getLog().debug("ProjectPaths = " + projectPaths);
OptionsConfiguration optionConfiguration = null;
if (options != null || optionsFile != null)
{
if (options == null)
{
options = new HashMap<String, String>();
}
if (optionsFile != null)
{
Properties optionProperties = new Properties();
FileInputStream optionsFileInputStream = null;
try
{
optionsFileInputStream = new FileInputStream(optionsFile);
optionProperties.load(optionsFileInputStream);
}
catch (FileNotFoundException e)
{
getLog().error(e);
throw new MojoExecutionException(e.getMessage());
}
catch (IOException e)
{
getLog().error(e);
throw new MojoExecutionException(e.getMessage());
}
finally
{
if (optionsFileInputStream != null)
{
try
{
optionsFileInputStream.close();
}
catch (IOException e)
{
getLog().error(e);
}
}
}
getLog().debug("loaded options file from "
+ optionsFile.getAbsolutePath() + ", contents: "
+ optionProperties);
for (Map.Entry<Object, Object> propertiesEntry
: optionProperties.entrySet())
{
if (!options.containsKey(propertiesEntry.getKey()))
{
options.put(
(String) propertiesEntry.getKey(),
(String) propertiesEntry.getValue());
}
}
}
getLog().debug("options = " + options);
optionConfiguration = new MapOptionsConfiguration(options);
}
Loglevel convertedLoglevel = null;
if (this.loglevel != null)
{
convertedLoglevel = Loglevel.getByKey(loglevel);
}
String encoding = defaultOutputEncoding;
if (encoding == null)
{
encoding = project.getProperties().getProperty(
"project.build.sourceEncoding");
}
UnitDescriptor unitDescriptor = new UnitDescriptor(
packaging,
projectPaths,
new DefaultTorqueGeneratorPaths());
unitDescriptor.setOverrideSourceProvider(fileSourceProvider);
unitDescriptor.setOverrideOptions(optionConfiguration);
unitDescriptor.setLoglevel(convertedLoglevel);
unitDescriptor.setDefaultOutputEncoding(encoding);
unitDescriptor.setAddDebuggingInfoToOutput(addDebuggingInfoToOutput);
getLog().debug("unit descriptor created");
if (overrideConfigDir != null)
{
CustomProjectPaths childProjectPaths
= new CustomProjectPaths(projectPaths);
childProjectPaths.setConfigurationDir(overrideConfigDir);
UnitDescriptor parentUnitDescriptor = new UnitDescriptor(
Packaging.DIRECTORY,
childProjectPaths,
new DefaultTorqueGeneratorPaths());
parentUnitDescriptor.setInheritsFrom(unitDescriptor);
parentUnitDescriptor.setOverrideSourceProvider(fileSourceProvider);
parentUnitDescriptor.setOverrideOptions(optionConfiguration);
parentUnitDescriptor.setLoglevel(convertedLoglevel);
parentUnitDescriptor.setDefaultOutputEncoding(encoding);
getLog().debug("child unit descriptor created from directory");
unitDescriptor = parentUnitDescriptor;
}
else if (overrideConfigPackage != null)
{
CustomProjectPaths childProjectPaths
= new CustomProjectPaths(projectPaths);
childProjectPaths.setConfigurationPackage(overrideConfigPackage);
UnitDescriptor parentUnitDescriptor = new UnitDescriptor(
Packaging.CLASSPATH,
childProjectPaths,
new DefaultTorqueGeneratorPaths());
parentUnitDescriptor.setInheritsFrom(unitDescriptor);
parentUnitDescriptor.setOverrideSourceProvider(fileSourceProvider);
parentUnitDescriptor.setOverrideOptions(optionConfiguration);
parentUnitDescriptor.setLoglevel(convertedLoglevel);
parentUnitDescriptor.setDefaultOutputEncoding(encoding);
getLog().debug("child unit descriptor created from package");
unitDescriptor = parentUnitDescriptor;
}
unitDescriptors.add(unitDescriptor);
try
{
getLog().debug("Generation started");
controller.run(unitDescriptors);
getLog().info("Generation successful");
}
catch (Exception e)
{
getLog().error(e);