author | ohrstrom |
Wed, 07 Mar 2012 13:11:27 +0100 | |
changeset 12085 | ce2780cb121f |
parent 7681 | langtools/make/tools/CompileProperties/CompilePropertiesTask.java@1f0819a3341f |
child 13631 | dc1212c348f9 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
7681 | 2 |
* Copyright (c) 2007, 2010, 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 |
||
12085
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
7681
diff
changeset
|
26 |
package anttasks; |
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
7681
diff
changeset
|
27 |
|
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
7681
diff
changeset
|
28 |
import compileproperties.CompileProperties; |
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
7681
diff
changeset
|
29 |
|
10 | 30 |
import java.io.File; |
31 |
import java.util.ArrayList; |
|
32 |
import java.util.List; |
|
33 |
||
34 |
import org.apache.tools.ant.BuildException; |
|
35 |
import org.apache.tools.ant.DirectoryScanner; |
|
36 |
import org.apache.tools.ant.Project; |
|
37 |
import org.apache.tools.ant.taskdefs.MatchingTask; |
|
38 |
||
39 |
public class CompilePropertiesTask extends MatchingTask { |
|
40 |
public void setSrcDir(File srcDir) { |
|
41 |
this.srcDir = srcDir; |
|
42 |
} |
|
43 |
||
44 |
public void setDestDir(File destDir) { |
|
45 |
this.destDir = destDir; |
|
46 |
} |
|
47 |
||
48 |
public void setSuperclass(String superclass) { |
|
49 |
this.superclass = superclass; |
|
50 |
} |
|
51 |
||
4700
d0ef13314ec4
6764569: [PATCH] Fix unused imports in list resource bundles
jjg
parents:
10
diff
changeset
|
52 |
@Override |
10 | 53 |
public void execute() { |
54 |
CompileProperties.Log log = new CompileProperties.Log() { |
|
55 |
public void error(String msg, Exception e) { |
|
56 |
log(msg, Project.MSG_ERR); |
|
57 |
} |
|
58 |
public void info(String msg) { |
|
59 |
log(msg, Project.MSG_INFO); |
|
60 |
} |
|
61 |
public void verbose(String msg) { |
|
62 |
log(msg, Project.MSG_VERBOSE); |
|
63 |
} |
|
64 |
}; |
|
65 |
List<String> mainOpts = new ArrayList<String>(); |
|
66 |
int count = 0; |
|
67 |
DirectoryScanner s = getDirectoryScanner(srcDir); |
|
68 |
for (String path: s.getIncludedFiles()) { |
|
69 |
if (path.endsWith(".properties")) { |
|
70 |
String destPath = |
|
71 |
path.substring(0, path.length() - ".properties".length()) + |
|
72 |
".java"; |
|
73 |
File srcFile = new File(srcDir, path); |
|
74 |
File destFile = new File(destDir, destPath); |
|
75 |
// Arguably, the comparison in the next line should be ">", not ">=" |
|
76 |
// but that assumes the resolution of the last modified time is fine |
|
77 |
// grained enough; in practice, it is better to use ">=". |
|
78 |
if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified()) |
|
79 |
continue; |
|
80 |
destFile.getParentFile().mkdirs(); |
|
81 |
mainOpts.add("-compile"); |
|
82 |
mainOpts.add(srcFile.getPath()); |
|
83 |
mainOpts.add(destFile.getPath()); |
|
84 |
mainOpts.add(superclass); |
|
85 |
count++; |
|
86 |
} |
|
87 |
} |
|
88 |
if (mainOpts.size() > 0) { |
|
89 |
log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO); |
|
90 |
CompileProperties cp = new CompileProperties(); |
|
91 |
cp.setLog(log); |
|
4700
d0ef13314ec4
6764569: [PATCH] Fix unused imports in list resource bundles
jjg
parents:
10
diff
changeset
|
92 |
boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()])); |
10 | 93 |
if (!ok) |
94 |
throw new BuildException("CompileProperties failed."); |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
private File srcDir; |
|
99 |
private File destDir; |
|
100 |
private String superclass = "java.util.ListResourceBundle"; |
|
101 |
} |