You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2006/04/20 07:37:46 UTC
svn commit: r395493 - in /db/torque/trunks/maven2-plugin: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/torque/ src/main/java/org/apache/torque/mojo/
src/test/ src/test/java/ src/test/java/org/ s...
Author: tfischer
Date: Wed Apr 19 22:37:44 2006
New Revision: 395493
URL: http://svn.apache.org/viewcvs?rev=395493&view=rev
Log:
Start of a Maven 2 Plugin.
Thanks to Raphael Pieroni for his initial version.
Added:
db/torque/trunks/maven2-plugin/
db/torque/trunks/maven2-plugin/pom.xml
db/torque/trunks/maven2-plugin/src/
db/torque/trunks/maven2-plugin/src/main/
db/torque/trunks/maven2-plugin/src/main/java/
db/torque/trunks/maven2-plugin/src/main/java/org/
db/torque/trunks/maven2-plugin/src/main/java/org/apache/
db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/
db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/
db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/DataModelTaskMojo.java
db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/OMMojo.java
db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/TexenTaskMojo.java
db/torque/trunks/maven2-plugin/src/test/
db/torque/trunks/maven2-plugin/src/test/java/
db/torque/trunks/maven2-plugin/src/test/java/org/
db/torque/trunks/maven2-plugin/src/test/java/org/apache/
db/torque/trunks/maven2-plugin/src/test/java/org/apache/torque/
db/torque/trunks/maven2-plugin/src/test/java/org/apache/torque/mojo/
db/torque/trunks/maven2-plugin/src/test/java/org/apache/torque/mojo/TorqueOMMojoTest.java
db/torque/trunks/maven2-plugin/src/test/resources/
db/torque/trunks/maven2-plugin/src/test/resources/projects/
db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/
db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/pom.xml
db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/
db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/
db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/
db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/
db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/id-table-schema.xml
db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/test-TorqueOMMojoTest-schema.xml
db/torque/trunks/maven2-plugin/src/test/resources/repository/
Added: db/torque/trunks/maven2-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/db/torque/trunks/maven2-plugin/pom.xml?rev=395493&view=auto
==============================================================================
--- db/torque/trunks/maven2-plugin/pom.xml (added)
+++ db/torque/trunks/maven2-plugin/pom.xml Wed Apr 19 22:37:44 2006
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.db.torque</groupId>
+ <artifactId>torque</artifactId>
+ <version>3.2.1-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>torque-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>Torque Maven2 Plugin</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-descriptor</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.db.torque</groupId>
+ <artifactId>generator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.8</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>3.1.11</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/TorqueOMMojoTest.java</include>
+ <include>**/TorqueSQLMojoTest.java</include>
+ <include>**/TorqueDataDtdMojoTest.java</include>
+ <include>**/TorqueDataSQLMojoTest.java</include>
+ <include>**/TorqueInsertSQLMojoTest.java</include>
+ <include>**/TorqueJDBCTest.java</include>
+ <include>**/TorqueDataDumpMojoTest.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/DataModelTaskMojo.java
URL: http://svn.apache.org/viewcvs/db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/DataModelTaskMojo.java?rev=395493&view=auto
==============================================================================
--- db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/DataModelTaskMojo.java (added)
+++ db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/DataModelTaskMojo.java Wed Apr 19 22:37:44 2006
@@ -0,0 +1,368 @@
+package org.apache.torque.mojo;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.torque.task.TorqueDataModelTask;
+
+/**
+ * The base class for all mojos wrapping DataModelTasks
+ *
+ * @author Raphael Pieroni (rafale_at_codehaus.org)
+ * @author <a href="fischer@seitenbau.de">Thomas Fischer</a>
+ */
+public abstract class DataModelTaskMojo
+ extends TexenTaskMojo
+{
+ /**
+ * The path to the directory where the schema files are located in.
+ *
+ * @parameter expression="${basedir}/src/main/torque/schema"
+ * @required
+ */
+ private String schemaDir;
+
+ /**
+ * The schema files which should be included in generation
+ * (in ant-style notation).
+ *
+ * @parameter expression="*schema.xml"
+ * @required
+ */
+ private String schemaIncludes;
+
+ /**
+ * The schema files which should be excluded in generation
+ * (in ant-style notation).
+ *
+ * @parameter expression="id-table-schema.xml"
+ */
+ private String schemaExcludes;
+
+ /**
+ * The name of the database for the generated files.
+ *
+ * @parameter
+ */
+ private String database;
+
+ /**
+ * The target package for the generated classes.
+ *
+ * @parameter expression="org.apache.torque"
+ */
+ private String targetPackage;
+
+ /**
+ * The file containing the generation report, relative to
+ * <code>outputDir</code>.
+ *
+ * @parameter expression="report.${project.artifact.artifactId}".${goal}.generation"
+ * @required
+ */
+ private String reportFile;
+
+ /**
+ * determines if this task should run only if the schema has changed.
+ *
+ * @parameter expression="true"
+ */
+ private boolean runOnlyOnSchemaChange;
+
+ /**
+ * Creates a new TorqueOMMojo object.
+ */
+ DataModelTaskMojo()
+ {
+ super(new TorqueDataModelTask());
+ }
+
+ /**
+ * Configures the Texen task which is wrapped by this mojo.
+ * In this implementation, the context properties, useClasspath,
+ * the output directory, the control template, the schema Fileset,
+ * the target package and the target database are set.
+ *
+ * @throws MojoExecutionException if an error occurs when setting the Tasks
+ * properties.
+ *
+ * @see TexenTaskMojo#configureTask()
+ */
+ protected void configureTask() throws MojoExecutionException
+ {
+ super.configureTask();
+
+ TorqueDataModelTask task
+ = (TorqueDataModelTask) super.getGeneratorTask();
+
+ task.setControlTemplate("om/Control.vm");
+
+ task.setOutputFile(reportFile);
+
+ task.setControlTemplate("om/Control.vm");
+
+ task.setTargetDatabase(database);
+
+ task.setTargetPackage(getTargetPackage());
+
+ {
+ FileSet fileSet = new FileSet();
+ fileSet.setDir(new File(schemaDir));
+ fileSet.setIncludes(schemaIncludes);
+ fileSet.setExcludes(schemaExcludes);
+
+ task.addFileset(fileSet);
+ }
+
+ }
+
+ /**
+ * Returns whether the schema has changed. This is done by comparing
+ * the modification date of all schema files to the modification date
+ * of the report file.
+ *
+ * @return whether the schema has changed.
+ */
+ protected boolean schemaChanged()
+ {
+ boolean schemaChanged = true;
+ File report = new File(super.getOutputDir(), this.reportFile);
+ if (report.exists())
+ {
+ FileSet fileSet = new FileSet();
+ fileSet.setDir(new File(schemaDir));
+ fileSet.setIncludes(schemaIncludes);
+ fileSet.setExcludes(schemaExcludes);
+
+ DirectoryScanner directoryScanner
+ = fileSet.getDirectoryScanner(getAntProject());
+
+ String[] fileNames = directoryScanner.getIncludedFiles();
+
+/* File schemaDirectory = new File(schemaDir);
+ FileFilter schemaFileFilter = new FileFilter() {
+ public boolean accept(File toCheck)
+ {
+ String path = toCheck.getAbsolutePath();
+ if (schemaExcludes != null
+ && !schemaExcludes.trim().equals("")
+ && Pattern.matches(schemaExcludes, path))
+ {
+ return false;
+ }
+ return Pattern.matches(schemaIncludes, path);
+ }
+ };
+ File[] schemaFiles = schemaDirectory.listFiles(schemaFileFilter);*/
+
+ // schema has changed if one of the schema files has a modification
+ // Date larger than the report.
+ schemaChanged = false;
+ for (int i = 0; i < fileNames.length; ++i)
+ {
+ File file = new File(fileNames[i]);
+ if (file.lastModified() > report.lastModified())
+ {
+ schemaChanged=true;
+ break;
+ }
+ }
+ }
+
+ return schemaChanged;
+ }
+
+ /**
+ * Returns the directory where the schema files are located.
+ *
+ * @return the the directory where the schema files are located.
+ */
+ public String getSchemaDir()
+ {
+ return schemaDir;
+ }
+
+ /**
+ * Sets the the directory where the schema files are located.
+ *
+ * @param schemaDir the directory where the schema files are located.
+ */
+ public void setSchemaDir(String schemaDir)
+ {
+ this.schemaDir = schemaDir;
+ }
+
+ /**
+ * Returns the default database for the generated files.
+ *
+ * @return the default database for the generated files.
+ */
+ public String getDatabase()
+ {
+ return database;
+ }
+
+ /**
+ * Sets the default database for the generated files.
+ *
+ * @param database the default database for the generated files.
+ *
+ * @todo check what this setting does
+ */
+ public void setDatabase(String database)
+ {
+ this.database = database;
+ }
+
+ /**
+ * Returns the target package for the generated classes.
+ *
+ * @return the target package for the generated classes.
+ */
+ public String getTargetPackage()
+ {
+ return targetPackage;
+ }
+
+ /**
+ * Sets the target package for the generated classes.
+ *
+ * param targetPackage the target package for the generated classes.
+ */
+ public void setTargetPackage(String targetPackage)
+ {
+ this.targetPackage = targetPackage;
+ }
+
+ /**
+ * Gets the path to the report file. The path is relative to
+ * <code>outputDir</code>.
+ *
+ * @return the path to the report file.
+ */
+ public String getReportFile()
+ {
+ return reportFile;
+ }
+
+ /**
+ * Sets the path to the report file. The path is relative to
+ * <code>outputDir</code>.
+ *
+ * @param reportFile the path to the report file.
+ */
+ public void setReportFile(String reportFile)
+ {
+ this.reportFile = reportFile;
+ }
+
+ /**
+ * Returns whether this mojo should be executed only if the schema has
+ * changed.
+ *
+ * @return true if the mojo only runs if the schema has changed,
+ * false otherwise.
+ */
+ public boolean isRunOnlyOnSchemaChange()
+ {
+ return runOnlyOnSchemaChange;
+ }
+
+ /**
+ * Sets whether this mojo should be executed only if the schema has
+ * changed.
+ *
+ * @param runOnlyOnSchemaChange whether the mojo only should run
+ * if the schema has changed.
+ */
+ public void setRunOnlyOnSchemaChange(boolean runOnlyOnSchemaChange)
+ {
+ this.runOnlyOnSchemaChange = runOnlyOnSchemaChange;
+ }
+
+ /**
+ * Runs the generation for the database layout defined in the schema.xml
+ * files.
+ *
+ * @throws MojoExecutionException If an error occurs during generation.
+ *
+ * @see TexenTaskMojo#execute()
+ * @see Mojo#execute()
+ */
+ public void execute() throws MojoExecutionException
+ {
+ if (!schemaChanged() && isRunOnlyOnSchemaChange())
+ {
+ getLog().info("Schema has not changed; skipping generation");
+ return;
+ }
+
+ super.execute();
+ }
+
+ /**
+ * Returns the schema files which are excluded from generation.
+ *
+ * @return the pattern for the excluded files.
+ */
+ public String getSchemaExcludes()
+ {
+ return schemaExcludes;
+ }
+
+ /**
+ * Sets the schema files which are excluded from generation.
+ *
+ * @param schemaExcludes the pattern for the excluded files.
+ */
+ public void setSchemaExcludes(String schemaExcludes)
+ {
+ this.schemaExcludes = schemaExcludes;
+ }
+
+ /**
+ * Returns the schema files which are included in generation.
+ *
+ * @return the pattern for the included files.
+ */
+ public String getSchemaIncludes()
+ {
+ return schemaIncludes;
+ }
+
+ /**
+ * Sets the schema files which are included in generation.
+ *
+ * @param schemaIncludes the pattern for the included files.
+ */
+ public void setSchemaIncludes(String schemaIncludes)
+ {
+ this.schemaIncludes = schemaIncludes;
+ }
+
+ /**
+ * Returns the name of the goal this mojo is providing.
+ *
+ * @return the name of the goal this mojo is providing, not null.
+ */
+ public abstract String getGoal();
+}
Added: db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/OMMojo.java
URL: http://svn.apache.org/viewcvs/db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/OMMojo.java?rev=395493&view=auto
==============================================================================
--- db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/OMMojo.java (added)
+++ db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/OMMojo.java Wed Apr 19 22:37:44 2006
@@ -0,0 +1,1031 @@
+package org.apache.torque.mojo;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.tools.ant.BuildException;
+
+/**
+ * A mojo for the Torque om task.
+ *
+ * @author Raphael Pieroni (rafale_at_codehaus.org)
+ * @author <a href="fischer@seitenbau.de">Thomas Fischer</a>
+ *
+ * @goal om
+ * @execute phase="generate-sources"
+ * @requiresDependencyResolution compile
+ */
+public class OMMojo
+ extends DataModelTaskMojo
+{
+ /**
+ * The context property for the database.
+ *
+ * @todo check if this is used from the context properties.
+ */
+ public static final String DATABASE_CONTEXT_PROPERTY
+ = "database";
+
+ /**
+ * The context property for the target package.
+ */
+ public static final String TARGET_PACKAGE_CONTEXT_PROPERTY
+ = "targetPackage";
+
+ /**
+ * The context property for the prefix of the class name for
+ * the generated base classes,
+ */
+ public static final String BASE_PREFIX_CONTEXT_PROPERTY
+ = "basePrefix";
+
+ /**
+ * The context property which determines the name suffix of
+ * generated bean classes.
+ */
+ public static final String BEAN_SUFFIX_CONTEXT_PROPERTY
+ = "beanSuffix";
+
+ /**
+ * The context property for the subpackage of the generated
+ * database Map classes.
+ */
+ public static final String SUBPACKAGE_MAP_CONTEXT_PROPERTY
+ = "subpackageMap";
+
+ /**
+ * The context property for the subpackage of the generated
+ * base Object, Peer, and Manager classes.
+ */
+ public static final String SUBPACKAGE_BASE_CONTEXT_PROPERTY
+ = "subpackageBase";
+
+ /**
+ * The context property for the subpackage of the generated
+ * base bean classes.
+ */
+ public static final String SUBPACKAGE_BASE_BEAN_CONTEXT_PROPERTY
+ = "subpackageBaseBean";
+
+ /**
+ * The context property for the subpackage of the generated
+ * bean classes.
+ */
+ public static final String SUBPACKAGE_BEAN_CONTEXT_PROPERTY
+ = "subpackageBean";
+
+ /**
+ * The context property for the subpackage of the generated
+ * manager classes.
+ */
+ public static final String SUBPACKAGE_MANAGER_CONTEXT_PROPERTY
+ = "subpackageManager";
+
+ /**
+ * The context property for the subpackage of the generated
+ * data object classes.
+ */
+ public static final String SUBPACKAGE_OBJECT_CONTEXT_PROPERTY
+ = "subpackageObject";
+
+ /**
+ * The context property for the subpackage of the generated
+ * peer classes.
+ */
+ public static final String SUBPACKAGE_PEER_CONTEXT_PROPERTY
+ = "subpackagePeer";
+
+ /**
+ * The context property where the generation of the getByName-
+ * Methods can be turned on and off.
+ */
+ public static final String ADD_GET_BY_NAME_METHOD_CONTEXT_PROPERTY
+ = "addGetByNameMethod";
+
+ /**
+ * The context property where it is configured whether the
+ * data objects implement a Retrievable interface.
+ */
+ public static final String ADD_INTAKE_RETRIEVABLE_CONTEXT_PROPERTY
+ = "addIntakeRetrievable";
+
+ /**
+ * The context property where it is configured whether the
+ * data objects implement a Retrievable interface.
+ */
+ public static final String RETRIEVABLE_INTERFACE_CONTEXT_PROPERTY
+ = "retrievableInterface";
+
+ /**
+ * The context property where the generation of the save
+ * methods can be turned on and off.
+ */
+ public static final String ADD_SAVE_METHOD_CONTEXT_PROPERTY
+ = "addSaveMethod";
+
+ /**
+ * The context property where the exception thown by save methods
+ * can be configured.
+ */
+ public static final String SAVE_EXCEPTION_CONTEXT_PROPERTY
+ = "saveException";
+
+ /**
+ * The context property where it is configured whether methods
+ * are generated to easily retrieve foreign key relationships.
+ */
+ public static final String COMPLEX_OBJECT_MODEL_CONTEXT_PROPERTY
+ = "complexObjectModel";
+
+ /**
+ * The context property which determines whether empty cached
+ * foreign key relations should be filled automatically.
+ */
+ public static final String SILENT_DB_FETCH_CONTEXT_PROPERTY
+ = "silentDbFetch";
+
+ /**
+ * The context property which determines whether manager classes
+ * are generated.
+ */
+ public static final String USE_MANAGERS_CONTEXT_PROPERTY
+ = "useManagers";
+
+ /**
+ * The context property which determines whether foreign key relationships
+ * are cached.
+ */
+ public static final String OBJECT_IS_CACHING_CONTEXT_PROPERTY
+ = "objectIsCaching";
+
+ /**
+ * The context property which determines whether isXXX methods are
+ * generated for boolean properties instead of getXXX methods.
+ */
+ public static final String CORRECT_GETTERS_CONTEXT_PROPERTY
+ = "correctGetters";
+
+ /**
+ * The context property which determines whether java5 generics
+ * and easy iteration are used in generated code.
+ */
+ public static final String ENABLE_JAVA_5_FEATURES_CONTEXT_PROPERTY
+ = "enableJava5Features";
+
+ /**
+ * The context property which determines whether time stamps are put
+ * into generated files.
+ */
+ public static final String ADD_TIME_STAMP_CONTEXT_PROPERTY
+ = "addTimeStamp";
+
+ /**
+ * The context property which determines whether bean classes
+ * should be generated.
+ */
+ public static final String GENERATE_BEANS_CONTEXT_PROPERTY
+ = "generateBeans";
+
+ /**
+ * The prefix for the base classes.
+ * @parameter expression="Base"
+ */
+ private String basePrefix;
+
+ /**
+ * The suffix for the class name of the bean classes.
+ * @parameter expression="Bean"
+ */
+ private String beanSuffix;
+
+ /**
+ * The subpackage (relative to <code>targetPackage</code>
+ * where Torque will put the generated Java classes for the database map.
+ *
+ * @parameter expression="map"
+ */
+ private String subpackageMap;
+
+ /**
+ * The subpackage (relative to <code>targetPackage</code>)
+ * where Torque will put the generated Peer Java classes.
+ * If not set, the Peer classes will be generated in
+ * <code>targetPackage</code>.
+ *
+ * @parameter
+ */
+ private String subpackagePeer;
+
+ /**
+ * The subpackage (relative to <code>targetPackage</code>)
+ * where Torque will put the generated data object Java classes.
+ * If not set, the object classes will be generated in
+ * <code>targetPackage</code>.
+ *
+ * @parameter
+ */
+ private String subpackageObject;
+
+ /**
+ * The subpackage (relative to <code>targetPackage</code>)
+ * where Torque will put the generated Java Manager classes,
+ * if they are generated at all.
+ * If not set, the Manager classes will be generated in
+ * <code>targetPackage</code>.
+ *
+ * @parameter
+ */
+ private String subpackageManager;
+
+ /**
+ * The subpackage (relative to <code>targetPackage</code>)
+ * where Torque will put the generated JavaBean classes,
+ * if they are generated at all.
+ *
+ * @parameter expression="bean"
+ */
+ private String subpackageBean;
+
+ /**
+ * The subpackage (relative to <code>targetPackage</code>)
+ * where Torque will put the generated BaseObject, BasePeer,
+ * (and BaseManager, if they are generated at all) Java classes.
+ * If not set, the Base classes will be generated in
+ * <code>targetPackage</code>.
+ *
+ * @parameter
+ */
+ private String subpackageBase;
+
+ /**
+ * The subpackage (relative to <code>targetPackage</code>)
+ * where Torque will put the generated BaseBean Java classes,
+ * if they are generated at all.
+ *
+ * @parameter expression="bean"
+ */
+ private String subpackageBaseBean;
+
+ /**
+ * If true, Torque adds methods to get database fields by name/position.
+ *
+ * @parameter expression="true"
+ */
+ private boolean addGetByNameMethod;
+
+ /**
+ * If true, the data objects will implement a Retrievable interface.
+ *
+ * @parameter expression="false"
+ */
+ private boolean addRetrievableInterface;
+
+ /**
+ * The fully qualified class name of the retrievable interface
+ * to be implemented by the data objects.
+ *
+ * @parameter expression="org.apache.turbine.om.Retrievable"
+ */
+ private String retrievableInterface;
+
+ /**
+ * Determines whether save()-Methods should be added to the data objects.
+ *
+ * @parameter expression="true"
+ */
+ private boolean addSaveMethod;
+
+ /**
+ * Defines which Exception should be thrown by the Object.save() method.
+ *
+ * @parameter expression="Exception"
+ */
+ private String saveException;
+
+ /**
+ * Determines whether a time stamp is added to generated objects.
+ *
+ * @parameter expression="true"
+ */
+ private boolean addTimeStamp;
+
+ /**
+ * If true, Torque generates data objects with collection support
+ * and methods to easily retrieve foreign key relationships.
+ *
+ * @parameter expression="true"
+ */
+ private boolean complexObjectModel;
+
+ /**
+ * If true, Torque will generate Manager classes that use JCS for caching.
+ *
+ * @parameter expression="false"
+ */
+ private boolean useManagers;
+
+ /**
+ * If true, Torque generates data objects that cache their foreign key
+ * relationships.
+ *
+ * @parameter expression="true"
+ */
+ private boolean objectIsCaching;
+
+ /**
+ * If true and objectIsCaching is true, Torque silently fetches
+ * foreign key relation collections if the collection is not yet
+ * initialized.
+ *
+ * @parameter expression="true"
+ */
+ private boolean silentDbFetch;
+
+ /**
+ * If true, Torque generates isXXX getter methods for boolean columns.
+ *
+ * @parameter expression="false"
+ */
+ private boolean correctGetters;
+
+ /**
+ * If true, Torque generates a bean object for each data object,
+ * plus methods to convert data objects to beans and vice versa.
+ *
+ * @parameter expression="true"
+ */
+ private boolean generateBeans;
+
+ /**
+ * Whether Java5 generics and iteration shorthand should be used
+ *Â in generated code.
+ *
+ * @parameter expression="false"
+ */
+ private boolean enableJava5Features;
+ /**
+ * Creates a new TorqueOMMojo object.
+ */
+ public OMMojo()
+ {
+ }
+
+ /**
+ * Generates the OM classes for a Torque project and adds them to
+ * the comile sources of the project.
+ *
+ * @throws MojoExecutionException If an error occurs during generation.
+ *
+ * @see TexenTaskMojo#execute()
+ * @see Mojo#execute()
+ */
+ public void execute() throws MojoExecutionException
+ {
+ super.execute();
+
+ try
+ {
+ File outputDirectory = new File(super.getOutputDir());
+ getLog().info ("torque java sources generated into: "
+ + outputDirectory.getAbsolutePath());
+
+ if (getProject() != null)
+ {
+ getProject().addCompileSourceRoot(outputDirectory.getPath());
+ }
+ }
+ catch (BuildException e)
+ {
+ getLog().error(e.getMessage());
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Returns the context properties for the Texen task.
+ *
+ * @return The PropertiesConfiguration containing all context properties,
+ * not null.
+ *
+ * @todo add all om properties.
+ * @todo add a way to add custom properties.
+ */
+ protected PropertiesConfiguration getMojoContextProperties()
+ {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty(
+ DATABASE_CONTEXT_PROPERTY,
+ super.getDatabase());
+
+ configuration.addProperty(
+ TARGET_PACKAGE_CONTEXT_PROPERTY,
+ getTargetPackage());
+
+ configuration.addProperty(
+ BASE_PREFIX_CONTEXT_PROPERTY,
+ basePrefix);
+
+ configuration.addProperty(
+ SUBPACKAGE_MAP_CONTEXT_PROPERTY,
+ subpackageMap);
+
+ configuration.addProperty(
+ SUBPACKAGE_BASE_CONTEXT_PROPERTY,
+ subpackageBase);
+
+ configuration.addProperty(
+ SUBPACKAGE_BASE_BEAN_CONTEXT_PROPERTY,
+ subpackageBaseBean);
+
+ configuration.addProperty(
+ SUBPACKAGE_BEAN_CONTEXT_PROPERTY,
+ subpackageBean);
+
+ configuration.addProperty(
+ SUBPACKAGE_MANAGER_CONTEXT_PROPERTY,
+ subpackageManager);
+
+ configuration.addProperty(
+ SUBPACKAGE_OBJECT_CONTEXT_PROPERTY,
+ subpackageObject);
+
+ configuration.addProperty(
+ SUBPACKAGE_PEER_CONTEXT_PROPERTY,
+ subpackagePeer);
+
+ configuration.addProperty(
+ ADD_GET_BY_NAME_METHOD_CONTEXT_PROPERTY,
+ Boolean.toString(addGetByNameMethod));
+
+ configuration.addProperty(
+ ADD_INTAKE_RETRIEVABLE_CONTEXT_PROPERTY,
+ Boolean.toString(addRetrievableInterface));
+
+ configuration.addProperty(
+ RETRIEVABLE_INTERFACE_CONTEXT_PROPERTY,
+ retrievableInterface);
+
+ configuration.addProperty(
+ ADD_SAVE_METHOD_CONTEXT_PROPERTY,
+ Boolean.toString(addSaveMethod));
+
+ configuration.addProperty(
+ ADD_TIME_STAMP_CONTEXT_PROPERTY,
+ Boolean.toString(addTimeStamp));
+
+ configuration.addProperty(
+ BEAN_SUFFIX_CONTEXT_PROPERTY,
+ beanSuffix);
+
+ configuration.addProperty(
+ GENERATE_BEANS_CONTEXT_PROPERTY,
+ Boolean.toString(generateBeans));
+
+ configuration.addProperty(
+ COMPLEX_OBJECT_MODEL_CONTEXT_PROPERTY,
+ Boolean.toString(complexObjectModel));
+
+ configuration.addProperty(
+ CORRECT_GETTERS_CONTEXT_PROPERTY,
+ Boolean.toString(correctGetters));
+
+ configuration.addProperty(
+ ENABLE_JAVA_5_FEATURES_CONTEXT_PROPERTY,
+ Boolean.toString(correctGetters));
+
+ configuration.addProperty(
+ OBJECT_IS_CACHING_CONTEXT_PROPERTY,
+ Boolean.toString(objectIsCaching));
+
+ configuration.addProperty(
+ SAVE_EXCEPTION_CONTEXT_PROPERTY,
+ saveException);
+
+ configuration.addProperty(
+ SILENT_DB_FETCH_CONTEXT_PROPERTY,
+ Boolean.toString(silentDbFetch));
+
+ configuration.addProperty(
+ USE_MANAGERS_CONTEXT_PROPERTY,
+ Boolean.toString(useManagers));
+
+ return configuration;
+ }
+
+ /**
+ * returns the goal for this project.
+ *
+ * @return "om";
+ * @see DataModelTaskMojo#getGoal()
+ */
+ public String getGoal()
+ {
+ return "om";
+ }
+
+ /**
+ * Returns the prefix for the base classes.
+ *
+ * @return the prefix for the base classes.
+ */
+ public String getBasePrefix()
+ {
+ return basePrefix;
+ }
+
+ /**
+ * Sets the prefix for the names of the base classes.
+ *
+ * @param basePrefix the prefix for the base classes.
+ */
+ public void setBasePrefix(String basePrefix)
+ {
+ this.basePrefix = basePrefix;
+ }
+
+ /**
+ * Returns the suffix for the names of the bean classes.
+ *
+ * @return the suffix for the bean classes.
+ */
+ public String getBeanSuffix()
+ {
+ return beanSuffix;
+ }
+
+ /**
+ * Sets the suffix for the names of the bean classes.
+ *
+ * @param beanSuffix the suffix for the bean classes.
+ */
+ public void setBeanSuffix(String beanSuffix)
+ {
+ this.beanSuffix = beanSuffix;
+ }
+
+ /**
+ * Gets the subpackage for the database map classes.
+ *
+ * @return the subpackage for the database map classes.
+ */
+ public String getSubpackageMap()
+ {
+ return subpackageMap;
+ }
+
+ /**
+ * Sets the subpackage for the database map classes.
+ *
+ * @param subpackageMap the subpackage for the database map classes.
+ */
+ public void setSubpackageMap(String subpackageMap)
+ {
+ this.subpackageMap = subpackageMap;
+ }
+
+ /**
+ * Gets the subpackage for the base Object, Peer, and Manager classes.
+ *
+ * @return the subpackage for the base Object, Peer, and Manager classes,
+ * or null if not set.
+ */
+ public String getSubpackageBase()
+ {
+ return subpackageBase;
+ }
+
+ /**
+ * Sets the subpackage for the base Object, Peer, and Manager classes.
+ *
+ * @param subpackageBase the subpackage for the base Object, Peer,
+ * and Manager classes.
+ */
+ public void setSubpackageBase(String subpackageBase)
+ {
+ this.subpackageBase = subpackageBase;
+ }
+
+ /**
+ * Gets the subpackage for the base peer, object, and manager classes.
+ *
+ * @return the subpackage for the base peer, object, and manager classes,
+ * or null if not set.
+ */
+ public String getSubpackageBaseBean()
+ {
+ return subpackageBaseBean;
+ }
+
+ /**
+ * Sets the subpackage for the base bean classes.
+ *
+ * @param subpackageBaseBean the subpackage for the base bean classes.
+ */
+ public void setSubpackageBaseBean(String subpackageBaseBean)
+ {
+ this.subpackageBaseBean = subpackageBaseBean;
+ }
+
+ /**
+ * Gets the subpackage for the bean classes.
+ *
+ * @return the subpackage for the bean classes.
+ */
+ public String getSubpackageBean()
+ {
+ return subpackageBean;
+ }
+
+ /**
+ * Sets the subpackage for the bean classes.
+ *
+ * @param subpackageBean the subpackage for the bean classes.
+ */
+ public void setSubpackageBean(String subpackageBean)
+ {
+ this.subpackageBean = subpackageBean;
+ }
+
+ /**
+ * Gets the subpackage for the manager classes.
+ *
+ * @return the subpackage for the manager classes, or null if not set.
+ */
+ public String getSubpackageManager()
+ {
+ return subpackageManager;
+ }
+
+ /**
+ * Sets the subpackage for the manager classes.
+ *
+ * @param subpackageManager the subpackage for the manager classes.
+ */
+ public void setSubpackageManager(String subpackageManager)
+ {
+ this.subpackageManager = subpackageManager;
+ }
+
+ /**
+ * Gets the subpackage for the data object classes.
+ *
+ * @return the subpackage for the data object classes.
+ */
+ public String getSubpackageObject()
+ {
+ return subpackageObject;
+ }
+
+ /**
+ * Sets the subpackage for the data object classes.
+ *
+ * @param subpackageObject the subpackage for the data object classes.
+ */
+ public void setSubpackageObject(String subpackageObject)
+ {
+ this.subpackageObject = subpackageObject;
+ }
+
+ /**
+ * Gets the subpackage for the peer classes.
+ *
+ * @return the subpackage for the peer classes, or null if not set.
+ */
+ public String getSubpackagePeer()
+ {
+ return subpackagePeer;
+ }
+
+ /**
+ * Sets the subpackage for the peer classes.
+ *
+ * @param subpackagePeer the subpackage for the peer classes.
+ */
+ public void setSubpackagePeer(String subpackagePeer)
+ {
+ this.subpackagePeer = subpackagePeer;
+ }
+
+ /**
+ * Returns whether Torque adds methods to get database fields
+ * by name/position.
+ *
+ * @return true if Torque adds methods to get database fields
+ * by name/position, false otherwise.
+ */
+ public boolean isAddGetByNameMethod()
+ {
+ return addGetByNameMethod;
+ }
+
+ /**
+ * Sets whether Torque should add methods to get database fields
+ * by name/position.
+ *
+ * @param addGetByNameMethod whether Torque should add methods to get
+ * database fields by name/position.
+ */
+ public void setAddGetByNameMethod(boolean addGetByNameMethod)
+ {
+ this.addGetByNameMethod = addGetByNameMethod;
+ }
+
+ /**
+ * Returns whether the data objects will implement an Retrievable interface.
+ *
+ * @return true if the data objects will implement an Retrievable interface,
+ * false otherwise.
+ */
+ public boolean isAddRetrievableInterface()
+ {
+ return addRetrievableInterface;
+ }
+
+ /**
+ * Sets whether the data objects should implement an Retrievable interface.
+ *
+ * @param addRetrievableInterface whether the data objects should implement
+ * a Retrievable interface.
+ */
+ public void setAddRetrievableInterface(boolean addRetrievableInterface)
+ {
+ this.addRetrievableInterface = addRetrievableInterface;
+ }
+
+ /**
+ * Returns whether Torque will add save methods to the data objects.
+ *
+ * @return true if Torque will add save methods to the data objects,
+ * false otherwise.
+ */
+ public boolean isAddSaveMethod()
+ {
+ return addSaveMethod;
+ }
+
+ /**
+ * Sets whether Torque should add save methods to the data objects.
+ *
+ * @param addSaveMethod whether Torque should add save methods to the
+ * data objects.
+ */
+ public void setAddSaveMethod(boolean addSaveMethod)
+ {
+ this.addSaveMethod = addSaveMethod;
+ }
+
+ /**
+ * Returns whether Torque puts time stamps in generated om files.
+ *
+ * @return true if Torque puts time stamps in generated om files,
+ * false otherwise.
+ */
+ public boolean isAddTimeStamp()
+ {
+ return addTimeStamp;
+ }
+
+ /**
+ * Sets whether Torque puts time stamps in generated om files.
+ *
+ * @param addTimeStamp whether Torque puts time stamps in generated
+ * om files.
+ */
+ public void setAddTimeStamp(boolean addTimeStamp)
+ {
+ this.addTimeStamp = addTimeStamp;
+ }
+
+ /**
+ * Returns whether Torque generates data objects with collection support
+ * and methods to easily retrieve foreign key relationships.
+ *
+ * @return true if Torque generates data objects with collection support
+ * and methods to easily retrieve foreign key relationships,
+ * false otherwise.
+ */
+ public boolean isComplexObjectModel()
+ {
+ return complexObjectModel;
+ }
+
+ /**
+ * Sets whether Torque generates data objects with collection support
+ * and methods to easily retrieve foreign key relationships.
+ *
+ * @param complexObjectModel whether Torque generates data objects
+ * with collection support and methods to easily retrieve
+ * foreign key relationships, false otherwise.
+ */
+ public void setComplexObjectModel(boolean complexObjectModel)
+ {
+ this.complexObjectModel = complexObjectModel;
+ }
+
+ /**
+ * Returns whether Torque generates isXXX getter methods for boolean
+ * columns.
+ *
+ * @return true if Torque generates isXXX getter methods for boolean
+ * columns, false if Torque generates getXXX getter methods
+ * for boolean columns.
+ */
+ public boolean isCorrectGetters()
+ {
+ return correctGetters;
+ }
+
+ /**
+ * Sets whether Torque generates isXXX getter methods for boolean
+ * columns.
+ *
+ * @param correctGetters true if Torque generates isXXX getter methods
+ * for boolean columns, false if Torque generates getXXX getter
+ * methods for boolean columns.
+ */
+ public void setCorrectGetters(boolean correctGetters)
+ {
+ this.correctGetters = correctGetters;
+ }
+
+ /**
+ * Returns whether Java5 generics and iteration shorthand will be used
+ * in generated code.
+ *
+ * @return true if Java5 generics and iteration shorthand will be used
+ * in generated code, false to generate 1.4-compliant code.
+ */
+ public boolean isEnableJava5Features()
+ {
+ return enableJava5Features;
+ }
+
+ /**
+ * Sets whether Java5 generics and iteration shorthand should be used
+ * in generated code.
+ *
+ * @param enableJava5Features true if Java5 generics and iteration
+ * shorthand will be used in generated code, false to generate
+ * 1.4-compliant code.
+ */
+ public void setEnableJava5Features(boolean enableJava5Features)
+ {
+ this.enableJava5Features = enableJava5Features;
+ }
+
+ /**
+ * Returns whether bean classes will be generated.
+ *
+ * @return true if bean classes will be generated, false otherwise.
+ */
+ public boolean isGenerateBeans()
+ {
+ return generateBeans;
+ }
+
+ /**
+ * Sets whether bean classes should be generated.
+ *
+ * @param generateBeans whether bean classes should be generated.
+ */
+ public void setGenerateBeans(boolean generateBeans)
+ {
+ this.generateBeans = generateBeans;
+ }
+
+ /**
+ * Returns whether data objects cache their foreign key relationships.
+ *
+ * @return true if data objects cache their foreign key relationships,
+ * false otherwise.
+ */
+ public boolean isObjectIsCaching()
+ {
+ return objectIsCaching;
+ }
+
+ /**
+ * Sets whether data objects cache their foreign key relationships.
+ *
+ * @param objectIsCaching true if data objects cache their
+ * foreign key relationships, false otherwise.
+ */
+ public void setObjectIsCaching(boolean objectIsCaching)
+ {
+ this.objectIsCaching = objectIsCaching;
+ }
+
+ /**
+ * Returns the fully qualified class name of the Retrievable interface
+ * which should be implemented by the generated data objects.
+ *
+ * @return the fully qualified class name of the Retrievable interface.
+ */
+ public String getRetrievableInterface()
+ {
+ return retrievableInterface;
+ }
+
+ /**
+ * Sets the fully qualified class name of the Retrievable interface
+ * which should be implemented by the generated data objects.
+ *
+ * @param retrievableInterface the fully qualified class name of the
+ * Retrievable interface.
+ */
+ public void setRetrievableInterface(String retrievableInterface)
+ {
+ this.retrievableInterface = retrievableInterface;
+ }
+
+ /**
+ * Returns the class name of the Exception which should be thrown
+ * by the save methods of the generated data objects.
+ *
+ * @return the class name of the Exception which should be thrown
+ * by the generated save methods.
+ */
+ public String getSaveException()
+ {
+ return saveException;
+ }
+
+ /**
+ * Sets the class name of the Exception which should be thrown
+ * by the save methods of the generated data objects.
+ *
+ * @param saveException the class name of the Exception
+ * which should be thrown by the generated save methods.
+ */
+ public void setSaveException(String saveException)
+ {
+ this.saveException = saveException;
+ }
+
+ /**
+ * Returns whether Torque silently fetches foreign key relation collections
+ * if the collection is not yet initialized.
+ *
+ * @return true if Torque silently fetches foreign key relation collections
+ * if the collection is not yet initialized, false otherwise.
+ */
+ public boolean isSilentDbFetch()
+ {
+ return silentDbFetch;
+ }
+
+ /**
+ * Sets whether Torque should silently fetches foreign key relation
+ * collections if the collection is not yet initialized.
+ *
+ * @param silentDbFetch whether Torque should silently fetch
+ * foreign key relation collections if the collection
+ * is not yet initialized.
+ */
+ public void setSilentDbFetch(boolean silentDbFetch)
+ {
+ this.silentDbFetch = silentDbFetch;
+ }
+
+ /**
+ * Returns whether Torque will generate Manager classes that use JCS
+ * for caching.
+ *
+ * @return true if Torque will generate Manager classes that use JCS
+ * for caching, false otherwise.
+ */
+ public boolean isUseManagers()
+ {
+ return useManagers;
+ }
+
+ /**
+ * Sets whether Torque should generate Manager classes that use JCS
+ * for caching.
+ *
+ * @param useManagers whether Torque should generate Manager classes
+ * that use JCS for caching.
+ */
+ public void setUseManagers(boolean useManagers)
+ {
+ this.useManagers = useManagers;
+ }
+}
Added: db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/TexenTaskMojo.java
URL: http://svn.apache.org/viewcvs/db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/TexenTaskMojo.java?rev=395493&view=auto
==============================================================================
--- db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/TexenTaskMojo.java (added)
+++ db/torque/trunks/maven2-plugin/src/main/java/org/apache/torque/mojo/TexenTaskMojo.java Wed Apr 19 22:37:44 2006
@@ -0,0 +1,369 @@
+package org.apache.torque.mojo;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.FileConfiguration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.tools.ant.Project;
+import org.apache.velocity.texen.ant.TexenTask;
+
+
+/**
+ * The base Class for all Mojos wrapping Texen Tasks.
+ *
+ * @author Rapha�l Pi�roni (rafale_at_codehaus.org)
+ * @author <a href="fischer@seitenbau.de">Thomas Fischer</a>
+ */
+public abstract class TexenTaskMojo
+ extends AbstractMojo
+{
+ /**
+ * The directory where Torque output is written to.
+ *
+ * @parameter expression="${project.build.directory}/generated-sources/torque"
+ * @required
+ */
+ private String outputDir;
+
+ /**
+ * The base path where the templates are read from, if they are not read
+ * from the classpath.
+ *
+ * @parameter expression="${basedir}/src/main/torque/templates"
+ */
+ private String templatePath;
+
+
+ /**
+ * Whether the templates should be loaded from the classpath.
+ *
+ * @parameter expression="true"
+ */
+ private boolean useClasspath;
+
+ /**
+ * A map where all user-defined context properties can be set.
+ * Overrides all other mojo configuration settings which are mapped
+ * to context properties.
+ */
+ private Map userContextProperties;
+
+ /**
+ * The path to the generated context property file.
+ *
+ * @parameter expression="${project.build.directory}/torque/context.properties"
+ * @required
+ */
+ private String contextPropertiesPath;
+
+ /**
+ * The Maven project this plugin runs in.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * The generator task to be executed by this mojo.
+ */
+ private TexenTask generatorTask;
+
+ /**
+ * The ant project for the generator task.
+ */
+ private Project antProject;
+
+ /**
+ * Creates a new instance of AbstractTorqueMojo.
+ *
+ * @throws IllegalArgumentException if generatorTask is null.
+ */
+ public TexenTaskMojo(TexenTask generatorTask)
+ {
+ if (generatorTask == null)
+ {
+ throw new IllegalArgumentException("generatorTask is null");
+ }
+
+ // because the Texen Task needs the ant project to load its
+ // files, we need to attach one to the Texen task
+ antProject = new Project();
+ antProject.init();
+ generatorTask.setProject(antProject);
+
+ this.generatorTask = generatorTask;
+ }
+
+ /**
+ * Sets the maven project.
+ *
+ * @param project the maven project where this plugin runs in.
+ */
+ public void setProject(MavenProject project)
+ {
+ this.project = project;
+ }
+
+ /**
+ * Returns the maven project.
+ *
+ * @return The maven project where this plugin runs in.
+ */
+ public MavenProject getProject()
+ {
+ return project;
+ }
+
+ /**
+ * Returns the ant project.
+ *
+ * @return The ant project assigned to the generator task.
+ */
+ protected Project getAntProject()
+ {
+ return antProject;
+ }
+
+ /**
+ * Sets the path to Torque's output directory.
+ *
+ * @param outputDir the path to Torque's output directory.
+ */
+ public void setOutputDir(String outputDir)
+ {
+ this.outputDir = outputDir;
+ }
+
+ /**
+ * Returns the path to Torque's output directory.
+ *
+ * @return the path to Torque's output directory. Not null if
+ * initialized correctly.
+ */
+ public String getOutputDir()
+ {
+ return this.outputDir;
+ }
+
+ /**
+ * Sets the path to Torque's templates, if the classpath is not used
+ * to load the templates.
+ *
+ * @param templatePath the path to Torque's templates.
+ */
+ public void setTemplatePath(String templatePath)
+ {
+ this.templatePath = templatePath;
+ }
+
+ /**
+ * Returns the path to Torque's templates, if the classpath is not used
+ * to load the templates.
+ *
+ * @return the path to Torque's templates.
+ */
+ public String getTemplatePath()
+ {
+ return this.templatePath;
+ }
+
+ /**
+ * Sets whether the classpath should be used to locate the templates.
+ *
+ * @param templatePath the path to Torque's templates.
+ */
+ public void setUseClasspath(boolean useClasspath)
+ {
+ this.useClasspath = useClasspath;
+ }
+
+ /**
+ * Returns whether the classpath is used to locate the templates.
+ *
+ * @return true if the classpath is used to locate the templates,
+ * false otherwise
+ */
+ public boolean getUseClasspath()
+ {
+ return this.useClasspath;
+ }
+
+ /**
+ * Sets the path to the generated property file used as Texen's context
+ * properties.
+ *
+ * @param generatedPropertyFilePath the path to the generated context
+ * properties file.
+ */
+ public void setContextPropertiesPath(String contextPropertiesPath)
+ {
+ this.contextPropertiesPath = contextPropertiesPath;
+ }
+
+ /**
+ * Returns the path to the generated property file used as Texen's context
+ * properties.
+ *
+ * @return the path to the generated context properties file.
+ */
+ public String getContextPropertiesPath()
+ {
+ return this.contextPropertiesPath;
+ }
+
+ /**
+ * Sets the map which defines user-defined context properties.
+ * The settings override all other mojo configuration settings
+ * which are mapped to context properties.
+ *
+ * @param contextProperties the user-defined context properties.
+ */
+ public void setUserContextProperties(Map userContextProperties)
+ {
+ this.userContextProperties = userContextProperties;
+ }
+
+ /**
+ * Returns the map which defines user-defined context properties.
+ *
+ * @return the map containing user-defined context properties,
+ * or null if not set.
+ */
+ public Map getUserContextProperties()
+ {
+ return userContextProperties;
+ }
+
+ /**
+ * returns the generator Task for this mojo.
+ *
+ * @return the generator Task, not null.
+ */
+ protected TexenTask getGeneratorTask()
+ {
+ return generatorTask;
+ }
+
+ /**
+ * Generates the context properties file for Texen.
+ * The file is written to the path contextPropertiesPath.
+ *
+ * @throws MojoExecutionException if an error occurs.
+ */
+ protected void generateContextProperties()
+ throws MojoExecutionException
+ {
+ try
+ {
+ FileConfiguration configuration = getMojoContextProperties();
+ if (userContextProperties != null)
+ {
+ for (Iterator contextPropertyIt
+ = userContextProperties.entrySet().iterator();
+ contextPropertyIt.hasNext() ; )
+ {
+ Map.Entry entry = (Map.Entry) contextPropertyIt.next();
+ configuration.addProperty(
+ entry.getKey().toString(),
+ entry.getValue().toString());
+ }
+ }
+ configuration.save(contextPropertiesPath);
+ }
+ catch (ConfigurationException e)
+ {
+ getLog().error("Error writing temporary context properties: "
+ + e.getMessage());
+ throw new MojoExecutionException(e.getMessage());
+ }
+ }
+
+ /**
+ * Configures the Texen task which is wrapped by this mojo.
+ * In this implementation, the context properties, useClasspath
+ * and the output directory are set. If more parameters need to be set,
+ * this method shouldb be overwritten in subclasses.
+ *
+ * @throws MojoExecutionException if an error occurs when setting the Tasks
+ * properties.
+ */
+ protected void configureTask()
+ throws MojoExecutionException
+ {
+ generatorTask.setContextProperties(contextPropertiesPath);
+
+ generatorTask.setUseClasspath(useClasspath);
+
+ if (templatePath != null)
+ {
+ try
+ {
+ generatorTask.setTemplatePath(templatePath);
+ }
+ catch (Exception e)
+ {
+ getLog().error("Error setting template path: "
+ + e.getMessage());
+ throw new MojoExecutionException(e.getMessage());
+ }
+ }
+
+ {
+ File outputDirectory = new File(outputDir);
+ getLog().debug("generating torque java sources into: "
+ + outputDirectory.getAbsolutePath());
+ outputDirectory.mkdirs();
+ generatorTask.setOutputDirectory(outputDirectory);
+ }
+ }
+
+ /**
+ * Executes the wrapped Texen task. Before this is done, the context
+ * properties file is generated and the Texen task is configured.
+ *
+ * @throws MojoExecutionException if an error occurs during execution.
+ *
+ * @see Mojo#execute()
+ */
+ public void execute() throws MojoExecutionException
+ {
+ generateContextProperties();
+ configureTask();
+ generatorTask.execute();
+ }
+
+ /**
+ * Returns the context properties for the Texen task which are defined
+ * in the configuration of the child mojo.
+ * This method needs to be overwritten in subclasses.
+ *
+ * @return The PropertiesConfiguration containing all context properties,
+ * not null.
+ */
+ protected abstract PropertiesConfiguration getMojoContextProperties();
+}
Added: db/torque/trunks/maven2-plugin/src/test/java/org/apache/torque/mojo/TorqueOMMojoTest.java
URL: http://svn.apache.org/viewcvs/db/torque/trunks/maven2-plugin/src/test/java/org/apache/torque/mojo/TorqueOMMojoTest.java?rev=395493&view=auto
==============================================================================
--- db/torque/trunks/maven2-plugin/src/test/java/org/apache/torque/mojo/TorqueOMMojoTest.java (added)
+++ db/torque/trunks/maven2-plugin/src/test/java/org/apache/torque/mojo/TorqueOMMojoTest.java Wed Apr 19 22:37:44 2006
@@ -0,0 +1,189 @@
+package org.apache.torque.mojo;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.torque.mojo.OMMojo;
+import org.codehaus.plexus.PlexusTestCase;
+
+
+/**
+ * Tests the TorqueOMMojo
+ *
+ * @author Rapha�l Pi�roni (rafale_at_codehaus.org)
+ */
+public class TorqueOMMojoTest
+ extends PlexusTestCase
+{
+ /**
+ * Test of execute method of class org.apache.torque.mojo.TorqueOMMojo;.
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testExecute()
+ throws Exception
+ {
+ System.out.println ("execute");
+
+ MavenProjectBuilder builder
+ = (MavenProjectBuilder) lookup(MavenProjectBuilder.ROLE);
+
+ ArtifactRepositoryLayout localRepositoryLayout
+ = (ArtifactRepositoryLayout) lookup(
+ ArtifactRepositoryLayout.ROLE,
+ "default");
+
+ ArtifactRepository localRepository
+ = new DefaultArtifactRepository(
+ "local",
+ "file://" + getBasedir() + File.separator
+ + "target/test-classes/repository",
+ localRepositoryLayout);
+
+ MavenProject mavenProject = builder.buildWithDependencies(
+ new File(
+ getBasedir(),
+ "target/test-classes/projects/TorqueOMMojoTest/pom.xml"),
+ localRepository,
+ null);
+
+ OMMojo instance = new OMMojo();
+
+ instance.setProject(mavenProject);
+
+ instance.setOutputDir(
+ mavenProject.getBuild().getDirectory()
+ + "/generated-sources/torque");
+
+ instance.setContextPropertiesPath(
+ mavenProject.getBuild().getDirectory()
+ + "/torque/context.properties");
+
+ instance.setSchemaDir(
+ mavenProject.getBasedir() + "/src/main/torque/schema");
+
+ instance.setUseClasspath(true);
+
+ instance.setBasePrefix("Base");
+
+ instance.setSubpackageMap("map");
+
+ instance.setTargetPackage("org.apache.torque.mojo.test");
+
+ instance.setSchemaIncludes("*schema.xml");
+
+ instance.setSchemaExcludes("id-table-schema.xml");
+
+ instance.setReportFile("torque."
+ + mavenProject.getArtifact().getArtifactId()
+ + "."
+ + instance.getGoal()
+ + ".generation");
+
+ instance.execute();
+
+ String generatedSourcesPackageDir
+ = "generated-sources/torque/org/apache/torque/mojo/test/";
+
+ assertTrue(
+ "BaseTestTable1.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir + "BaseTestTable1.java")
+ .exists());
+
+ assertTrue(
+ "BaseTestTable2.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir + "BaseTestTable2.java")
+ .exists());
+
+ assertTrue(
+ "BaseTestTable1Peer.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir + "BaseTestTable1Peer.java")
+ .exists());
+
+ assertTrue(
+ "BaseTestTable2Peer.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir + "BaseTestTable2Peer.java")
+ .exists());
+
+ assertTrue(
+ "TestTable1.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir + "TestTable1.java")
+ .exists());
+
+ assertTrue(
+ "TestTable2.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir + "TestTable2.java")
+ .exists());
+
+ assertTrue(
+ "TestTable1Peer.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir + "TestTable1Peer.java")
+ .exists());
+
+ assertTrue(
+ "TestTable2Peer.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir + "TestTable2Peer.java")
+ .exists());
+
+ assertTrue(
+ "TestTable1MapBuilder.java must exist",
+ new File(
+ mavenProject.getBuild().getDirectory(),
+ generatedSourcesPackageDir
+ + "map/TestTable1MapBuilder.java")
+ .exists());
+
+ assertTrue(
+ "TestTable2MapBuilder.java must exist",
+ new File(
+ mavenProject.getBuild ().getDirectory(),
+ generatedSourcesPackageDir
+ + "map/TestTable2MapBuilder.java")
+ .exists());
+
+ assertTrue(
+ "Project does not contain "
+ + mavenProject.getBuild().getDirectory()
+ + "/generated-sources/torque"
+ + " as compile source",
+ mavenProject.getCompileSourceRoots().contains(
+ mavenProject.getBuild ().getDirectory()
+ + "/generated-sources/torque"));
+ }
+}
\ No newline at end of file
Added: db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/pom.xml
URL: http://svn.apache.org/viewcvs/db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/pom.xml?rev=395493&view=auto
==============================================================================
--- db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/pom.xml (added)
+++ db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/pom.xml Wed Apr 19 22:37:44 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- -->
+<!-- Copyright 2001-2005 The Apache Software Foundation. -->
+<!-- -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
+<!-- you may not use this file except in compliance with the License. -->
+<!-- You may obtain a copy of the License at -->
+<!-- -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
+<!-- -->
+<!-- Unless required by applicable law or agreed to in writing, software -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
+<!-- See the License for the specific language governing permissions and -->
+<!-- limitations under the License. -->
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>torque</groupId>
+ <artifactId>test-TorqueOMMojoTest</artifactId>
+ <version>1.0</version>
+ <name>Test project 1</name>
+</project>
Added: db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/id-table-schema.xml
URL: http://svn.apache.org/viewcvs/db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/id-table-schema.xml?rev=395493&view=auto
==============================================================================
--- db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/id-table-schema.xml (added)
+++ db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/id-table-schema.xml Wed Apr 19 22:37:44 2006
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
+<!--
+ Copyright 2001-2005 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_2.dtd">
+
+<!-- ==================================================================== -->
+<!-- -->
+<!-- I D B R O K E R S C H E M A -->
+<!-- -->
+<!-- ==================================================================== -->
+<!-- This is the XML schema use by Torque to generate the SQL for -->
+<!-- ID_TABLE table used by the id broker mechanism in Torque. -->
+<!-- ==================================================================== -->
+<!-- @author: <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a> -->
+<!-- @version $Id: id-table-schema.xml 279108 2005-09-06 21:04:30Z tfischer $ -->
+<!-- ==================================================================== -->
+
+<database name="@DATABASE_DEFAULT@">
+ <table name="ID_TABLE" idMethod="idbroker">
+ <column name="ID_TABLE_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="TABLE_NAME" required="true" size="250" type="VARCHAR"/>
+ <column name="NEXT_ID" type="INTEGER"/>
+ <column name="QUANTITY" type="INTEGER"/>
+
+ <unique>
+ <unique-column name="TABLE_NAME"/>
+ </unique>
+
+ </table>
+</database>
Added: db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/test-TorqueOMMojoTest-schema.xml
URL: http://svn.apache.org/viewcvs/db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/test-TorqueOMMojoTest-schema.xml?rev=395493&view=auto
==============================================================================
--- db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/test-TorqueOMMojoTest-schema.xml (added)
+++ db/torque/trunks/maven2-plugin/src/test/resources/projects/TorqueOMMojoTest/src/main/torque/schema/test-TorqueOMMojoTest-schema.xml Wed Apr 19 22:37:44 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
+<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_2.dtd">
+
+<!--
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<database name="testdatabase">
+
+ <table name="TEST_TABLE_1" idMethod="idbroker">
+ <column name="ATTRIBUTE_1" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="ATTRIBUTE_2" required="true" size="32" type="VARCHAR"/>
+ <column name="ATTRIBUTE_3" type="BOOLEANINT"/>
+
+ <unique>
+ <unique-column name="ATTRIBUTE_2"/>
+ </unique>
+ </table>
+
+ <table name="TEST_TABLE_2">
+ <column name="ATTRIBUTE_1" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="ATTRIBUTE_2" required="true" primaryKey="true" type="INTEGER"/>
+
+ <foreign-key foreignTable="TEST_TABLE_1">
+ <reference local="ATTRIBUTE_1" foreign="ATTRIBUTE_1"/>
+ </foreign-key>
+ </table>
+
+</database>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org