make/tools/anttasks/CompilePropertiesTask.java

Mon, 03 Nov 2014 12:35:10 -0800

author
asaha
date
Mon, 03 Nov 2014 12:35:10 -0800
changeset 2661
05824e9d8171
parent 1305
9d47f4850714
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u31-b07 for changeset 03b8ef4cf0c0

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

mercurial