[#6140] Add <clean/> to <target/> in code generator configuration
This commit is contained in:
parent
308311a544
commit
464b8c9548
@ -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<File> keep, Set<File> ignore) {
|
||||
if (!targetClean)
|
||||
return;
|
||||
|
||||
if (file != null) {
|
||||
|
||||
// Just a Murphy's Law safeguard in case a user misconfigures their config...
|
||||
|
||||
@ -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 <generate/> element should be optional
|
||||
if (g.getGenerate() == null)
|
||||
g.setGenerate(new Generate());
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -16207,6 +16207,33 @@ public class CaseInsensitiveOrderProvider implements Comparator<Definition> {
|
||||
|
||||
</html></content>
|
||||
</section>
|
||||
|
||||
<section id="codegen-config-target">
|
||||
<title>Output target configuration</title>
|
||||
<content><html>
|
||||
<p>
|
||||
In the previous sections, we've seen the <code><target/></code> element which configures the location of your generated output. The following XML snippet illustrates some additional flags that can be specified in that section:
|
||||
</p>
|
||||
|
||||
</html><![CDATA[
|
||||
<configuration>
|
||||
...
|
||||
<generator>
|
||||
...
|
||||
<target>
|
||||
<packageName>[org.jooq.your.packagename]</packageName>
|
||||
<directory>[/path/to/your/dir]</directory>
|
||||
<encoding>UTF-8</encoding>
|
||||
</target>
|
||||
</generator>
|
||||
</configuration>]]><html>
|
||||
<ul>
|
||||
<li><strong>packageName</strong>: Specifies the root package name inside of which all generated code is located. This package is located inside of the <code><directory/></code>. The package name is part of the <reference id="codegen-generatorstrategy" title="generator strategy"/> and can be modified by a custom implementation, if so desired.</li>
|
||||
<li><strong>directory</strong>: Specifies the root directoy inside of which all generated code is located.</li>
|
||||
<li><strong>encoding</strong>: The encoding that should be used for generated classes.</li>
|
||||
</ul>
|
||||
</html></content>
|
||||
</section>
|
||||
</sections>
|
||||
</section>
|
||||
|
||||
|
||||
@ -16207,6 +16207,35 @@ public class CaseInsensitiveOrderProvider implements Comparator<Definition> {
|
||||
|
||||
</html></content>
|
||||
</section>
|
||||
|
||||
<section id="codegen-config-target">
|
||||
<title>Output target configuration</title>
|
||||
<content><html>
|
||||
<p>
|
||||
In the previous sections, we've seen the <code><target/></code> element which configures the location of your generated output. The following XML snippet illustrates some additional flags that can be specified in that section:
|
||||
</p>
|
||||
|
||||
</html><![CDATA[
|
||||
<configuration>
|
||||
...
|
||||
<generator>
|
||||
...
|
||||
<target>
|
||||
<packageName>[org.jooq.your.packagename]</packageName>
|
||||
<directory>[/path/to/your/dir]</directory>
|
||||
<encoding>UTF-8</encoding>
|
||||
<clean>true</clean>
|
||||
</target>
|
||||
</generator>
|
||||
</configuration>]]><html>
|
||||
<ul>
|
||||
<li><strong>packageName</strong>: Specifies the root package name inside of which all generated code is located. This package is located inside of the <code><directory/></code>. The package name is part of the <reference id="codegen-generatorstrategy" title="generator strategy"/> and can be modified by a custom implementation, if so desired.</li>
|
||||
<li><strong>directory</strong>: Specifies the root directoy inside of which all generated code is located.</li>
|
||||
<li><strong>encoding</strong>: The encoding that should be used for generated classes.</li>
|
||||
<li><strong>clean</strong>: Whether the target package (<code><packageName/></code>) should be cleaned to contain only generated code after a generation run. Defaults to true.</li>
|
||||
</ul>
|
||||
</html></content>
|
||||
</section>
|
||||
</sections>
|
||||
</section>
|
||||
|
||||
|
||||
@ -14331,6 +14331,33 @@ result.forEach((Object[] entities) -> {
|
||||
</html></content>
|
||||
</section>
|
||||
|
||||
<section id="codegen-config-target">
|
||||
<title>Output target configuration</title>
|
||||
<content><html>
|
||||
<p>
|
||||
In the previous sections, we've seen the <code><target/></code> element which configures the location of your generated output. The following XML snippet illustrates some additional flags that can be specified in that section:
|
||||
</p>
|
||||
|
||||
</html><![CDATA[
|
||||
<configuration>
|
||||
...
|
||||
<generator>
|
||||
...
|
||||
<target>
|
||||
<packageName>[org.jooq.your.packagename]</packageName>
|
||||
<directory>[/path/to/your/dir]</directory>
|
||||
<encoding>UTF-8</encoding>
|
||||
</target>
|
||||
</generator>
|
||||
</configuration>]]><html>
|
||||
<ul>
|
||||
<li><strong>packageName</strong>: Specifies the root package name inside of which all generated code is located. This package is located inside of the <code><directory/></code>. The package name is part of the <reference id="codegen-generatorstrategy" title="generator strategy"/> and can be modified by a custom implementation, if so desired.</li>
|
||||
<li><strong>directory</strong>: Specifies the root directoy inside of which all generated code is located.</li>
|
||||
<li><strong>encoding</strong>: The encoding that should be used for generated classes.</li>
|
||||
</ul>
|
||||
</html></content>
|
||||
</section>
|
||||
|
||||
<section id="codegen-programmatic">
|
||||
<title>Programmatic generator configuration</title>
|
||||
<content><html>
|
||||
|
||||
@ -15908,6 +15908,33 @@ configuration {
|
||||
|
||||
</html></content>
|
||||
</section>
|
||||
|
||||
<section id="codegen-config-target">
|
||||
<title>Output target configuration</title>
|
||||
<content><html>
|
||||
<p>
|
||||
In the previous sections, we've seen the <code><target/></code> element which configures the location of your generated output. The following XML snippet illustrates some additional flags that can be specified in that section:
|
||||
</p>
|
||||
|
||||
</html><![CDATA[
|
||||
<configuration>
|
||||
...
|
||||
<generator>
|
||||
...
|
||||
<target>
|
||||
<packageName>[org.jooq.your.packagename]</packageName>
|
||||
<directory>[/path/to/your/dir]</directory>
|
||||
<encoding>UTF-8</encoding>
|
||||
</target>
|
||||
</generator>
|
||||
</configuration>]]><html>
|
||||
<ul>
|
||||
<li><strong>packageName</strong>: Specifies the root package name inside of which all generated code is located. This package is located inside of the <code><directory/></code>. The package name is part of the <reference id="codegen-generatorstrategy" title="generator strategy"/> and can be modified by a custom implementation, if so desired.</li>
|
||||
<li><strong>directory</strong>: Specifies the root directoy inside of which all generated code is located.</li>
|
||||
<li><strong>encoding</strong>: The encoding that should be used for generated classes.</li>
|
||||
</ul>
|
||||
</html></content>
|
||||
</section>
|
||||
</sections>
|
||||
</section>
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1126,6 +1126,10 @@ e.g. org.jooq.generated.schema1, org.jooq.generated.schema2]]></jxb:javadoc></jx
|
||||
<element name="encoding" type="string" default="UTF-8" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The file encoding to be used with all output files.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="clean" type="boolean" default="true" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether the target package should be cleaned to contain only generated code after a generation run.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user