author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 36161 | langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/Util.java@a025c0619f25 |
permissions | -rw-r--r-- |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
1 |
/* |
35356
e919fd8db52c
8056989: Sjavac --server option should be optional
alundblad
parents:
34991
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 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
28 |
import java.io.File; |
26991
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
29 |
import java.io.PrintWriter; |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
30 |
import java.io.StringWriter; |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
31 |
import java.nio.file.Path; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
32 |
import java.util.Arrays; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
33 |
import java.util.Collection; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
34 |
import java.util.HashSet; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
35 |
import java.util.Map; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
36 |
import java.util.Set; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
37 |
import java.util.StringTokenizer; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
38 |
import java.util.function.Function; |
36161
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
35356
diff
changeset
|
39 |
import java.util.regex.Pattern; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
40 |
import java.util.stream.Collectors; |
36161
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
35356
diff
changeset
|
41 |
import java.util.stream.Stream; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
42 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
43 |
/** |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
44 |
* Utilities. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
45 |
* |
26098
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
25299
diff
changeset
|
46 |
* <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
|
47 |
* 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
|
48 |
* 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
|
49 |
* deletion without notice.</b> |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
50 |
*/ |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
51 |
public class Util { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
52 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
53 |
public static String toFileSystemPath(String pkgId) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
54 |
if (pkgId == null || pkgId.length()==0) return null; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
55 |
String pn; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
56 |
if (pkgId.charAt(0) == ':') { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
57 |
// When the module is the default empty module. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
58 |
// Do not prepend the module directory, because there is none. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
59 |
// Thus :java.foo.bar translates to java/foo/bar (or \) |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
60 |
pn = pkgId.substring(1).replace('.',File.separatorChar); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
61 |
} else { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
62 |
// There is a module. Thus jdk.base:java.foo.bar translates |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
63 |
// into jdk.base/java/foo/bar |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
64 |
int cp = pkgId.indexOf(':'); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
65 |
String mn = pkgId.substring(0,cp); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
66 |
pn = mn+File.separatorChar+pkgId.substring(cp+1).replace('.',File.separatorChar); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
67 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
68 |
return pn; |
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 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
71 |
public static String justPackageName(String pkgName) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
72 |
int c = pkgName.indexOf(":"); |
26104
34de7e01b3c1
8054215: Use com.sun.tools.javac.util.Assert instead of 'assert'
alundblad
parents:
26098
diff
changeset
|
73 |
if (c == -1) |
34de7e01b3c1
8054215: Use com.sun.tools.javac.util.Assert instead of 'assert'
alundblad
parents:
26098
diff
changeset
|
74 |
throw new IllegalArgumentException("Expected ':' in package name (" + pkgName + ")"); |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
75 |
return pkgName.substring(c+1); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
76 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
77 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
78 |
public static String extractStringOption(String opName, String s) { |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
79 |
return extractStringOption(opName, s, null); |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
80 |
} |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
81 |
|
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
82 |
public static String extractStringOption(String opName, String s, String deflt) { |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
83 |
int p = s.indexOf(opName+"="); |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
84 |
if (p == -1) return deflt; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
85 |
p+=opName.length()+1; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
86 |
int pe = s.indexOf(',', p); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
87 |
if (pe == -1) pe = s.length(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
88 |
return s.substring(p, pe); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
89 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
90 |
|
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
91 |
public static boolean extractBooleanOption(String opName, String s, boolean deflt) { |
35356
e919fd8db52c
8056989: Sjavac --server option should be optional
alundblad
parents:
34991
diff
changeset
|
92 |
String str = extractStringOption(opName, s); |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
93 |
return "true".equals(str) ? true |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
94 |
: "false".equals(str) ? false |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
95 |
: deflt; |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
96 |
} |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
97 |
|
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
98 |
public static int extractIntOption(String opName, String s) { |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
99 |
return extractIntOption(opName, s, 0); |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
100 |
} |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
101 |
|
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
102 |
public static int extractIntOption(String opName, String s, int deflt) { |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
103 |
int p = s.indexOf(opName+"="); |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
24067
diff
changeset
|
104 |
if (p == -1) return deflt; |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
105 |
p+=opName.length()+1; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
106 |
int pe = s.indexOf(',', p); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
107 |
if (pe == -1) pe = s.length(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
108 |
int v = 0; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
109 |
try { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
110 |
v = Integer.parseInt(s.substring(p, pe)); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
111 |
} catch (Exception e) {} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
112 |
return v; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
113 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
114 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
115 |
/** |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
116 |
* Extract the package name from a fully qualified class name. |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
117 |
* |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
118 |
* Example: Given "pkg.subpkg.A" this method returns ":pkg.subpkg". |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
119 |
* Given "C" this method returns ":". |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
120 |
* |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
121 |
* @returns package name of the given class name |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
122 |
*/ |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
123 |
public static String pkgNameOfClassName(String fqClassName) { |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
124 |
int i = fqClassName.lastIndexOf('.'); |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
125 |
String pkg = i == -1 ? "" : fqClassName.substring(0, i); |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
126 |
return ":" + pkg; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
127 |
} |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
128 |
|
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
129 |
/** |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
130 |
* Clean out unwanted sub options supplied inside a primary option. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
131 |
* For example to only had portfile remaining from: |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
132 |
* settings="--server:id=foo,portfile=bar" |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
133 |
* do settings = cleanOptions("--server:",Util.set("-portfile"),settings); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
134 |
* now settings equals "--server:portfile=bar" |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
135 |
* |
31751 | 136 |
* @param allowedSubOptions A set of the allowed sub options, id portfile etc. |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
137 |
* @param s The option settings string. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
138 |
*/ |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
139 |
public static String cleanSubOptions(Set<String> allowedSubOptions, String s) { |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
140 |
StringBuilder sb = new StringBuilder(); |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
141 |
StringTokenizer st = new StringTokenizer(s, ","); |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
142 |
while (st.hasMoreTokens()) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
143 |
String o = st.nextToken(); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
144 |
int p = o.indexOf('='); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
145 |
if (p>0) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
146 |
String key = o.substring(0,p); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
147 |
String val = o.substring(p+1); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
148 |
if (allowedSubOptions.contains(key)) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
149 |
if (sb.length() > 0) sb.append(','); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
150 |
sb.append(key+"="+val); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
151 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
152 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
153 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
154 |
return sb.toString(); |
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 |
|
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 |
* Convenience method to create a set with strings. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
159 |
*/ |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
160 |
public static Set<String> set(String... ss) { |
22163 | 161 |
Set<String> set = new HashSet<>(); |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
162 |
set.addAll(Arrays.asList(ss)); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
163 |
return set; |
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 |
|
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 |
* Normalize windows drive letter paths to upper case to enable string |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
168 |
* comparison. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
169 |
* |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
170 |
* @param file File name to normalize |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
171 |
* @return The normalized string if file has a drive letter at the beginning, |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
172 |
* otherwise the original string. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
173 |
*/ |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
174 |
public static String normalizeDriveLetter(String file) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
175 |
if (file.length() > 2 && file.charAt(1) == ':') { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
176 |
return Character.toUpperCase(file.charAt(0)) + file.substring(1); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
177 |
} else if (file.length() > 3 && file.charAt(0) == '*' |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
178 |
&& file.charAt(2) == ':') { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
179 |
// Handle a wildcard * at the beginning of the string. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
180 |
return file.substring(0, 1) + Character.toUpperCase(file.charAt(1)) |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
181 |
+ file.substring(2); |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
182 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
183 |
return file; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
184 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
185 |
|
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
186 |
/** |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
187 |
* Locate the setting for the server properties. |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
188 |
*/ |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
189 |
public static String findServerSettings(String[] args) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
190 |
for (String s : args) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
191 |
if (s.startsWith("--server:")) { |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
192 |
return s; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
193 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
194 |
} |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
195 |
return null; |
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
196 |
} |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
197 |
|
26991
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
198 |
public static <E> Set<E> union(Set<? extends E> s1, |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
199 |
Set<? extends E> s2) { |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
200 |
Set<E> union = new HashSet<>(); |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
201 |
union.addAll(s1); |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
202 |
union.addAll(s2); |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
203 |
return union; |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
204 |
} |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
205 |
|
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
206 |
public static <E> Set<E> subtract(Set<? extends E> orig, |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
207 |
Set<? extends E> toSubtract) { |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
208 |
Set<E> difference = new HashSet<>(orig); |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
209 |
difference.removeAll(toSubtract); |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
210 |
return difference; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
211 |
} |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
212 |
|
26991
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
213 |
public static String getStackTrace(Throwable t) { |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
214 |
StringWriter sw = new StringWriter(); |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
215 |
t.printStackTrace(new PrintWriter(sw)); |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
216 |
return sw.toString(); |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
217 |
} |
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
218 |
|
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
219 |
// TODO: Remove when refactoring from java.io.File to java.nio.file.Path. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
220 |
public static File pathToFile(Path path) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
221 |
return path == null ? null : path.toFile(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
22449
diff
changeset
|
222 |
} |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
223 |
|
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
224 |
public static <E> Set<E> intersection(Collection<? extends E> c1, |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
225 |
Collection<? extends E> c2) { |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
226 |
Set<E> intersection = new HashSet<E>(c1); |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
227 |
intersection.retainAll(c2); |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
228 |
return intersection; |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
229 |
} |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
230 |
|
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
231 |
public static <I, T> Map<I, T> indexBy(Collection<? extends T> c, |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
232 |
Function<? super T, ? extends I> indexFunction) { |
31116
2c8162f88493
8087115: Due to a javac type inference issue, sjavac doesn't compile with 8u31
alundblad
parents:
31115
diff
changeset
|
233 |
return c.stream().collect(Collectors.<T, I, T>toMap(indexFunction, o -> o)); |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
26991
diff
changeset
|
234 |
} |
34991
ff8be37d1164
8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents:
31751
diff
changeset
|
235 |
|
ff8be37d1164
8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents:
31751
diff
changeset
|
236 |
public static String fileSuffix(Path file) { |
ff8be37d1164
8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents:
31751
diff
changeset
|
237 |
String fileNameStr = file.getFileName().toString(); |
ff8be37d1164
8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents:
31751
diff
changeset
|
238 |
int dotIndex = fileNameStr.indexOf('.'); |
ff8be37d1164
8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents:
31751
diff
changeset
|
239 |
return dotIndex == -1 ? "" : fileNameStr.substring(dotIndex); |
ff8be37d1164
8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents:
31751
diff
changeset
|
240 |
} |
36161
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
35356
diff
changeset
|
241 |
|
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
35356
diff
changeset
|
242 |
public static Stream<String> getLines(String str) { |
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
35356
diff
changeset
|
243 |
return str.isEmpty() |
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
35356
diff
changeset
|
244 |
? Stream.empty() |
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
35356
diff
changeset
|
245 |
: Stream.of(str.split(Pattern.quote(System.lineSeparator()))); |
a025c0619f25
8147569: Error messages from sjavac server does not always get relayed back to client
alundblad
parents:
35356
diff
changeset
|
246 |
} |
15368
2577ddb7e710
8004658: Add internal smart javac wrapper to solve JEP 139
ohrstrom
parents:
diff
changeset
|
247 |
} |