Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/make/tools/anttasks/CompilePropertiesTask.java
32285 views
/*1* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package anttasks;2627import compileproperties.CompileProperties;2829import java.io.File;30import java.util.ArrayList;31import java.util.List;3233import org.apache.tools.ant.BuildException;34import org.apache.tools.ant.DirectoryScanner;35import org.apache.tools.ant.Project;36import org.apache.tools.ant.taskdefs.MatchingTask;3738public class CompilePropertiesTask extends MatchingTask {39public void setSrcDir(File srcDir) {40this.srcDir = srcDir;41}4243public void setDestDir(File destDir) {44this.destDir = destDir;45}4647public void setSuperclass(String superclass) {48this.superclass = superclass;49}5051@Override52public void execute() {53CompileProperties.Log log = new CompileProperties.Log() {54public void error(String msg, Exception e) {55log(msg, Project.MSG_ERR);56}57public void info(String msg) {58log(msg, Project.MSG_INFO);59}60public void verbose(String msg) {61log(msg, Project.MSG_VERBOSE);62}63};64List<String> mainOpts = new ArrayList<String>();65int count = 0;66DirectoryScanner s = getDirectoryScanner(srcDir);67for (String path: s.getIncludedFiles()) {68if (path.endsWith(".properties")) {69String destPath =70path.substring(0, path.length() - ".properties".length()) +71".java";72File srcFile = new File(srcDir, path);73File destFile = new File(destDir, destPath);74// Arguably, the comparison in the next line should be ">", not ">="75// but that assumes the resolution of the last modified time is fine76// grained enough; in practice, it is better to use ">=".77if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified())78continue;79destFile.getParentFile().mkdirs();80mainOpts.add("-compile");81mainOpts.add(srcFile.getPath());82mainOpts.add(destFile.getPath());83mainOpts.add(superclass);84count++;85}86}87if (mainOpts.size() > 0) {88log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);89CompileProperties cp = new CompileProperties();90cp.setLog(log);91boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));92if (!ok)93throw new BuildException("CompileProperties failed.");94}95}9697private File srcDir;98private File destDir;99private String superclass = "java.util.ListResourceBundle";100}101102103