src/share/classes/com/sun/tools/sjavac/CopyFile.java

Mon, 11 Mar 2013 19:03:35 -0700

author
ohrstrom
date
Mon, 11 Mar 2013 19:03:35 -0700
changeset 1625
fbb6e470079d
parent 1504
22e417cdddee
child 2227
998b10c43157
permissions
-rw-r--r--

8009843: sjavac should accept -cp as synonym for -classpath
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 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 com.sun.tools.sjavac;
    28 import java.io.*;
    29 import java.net.URI;
    30 import java.util.Set;
    31 import java.util.HashSet;
    32 import java.util.Map;
    34 /**
    35  * The copy file transform simply copies a matching file from -src to -d .
    36  * Such files are typically images, xml documents and other data files.
    37  *
    38  * <p><b>This is NOT part of any supported API.
    39  * If you write code that depends on this, you do so at your own
    40  * risk.  This code and its internal interfaces are subject to change
    41  * or deletion without notice.</b></p>
    42  */
    43 public class CopyFile implements Transformer {
    45     public void setExtra(String e) {
    46     }
    48     public void setExtra(String[] a) {
    49     }
    51     public boolean transform(Map<String,Set<URI>> pkgSrcs,
    52                              Set<URI> visibleSrcs,
    53                              Map<URI,Set<String>> visibleClasses,
    54                              Map<String,Set<String>> oldPackageDependents,
    55                              URI destRoot,
    56                              Map<String,Set<URI>>    packageArtifacts,
    57                              Map<String,Set<String>> packageDependencies,
    58                              Map<String,String>      packagePubapis,
    59                              int debugLevel,
    60                              boolean incremental,
    61                              int numCores,
    62                              PrintStream out,
    63                              PrintStream err)
    64     {
    65         boolean rc = true;
    66         String dest_filename;
    67         File dest;
    69         for (String pkgName : pkgSrcs.keySet()) {
    70             String pkgNameF = Util.toFileSystemPath(pkgName);
    71             for (URI u : pkgSrcs.get(pkgName)) {
    72                 File src = new File(u);
    73                 File destDir;
    74                 destDir = new File(destRoot.getPath()+File.separator+pkgNameF);
    75                 dest_filename = destRoot.getPath()+File.separator+pkgNameF+File.separator+src.getName();
    76                 dest = new File(dest_filename);
    78                 if (!destDir.isDirectory()) {
    79                     if (!destDir.mkdirs()) {
    80                        Log.error("Error: The copier could not create the directory "+
    81                                            destDir.getPath());
    82                         return false;
    83                     }
    84                 }
    86                 Set<URI> as = packageArtifacts.get(pkgName);
    87                 if (as == null) {
    88                     as = new HashSet<URI>();
    89                     packageArtifacts.put(pkgName, as);
    90                 }
    91                 as.add(dest.toURI());
    93                 if (dest.exists() && dest.lastModified() > src.lastModified()) {
    94                     // A copied file exists, and its timestamp is newer than the source.
    95                     continue;
    96                 }
    98                 Log.info("Copying "+pkgNameF+File.separator+src.getName());
   100                 try (InputStream fin = new FileInputStream(src);
   101                      OutputStream fout = new FileOutputStream(dest)) {
   102                     byte[] buf = new byte[1024];
   103                     int len;
   104                     while ((len = fin.read(buf)) > 0){
   105                         fout.write(buf, 0, len);
   106                     }
   107                 }
   108                 catch(IOException e){
   109                     Log.error("Could not copy the file "+src.getPath()+" to "+dest.getPath());
   110                     rc = false;
   111                 }
   112             }
   113         }
   114         return rc;
   115     }
   116 }

mercurial