author | rkennke |
Fri, 12 Oct 2018 16:25:24 +0200 | |
changeset 52107 | 0c1e44da019c |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
1 |
/* |
34914
dfdc5df47041
8145557: Unused method in JavacState should be removed
alundblad
parents:
32542
diff
changeset
|
2 |
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
4 |
* |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
10 |
* |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
15 |
* accompanied this code). |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
16 |
* |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
20 |
* |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
23 |
* questions. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
24 |
*/ |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
25 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
26 |
package com.sun.tools.sjavac; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
27 |
|
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
28 |
import java.io.BufferedWriter; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
29 |
import java.io.File; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
30 |
import java.io.FileInputStream; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
31 |
import java.io.FileOutputStream; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
32 |
import java.io.IOException; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
33 |
import java.io.OutputStreamWriter; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
34 |
import java.io.PrintStream; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
35 |
import java.io.Writer; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
36 |
import java.net.URI; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
37 |
import java.text.MessageFormat; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
38 |
import java.util.ArrayList; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
39 |
import java.util.Collections; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
40 |
import java.util.HashSet; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
41 |
import java.util.Iterator; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
42 |
import java.util.List; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
43 |
import java.util.Map; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
44 |
import java.util.Properties; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
45 |
import java.util.Set; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
46 |
|
32335 | 47 |
import com.sun.tools.sjavac.comp.CompilationService; |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
48 |
import com.sun.tools.sjavac.options.Options; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
49 |
import com.sun.tools.sjavac.pubapi.PubApi; |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
50 |
|
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
51 |
/** |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
52 |
* Compile properties transform a properties file into a Java source file. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
53 |
* Java has built in support for reading properties from either a text file |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
54 |
* in the source or a compiled java source file. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
55 |
* |
26098
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
25299
diff
changeset
|
56 |
* <p><b>This is NOT part of any supported API. |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
25299
diff
changeset
|
57 |
* If you write code that depends on this, you do so at your own risk. |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
25299
diff
changeset
|
58 |
* This code and its internal interfaces are subject to change or |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
25299
diff
changeset
|
59 |
* deletion without notice.</b> |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
60 |
*/ |
26098
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
25299
diff
changeset
|
61 |
public class CompileProperties implements Transformer { |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
62 |
// Any extra information passed from the command line, for example if: |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
63 |
// -tr .proppp=com.sun.tools.javac.smart.CompileProperties,sun.util.resources.LocaleNamesBundle |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
64 |
// then extra will be "sun.util.resources.LocaleNamesBundle" |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
65 |
String extra; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
66 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
67 |
public void setExtra(String e) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
68 |
extra = e; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
69 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
70 |
|
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
71 |
public void setExtra(Options a) { |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
72 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
73 |
|
32335 | 74 |
public boolean transform(CompilationService compilationService, |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
75 |
Map<String,Set<URI>> pkgSrcs, |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
76 |
Set<URI> visibleSrcs, |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
77 |
Map<String,Set<String>> oldPackageDependents, |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
78 |
URI destRoot, |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
79 |
Map<String,Set<URI>> packageArtifacts, |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
80 |
Map<String,Map<String, Set<String>>> packageDependencies, |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
81 |
Map<String,Map<String, Set<String>>> packageCpDependencies, |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
82 |
Map<String, PubApi> packagePublicApis, |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26107
diff
changeset
|
83 |
Map<String, PubApi> dependencyPublicApis, |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
84 |
int debugLevel, |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
85 |
boolean incremental, |
36161
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
34914
diff
changeset
|
86 |
int numCores) { |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
87 |
boolean rc = true; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
88 |
for (String pkgName : pkgSrcs.keySet()) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
89 |
String pkgNameF = Util.toFileSystemPath(pkgName); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
90 |
for (URI u : pkgSrcs.get(pkgName)) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
91 |
File src = new File(u); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
92 |
boolean r = compile(pkgName, pkgNameF, src, new File(destRoot), debugLevel, |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
93 |
packageArtifacts); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
94 |
if (r == false) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
95 |
rc = false; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
96 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
97 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
98 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
99 |
return rc; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
100 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
101 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
102 |
boolean compile(String pkgName, String pkgNameF, File src, File destRoot, int debugLevel, |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
103 |
Map<String,Set<URI>> packageArtifacts) |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
104 |
{ |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
105 |
String superClass = "java.util.ListResourceBundle"; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
106 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
107 |
if (extra != null) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
108 |
superClass = extra; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
109 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
110 |
// Load the properties file. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
111 |
Properties p = new Properties(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
112 |
try { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
113 |
p.load(new FileInputStream(src)); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
114 |
} catch (IOException e) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
115 |
Log.error("Error reading file "+src.getPath()); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
116 |
return false; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
117 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
118 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
119 |
// Calculate the name of the Java source file to be generated. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
120 |
int dp = src.getName().lastIndexOf("."); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
121 |
String classname = src.getName().substring(0,dp); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
122 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
123 |
// Sort the properties in increasing key order. |
22163 | 124 |
List<String> sortedKeys = new ArrayList<>(); |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
125 |
for (Object key : p.keySet()) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
126 |
sortedKeys.add((String)key); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
127 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
128 |
Collections.sort(sortedKeys); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
129 |
Iterator<String> keys = sortedKeys.iterator(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
130 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
131 |
// Collect the properties into a string buffer. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
132 |
StringBuilder data = new StringBuilder(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
133 |
while (keys.hasNext()) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
134 |
String key = keys.next(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
135 |
data.append(" { \"" + escape(key) + "\", \"" + |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
136 |
escape((String)p.get(key)) + "\" },\n"); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
137 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
138 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
139 |
// Create dest file name. It is derived from the properties file name. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
140 |
String destFilename = destRoot.getPath()+File.separator+pkgNameF+File.separator+classname+".java"; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
141 |
File dest = new File(destFilename); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
142 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
143 |
// Make sure the dest directories exist. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
144 |
if (!dest.getParentFile().isDirectory()) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
145 |
if (!dest.getParentFile().mkdirs()) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
146 |
Log.error("Could not create the directory "+dest.getParentFile().getPath()); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
147 |
return false; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
148 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
149 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
150 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
151 |
Set<URI> as = packageArtifacts.get(pkgName); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
152 |
if (as == null) { |
22163 | 153 |
as = new HashSet<>(); |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
154 |
packageArtifacts.put(pkgName, as); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
155 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
156 |
as.add(dest.toURI()); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
157 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
158 |
if (dest.exists() && dest.lastModified() > src.lastModified()) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
159 |
// A generated file exists, and its timestamp is newer than the source. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
160 |
// Assume that we do not need to regenerate the dest file! |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
161 |
// Thus we are done. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
162 |
return true; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
163 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
164 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
165 |
String packageString = "package " + pkgNameF.replace(File.separatorChar,'.') + ";\n\n"; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
166 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
167 |
Log.info("Compiling property file "+pkgNameF+File.separator+src.getName()); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
168 |
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dest)))) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
169 |
MessageFormat format = new MessageFormat(FORMAT); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
170 |
writer.write(format.format(new Object[] { packageString, classname, superClass, data })); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
171 |
} catch ( IOException e ) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
172 |
Log.error("Could not write file "+dest.getPath()); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
173 |
return false; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
174 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
175 |
return true; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
176 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
177 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
178 |
private static final String FORMAT = |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
179 |
"{0}" + |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
180 |
"public final class {1} extends {2} '{'\n" + |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
181 |
" protected final Object[][] getContents() '{'\n" + |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
182 |
" return new Object[][] '{'\n" + |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
183 |
"{3}" + |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
184 |
" };\n" + |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
185 |
" }\n" + |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
186 |
"}\n"; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
187 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
188 |
public static String escape(String theString) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
189 |
int len = theString.length(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
190 |
StringBuilder outBuffer = new StringBuilder(len*2); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
191 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
192 |
for(int x=0; x<len; x++) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
193 |
char aChar = theString.charAt(x); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
194 |
switch(aChar) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
195 |
case '\\':outBuffer.append('\\'); outBuffer.append('\\'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
196 |
break; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
197 |
case '\t':outBuffer.append('\\'); outBuffer.append('t'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
198 |
break; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
199 |
case '\n':outBuffer.append('\\'); outBuffer.append('n'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
200 |
break; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
201 |
case '\r':outBuffer.append('\\'); outBuffer.append('r'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
202 |
break; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
203 |
case '\f':outBuffer.append('\\'); outBuffer.append('f'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
204 |
break; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
205 |
default: |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
206 |
if ((aChar < 0x0020) || (aChar > 0x007e)) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
207 |
outBuffer.append('\\'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
208 |
outBuffer.append('u'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
209 |
outBuffer.append(toHex((aChar >> 12) & 0xF)); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
210 |
outBuffer.append(toHex((aChar >> 8) & 0xF)); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
211 |
outBuffer.append(toHex((aChar >> 4) & 0xF)); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
212 |
outBuffer.append(toHex( aChar & 0xF)); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
213 |
} else { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
214 |
if (aChar == '"') { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
215 |
outBuffer.append('\\'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
216 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
217 |
outBuffer.append(aChar); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
218 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
219 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
220 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
221 |
return outBuffer.toString(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
222 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
223 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
224 |
private static char toHex(int nibble) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
225 |
return hexDigit[(nibble & 0xF)]; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
226 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
227 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
228 |
private static final char[] hexDigit = { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
229 |
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
230 |
}; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
231 |
} |