Author: tfischer
Date: Tue Mar 2 10:31:49 2010
New Revision: 917947
URL: http://svn.apache.org/viewvc?rev=917947&view=rev
Log:
- replaced booleans compileNewFileTargetDir and compileModifiedFileTargetDir by switches newFileTargetDirUsage
and modifiedFileTargetDirUsage
Modified:
db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/gf/maven/TorqueGfMojo.java
db/torque/torque4/trunk/maven-torque-generator-plugin/src/test/java/org/apache/torque/gf/maven/GettingStartedTest.java
Modified: db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/gf/maven/TorqueGfMojo.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/gf/maven/TorqueGfMojo.java?rev=917947&r1=917946&r2=917947&view=diff
==============================================================================
--- db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/gf/maven/TorqueGfMojo.java
(original)
+++ db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/gf/maven/TorqueGfMojo.java
Tue Mar 2 10:31:49 2010
@@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Set;
+import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -51,6 +52,81 @@
*/
public class TorqueGfMojo extends AbstractMojo implements Mojo
{
+ private enum TargetDirUsage
+ {
+ /**
+ * The target dir will be added to the maven project's
+ * compileSourceRoot.
+ */
+ COMPILE("compile"),
+ /**
+ * The target dir will be added to the maven project's
+ * testCompileSourceRoot.
+ */
+ TEST_COMPILE("test-compile"),
+ /**
+ * The target dir will be added to the maven project's resources.
+ */
+ RESOURCE("resource"),
+ /**
+ * The target dir will be added to the maven project's test resources.
+ */
+ TEST_RESOURCE("test-resource"),
+ /**
+ * The target dir will not be used in the maven build.
+ */
+ NONE("none");
+
+ private String key;
+
+ /**
+ * Constructor.
+ *
+ * @param key the key for the enum.
+ */
+ private TargetDirUsage(String key)
+ {
+ this.key = key;
+ }
+
+ @Override
+ public String toString()
+ {
+ return key;
+ }
+
+ /**
+ * Returns the key of the Usage.
+ *
+ * @return the key, not null.
+ */
+ public String getKey()
+ {
+ return key;
+ }
+
+ public static TargetDirUsage get(String key)
+ throws MojoExecutionException
+ {
+ for (TargetDirUsage candidate : values())
+ {
+ if (candidate.getKey().equals(key))
+ {
+ return candidate;
+ }
+ }
+ StringBuilder errorMessage = new StringBuilder()
+ .append("newFileTargetDirUsage contains illegal value: ")
+ .append(key)
+ .append(". Possible values are :");
+ for (TargetDirUsage targetDirUsage: values())
+ {
+ errorMessage.append(" ").append(targetDirUsage.getKey());
+ }
+ throw new MojoExecutionException(errorMessage.toString());
+ }
+ }
+
/**
* The packaging type of the generation unit, either "directory" , "jar"
* or "classpath".
@@ -137,24 +213,76 @@
private String jarFile;
/**
- * Whether the generated files in newFileTargetDir should be treated
- * as compileable sources.
+ * What to do with the generated files in newFileTargetDir.
+ * Possible values are:
+ * <ul>
+ * <li>
+ * compile: The generated files are treated as compileable sources.
+ * In maven-speak, this means the newFileTargetDir will be added as
+ * compileSourceRoot of the maven project.
+ * </li>
+ * <li>
+ * test-compile: The generated files are treated as compileable
+ * test sources.
+ * In maven-speak, this means the newFileTargetDir will be added as
+ * testCompileSourceRoot of the maven project.
+ * </li>
+ * <li>
+ * resource: The generated files are treated as resource.
+ * This means the newFileTargetDir will be added to the
+ * resources of the maven project.
+ * </li>
+ * <li>
+ * test-resource: The generated files are treated as test resource.
+ * This means the newFileTargetDir will be added to the
+ * test resources of the maven project.
+ * </li>
+ * <li>
+ * none: The generated files are not used in the maven build.
+ * </li>
*
- * @parameter expression="true"
+ * @parameter expression="compile"
+ * @required
*/
- private boolean compileNewFileTargetDir;
+ private String newFileTargetDirUsage;
/**
- * Whether the generated files in modifiedFileTargetDir should be treated
- * as compileable sources.
+ * What to do with the generated files in modifiedFileTargetDir.
+ * Possible values are:
+ * <ul>
+ * <li>
+ * compile: The generated files are treated as compileable sources.
+ * In maven-speak, this means the modifiedFileTargetDir will be added
+ * as compileSourceRoot of the maven project.
+ * </li>
+ * <li>
+ * test-compile: The generated files are treated as compileable
+ * test sources.
+ * In maven-speak, this means the modifiedFileTargetDir will be added
+ * as testCompileSourceRoot of the maven project.
+ * </li>
+ * <li>
+ * resource: The generated files are treated as resource.
+ * This means the modifiedFileTargetDir will be added to the
+ * resources of the maven project.
+ * </li>
+ * <li>
+ * test-resource: The generated files are treated as test resource.
+ * This means the modifiedFileTargetDir will be added to the
+ * test resources of the maven project.
+ * </li>
+ * <li>
+ * none: The generated files are not used in the maven build.
+ * </li>
*
- * @parameter expression="true"
+ * @parameter expression="compile"
+ * @required
*/
- private boolean compileModifiedFileTargetDir;
+ private String modifiedFileTargetDirUsage;
/**
* The config directory of the project overriding the settings.
- * Then, the settings of this directory are used as "child"
+ * If set, the settings of this directory are used as "child"
* and the "normal" settings are used as "parent".
*
* @parameter
@@ -191,6 +319,12 @@
Controller controller = new Controller();
List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
+ // Do conversion here so illegal values are discovered before generation
+ TargetDirUsage newFileTargetDirUsageConverted
+ = TargetDirUsage.get(newFileTargetDirUsage);
+ TargetDirUsage modifiedFileTargetDirUsageConverted
+ = TargetDirUsage.get(modifiedFileTargetDirUsage);
+
UnitDescriptor.Packaging packaging;
if ("jar".equals(this.packaging))
{
@@ -332,26 +466,79 @@
throw new MojoExecutionException(e.getMessage());
}
- if (compileNewFileTargetDir
- && projectPaths.getNewFileTargetPath().exists())
+ File newFileTargetPath = projectPaths.getNewFileTargetPath();
+ if (newFileTargetPath.exists())
{
- getLog().debug("Adding newFileTargetDir "
- + projectPaths.getNewFileTargetPath()
- + " as CompileSourceRoot");
-
- project.addCompileSourceRoot(
- projectPaths.getNewFileTargetPath().toString());
+ switch (newFileTargetDirUsageConverted)
+ {
+ case COMPILE:
+ project.addCompileSourceRoot(newFileTargetPath.toString());
+ getLog().debug("Added "
+ + newFileTargetPath.toString()
+ + " as compile source root");
+ break;
+ case TEST_COMPILE:
+ project.addTestCompileSourceRoot(newFileTargetPath.toString());
+ getLog().debug("Added "
+ + newFileTargetPath.toString()
+ + " as test compile source root");
+ break;
+ case RESOURCE:
+ Resource resource = new Resource();
+ resource.setDirectory(newFileTargetPath.toString());
+ project.addResource(resource);
+ getLog().debug("Added "
+ + newFileTargetPath.toString()
+ + " to the project resources");
+ break;
+ case TEST_RESOURCE:
+ resource = new Resource();
+ resource.setDirectory(newFileTargetPath.toString());
+ project.addTestResource(resource);
+ getLog().debug("Added "
+ + newFileTargetPath.toString()
+ + " to the project test resources");
+ break;
+ case NONE:
+ }
}
- if (compileModifiedFileTargetDir
- && projectPaths.getModifiedFileTargetPath().exists())
+ File modifiedFileTargetPath = projectPaths.getModifiedFileTargetPath();
+ if (modifiedFileTargetPath.exists())
{
- getLog().debug("Adding modifiedFileTargetDir "
- + projectPaths.getModifiedFileTargetPath()
- + " as CompileSourceRoot");
-
- project.addCompileSourceRoot(
- projectPaths.getModifiedFileTargetPath().toString());
+ switch (modifiedFileTargetDirUsageConverted)
+ {
+ case COMPILE:
+ project.addCompileSourceRoot(modifiedFileTargetPath.toString());
+ getLog().debug("Added "
+ + modifiedFileTargetPath.toString()
+ + " as compile source root");
+ break;
+ case TEST_COMPILE:
+ project.addTestCompileSourceRoot(
+ modifiedFileTargetPath.toString());
+ getLog().debug("Added "
+ + modifiedFileTargetPath.toString()
+ + " as test compile source root");
+ break;
+ case RESOURCE:
+ Resource resource = new Resource();
+ resource.setDirectory(modifiedFileTargetPath.toString());
+ project.addResource(resource);
+ getLog().debug("Added "
+ + modifiedFileTargetPath.toString()
+ + " to the project resources");
+ break;
+ case TEST_RESOURCE:
+ resource = new Resource();
+ resource.setDirectory(modifiedFileTargetPath.toString());
+ project.addTestResource(resource);
+ getLog().debug("Added "
+ + modifiedFileTargetPath.toString()
+ + " to the project test resources");
+ break;
+ case NONE:
+ }
}
}
@@ -425,4 +612,34 @@
{
this.project = project;
}
+
+ /**
+ * Sets the usage for the newFileTargetDir.
+ *
+ * @param newFileTargetDirUsage the new usage, not null.
+ */
+ public void setNewFileTargetDirUsage(String newFileTargetDirUsage)
+ {
+ if (newFileTargetDirUsage == null)
+ {
+ throw new NullPointerException(
+ "newFileTargetDirUsage must not be null");
+ }
+ this.newFileTargetDirUsage = newFileTargetDirUsage;
+ }
+
+ /**
+ * Sets the usage for the modifiedFileTargetDir.
+ *
+ * @param modifiedFileTargetDirUsage the new usage, not null.
+ */
+ public void setModifiedFileTargetDirUsage(String modifiedFileTargetDirUsage)
+ {
+ if (modifiedFileTargetDirUsage == null)
+ {
+ throw new NullPointerException(
+ "modifiedFileTargetDirUsage must not be null");
+ }
+ this.modifiedFileTargetDirUsage = modifiedFileTargetDirUsage;
+ }
}
Modified: db/torque/torque4/trunk/maven-torque-generator-plugin/src/test/java/org/apache/torque/gf/maven/GettingStartedTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/maven-torque-generator-plugin/src/test/java/org/apache/torque/gf/maven/GettingStartedTest.java?rev=917947&r1=917946&r2=917947&view=diff
==============================================================================
--- db/torque/torque4/trunk/maven-torque-generator-plugin/src/test/java/org/apache/torque/gf/maven/GettingStartedTest.java
(original)
+++ db/torque/torque4/trunk/maven-torque-generator-plugin/src/test/java/org/apache/torque/gf/maven/GettingStartedTest.java
Tue Mar 2 10:31:49 2010
@@ -36,6 +36,8 @@
mojo.setPackaging("directory");
mojo.setProjectRootDir(new File("src/test/gettingStarted"));
mojo.setNewFileTargetDir(target);
+ mojo.setNewFileTargetDirUsage("compile");
+ mojo.setModifiedFileTargetDirUsage("compile");
mojo.setProject(new MavenProject());
mojo.execute();
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org
|