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

     1 /*
     2  * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
     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
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    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  *
    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.
    24  */
    26 package anttasks;
    28 import compileproperties.CompileProperties;
    30 import java.io.File;
    31 import java.util.ArrayList;
    32 import java.util.List;
    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;
    39 public class CompilePropertiesTask extends MatchingTask {
    40     public void setSrcDir(File srcDir) {
    41         this.srcDir = srcDir;
    42     }
    44     public void setDestDir(File destDir) {
    45         this.destDir = destDir;
    46     }
    48     public void setSuperclass(String superclass) {
    49         this.superclass = superclass;
    50     }
    52     @Override
    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);
    92             boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));
    93             if (!ok)
    94                 throw new BuildException("CompileProperties failed.");
    95         }
    96     }
    98     private File srcDir;
    99     private File destDir;
   100     private String superclass = "java.util.ListResourceBundle";
   101 }

mercurial