From 464b8c9548cdc42e77f112a18df443ad304ab9b0 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Thu, 18 Jan 2018 16:32:26 +0100 Subject: [PATCH] [#6140] Add to in code generator configuration --- .../java/org/jooq/util/AbstractGenerator.java | 14 +++++++++ .../java/org/jooq/util/GenerationTool.java | 3 ++ .../main/java/org/jooq/util/Generator.java | 9 ++++++ .../resources/org/jooq/web/manual-3.10.xml | 27 ++++++++++++++++ .../resources/org/jooq/web/manual-3.11.xml | 29 +++++++++++++++++ .../resources/org/jooq/web/manual-3.8.xml | 27 ++++++++++++++++ .../resources/org/jooq/web/manual-3.9.xml | 27 ++++++++++++++++ .../main/java/org/jooq/util/jaxb/Target.java | 31 +++++++++++++++++++ .../resources/xsd/jooq-codegen-3.11.0.xsd | 4 +++ 9 files changed, 171 insertions(+) diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java index e359c1405a..000b9e96ad 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java @@ -121,6 +121,7 @@ abstract class AbstractGenerator implements Generator { protected GeneratorStrategyWrapper strategy; protected String targetEncoding = "UTF-8"; + protected boolean targetClean = true; final Language language; AbstractGenerator(Language language) { @@ -877,6 +878,16 @@ abstract class AbstractGenerator implements Generator { this.targetEncoding = encoding; } + @Override + public boolean getTargetClean() { + return targetClean; + } + + @Override + public void setTargetClean(boolean clean) { + this.targetClean = clean; + } + /** * If file is a directory, recursively empty its children. * If file is a file, delete it. @@ -890,6 +901,9 @@ abstract class AbstractGenerator implements Generator { * If file is a file, delete it, except if it is in the list of files to keep. */ protected void empty(File file, String suffix, Set keep, Set ignore) { + if (!targetClean) + return; + if (file != null) { // Just a Murphy's Law safeguard in case a user misconfigures their config... diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java b/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java index 4f6f877d10..264ada72d0 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java @@ -571,6 +571,9 @@ public class GenerationTool { generator.setTargetDirectory(g.getTarget().getDirectory()); generator.setTargetEncoding(g.getTarget().getEncoding()); + if (g.getTarget().isClean() != null) + generator.setTargetClean(g.getTarget().isClean()); + // [#1394] The element should be optional if (g.getGenerate() == null) g.setGenerate(new Generate()); diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/Generator.java b/jOOQ-codegen/src/main/java/org/jooq/util/Generator.java index 6f2ae7f0cc..791784cef8 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/Generator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/Generator.java @@ -748,4 +748,13 @@ public interface Generator { */ void setTargetPackage(String packageName); + /** + * Whether the target package should be cleaned to contain only generated code after a generation run. + */ + boolean getTargetClean(); + + /** + * Whether the target package should be cleaned to contain only generated code after a generation run. + */ + void setTargetClean(boolean clean); } diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.10.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.10.xml index 7385de7046..ef9c280e0e 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.10.xml +++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.10.xml @@ -16207,6 +16207,33 @@ public class CaseInsensitiveOrderProvider implements Comparator { + +
+ Output target configuration + +

+ In the previous sections, we've seen the <target/> element which configures the location of your generated output. The following XML snippet illustrates some additional flags that can be specified in that section: +

+ + + ... + + ... + + [org.jooq.your.packagename] + [/path/to/your/dir] + UTF-8 + + +]]> +
    +
  • packageName: Specifies the root package name inside of which all generated code is located. This package is located inside of the <directory/>. The package name is part of the and can be modified by a custom implementation, if so desired.
  • +
  • directory: Specifies the root directoy inside of which all generated code is located.
  • +
  • encoding: The encoding that should be used for generated classes.
  • +
+
+
diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml index b5ddd253d0..de4a097e29 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml +++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml @@ -16207,6 +16207,35 @@ public class CaseInsensitiveOrderProvider implements Comparator { + +
+ Output target configuration + +

+ In the previous sections, we've seen the <target/> element which configures the location of your generated output. The following XML snippet illustrates some additional flags that can be specified in that section: +

+ + + ... + + ... + + [org.jooq.your.packagename] + [/path/to/your/dir] + UTF-8 + true + + +]]> +
    +
  • packageName: Specifies the root package name inside of which all generated code is located. This package is located inside of the <directory/>. The package name is part of the and can be modified by a custom implementation, if so desired.
  • +
  • directory: Specifies the root directoy inside of which all generated code is located.
  • +
  • encoding: The encoding that should be used for generated classes.
  • +
  • clean: Whether the target package (<packageName/>) should be cleaned to contain only generated code after a generation run. Defaults to true.
  • +
+
+
diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.8.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.8.xml index 0527de512a..7c27ef9013 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.8.xml +++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.8.xml @@ -14331,6 +14331,33 @@ result.forEach((Object[] entities) -> { +
+ Output target configuration + +

+ In the previous sections, we've seen the <target/> element which configures the location of your generated output. The following XML snippet illustrates some additional flags that can be specified in that section: +

+ + + ... + + ... + + [org.jooq.your.packagename] + [/path/to/your/dir] + UTF-8 + + +]]> +
    +
  • packageName: Specifies the root package name inside of which all generated code is located. This package is located inside of the <directory/>. The package name is part of the and can be modified by a custom implementation, if so desired.
  • +
  • directory: Specifies the root directoy inside of which all generated code is located.
  • +
  • encoding: The encoding that should be used for generated classes.
  • +
+
+
+
Programmatic generator configuration diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.9.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.9.xml index 333f5ec130..35201ca7df 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.9.xml +++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.9.xml @@ -15908,6 +15908,33 @@ configuration {
+ +
+ Output target configuration + +

+ In the previous sections, we've seen the <target/> element which configures the location of your generated output. The following XML snippet illustrates some additional flags that can be specified in that section: +

+ + + ... + + ... + + [org.jooq.your.packagename] + [/path/to/your/dir] + UTF-8 + + +]]> +
    +
  • packageName: Specifies the root package name inside of which all generated code is located. This package is located inside of the <directory/>. The package name is part of the and can be modified by a custom implementation, if so desired.
  • +
  • directory: Specifies the root directoy inside of which all generated code is located.
  • +
  • encoding: The encoding that should be used for generated classes.
  • +
+
+
diff --git a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Target.java b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Target.java index d6d9b69272..b1ac16f0c1 100644 --- a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Target.java +++ b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Target.java @@ -43,6 +43,8 @@ public class Target implements Serializable @XmlElement(defaultValue = "UTF-8") @XmlJavaTypeAdapter(StringAdapter.class) protected String encoding = "UTF-8"; + @XmlElement(defaultValue = "true") + protected Boolean clean = true; /** * The destination package of your generated classes (within the destination directory) @@ -119,6 +121,30 @@ public class Target implements Serializable this.encoding = value; } + /** + * Whether the target package should be cleaned to contain only generated code after a generation run. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isClean() { + return clean; + } + + /** + * Sets the value of the clean property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setClean(Boolean value) { + this.clean = value; + } + public Target withPackageName(String value) { setPackageName(value); return this; @@ -134,4 +160,9 @@ public class Target implements Serializable return this; } + public Target withClean(Boolean value) { + setClean(value); + return this; + } + } diff --git a/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd b/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd index 93a9ac1d6b..5f2fd44cf6 100644 --- a/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd +++ b/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd @@ -1126,6 +1126,10 @@ e.g. org.jooq.generated.schema1, org.jooq.generated.schema2]]> + + + +