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

ohrstrom@1504 1 /*
ohrstrom@1504 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
ohrstrom@1504 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohrstrom@1504 4 *
ohrstrom@1504 5 * This code is free software; you can redistribute it and/or modify it
ohrstrom@1504 6 * under the terms of the GNU General Public License version 2 only, as
ohrstrom@1504 7 * published by the Free Software Foundation. Oracle designates this
ohrstrom@1504 8 * particular file as subject to the "Classpath" exception as provided
ohrstrom@1504 9 * by Oracle in the LICENSE file that accompanied this code.
ohrstrom@1504 10 *
ohrstrom@1504 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohrstrom@1504 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohrstrom@1504 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohrstrom@1504 14 * version 2 for more details (a copy is included in the LICENSE file that
ohrstrom@1504 15 * accompanied this code).
ohrstrom@1504 16 *
ohrstrom@1504 17 * You should have received a copy of the GNU General Public License version
ohrstrom@1504 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohrstrom@1504 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohrstrom@1504 20 *
ohrstrom@1504 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohrstrom@1504 22 * or visit www.oracle.com if you need additional information or have any
ohrstrom@1504 23 * questions.
ohrstrom@1504 24 */
ohrstrom@1504 25
ohrstrom@1504 26 package com.sun.tools.sjavac;
ohrstrom@1504 27
ohrstrom@1504 28 import java.io.*;
ohrstrom@1504 29 import java.net.URI;
ohrstrom@1504 30 import java.util.Set;
ohrstrom@1504 31 import java.util.HashSet;
ohrstrom@1504 32 import java.util.Map;
ohrstrom@1504 33
ohrstrom@1504 34 /**
ohrstrom@1504 35 * The copy file transform simply copies a matching file from -src to -d .
ohrstrom@1504 36 * Such files are typically images, xml documents and other data files.
ohrstrom@1504 37 *
ohrstrom@1504 38 * <p><b>This is NOT part of any supported API.
ohrstrom@1504 39 * If you write code that depends on this, you do so at your own
ohrstrom@1504 40 * risk. This code and its internal interfaces are subject to change
ohrstrom@1504 41 * or deletion without notice.</b></p>
ohrstrom@1504 42 */
ohrstrom@1504 43 public class CopyFile implements Transformer {
ohrstrom@1504 44
ohrstrom@1504 45 public void setExtra(String e) {
ohrstrom@1504 46 }
ohrstrom@1504 47
ohrstrom@1504 48 public void setExtra(String[] a) {
ohrstrom@1504 49 }
ohrstrom@1504 50
ohrstrom@1504 51 public boolean transform(Map<String,Set<URI>> pkgSrcs,
ohrstrom@1504 52 Set<URI> visibleSrcs,
ohrstrom@1504 53 Map<URI,Set<String>> visibleClasses,
ohrstrom@1504 54 Map<String,Set<String>> oldPackageDependents,
ohrstrom@1504 55 URI destRoot,
ohrstrom@1504 56 Map<String,Set<URI>> packageArtifacts,
ohrstrom@1504 57 Map<String,Set<String>> packageDependencies,
ohrstrom@1504 58 Map<String,String> packagePubapis,
ohrstrom@1504 59 int debugLevel,
ohrstrom@1504 60 boolean incremental,
ohrstrom@1504 61 int numCores,
ohrstrom@1504 62 PrintStream out,
ohrstrom@1504 63 PrintStream err)
ohrstrom@1504 64 {
ohrstrom@1504 65 boolean rc = true;
ohrstrom@1504 66 String dest_filename;
ohrstrom@1504 67 File dest;
ohrstrom@1504 68
ohrstrom@1504 69 for (String pkgName : pkgSrcs.keySet()) {
ohrstrom@1504 70 String pkgNameF = Util.toFileSystemPath(pkgName);
ohrstrom@1504 71 for (URI u : pkgSrcs.get(pkgName)) {
ohrstrom@1504 72 File src = new File(u);
ohrstrom@1504 73 File destDir;
ohrstrom@1504 74 destDir = new File(destRoot.getPath()+File.separator+pkgNameF);
ohrstrom@1504 75 dest_filename = destRoot.getPath()+File.separator+pkgNameF+File.separator+src.getName();
ohrstrom@1504 76 dest = new File(dest_filename);
ohrstrom@1504 77
ohrstrom@1504 78 if (!destDir.isDirectory()) {
ohrstrom@1504 79 if (!destDir.mkdirs()) {
ohrstrom@1504 80 Log.error("Error: The copier could not create the directory "+
ohrstrom@1504 81 destDir.getPath());
ohrstrom@1504 82 return false;
ohrstrom@1504 83 }
ohrstrom@1504 84 }
ohrstrom@1504 85
ohrstrom@1504 86 Set<URI> as = packageArtifacts.get(pkgName);
ohrstrom@1504 87 if (as == null) {
ohrstrom@1504 88 as = new HashSet<URI>();
ohrstrom@1504 89 packageArtifacts.put(pkgName, as);
ohrstrom@1504 90 }
ohrstrom@1504 91 as.add(dest.toURI());
ohrstrom@1504 92
ohrstrom@1504 93 if (dest.exists() && dest.lastModified() > src.lastModified()) {
ohrstrom@1504 94 // A copied file exists, and its timestamp is newer than the source.
ohrstrom@1504 95 continue;
ohrstrom@1504 96 }
ohrstrom@1504 97
ohrstrom@1504 98 Log.info("Copying "+pkgNameF+File.separator+src.getName());
ohrstrom@1504 99
ohrstrom@1504 100 try (InputStream fin = new FileInputStream(src);
ohrstrom@1504 101 OutputStream fout = new FileOutputStream(dest)) {
ohrstrom@1504 102 byte[] buf = new byte[1024];
ohrstrom@1504 103 int len;
ohrstrom@1504 104 while ((len = fin.read(buf)) > 0){
ohrstrom@1504 105 fout.write(buf, 0, len);
ohrstrom@1504 106 }
ohrstrom@1504 107 }
ohrstrom@1504 108 catch(IOException e){
ohrstrom@1504 109 Log.error("Could not copy the file "+src.getPath()+" to "+dest.getPath());
ohrstrom@1504 110 rc = false;
ohrstrom@1504 111 }
ohrstrom@1504 112 }
ohrstrom@1504 113 }
ohrstrom@1504 114 return rc;
ohrstrom@1504 115 }
ohrstrom@1504 116 }

mercurial