Skip to content

Commit b17491f

Browse files
committed
HBX-3204: Improve the implementation of classes JDBCConfigurationTask, JPAConfigurationTask, JavaFormatterTask and ExporterTask
Signed-off-by: Koen Aers <[email protected]>
1 parent 66788cc commit b17491f

File tree

7 files changed

+50
-30
lines changed

7 files changed

+50
-30
lines changed

ant/src/main/java/org/hibernate/tool/ant/ConfigurationTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void setEntityResolver(String entityResolverName) {
133133
}
134134

135135
public void setNamingStrategy(String namingStrategy) {
136+
log("setting unused naming strategy: " + namingStrategy);
136137
}
137138

138139
@Override

ant/src/main/java/org/hibernate/tool/ant/ExporterTask.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ public void setTemplatePath(Path path) {
7474
templatePath = path;
7575
}
7676

77-
public void setTemplatePrefix(String s) {
78-
}
79-
8077
public void validateParameters() {
8178
if(getDestdir()==null) {
8279
throw new BuildException("destdir must be set, either locally or on <hibernatetool>");

ant/src/main/java/org/hibernate/tool/ant/JDBCConfigurationTask.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,35 @@
2020
package org.hibernate.tool.ant;
2121

2222
import java.io.File;
23-
import java.lang.reflect.Constructor;
2423
import java.util.Map;
2524
import java.util.Properties;
2625

27-
import org.apache.tools.ant.BuildException;
28-
import org.apache.tools.ant.Project;
2926
import org.apache.tools.ant.types.Path;
3027
import org.hibernate.boot.cfgxml.internal.ConfigLoader;
31-
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
3228
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
3329
import org.hibernate.tool.api.metadata.MetadataDescriptor;
3430
import org.hibernate.tool.api.metadata.MetadataDescriptorFactory;
3531
import org.hibernate.tool.api.metadata.MetadataConstants;
3632
import org.hibernate.tool.api.reveng.RevengSettings;
3733
import org.hibernate.tool.api.reveng.RevengStrategy;
3834
import org.hibernate.tool.api.reveng.RevengStrategyFactory;
39-
import org.hibernate.tool.util.ReflectionUtil;
4035

4136

4237
/**
4338
* @author max
4439
* @author <a href='mailto:[email protected]'>Alexandru Popescu</a>
4540
*/
4641
public class JDBCConfigurationTask extends ConfigurationTask {
47-
//not expfosed here.
48-
private boolean preferBasicCompositeIds = true;
42+
43+
boolean preferBasicCompositeIds = true;
4944

50-
private String reverseEngineeringStrategyClass;
51-
private String packageName;
52-
private Path revengFiles;
45+
String reverseEngineeringStrategyClass;
46+
String packageName;
47+
Path revengFiles;
5348

54-
private boolean detectOneToOne = true;
55-
private boolean detectManyToMany = true;
56-
private boolean detectOptimisticLock = true;
49+
boolean detectOneToOne = true;
50+
boolean detectManyToMany = true;
51+
boolean detectOptimisticLock = true;
5752

5853
public JDBCConfigurationTask() {
5954
setDescription("JDBC Configuration (for reverse engineering)");
@@ -138,4 +133,16 @@ private Properties loadProperties() {
138133
}
139134
return result;
140135
}
136+
137+
public Object clone() throws CloneNotSupportedException {
138+
JDBCConfigurationTask jct = (JDBCConfigurationTask) super.clone();
139+
jct.preferBasicCompositeIds = this.preferBasicCompositeIds;
140+
jct.reverseEngineeringStrategyClass = this.reverseEngineeringStrategyClass;
141+
jct.packageName = this.packageName;
142+
jct.revengFiles = this.revengFiles;
143+
jct.detectOneToOne = this.detectOneToOne;
144+
jct.detectManyToMany = this.detectManyToMany;
145+
jct.detectOptimisticLock = this.detectOptimisticLock;
146+
return jct;
147+
}
141148
}

ant/src/main/java/org/hibernate/tool/ant/JPAConfigurationTask.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
public class JPAConfigurationTask extends ConfigurationTask {
3131

32-
private String persistenceUnit = null;
32+
String persistenceUnit = null;
3333

3434
public JPAConfigurationTask() {
3535
setDescription("JPA Configuration");
@@ -49,7 +49,8 @@ protected MetadataDescriptor createMetadataDescriptor() {
4949
Throwable cause = t.getCause();
5050
if (cause != null) {
5151
throw new BuildException(cause);
52-
} else {
52+
}
53+
else {
5354
throw new BuildException("Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?",t);
5455
}
5556
}
@@ -65,11 +66,17 @@ public void setPersistenceUnit(String persistenceUnit) {
6566
}
6667

6768
public void setConfigurationFile(File configurationFile) {
68-
complain("configurationfile");
69+
complain();
70+
}
71+
72+
private void complain() {
73+
throw new BuildException("<" + getTaskName() + "> currently only support autodiscovery from META-INF/persistence.xml. Thus setting the configurationfile attribute is not allowed");
6974
}
7075

71-
private void complain(String param) {
72-
throw new BuildException("<" + getTaskName() + "> currently only support autodiscovery from META-INF/persistence.xml. Thus setting the " + param + " attribute is not allowed");
76+
public Object clone() throws CloneNotSupportedException {
77+
JPAConfigurationTask jct = (JPAConfigurationTask) super.clone();
78+
jct.persistenceUnit = this.persistenceUnit;
79+
return jct;
7380
}
7481

7582

ant/src/main/java/org/hibernate/tool/ant/JavaFormatterTask.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
public class JavaFormatterTask extends Task {
3939

40-
private final List<FileSet> fileSets = new ArrayList<FileSet>();
41-
private boolean failOnError;
40+
final List<FileSet> fileSets = new ArrayList<FileSet>();
41+
boolean failOnError;
4242

4343
public void addConfiguredFileSet(FileSet fileSet) {
4444
fileSets.add(fileSet);
@@ -68,14 +68,17 @@ public void execute() throws BuildException {
6868
if (!ok) {
6969
failed++;
7070
getProject().log(this, "Formatting failed - skipping " + file, Project.MSG_WARN);
71-
} else {
71+
}
72+
else {
7273
getProject().log(this, "Formatted " + file, Project.MSG_VERBOSE);
7374
}
74-
} catch (RuntimeException ee) {
75+
}
76+
catch (RuntimeException ee) {
7577
failed++;
7678
if (failOnError) {
7779
throw new BuildException("Java formatting failed on " + file, ee);
78-
} else {
80+
}
81+
else {
7982
getProject().log(this, "Java formatting failed on " + file + ", " + ee.getLocalizedMessage(), Project.MSG_ERR);
8083
}
8184
}
@@ -104,7 +107,14 @@ private File[] getFiles() {
104107
}
105108
}
106109

107-
return (File[]) files.toArray(new File[0]);
110+
return files.toArray(new File[0]);
108111
}
109112

113+
public Object clone() throws CloneNotSupportedException {
114+
JavaFormatterTask jft = (JavaFormatterTask) super.clone();
115+
jft.fileSets.addAll(this.fileSets);
116+
jft.failOnError = this.failOnError;
117+
return jft;
118+
}
119+
110120
}

orm/src/main/java/org/hibernate/tool/internal/export/common/AbstractExporter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ protected void cleanUpContext() {
9999
iterator = getProperties().entrySet().iterator();
100100
while ( iterator.hasNext() ) {
101101
Entry<Object, Object> element = iterator.next();
102-
Object value = transformValue(element.getValue());
103102
String key = element.getKey().toString();
104103
if(key.startsWith(ExporterSettings.PREFIX_KEY)) {
105104
getTemplateHelper().removeFromContext(key.substring(ExporterSettings.PREFIX_KEY.length()));

test/common/src/main/resources/org/hibernate/tool/ant/GenericExport/build.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
</configuration>
1818

1919
<hbmtemplate
20-
templateprefix="pojo/"
21-
template="pojo/Pojo.ftl"
20+
template="pojo/Pojo.ftl"
2221
filepattern="X{package-name}/{class-name}.java"
2322
foreach="entity">
2423
<property key="jdk5" value="false" />

0 commit comments

Comments
 (0)