|
9 | 9 | import java.io.FileNotFoundException; |
10 | 10 | import java.io.IOException; |
11 | 11 | import java.util.ArrayList; |
12 | | -import java.util.Iterator; |
13 | 12 | import java.util.LinkedList; |
14 | 13 | import java.util.List; |
15 | 14 | import java.util.Properties; |
|
27 | 26 | */ |
28 | 27 | public class ConfigurationTask extends Task { |
29 | 28 |
|
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; |
34 | 33 | protected String entityResolver; |
35 | | - |
| 34 | + |
36 | 35 | public ConfigurationTask() { |
37 | | - setDescription("Standard Configuration"); |
| 36 | + setDescription( "Standard Configuration" ); |
38 | 37 | } |
39 | | - |
| 38 | + |
40 | 39 | public void addConfiguredFileSet(FileSet fileSet) { |
41 | | - fileSets.add(fileSet); |
| 40 | + fileSets.add( fileSet ); |
42 | 41 | } |
43 | 42 |
|
44 | | - /** |
45 | | - * @return |
46 | | - */ |
47 | 43 | public final MetadataDescriptor getMetadataDescriptor() { |
48 | | - if (metadataDescriptor == null) { |
| 44 | + if ( metadataDescriptor == null ) { |
49 | 45 | metadataDescriptor = createMetadataDescriptor(); |
50 | 46 | } |
51 | 47 | return metadataDescriptor; |
52 | 48 | } |
53 | | - |
| 49 | + |
54 | 50 | protected MetadataDescriptor createMetadataDescriptor() { |
55 | 51 | return MetadataDescriptorFactory |
56 | 52 | .createNativeDescriptor( |
57 | | - configurationFile, |
58 | | - getFiles(), |
59 | | - loadPropertiesFile()); |
| 53 | + configurationFile, |
| 54 | + getFiles(), |
| 55 | + loadPropertiesFile() ); |
60 | 56 | } |
61 | | - |
| 57 | + |
62 | 58 | protected Properties loadPropertiesFile() { |
63 | | - if (propertyFile!=null) { |
| 59 | + if ( propertyFile != null ) { |
64 | 60 | 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 ); |
69 | 63 | return properties; |
70 | | - } |
| 64 | + } |
71 | 65 | 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 ); |
76 | 67 | } |
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 ); |
84 | 70 | } |
85 | | - } else { |
| 71 | + } |
| 72 | + else { |
86 | 73 | return null; |
87 | 74 | } |
88 | 75 | } |
89 | | - |
90 | | - |
| 76 | + |
| 77 | + |
91 | 78 | protected File[] getFiles() { |
92 | 79 |
|
93 | 80 | List<File> files = new LinkedList<File>(); |
94 | | - for ( Iterator<FileSet> i = fileSets.iterator(); i.hasNext(); ) { |
| 81 | + for ( FileSet fs : fileSets ) { |
95 | 82 |
|
96 | | - FileSet fs = i.next(); |
97 | 83 | DirectoryScanner ds = fs.getDirectoryScanner( getProject() ); |
98 | 84 |
|
99 | 85 | 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 ); |
102 | 88 | if ( !f.isFile() ) { |
103 | | - f = new File( ds.getBasedir(), dsFiles[j] ); |
| 89 | + f = new File( ds.getBasedir(), dsFile ); |
104 | 90 | } |
105 | 91 |
|
106 | 92 | files.add( f ); |
107 | 93 | } |
108 | 94 | } |
109 | 95 |
|
110 | | - return (File[]) files.toArray(new File[files.size()]); |
| 96 | + return files.toArray( new File[0] ); |
111 | 97 | } |
112 | 98 |
|
113 | | - |
| 99 | + |
114 | 100 | public File getConfigurationFile() { |
115 | 101 | return configurationFile; |
116 | 102 | } |
| 103 | + |
117 | 104 | public void setConfigurationFile(File configurationFile) { |
118 | 105 | this.configurationFile = configurationFile; |
119 | 106 | } |
| 107 | + |
120 | 108 | public File getPropertyFile() { |
121 | 109 | return propertyFile; |
122 | 110 | } |
| 111 | + |
123 | 112 | public void setPropertyFile(File propertyFile) { |
124 | 113 | this.propertyFile = propertyFile; |
125 | 114 | } |
126 | | - |
| 115 | + |
127 | 116 | public void setEntityResolver(String entityResolverName) { |
128 | 117 | this.entityResolver = entityResolverName; |
129 | 118 | } |
130 | | - |
| 119 | + |
131 | 120 | public void setNamingStrategy(String namingStrategy) { |
132 | 121 | } |
| 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 | + |
133 | 133 | } |
0 commit comments