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