author | mcimadamore |
Mon, 04 Dec 2017 17:54:49 +0000 | |
changeset 48054 | 702043a4cdeb |
parent 47702 | cf8310446245 |
child 48746 | c9ab849cd2f5 |
permissions | -rw-r--r-- |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
1 |
/* |
43145
35ee451a5fd3
8172474: javac should enable doclint checking for HTML 5
jjg
parents:
42822
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
4 |
* |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
10 |
* |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
16 |
* |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
20 |
* |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
23 |
* questions. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
24 |
*/ |
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
34480
diff
changeset
|
25 |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.main; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
27 |
|
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
28 |
import java.io.IOException; |
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
34752
diff
changeset
|
29 |
import java.nio.file.Files; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
30 |
import java.nio.file.Path; |
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
34752
diff
changeset
|
31 |
import java.nio.file.Paths; |
36526 | 32 |
import java.util.Arrays; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
33 |
import java.util.Collections; |
36526 | 34 |
import java.util.EnumSet; |
35 |
import java.util.HashSet; |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
36 |
import java.util.Iterator; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
37 |
import java.util.LinkedHashMap; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
38 |
import java.util.LinkedHashSet; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
39 |
import java.util.Map; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
40 |
import java.util.Set; |
44450
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
41 |
import java.util.function.Predicate; |
36526 | 42 |
import java.util.regex.Matcher; |
43 |
import java.util.regex.Pattern; |
|
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
44 |
import java.util.stream.Stream; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
45 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
46 |
import javax.lang.model.SourceVersion; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
47 |
import javax.tools.JavaFileManager; |
36526 | 48 |
import javax.tools.JavaFileManager.Location; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
49 |
import javax.tools.JavaFileObject; |
36526 | 50 |
import javax.tools.JavaFileObject.Kind; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
51 |
import javax.tools.StandardJavaFileManager; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
52 |
import javax.tools.StandardLocation; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
53 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
54 |
import com.sun.tools.doclint.DocLint; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
55 |
import com.sun.tools.javac.code.Lint.LintCategory; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
56 |
import com.sun.tools.javac.code.Source; |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47702
diff
changeset
|
57 |
import com.sun.tools.javac.code.Source.Feature; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
58 |
import com.sun.tools.javac.file.BaseFileManager; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
59 |
import com.sun.tools.javac.file.JavacFileManager; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
60 |
import com.sun.tools.javac.jvm.Profile; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
61 |
import com.sun.tools.javac.jvm.Target; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
62 |
import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
63 |
import com.sun.tools.javac.platform.PlatformDescription; |
31936 | 64 |
import com.sun.tools.javac.platform.PlatformUtils; |
36526 | 65 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
66 |
import com.sun.tools.javac.resources.CompilerProperties.Warnings; |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
67 |
import com.sun.tools.javac.util.Context; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
68 |
import com.sun.tools.javac.util.JCDiagnostic; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
69 |
import com.sun.tools.javac.util.List; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
70 |
import com.sun.tools.javac.util.ListBuffer; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
71 |
import com.sun.tools.javac.util.Log; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
72 |
import com.sun.tools.javac.util.Log.PrefixKind; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
73 |
import com.sun.tools.javac.util.Log.WriterKind; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
74 |
import com.sun.tools.javac.util.Options; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
75 |
import com.sun.tools.javac.util.PropagatedException; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
76 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
77 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
78 |
* Shared option and argument handling for command line and API usage of javac. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
79 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
80 |
public class Arguments { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
81 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
82 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
83 |
* The context key for the arguments. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
84 |
*/ |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31936
diff
changeset
|
85 |
public static final Context.Key<Arguments> argsKey = new Context.Key<>(); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
86 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
87 |
private String ownName; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
88 |
private Set<String> classNames; |
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
34752
diff
changeset
|
89 |
private Set<Path> files; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
90 |
private Map<Option, String> deferredFileManagerOptions; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
91 |
private Set<JavaFileObject> fileObjects; |
36526 | 92 |
private boolean emptyAllowed; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
93 |
private final Options options; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
94 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
95 |
private JavaFileManager fileManager; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
96 |
private final Log log; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
97 |
private final Context context; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
98 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
99 |
private enum ErrorMode { ILLEGAL_ARGUMENT, ILLEGAL_STATE, LOG }; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
100 |
private ErrorMode errorMode; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
101 |
private boolean errors; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
102 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
103 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
104 |
* Gets the Arguments instance for this context. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
105 |
* |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
106 |
* @param context the content |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
107 |
* @return the Arguments instance for this context. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
108 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
109 |
public static Arguments instance(Context context) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
110 |
Arguments instance = context.get(argsKey); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
111 |
if (instance == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
112 |
instance = new Arguments(context); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
113 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
114 |
return instance; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
115 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
116 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
117 |
protected Arguments(Context context) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
118 |
context.put(argsKey, this); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
119 |
options = Options.instance(context); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
120 |
log = Log.instance(context); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
121 |
this.context = context; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
122 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
123 |
// Ideally, we could init this here and update/configure it as |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
124 |
// needed, but right now, initializing a file manager triggers |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
125 |
// initialization of other items in the context, such as Lint |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
126 |
// and FSInfo, which should not be initialized until after |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
127 |
// processArgs |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
128 |
// fileManager = context.get(JavaFileManager.class); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
129 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
130 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
131 |
private final OptionHelper cmdLineHelper = new OptionHelper() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
132 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
133 |
public String get(Option option) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
134 |
return options.get(option); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
135 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
136 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
137 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
138 |
public void put(String name, String value) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
139 |
options.put(name, value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
140 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
141 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
142 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
143 |
public void remove(String name) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
144 |
options.remove(name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
145 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
146 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
147 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
148 |
public boolean handleFileManagerOption(Option option, String value) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
149 |
options.put(option, value); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
150 |
deferredFileManagerOptions.put(option, value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
151 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
152 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
153 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
154 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
155 |
public Log getLog() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
156 |
return log; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
157 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
158 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
159 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
160 |
public String getOwnName() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
161 |
return ownName; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
162 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
163 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
164 |
@Override |
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
34752
diff
changeset
|
165 |
public void addFile(Path p) { |
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
34752
diff
changeset
|
166 |
files.add(p); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
167 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
168 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
169 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
170 |
public void addClassName(String s) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
171 |
classNames.add(s); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
172 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
173 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
174 |
}; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
175 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
176 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
177 |
* Initializes this Args instance with a set of command line args. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
178 |
* The args will be processed in conjunction with the full set of |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
179 |
* command line options, including -help, -version etc. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
180 |
* The args may also contain class names and filenames. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
181 |
* Any errors during this call, and later during validate, will be reported |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
182 |
* to the log. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
183 |
* @param ownName the name of this tool; used to prefix messages |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
184 |
* @param args the args to be processed |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
185 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
186 |
public void init(String ownName, String... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
187 |
this.ownName = ownName; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
188 |
errorMode = ErrorMode.LOG; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
189 |
files = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
190 |
deferredFileManagerOptions = new LinkedHashMap<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
191 |
fileObjects = null; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
192 |
classNames = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
193 |
processArgs(List.from(args), Option.getJavaCompilerOptions(), cmdLineHelper, true, false); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
194 |
if (errors) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
195 |
log.printLines(PrefixKind.JAVAC, "msg.usage", ownName); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
196 |
} |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
197 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
198 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
199 |
private final OptionHelper apiHelper = new GrumpyHelper(null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
200 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
201 |
public String get(Option option) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
202 |
return options.get(option); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
203 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
204 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
205 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
206 |
public void put(String name, String value) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
207 |
options.put(name, value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
208 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
209 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
210 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
211 |
public void remove(String name) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
212 |
options.remove(name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
213 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
214 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
215 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
216 |
public Log getLog() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
217 |
return Arguments.this.log; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
218 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
219 |
}; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
220 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
221 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
222 |
* Initializes this Args instance with the parameters for a JavacTask. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
223 |
* The options will be processed in conjunction with the restricted set |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
224 |
* of tool options, which does not include -help, -version, etc, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
225 |
* nor does it include classes and filenames, which should be specified |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
226 |
* separately. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
227 |
* File manager options are handled directly by the file manager. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
228 |
* Any errors found while processing individual args will be reported |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
229 |
* via IllegalArgumentException. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
230 |
* Any subsequent errors during validate will be reported via IllegalStateException. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
231 |
* @param ownName the name of this tool; used to prefix messages |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
232 |
* @param options the options to be processed |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
233 |
* @param classNames the classes to be subject to annotation processing |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
234 |
* @param files the files to be compiled |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
235 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
236 |
public void init(String ownName, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
237 |
Iterable<String> options, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
238 |
Iterable<String> classNames, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
239 |
Iterable<? extends JavaFileObject> files) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
240 |
this.ownName = ownName; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
241 |
this.classNames = toSet(classNames); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
242 |
this.fileObjects = toSet(files); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
243 |
this.files = null; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
244 |
errorMode = ErrorMode.ILLEGAL_ARGUMENT; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
245 |
if (options != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
246 |
processArgs(toList(options), Option.getJavacToolOptions(), apiHelper, false, true); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
247 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
248 |
errorMode = ErrorMode.ILLEGAL_STATE; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
249 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
250 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
251 |
/** |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
252 |
* Minimal initialization for tools, like javadoc, |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
253 |
* to be able to process javac options for themselves, |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
254 |
* and then call validate. |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
255 |
* @param ownName the name of this tool; used to prefix messages |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
256 |
*/ |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
257 |
public void init(String ownName) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
258 |
this.ownName = ownName; |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
259 |
errorMode = ErrorMode.LOG; |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
260 |
} |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
261 |
|
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
262 |
/** |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
263 |
* Gets the files to be compiled. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
264 |
* @return the files to be compiled |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
265 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
266 |
public Set<JavaFileObject> getFileObjects() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
267 |
if (fileObjects == null) { |
36526 | 268 |
fileObjects = new LinkedHashSet<>(); |
269 |
} |
|
270 |
if (files != null) { |
|
271 |
JavacFileManager jfm = (JavacFileManager) getFileManager(); |
|
272 |
for (JavaFileObject fo: jfm.getJavaFileObjectsFromPaths(files)) |
|
273 |
fileObjects.add(fo); |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
274 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
275 |
return fileObjects; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
276 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
277 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
278 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
279 |
* Gets the classes to be subject to annotation processing. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
280 |
* @return the classes to be subject to annotation processing |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
281 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
282 |
public Set<String> getClassNames() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
283 |
return classNames; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
284 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
285 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
286 |
/** |
44450
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
287 |
* Handles the {@code --release} option. |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
288 |
* |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
289 |
* @param additionalOptions a predicate to handle additional options implied by the |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
290 |
* {@code --release} option. The predicate should return true if all the additional |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
291 |
* options were processed successfully. |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
292 |
* @return true if successful, false otherwise |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
293 |
*/ |
44450
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
294 |
public boolean handleReleaseOptions(Predicate<Iterable<String>> additionalOptions) { |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
295 |
String platformString = options.get(Option.RELEASE); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
296 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
297 |
checkOptionAllowed(platformString == null, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
298 |
option -> error("err.release.bootclasspath.conflict", option.getPrimaryName()), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
299 |
Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND, |
36526 | 300 |
Option.XBOOTCLASSPATH_PREPEND, |
301 |
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
|
302 |
Option.EXTDIRS, Option.DJAVA_EXT_DIRS, |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44450
diff
changeset
|
303 |
Option.SOURCE, Option.TARGET, |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44450
diff
changeset
|
304 |
Option.SYSTEM, Option.UPGRADE_MODULE_PATH); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
305 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
306 |
if (platformString != null) { |
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47216
diff
changeset
|
307 |
PlatformDescription platformDescription = |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47216
diff
changeset
|
308 |
PlatformUtils.lookupPlatformDescription(platformString); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
309 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
310 |
if (platformDescription == null) { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
311 |
error("err.unsupported.release.version", platformString); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
312 |
return false; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
313 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
314 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
315 |
options.put(Option.SOURCE, platformDescription.getSourceVersion()); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
316 |
options.put(Option.TARGET, platformDescription.getTargetVersion()); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
317 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
318 |
context.put(PlatformDescription.class, platformDescription); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
319 |
|
44450
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
320 |
if (!additionalOptions.test(platformDescription.getAdditionalOptions())) |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
321 |
return false; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
322 |
|
47702
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47216
diff
changeset
|
323 |
JavaFileManager platformFM = platformDescription.getFileManager(); |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47216
diff
changeset
|
324 |
DelegatingJavaFileManager.installReleaseFileManager(context, |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47216
diff
changeset
|
325 |
platformFM, |
cf8310446245
8139607: -release option forces StandardJavaFileManager
jlahoda
parents:
47216
diff
changeset
|
326 |
getFileManager()); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
327 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
328 |
|
44450
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
329 |
return true; |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
330 |
} |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
331 |
|
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
332 |
/** |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
333 |
* Processes strings containing options and operands. |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
334 |
* @param args the strings to be processed |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
335 |
* @param allowableOpts the set of option declarations that are applicable |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
336 |
* @param helper a help for use by Option.process |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
337 |
* @param allowOperands whether or not to check for files and classes |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
338 |
* @param checkFileManager whether or not to check if the file manager can handle |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
339 |
* options which are not recognized by any of allowableOpts |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
340 |
* @return true if all the strings were successfully processed; false otherwise |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
341 |
* @throws IllegalArgumentException if a problem occurs and errorMode is set to |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
342 |
* ILLEGAL_ARGUMENT |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
343 |
*/ |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
344 |
private boolean processArgs(Iterable<String> args, |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
345 |
Set<Option> allowableOpts, OptionHelper helper, |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
346 |
boolean allowOperands, boolean checkFileManager) { |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
347 |
if (!doProcessArgs(args, allowableOpts, helper, allowOperands, checkFileManager)) |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
348 |
return false; |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
349 |
|
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
350 |
if (!handleReleaseOptions(extra -> doProcessArgs(extra, allowableOpts, helper, allowOperands, checkFileManager))) |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
351 |
return false; |
eb4f067bae4c
8175277: javadoc AssertionError when specified with release 8
ksrini
parents:
44291
diff
changeset
|
352 |
|
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
353 |
options.notifyListeners(); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
354 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
355 |
return true; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
356 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
357 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
358 |
private boolean doProcessArgs(Iterable<String> args, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
359 |
Set<Option> allowableOpts, OptionHelper helper, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
360 |
boolean allowOperands, boolean checkFileManager) { |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
361 |
JavaFileManager fm = checkFileManager ? getFileManager() : null; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
362 |
Iterator<String> argIter = args.iterator(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
363 |
while (argIter.hasNext()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
364 |
String arg = argIter.next(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
365 |
if (arg.isEmpty()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
366 |
error("err.invalid.flag", arg); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
367 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
368 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
369 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
370 |
Option option = null; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
371 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
372 |
// first, check the provided set of javac options |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
373 |
if (arg.startsWith("-")) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
374 |
option = Option.lookup(arg, allowableOpts); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
375 |
} else if (allowOperands && Option.SOURCEFILE.matches(arg)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
376 |
option = Option.SOURCEFILE; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
377 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
378 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
379 |
if (option != null) { |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
380 |
try { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
381 |
option.handleOption(helper, arg, argIter); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
382 |
} catch (Option.InvalidValueException e) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
383 |
error(e); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
384 |
return false; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
385 |
} |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
386 |
continue; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
387 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
388 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
389 |
// check file manager option |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
390 |
if (fm != null && fm.handleOption(arg, argIter)) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
391 |
continue; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
392 |
} |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
393 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
394 |
// none of the above |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
395 |
error("err.invalid.flag", arg); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
396 |
return false; |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
397 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
398 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
399 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
400 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
401 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
402 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
403 |
* Validates the overall consistency of the options and operands |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
404 |
* processed by processOptions. |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
405 |
* @return true if all args are successfully validated; false otherwise. |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
406 |
* @throws IllegalStateException if a problem is found and errorMode is set to |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
407 |
* ILLEGAL_STATE |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
408 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
409 |
public boolean validate() { |
36526 | 410 |
JavaFileManager fm = getFileManager(); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
411 |
if (options.isSet(Option.MODULE)) { |
36526 | 412 |
if (!fm.hasLocation(StandardLocation.CLASS_OUTPUT)) { |
413 |
log.error(Errors.OutputDirMustBeSpecifiedWithDashMOption); |
|
414 |
} else if (!fm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) { |
|
415 |
log.error(Errors.ModulesourcepathMustBeSpecifiedWithDashMOption); |
|
416 |
} else { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
417 |
java.util.List<String> modules = Arrays.asList(options.get(Option.MODULE).split(",")); |
36526 | 418 |
try { |
419 |
for (String module : modules) { |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
42260
diff
changeset
|
420 |
Location sourceLoc = fm.getLocationForModule(StandardLocation.MODULE_SOURCE_PATH, module); |
36526 | 421 |
if (sourceLoc == null) { |
422 |
log.error(Errors.ModuleNotFoundInModuleSourcePath(module)); |
|
423 |
} else { |
|
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
42260
diff
changeset
|
424 |
Location classLoc = fm.getLocationForModule(StandardLocation.CLASS_OUTPUT, module); |
36526 | 425 |
|
426 |
for (JavaFileObject file : fm.list(sourceLoc, "", EnumSet.of(JavaFileObject.Kind.SOURCE), true)) { |
|
427 |
String className = fm.inferBinaryName(sourceLoc, file); |
|
428 |
JavaFileObject classFile = fm.getJavaFileForInput(classLoc, className, Kind.CLASS); |
|
429 |
||
430 |
if (classFile == null || classFile.getLastModified() < file.getLastModified()) { |
|
431 |
if (fileObjects == null) |
|
432 |
fileObjects = new HashSet<>(); |
|
433 |
fileObjects.add(file); |
|
434 |
} |
|
435 |
} |
|
436 |
} |
|
437 |
} |
|
438 |
} catch (IOException ex) { |
|
439 |
log.printLines(PrefixKind.JAVAC, "msg.io"); |
|
440 |
ex.printStackTrace(log.getWriter(WriterKind.NOTICE)); |
|
441 |
return false; |
|
442 |
} |
|
443 |
} |
|
444 |
} |
|
445 |
||
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
446 |
if (isEmpty()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
447 |
// It is allowed to compile nothing if just asking for help or version info. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
448 |
// But also note that none of these options are supported in API mode. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
449 |
if (options.isSet(Option.HELP) |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
450 |
|| options.isSet(Option.X) |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
451 |
|| options.isSet(Option.VERSION) |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
452 |
|| options.isSet(Option.FULLVERSION) |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
453 |
|| options.isSet(Option.MODULE)) { |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
454 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
455 |
} |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
456 |
|
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
457 |
if (!emptyAllowed) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
458 |
if (!errors) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
459 |
if (JavaCompiler.explicitAnnotationProcessingRequested(options)) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
460 |
error("err.no.source.files.classes"); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
461 |
} else { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
462 |
error("err.no.source.files"); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
463 |
} |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
464 |
} |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
465 |
return false; |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
466 |
} |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
467 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
468 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
469 |
if (!checkDirectory(Option.D)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
470 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
471 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
472 |
if (!checkDirectory(Option.S)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
473 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
474 |
} |
34480
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
32454
diff
changeset
|
475 |
if (!checkDirectory(Option.H)) { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
32454
diff
changeset
|
476 |
return false; |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
32454
diff
changeset
|
477 |
} |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
478 |
|
36526 | 479 |
// The following checks are to help avoid accidental confusion between |
480 |
// directories of modules and exploded module directories. |
|
481 |
if (fm instanceof StandardJavaFileManager) { |
|
482 |
StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager; |
|
483 |
if (sfm.hasLocation(StandardLocation.CLASS_OUTPUT)) { |
|
484 |
Path outDir = sfm.getLocationAsPaths(StandardLocation.CLASS_OUTPUT).iterator().next(); |
|
485 |
if (sfm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) { |
|
486 |
// multi-module mode |
|
487 |
if (Files.exists(outDir.resolve("module-info.class"))) { |
|
488 |
log.error(Errors.MultiModuleOutdirCannotBeExplodedModule(outDir)); |
|
489 |
} |
|
490 |
} else { |
|
491 |
// single-module or legacy mode |
|
492 |
boolean lintPaths = options.isUnset(Option.XLINT_CUSTOM, |
|
493 |
"-" + LintCategory.PATH.option); |
|
494 |
if (lintPaths) { |
|
495 |
Path outDirParent = outDir.getParent(); |
|
496 |
if (outDirParent != null && Files.exists(outDirParent.resolve("module-info.class"))) { |
|
497 |
log.warning(LintCategory.PATH, Warnings.OutdirIsInExplodedModule(outDir)); |
|
498 |
} |
|
499 |
} |
|
500 |
} |
|
501 |
} |
|
502 |
} |
|
503 |
||
504 |
||
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
505 |
String sourceString = options.get(Option.SOURCE); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
506 |
Source source = (sourceString != null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
507 |
? Source.lookup(sourceString) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
508 |
: Source.DEFAULT; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
509 |
String targetString = options.get(Option.TARGET); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
510 |
Target target = (targetString != null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
511 |
? Target.lookup(targetString) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
512 |
: Target.DEFAULT; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
513 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
514 |
// We don't check source/target consistency for CLDC, as J2ME |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
515 |
// profiles are not aligned with J2SE targets; moreover, a |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
516 |
// single CLDC target may have many profiles. In addition, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
517 |
// this is needed for the continued functioning of the JSR14 |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
518 |
// prototype. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
519 |
if (Character.isDigit(target.name.charAt(0))) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
520 |
if (target.compareTo(source.requiredTarget()) < 0) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
521 |
if (targetString != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
522 |
if (sourceString == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
523 |
error("warn.target.default.source.conflict", |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
524 |
targetString, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
525 |
source.requiredTarget().name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
526 |
} else { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
527 |
error("warn.source.target.conflict", |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
528 |
sourceString, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
529 |
source.requiredTarget().name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
530 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
531 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
532 |
} else { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
533 |
target = source.requiredTarget(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
534 |
options.put("-target", target.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
535 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
536 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
537 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
538 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
539 |
String profileString = options.get(Option.PROFILE); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
540 |
if (profileString != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
541 |
Profile profile = Profile.lookup(profileString); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
542 |
if (!profile.isValid(target)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
543 |
error("warn.profile.target.conflict", profileString, target.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
544 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
545 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
546 |
// This check is only effective in command line mode, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
547 |
// where the file manager options are added to options |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
548 |
if (options.get(Option.BOOT_CLASS_PATH) != null) { |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
549 |
error("err.profile.bootclasspath.conflict"); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
550 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
551 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
552 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
553 |
if (options.isSet(Option.SOURCE_PATH) && options.isSet(Option.MODULE_SOURCE_PATH)) { |
36526 | 554 |
error("err.sourcepath.modulesourcepath.conflict"); |
555 |
} |
|
556 |
||
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
557 |
boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
558 |
if (lintOptions && source.compareTo(Source.DEFAULT) < 0 && !options.isSet(Option.RELEASE)) { |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
559 |
if (fm instanceof BaseFileManager) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
560 |
if (((BaseFileManager) fm).isDefaultBootClassPath()) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45156
diff
changeset
|
561 |
log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name)); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
562 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
563 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
564 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
565 |
boolean obsoleteOptionFound = false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
566 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
567 |
if (source.compareTo(Source.MIN) < 0) { |
36526 | 568 |
log.error(Errors.OptionRemovedSource(source.name, Source.MIN.name)); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
569 |
} else if (source == Source.MIN && lintOptions) { |
36526 | 570 |
log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteSource(source.name)); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
571 |
obsoleteOptionFound = true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
572 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
573 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
574 |
if (target.compareTo(Target.MIN) < 0) { |
36526 | 575 |
log.error(Errors.OptionRemovedTarget(target.name, Target.MIN.name)); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
576 |
} else if (target == Target.MIN && lintOptions) { |
36526 | 577 |
log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteTarget(target.name)); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
578 |
obsoleteOptionFound = true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
579 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
580 |
|
36526 | 581 |
final Target t = target; |
582 |
checkOptionAllowed(t.compareTo(Target.JDK1_8) <= 0, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
583 |
option -> error("err.option.not.allowed.with.target", option.getPrimaryName(), t.name), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
584 |
Option.BOOT_CLASS_PATH, |
36526 | 585 |
Option.XBOOTCLASSPATH_PREPEND, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND, |
586 |
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
587 |
Option.EXTDIRS, Option.DJAVA_EXT_DIRS, |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
588 |
Option.PROFILE); |
36526 | 589 |
|
590 |
checkOptionAllowed(t.compareTo(Target.JDK1_9) >= 0, |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
591 |
option -> error("err.option.not.allowed.with.target", option.getPrimaryName(), t.name), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
592 |
Option.MODULE_SOURCE_PATH, Option.UPGRADE_MODULE_PATH, |
43273
2614e1907a0b
8170692: inconsistent check of module-related options against target version
vromero
parents:
43145
diff
changeset
|
593 |
Option.SYSTEM, Option.MODULE_PATH, Option.ADD_MODULES, |
2614e1907a0b
8170692: inconsistent check of module-related options against target version
vromero
parents:
43145
diff
changeset
|
594 |
Option.ADD_EXPORTS, Option.ADD_OPENS, Option.ADD_READS, |
2614e1907a0b
8170692: inconsistent check of module-related options against target version
vromero
parents:
43145
diff
changeset
|
595 |
Option.LIMIT_MODULES, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
596 |
Option.PATCH_MODULE); |
36526 | 597 |
|
598 |
if (fm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) { |
|
599 |
if (!options.isSet(Option.PROC, "only") |
|
600 |
&& !fm.hasLocation(StandardLocation.CLASS_OUTPUT)) { |
|
601 |
log.error(Errors.NoOutputDir); |
|
602 |
} |
|
603 |
} |
|
604 |
||
605 |
if (fm.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH) && |
|
606 |
fm.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) { |
|
607 |
log.error(Errors.ProcessorpathNoProcessormodulepath); |
|
608 |
} |
|
609 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
610 |
if (obsoleteOptionFound && lintOptions) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45156
diff
changeset
|
611 |
log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteSuppression); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
612 |
} |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
613 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
614 |
SourceVersion sv = Source.toSourceVersion(source); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
615 |
validateAddExports(sv); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
616 |
validateAddModules(sv); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
617 |
validateAddReads(sv); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
618 |
validateLimitModules(sv); |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
619 |
validateDefaultModuleForCreatedFiles(sv); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
620 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
621 |
if (lintOptions && options.isSet(Option.ADD_OPENS)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
622 |
log.warning(LintCategory.OPTIONS, Warnings.AddopensIgnored); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
623 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
624 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
625 |
return !errors && (log.nerrors == 0); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
626 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
627 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
628 |
private void validateAddExports(SourceVersion sv) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
629 |
String addExports = options.get(Option.ADD_EXPORTS); |
36526 | 630 |
if (addExports != null) { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
631 |
// Each entry must be of the form sourceModule/sourcePackage=target-list where |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
632 |
// target-list is a comma separated list of module or ALL-UNNAMED. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
633 |
// Empty items in the target-list are ignored. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
634 |
// There must be at least one item in the list; this is handled in Option.ADD_EXPORTS. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
635 |
Pattern p = Option.ADD_EXPORTS.getPattern(); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
636 |
for (String e : addExports.split("\0")) { |
36526 | 637 |
Matcher m = p.matcher(e); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
638 |
if (m.matches()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
639 |
String sourceModuleName = m.group(1); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
640 |
if (!SourceVersion.isName(sourceModuleName, sv)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
641 |
// syntactically invalid source name: e.g. --add-exports m!/p1=m2 |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
642 |
log.warning(Warnings.BadNameForOption(Option.ADD_EXPORTS, sourceModuleName)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
643 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
644 |
String sourcePackageName = m.group(2); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
645 |
if (!SourceVersion.isName(sourcePackageName, sv)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
646 |
// syntactically invalid source name: e.g. --add-exports m1/p!=m2 |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
647 |
log.warning(Warnings.BadNameForOption(Option.ADD_EXPORTS, sourcePackageName)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
648 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
649 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
650 |
String targetNames = m.group(3); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
651 |
for (String targetName : targetNames.split(",")) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
652 |
switch (targetName) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
653 |
case "": |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
654 |
case "ALL-UNNAMED": |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
655 |
break; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
656 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
657 |
default: |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
658 |
if (!SourceVersion.isName(targetName, sv)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
659 |
// syntactically invalid target name: e.g. --add-exports m1/p1=m! |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
660 |
log.warning(Warnings.BadNameForOption(Option.ADD_EXPORTS, targetName)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
661 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
662 |
break; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
663 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
664 |
} |
36526 | 665 |
} |
666 |
} |
|
667 |
} |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
668 |
} |
36526 | 669 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
670 |
private void validateAddReads(SourceVersion sv) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
671 |
String addReads = options.get(Option.ADD_READS); |
36526 | 672 |
if (addReads != null) { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
673 |
// Each entry must be of the form source=target-list where target-list is a |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
674 |
// comma-separated list of module or ALL-UNNAMED. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
675 |
// Empty items in the target list are ignored. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
676 |
// There must be at least one item in the list; this is handled in Option.ADD_READS. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
677 |
Pattern p = Option.ADD_READS.getPattern(); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
678 |
for (String e : addReads.split("\0")) { |
36526 | 679 |
Matcher m = p.matcher(e); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
680 |
if (m.matches()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
681 |
String sourceName = m.group(1); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
682 |
if (!SourceVersion.isName(sourceName, sv)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
683 |
// syntactically invalid source name: e.g. --add-reads m!=m2 |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
684 |
log.warning(Warnings.BadNameForOption(Option.ADD_READS, sourceName)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
685 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
686 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
687 |
String targetNames = m.group(2); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
688 |
for (String targetName : targetNames.split(",", -1)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
689 |
switch (targetName) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
690 |
case "": |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
691 |
case "ALL-UNNAMED": |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
692 |
break; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
693 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
694 |
default: |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
695 |
if (!SourceVersion.isName(targetName, sv)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
696 |
// syntactically invalid target name: e.g. --add-reads m1=m! |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
697 |
log.warning(Warnings.BadNameForOption(Option.ADD_READS, targetName)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
698 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
699 |
break; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
700 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
701 |
} |
36526 | 702 |
} |
703 |
} |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
704 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
705 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
706 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
707 |
private void validateAddModules(SourceVersion sv) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
708 |
String addModules = options.get(Option.ADD_MODULES); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
709 |
if (addModules != null) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
710 |
// Each entry must be of the form target-list where target-list is a |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
711 |
// comma separated list of module names, or ALL-DEFAULT, ALL-SYSTEM, |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
712 |
// or ALL-MODULE_PATH. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
713 |
// Empty items in the target list are ignored. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
714 |
// There must be at least one item in the list; this is handled in Option.ADD_MODULES. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
715 |
for (String moduleName : addModules.split(",")) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
716 |
switch (moduleName) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
717 |
case "": |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
718 |
case "ALL-SYSTEM": |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
719 |
case "ALL-MODULE-PATH": |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
720 |
break; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
721 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
722 |
default: |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
723 |
if (!SourceVersion.isName(moduleName, sv)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
724 |
// syntactically invalid module name: e.g. --add-modules m1,m! |
42269
24a766b7c106
8164590: javac --inherit-runtime-environment fails with "cannot find modules: ALL-DEFAULT"
jjg
parents:
42261
diff
changeset
|
725 |
log.error(Errors.BadNameForOption(Option.ADD_MODULES, moduleName)); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
726 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
727 |
break; |
36526 | 728 |
} |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
729 |
} |
36526 | 730 |
} |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
731 |
} |
36526 | 732 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
733 |
private void validateLimitModules(SourceVersion sv) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
734 |
String limitModules = options.get(Option.LIMIT_MODULES); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
735 |
if (limitModules != null) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
736 |
// Each entry must be of the form target-list where target-list is a |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
737 |
// comma separated list of module names, or ALL-DEFAULT, ALL-SYSTEM, |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
738 |
// or ALL-MODULE_PATH. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
739 |
// Empty items in the target list are ignored. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
740 |
// There must be at least one item in the list; this is handled in Option.LIMIT_EXPORTS. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
741 |
for (String moduleName : limitModules.split(",")) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
742 |
switch (moduleName) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
743 |
case "": |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
744 |
break; |
36526 | 745 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
746 |
default: |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
747 |
if (!SourceVersion.isName(moduleName, sv)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
748 |
// syntactically invalid module name: e.g. --limit-modules m1,m! |
42269
24a766b7c106
8164590: javac --inherit-runtime-environment fails with "cannot find modules: ALL-DEFAULT"
jjg
parents:
42261
diff
changeset
|
749 |
log.error(Errors.BadNameForOption(Option.LIMIT_MODULES, moduleName)); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
750 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
751 |
break; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
752 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
753 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
40308
diff
changeset
|
754 |
} |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
755 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
756 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
757 |
private void validateDefaultModuleForCreatedFiles(SourceVersion sv) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
758 |
String moduleName = options.get(Option.DEFAULT_MODULE_FOR_CREATED_FILES); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
759 |
if (moduleName != null) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
760 |
if (!SourceVersion.isName(moduleName, sv)) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
761 |
// syntactically invalid module name: e.g. --default-module-for-created-files m! |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
762 |
log.error(Errors.BadNameForOption(Option.DEFAULT_MODULE_FOR_CREATED_FILES, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
763 |
moduleName)); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
764 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
765 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
766 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43772
diff
changeset
|
767 |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
768 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
769 |
* Returns true if there are no files or classes specified for use. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
770 |
* @return true if there are no files or classes specified for use |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
771 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
772 |
public boolean isEmpty() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
773 |
return ((files == null) || files.isEmpty()) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
774 |
&& ((fileObjects == null) || fileObjects.isEmpty()) |
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
775 |
&& (classNames == null || classNames.isEmpty()); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
776 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
777 |
|
36526 | 778 |
public void allowEmpty() { |
779 |
this.emptyAllowed = true; |
|
780 |
} |
|
781 |
||
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
782 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
783 |
* Gets the file manager options which may have been deferred |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
784 |
* during processArgs. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
785 |
* @return the deferred file manager options |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
786 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
787 |
public Map<Option, String> getDeferredFileManagerOptions() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
788 |
return deferredFileManagerOptions; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
789 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
790 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
791 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
792 |
* Gets any options specifying plugins to be run. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
793 |
* @return options for plugins |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
794 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
795 |
public Set<List<String>> getPluginOpts() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
796 |
String plugins = options.get(Option.PLUGIN); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
797 |
if (plugins == null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
798 |
return Collections.emptySet(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
799 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
800 |
Set<List<String>> pluginOpts = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
801 |
for (String plugin: plugins.split("\\x00")) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
802 |
pluginOpts.add(List.from(plugin.split("\\s+"))); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
803 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
804 |
return Collections.unmodifiableSet(pluginOpts); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
805 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
806 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
807 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
808 |
* Gets any options specifying how doclint should be run. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
809 |
* An empty list is returned if no doclint options are specified |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
810 |
* or if the only doclint option is -Xdoclint:none. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
811 |
* @return options for doclint |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
812 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
813 |
public List<String> getDocLintOpts() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
814 |
String xdoclint = options.get(Option.XDOCLINT); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
815 |
String xdoclintCustom = options.get(Option.XDOCLINT_CUSTOM); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
816 |
if (xdoclint == null && xdoclintCustom == null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
817 |
return List.nil(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
818 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
819 |
Set<String> doclintOpts = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
820 |
if (xdoclint != null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
821 |
doclintOpts.add(DocLint.XMSGS_OPTION); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
822 |
if (xdoclintCustom != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
823 |
for (String s: xdoclintCustom.split("\\s+")) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
824 |
if (s.isEmpty()) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
825 |
continue; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
826 |
doclintOpts.add(DocLint.XMSGS_CUSTOM_PREFIX + s); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
827 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
828 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
829 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
830 |
if (doclintOpts.equals(Collections.singleton(DocLint.XMSGS_CUSTOM_PREFIX + "none"))) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
831 |
return List.nil(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
832 |
|
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
833 |
String checkPackages = options.get(Option.XDOCLINT_PACKAGE); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
834 |
if (checkPackages != null) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
835 |
for (String s : checkPackages.split("\\s+")) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
836 |
doclintOpts.add(DocLint.XCHECK_PACKAGE + s); |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
837 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
838 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
839 |
|
43145
35ee451a5fd3
8172474: javac should enable doclint checking for HTML 5
jjg
parents:
42822
diff
changeset
|
840 |
String format = options.get(Option.DOCLINT_FORMAT); |
35ee451a5fd3
8172474: javac should enable doclint checking for HTML 5
jjg
parents:
42822
diff
changeset
|
841 |
if (format != null) { |
35ee451a5fd3
8172474: javac should enable doclint checking for HTML 5
jjg
parents:
42822
diff
changeset
|
842 |
doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + format); |
35ee451a5fd3
8172474: javac should enable doclint checking for HTML 5
jjg
parents:
42822
diff
changeset
|
843 |
} |
35ee451a5fd3
8172474: javac should enable doclint checking for HTML 5
jjg
parents:
42822
diff
changeset
|
844 |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
845 |
// standard doclet normally generates H1, H2, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
846 |
// so for now, allow user comments to assume that |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
847 |
doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
848 |
return List.from(doclintOpts.toArray(new String[doclintOpts.size()])); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
849 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
850 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
851 |
private boolean checkDirectory(Option option) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
852 |
String value = options.get(option); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
853 |
if (value == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
854 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
855 |
} |
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
34752
diff
changeset
|
856 |
Path file = Paths.get(value); |
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
34752
diff
changeset
|
857 |
if (Files.exists(file) && !Files.isDirectory(file)) { |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
858 |
error("err.file.not.directory", value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
859 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
860 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
861 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
862 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
863 |
|
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
864 |
private interface ErrorReporter { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
865 |
void report(Option o); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
866 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
867 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
868 |
void checkOptionAllowed(boolean allowed, ErrorReporter r, Option... opts) { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
869 |
if (!allowed) { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
870 |
Stream.of(opts) |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
871 |
.filter(options :: isSet) |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
872 |
.forEach(r :: report); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
873 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
874 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29780
diff
changeset
|
875 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
876 |
void error(JCDiagnostic.Error error) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
877 |
errors = true; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
878 |
switch (errorMode) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
879 |
case ILLEGAL_ARGUMENT: { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
880 |
String msg = log.localize(error); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
881 |
throw new PropagatedException(new IllegalArgumentException(msg)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
882 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
883 |
case ILLEGAL_STATE: { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
884 |
String msg = log.localize(error); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
885 |
throw new PropagatedException(new IllegalStateException(msg)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
886 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
887 |
case LOG: |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
888 |
report(error); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
889 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
890 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
891 |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
892 |
void error(String key, Object... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
893 |
errors = true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
894 |
switch (errorMode) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
895 |
case ILLEGAL_ARGUMENT: { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
896 |
String msg = log.localize(PrefixKind.JAVAC, key, args); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
897 |
throw new PropagatedException(new IllegalArgumentException(msg)); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
898 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
899 |
case ILLEGAL_STATE: { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
900 |
String msg = log.localize(PrefixKind.JAVAC, key, args); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
901 |
throw new PropagatedException(new IllegalStateException(msg)); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
902 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
903 |
case LOG: |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
904 |
report(key, args); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
905 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
906 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
907 |
|
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
908 |
void error(Option.InvalidValueException f) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
909 |
String msg = f.getMessage(); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
910 |
errors = true; |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
911 |
switch (errorMode) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
912 |
case ILLEGAL_ARGUMENT: { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
913 |
throw new PropagatedException(new IllegalArgumentException(msg, f.getCause())); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
914 |
} |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
915 |
case ILLEGAL_STATE: { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
916 |
throw new PropagatedException(new IllegalStateException(msg, f.getCause())); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
917 |
} |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
918 |
case LOG: |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
919 |
log.printRawLines(ownName + ": " + msg); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
920 |
} |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
921 |
} |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41938
diff
changeset
|
922 |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
923 |
void warning(String key, Object... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
924 |
report(key, args); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
925 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
926 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
927 |
private void report(String key, Object... args) { |
36526 | 928 |
// Would be good to have support for -XDrawDiagnostics here |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
929 |
log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args)); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
930 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
931 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
932 |
private void report(JCDiagnostic.Error error) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
933 |
// Would be good to have support for -XDrawDiagnostics here |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
934 |
log.printRawLines(ownName + ": " + log.localize(error)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
935 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
936 |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
937 |
private JavaFileManager getFileManager() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
938 |
if (fileManager == null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
939 |
fileManager = context.get(JavaFileManager.class); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
940 |
return fileManager; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
941 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
942 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
943 |
<T> ListBuffer<T> toList(Iterable<? extends T> items) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
944 |
ListBuffer<T> list = new ListBuffer<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
945 |
if (items != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
946 |
for (T item : items) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
947 |
list.add(item); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
948 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
949 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
950 |
return list; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
951 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
952 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
953 |
<T> Set<T> toSet(Iterable<? extends T> items) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
954 |
Set<T> set = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
955 |
if (items != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
956 |
for (T item : items) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
957 |
set.add(item); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
958 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
959 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
960 |
return set; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
961 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
962 |
} |