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