Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.compiler/share/classes/com/sun/tools/sjavac/CopyFile.java
41175 views
1
/*
2
* Copyright (c) 2012, 2021, 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
*/
25
26
package com.sun.tools.sjavac;
27
28
import java.io.File;
29
import java.io.IOException;
30
import java.net.URI;
31
import java.nio.file.Files;
32
import java.nio.file.StandardCopyOption;
33
import java.util.HashSet;
34
import java.util.Map;
35
import java.util.Set;
36
37
import com.sun.tools.sjavac.comp.CompilationService;
38
import com.sun.tools.sjavac.options.Options;
39
import com.sun.tools.sjavac.pubapi.PubApi;
40
41
/**
42
* The copy file transform simply copies a matching file from -src to -d .
43
* Such files are typically images, xml documents and other data files.
44
*
45
* <p><b>This is NOT part of any supported API.
46
* If you write code that depends on this, you do so at your own risk.
47
* This code and its internal interfaces are subject to change or
48
* deletion without notice.</b>
49
*/
50
public class CopyFile implements Transformer {
51
52
public void setExtra(String e) {
53
}
54
55
public void setExtra(Options a) {
56
}
57
58
public boolean transform(CompilationService compilationService,
59
Map<String,Set<URI>> pkgSrcs,
60
Set<URI> visibleSrcs,
61
Map<String,Set<String>> oldPackageDependents,
62
URI destRoot,
63
Map<String,Set<URI>> packageArtifacts,
64
Map<String,Map<String, Set<String>>> packageDependencies,
65
Map<String,Map<String, Set<String>>> packageCpDependencies,
66
Map<String, PubApi> packagePubapis,
67
Map<String, PubApi> dependencyPubapis,
68
int debugLevel,
69
boolean incremental,
70
int numCores)
71
{
72
boolean rc = true;
73
String dest_filename;
74
File dest;
75
76
for (String pkgName : pkgSrcs.keySet()) {
77
String pkgNameF = Util.toFileSystemPath(pkgName);
78
for (URI u : pkgSrcs.get(pkgName)) {
79
File src = new File(u);
80
File destDir;
81
destDir = new File(destRoot.getPath()+File.separator+pkgNameF);
82
dest_filename = destRoot.getPath()+File.separator+pkgNameF+File.separator+src.getName();
83
dest = new File(dest_filename);
84
85
if (!destDir.isDirectory()) {
86
if (!destDir.mkdirs()) {
87
Log.error("Error: The copier could not create the directory "+
88
destDir.getPath());
89
return false;
90
}
91
}
92
93
Set<URI> as = packageArtifacts.get(pkgName);
94
if (as == null) {
95
as = new HashSet<>();
96
packageArtifacts.put(pkgName, as);
97
}
98
as.add(dest.toURI());
99
100
if (dest.exists() && dest.lastModified() > src.lastModified()) {
101
// A copied file exists, and its timestamp is newer than the source.
102
continue;
103
}
104
105
Log.info("Copying "+pkgNameF+File.separator+src.getName());
106
107
try {
108
Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
109
}
110
catch(IOException e){
111
Log.error("Could not copy the file "+src.getPath()+" to "+dest.getPath());
112
rc = false;
113
}
114
}
115
}
116
return rc;
117
}
118
}
119
120