author | ohair |
Tue, 25 May 2010 15:54:51 -0700 | |
changeset 5520 | 86e4b9a9da40 |
parent 4700 | d0ef13314ec4 |
child 7681 | 1f0819a3341f |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
import java.io.File; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.List; |
|
29 |
||
30 |
import org.apache.tools.ant.BuildException; |
|
31 |
import org.apache.tools.ant.DirectoryScanner; |
|
32 |
import org.apache.tools.ant.Project; |
|
33 |
import org.apache.tools.ant.taskdefs.MatchingTask; |
|
34 |
||
35 |
public class CompilePropertiesTask extends MatchingTask { |
|
36 |
public void setSrcDir(File srcDir) { |
|
37 |
this.srcDir = srcDir; |
|
38 |
} |
|
39 |
||
40 |
public void setDestDir(File destDir) { |
|
41 |
this.destDir = destDir; |
|
42 |
} |
|
43 |
||
44 |
public void setSuperclass(String superclass) { |
|
45 |
this.superclass = superclass; |
|
46 |
} |
|
47 |
||
4700
d0ef13314ec4
6764569: [PATCH] Fix unused imports in list resource bundles
jjg
parents:
10
diff
changeset
|
48 |
@Override |
10 | 49 |
public void execute() { |
50 |
CompileProperties.Log log = new CompileProperties.Log() { |
|
51 |
public void error(String msg, Exception e) { |
|
52 |
log(msg, Project.MSG_ERR); |
|
53 |
} |
|
54 |
public void info(String msg) { |
|
55 |
log(msg, Project.MSG_INFO); |
|
56 |
} |
|
57 |
public void verbose(String msg) { |
|
58 |
log(msg, Project.MSG_VERBOSE); |
|
59 |
} |
|
60 |
}; |
|
61 |
List<String> mainOpts = new ArrayList<String>(); |
|
62 |
int count = 0; |
|
63 |
DirectoryScanner s = getDirectoryScanner(srcDir); |
|
64 |
for (String path: s.getIncludedFiles()) { |
|
65 |
if (path.endsWith(".properties")) { |
|
66 |
String destPath = |
|
67 |
path.substring(0, path.length() - ".properties".length()) + |
|
68 |
".java"; |
|
69 |
File srcFile = new File(srcDir, path); |
|
70 |
File destFile = new File(destDir, destPath); |
|
71 |
// Arguably, the comparison in the next line should be ">", not ">=" |
|
72 |
// but that assumes the resolution of the last modified time is fine |
|
73 |
// grained enough; in practice, it is better to use ">=". |
|
74 |
if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified()) |
|
75 |
continue; |
|
76 |
destFile.getParentFile().mkdirs(); |
|
77 |
mainOpts.add("-compile"); |
|
78 |
mainOpts.add(srcFile.getPath()); |
|
79 |
mainOpts.add(destFile.getPath()); |
|
80 |
mainOpts.add(superclass); |
|
81 |
count++; |
|
82 |
} |
|
83 |
} |
|
84 |
if (mainOpts.size() > 0) { |
|
85 |
log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO); |
|
86 |
CompileProperties cp = new CompileProperties(); |
|
87 |
cp.setLog(log); |
|
4700
d0ef13314ec4
6764569: [PATCH] Fix unused imports in list resource bundles
jjg
parents:
10
diff
changeset
|
88 |
boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()])); |
10 | 89 |
if (!ok) |
90 |
throw new BuildException("CompileProperties failed."); |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
private File srcDir; |
|
95 |
private File destDir; |
|
96 |
private String superclass = "java.util.ListResourceBundle"; |
|
97 |
} |