Skip to content

Commit 4d910b6

Browse files
committed
HBX-3202: Improve the implementation of class ConfigurationTask
Signed-off-by: Koen Aers <[email protected]>
1 parent 47fd71c commit 4d910b6

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

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

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.io.FileNotFoundException;
1010
import java.io.IOException;
1111
import java.util.ArrayList;
12-
import java.util.Iterator;
1312
import java.util.LinkedList;
1413
import java.util.List;
1514
import java.util.Properties;
@@ -27,107 +26,108 @@
2726
*/
2827
public class ConfigurationTask extends Task {
2928

30-
private List<FileSet> fileSets = new ArrayList<FileSet>();
31-
private MetadataDescriptor metadataDescriptor;
32-
private File configurationFile;
33-
private File propertyFile;
29+
List<FileSet> fileSets = new ArrayList<FileSet>();
30+
MetadataDescriptor metadataDescriptor;
31+
File configurationFile;
32+
File propertyFile;
3433
protected String entityResolver;
35-
34+
3635
public ConfigurationTask() {
37-
setDescription("Standard Configuration");
36+
setDescription( "Standard Configuration" );
3837
}
39-
38+
4039
public void addConfiguredFileSet(FileSet fileSet) {
41-
fileSets.add(fileSet);
40+
fileSets.add( fileSet );
4241
}
4342

44-
/**
45-
* @return
46-
*/
4743
public final MetadataDescriptor getMetadataDescriptor() {
48-
if (metadataDescriptor == null) {
44+
if ( metadataDescriptor == null ) {
4945
metadataDescriptor = createMetadataDescriptor();
5046
}
5147
return metadataDescriptor;
5248
}
53-
49+
5450
protected MetadataDescriptor createMetadataDescriptor() {
5551
return MetadataDescriptorFactory
5652
.createNativeDescriptor(
57-
configurationFile,
58-
getFiles(),
59-
loadPropertiesFile());
53+
configurationFile,
54+
getFiles(),
55+
loadPropertiesFile() );
6056
}
61-
57+
6258
protected Properties loadPropertiesFile() {
63-
if (propertyFile!=null) {
59+
if ( propertyFile != null ) {
6460
Properties properties = new Properties(); // TODO: should we "inherit" from the ant projects properties ?
65-
FileInputStream is = null;
66-
try {
67-
is = new FileInputStream(propertyFile);
68-
properties.load(is);
61+
try (FileInputStream is = new FileInputStream( propertyFile )) {
62+
properties.load( is );
6963
return properties;
70-
}
64+
}
7165
catch (FileNotFoundException e) {
72-
throw new BuildException(propertyFile + " not found.",e);
73-
}
74-
catch (IOException e) {
75-
throw new BuildException("Problem while loading " + propertyFile,e);
66+
throw new BuildException( propertyFile + " not found.", e );
7667
}
77-
finally {
78-
if (is != null) {
79-
try {
80-
is.close();
81-
} catch (IOException e) {
82-
}
83-
}
68+
catch (IOException e) {
69+
throw new BuildException( "Problem while loading " + propertyFile, e );
8470
}
85-
} else {
71+
}
72+
else {
8673
return null;
8774
}
8875
}
89-
90-
76+
77+
9178
protected File[] getFiles() {
9279

9380
List<File> files = new LinkedList<File>();
94-
for ( Iterator<FileSet> i = fileSets.iterator(); i.hasNext(); ) {
81+
for ( FileSet fs : fileSets ) {
9582

96-
FileSet fs = i.next();
9783
DirectoryScanner ds = fs.getDirectoryScanner( getProject() );
9884

9985
String[] dsFiles = ds.getIncludedFiles();
100-
for (int j = 0; j < dsFiles.length; j++) {
101-
File f = new File(dsFiles[j]);
86+
for ( String dsFile : dsFiles ) {
87+
File f = new File( dsFile );
10288
if ( !f.isFile() ) {
103-
f = new File( ds.getBasedir(), dsFiles[j] );
89+
f = new File( ds.getBasedir(), dsFile );
10490
}
10591

10692
files.add( f );
10793
}
10894
}
10995

110-
return (File[]) files.toArray(new File[files.size()]);
96+
return files.toArray( new File[0] );
11197
}
11298

113-
99+
114100
public File getConfigurationFile() {
115101
return configurationFile;
116102
}
103+
117104
public void setConfigurationFile(File configurationFile) {
118105
this.configurationFile = configurationFile;
119106
}
107+
120108
public File getPropertyFile() {
121109
return propertyFile;
122110
}
111+
123112
public void setPropertyFile(File propertyFile) {
124113
this.propertyFile = propertyFile;
125114
}
126-
115+
127116
public void setEntityResolver(String entityResolverName) {
128117
this.entityResolver = entityResolverName;
129118
}
130-
119+
131120
public void setNamingStrategy(String namingStrategy) {
132121
}
122+
123+
@Override
124+
public Object clone() throws CloneNotSupportedException {
125+
ConfigurationTask ct = (ConfigurationTask) super.clone();
126+
ct.fileSets.addAll( this.fileSets );
127+
ct.metadataDescriptor = this.metadataDescriptor;
128+
ct.propertyFile = this.propertyFile;
129+
ct.entityResolver = this.entityResolver;
130+
return ct;
131+
}
132+
133133
}

0 commit comments

Comments
 (0)