author | jjg |
Fri, 22 Aug 2014 16:28:16 -0700 | |
changeset 26264 | a09fedde76be |
child 29427 | 44f4e6905b67 |
permissions | -rw-r--r-- |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
1 |
/* |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
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 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
25 |
package com.sun.tools.javac.main; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
26 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
27 |
import java.io.File; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
28 |
import java.util.Collections; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
29 |
import java.util.Iterator; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
30 |
import java.util.LinkedHashMap; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
31 |
import java.util.LinkedHashSet; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
32 |
import java.util.Map; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
33 |
import java.util.Set; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
34 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
35 |
import javax.tools.JavaFileManager; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
36 |
import javax.tools.JavaFileObject; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
37 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
38 |
import com.sun.tools.doclint.DocLint; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.code.Lint.LintCategory; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.code.Source; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.file.JavacFileManager; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.jvm.Profile; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
43 |
import com.sun.tools.javac.jvm.Target; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
44 |
import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
45 |
import com.sun.tools.javac.util.BaseFileManager; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
46 |
import com.sun.tools.javac.util.Context; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
47 |
import com.sun.tools.javac.util.List; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
48 |
import com.sun.tools.javac.util.ListBuffer; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
49 |
import com.sun.tools.javac.util.Log; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
50 |
import com.sun.tools.javac.util.Log.PrefixKind; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
51 |
import com.sun.tools.javac.util.Options; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
52 |
import com.sun.tools.javac.util.PropagatedException; |
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 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
55 |
* 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
|
56 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
57 |
public class Arguments { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
58 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
59 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
60 |
* The context key for the arguments. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
61 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
62 |
protected static final Context.Key<Arguments> argsKey = new Context.Key<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
63 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
64 |
private String ownName; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
65 |
private Set<String> classNames; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
66 |
private Set<File> files; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
67 |
private Map<Option, String> deferredFileManagerOptions; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
68 |
private Set<JavaFileObject> fileObjects; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
69 |
private final Options options; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
70 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
71 |
private JavaFileManager fileManager; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
72 |
private final Log log; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
73 |
private final Context context; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
74 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
75 |
private enum ErrorMode { ILLEGAL_ARGUMENT, ILLEGAL_STATE, LOG }; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
76 |
private ErrorMode errorMode; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
77 |
private boolean errors; |
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 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
80 |
* Gets the Arguments instance for this context. |
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 |
* @param context the content |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
83 |
* @return the Arguments instance for this context. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
84 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
85 |
public static Arguments instance(Context context) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
86 |
Arguments instance = context.get(argsKey); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
87 |
if (instance == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
88 |
instance = new Arguments(context); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
89 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
90 |
return instance; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
91 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
92 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
93 |
protected Arguments(Context context) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
94 |
context.put(argsKey, this); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
95 |
options = Options.instance(context); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
96 |
log = Log.instance(context); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
97 |
this.context = context; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
98 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
99 |
// 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
|
100 |
// needed, but right now, initializing a file manager triggers |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
101 |
// initialization of other items in the context, such as Lint |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
102 |
// and FSInfo, which should not be initialized until after |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
103 |
// processArgs |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
104 |
// fileManager = context.get(JavaFileManager.class); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
105 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
106 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
107 |
private final OptionHelper cmdLineHelper = new OptionHelper() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
108 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
109 |
public String get(Option option) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
110 |
return options.get(option); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
111 |
} |
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 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
114 |
public void put(String name, String value) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
115 |
options.put(name, value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
116 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
117 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
118 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
119 |
public void remove(String name) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
120 |
options.remove(name); |
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 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
123 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
124 |
public boolean handleFileManagerOption(Option option, String value) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
125 |
options.put(option.getText(), value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
126 |
deferredFileManagerOptions.put(option, value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
127 |
return true; |
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 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
131 |
public Log getLog() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
132 |
return log; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
133 |
} |
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 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
136 |
public String getOwnName() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
137 |
return ownName; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
138 |
} |
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 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
141 |
public void error(String key, Object... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
142 |
Arguments.this.error(key, args); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
143 |
} |
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 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
146 |
public void addFile(File f) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
147 |
files.add(f); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
148 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
149 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
150 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
151 |
public void addClassName(String s) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
152 |
classNames.add(s); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
153 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
154 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
155 |
}; |
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 |
* 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
|
159 |
* 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
|
160 |
* command line options, including -help, -version etc. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
161 |
* The args may also contain class names and filenames. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
162 |
* 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
|
163 |
* to the log. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
164 |
* @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
|
165 |
* @param args the args to be processed |
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 |
public void init(String ownName, String... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
168 |
this.ownName = ownName; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
169 |
errorMode = ErrorMode.LOG; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
170 |
files = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
171 |
deferredFileManagerOptions = new LinkedHashMap<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
172 |
fileObjects = null; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
173 |
classNames = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
174 |
processArgs(List.from(args), Option.getJavaCompilerOptions(), cmdLineHelper, true, false); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
175 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
176 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
177 |
private final OptionHelper apiHelper = new GrumpyHelper(null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
178 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
179 |
public String get(Option option) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
180 |
return options.get(option.getText()); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
181 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
182 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
183 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
184 |
public void put(String name, String value) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
185 |
options.put(name, value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
186 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
187 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
188 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
189 |
public void remove(String name) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
190 |
options.remove(name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
191 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
192 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
193 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
194 |
public void error(String key, Object... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
195 |
Arguments.this.error(key, args); |
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 |
@Override |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
199 |
public Log getLog() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
200 |
return Arguments.this.log; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
201 |
} |
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 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
205 |
* Initializes this Args instance with the parameters for a JavacTask. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
206 |
* 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
|
207 |
* of tool options, which does not include -help, -version, etc, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
208 |
* 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
|
209 |
* separately. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
210 |
* File manager options are handled directly by the file manager. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
211 |
* Any errors found while processing individual args will be reported |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
212 |
* via IllegalArgumentException. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
213 |
* Any subsequent errors during validate will be reported via IllegalStateException. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
214 |
* @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
|
215 |
* @param options the options to be processed |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
216 |
* @param classNames the classes to be subject to annotation processing |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
217 |
* @param files the files to be compiled |
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 |
public void init(String ownName, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
220 |
Iterable<String> options, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
221 |
Iterable<String> classNames, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
222 |
Iterable<? extends JavaFileObject> files) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
223 |
this.ownName = ownName; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
224 |
this.classNames = toSet(classNames); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
225 |
this.fileObjects = toSet(files); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
226 |
this.files = null; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
227 |
errorMode = ErrorMode.ILLEGAL_ARGUMENT; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
228 |
if (options != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
229 |
processArgs(toList(options), Option.getJavacToolOptions(), apiHelper, false, true); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
230 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
231 |
errorMode = ErrorMode.ILLEGAL_STATE; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
232 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
233 |
|
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 |
* Gets the files to be compiled. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
236 |
* @return the files to be compiled |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
237 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
238 |
public Set<JavaFileObject> getFileObjects() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
239 |
if (fileObjects == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
240 |
if (files == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
241 |
fileObjects = Collections.emptySet(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
242 |
} else { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
243 |
fileObjects = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
244 |
JavacFileManager jfm = (JavacFileManager) getFileManager(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
245 |
for (JavaFileObject fo: jfm.getJavaFileObjectsFromFiles(files)) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
246 |
fileObjects.add(fo); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
247 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
248 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
249 |
return fileObjects; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
250 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
251 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
252 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
253 |
* Gets the classes to be subject to annotation processing. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
254 |
* @return the classes to be subject to annotation processing |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
255 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
256 |
public Set<String> getClassNames() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
257 |
return classNames; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
258 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
259 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
260 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
261 |
* Processes strings containing options and operands. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
262 |
* @param args the strings to be processed |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
263 |
* @param allowableOpts the set of option declarations that are applicable |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
264 |
* @param helper a help for use by Option.process |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
265 |
* @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
|
266 |
* @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
|
267 |
* options which are not recognized by any of allowableOpts |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
268 |
* @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
|
269 |
* @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
|
270 |
* ILLEGAL_ARGUMENT |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
271 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
272 |
private boolean processArgs(Iterable<String> args, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
273 |
Set<Option> allowableOpts, OptionHelper helper, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
274 |
boolean allowOperands, boolean checkFileManager) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
275 |
JavaFileManager fm = checkFileManager ? getFileManager() : null; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
276 |
Iterator<String> argIter = args.iterator(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
277 |
while (argIter.hasNext()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
278 |
String arg = argIter.next(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
279 |
if (arg.isEmpty()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
280 |
error("err.invalid.flag", arg); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
281 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
282 |
} |
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 |
Option option = null; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
285 |
if (arg.startsWith("-")) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
286 |
for (Option o : allowableOpts) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
287 |
if (o.matches(arg)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
288 |
option = o; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
289 |
break; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
290 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
291 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
292 |
} else if (allowOperands && Option.SOURCEFILE.matches(arg)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
293 |
option = Option.SOURCEFILE; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
294 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
295 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
296 |
if (option == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
297 |
if (fm != null && fm.handleOption(arg, argIter)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
298 |
continue; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
299 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
300 |
error("err.invalid.flag", arg); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
301 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
302 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
303 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
304 |
if (option.hasArg()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
305 |
if (!argIter.hasNext()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
306 |
error("err.req.arg", arg); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
307 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
308 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
309 |
String operand = argIter.next(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
310 |
if (option.process(helper, arg, operand)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
311 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
312 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
313 |
} else { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
314 |
if (option.process(helper, arg)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
315 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
316 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
317 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
318 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
319 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
320 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
321 |
options.notifyListeners(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
322 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
323 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
324 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
325 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
326 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
327 |
* Validates the overall consistency of the options and operands |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
328 |
* processed by processOptions. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
329 |
* @return true if all args are successfully validating; false otherwise. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
330 |
* @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
|
331 |
* ILLEGAL_STATE |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
332 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
333 |
public boolean validate() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
334 |
if (isEmpty()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
335 |
// 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
|
336 |
// 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
|
337 |
if (options.isSet(Option.HELP) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
338 |
|| options.isSet(Option.X) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
339 |
|| options.isSet(Option.VERSION) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
340 |
|| options.isSet(Option.FULLVERSION)) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
341 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
342 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
343 |
if (JavaCompiler.explicitAnnotationProcessingRequested(options)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
344 |
error("err.no.source.files.classes"); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
345 |
} else { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
346 |
error("err.no.source.files"); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
347 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
348 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
349 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
350 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
351 |
if (!checkDirectory(Option.D)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
352 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
353 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
354 |
if (!checkDirectory(Option.S)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
355 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
356 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
357 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
358 |
String sourceString = options.get(Option.SOURCE); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
359 |
Source source = (sourceString != null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
360 |
? Source.lookup(sourceString) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
361 |
: Source.DEFAULT; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
362 |
String targetString = options.get(Option.TARGET); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
363 |
Target target = (targetString != null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
364 |
? Target.lookup(targetString) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
365 |
: Target.DEFAULT; |
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 |
// 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
|
368 |
// profiles are not aligned with J2SE targets; moreover, a |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
369 |
// single CLDC target may have many profiles. In addition, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
370 |
// this is needed for the continued functioning of the JSR14 |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
371 |
// prototype. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
372 |
if (Character.isDigit(target.name.charAt(0))) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
373 |
if (target.compareTo(source.requiredTarget()) < 0) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
374 |
if (targetString != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
375 |
if (sourceString == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
376 |
error("warn.target.default.source.conflict", |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
377 |
targetString, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
378 |
source.requiredTarget().name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
379 |
} else { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
380 |
error("warn.source.target.conflict", |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
381 |
sourceString, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
382 |
source.requiredTarget().name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
383 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
384 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
385 |
} else { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
386 |
target = source.requiredTarget(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
387 |
options.put("-target", target.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
388 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
389 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
390 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
391 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
392 |
String profileString = options.get(Option.PROFILE); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
393 |
if (profileString != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
394 |
Profile profile = Profile.lookup(profileString); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
395 |
if (!profile.isValid(target)) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
396 |
error("warn.profile.target.conflict", profileString, target.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
397 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
398 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
399 |
// This check is only effective in command line mode, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
400 |
// where the file manager options are added to options |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
401 |
if (options.get(Option.BOOTCLASSPATH) != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
402 |
error("err.profile.bootclasspath.conflict"); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
403 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
404 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
405 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
406 |
boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
407 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
408 |
if (lintOptions && source.compareTo(Source.DEFAULT) < 0) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
409 |
JavaFileManager fm = getFileManager(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
410 |
if (fm instanceof BaseFileManager) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
411 |
if (((BaseFileManager) fm).isDefaultBootClassPath()) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
412 |
log.warning(LintCategory.OPTIONS, "source.no.bootclasspath", source.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
413 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
414 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
415 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
416 |
boolean obsoleteOptionFound = false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
417 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
418 |
if (source.compareTo(Source.MIN) < 0) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
419 |
log.error("option.removed.source", source.name, Source.MIN.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
420 |
} else if (source == Source.MIN && lintOptions) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
421 |
log.warning(LintCategory.OPTIONS, "option.obsolete.source", source.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
422 |
obsoleteOptionFound = true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
423 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
424 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
425 |
if (target.compareTo(Target.MIN) < 0) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
426 |
log.error("option.removed.target", target.name, Target.MIN.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
427 |
} else if (target == Target.MIN && lintOptions) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
428 |
log.warning(LintCategory.OPTIONS, "option.obsolete.target", target.name); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
429 |
obsoleteOptionFound = true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
430 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
431 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
432 |
if (obsoleteOptionFound) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
433 |
log.warning(LintCategory.OPTIONS, "option.obsolete.suppression"); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
434 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
435 |
return !errors; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
436 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
437 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
438 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
439 |
* 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
|
440 |
* @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
|
441 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
442 |
public boolean isEmpty() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
443 |
return ((files == null) || files.isEmpty()) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
444 |
&& ((fileObjects == null) || fileObjects.isEmpty()) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
445 |
&& classNames.isEmpty(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
446 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
447 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
448 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
449 |
* Gets the file manager options which may have been deferred |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
450 |
* during processArgs. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
451 |
* @return the deferred file manager options |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
452 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
453 |
public Map<Option, String> getDeferredFileManagerOptions() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
454 |
return deferredFileManagerOptions; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
455 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
456 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
457 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
458 |
* Gets any options specifying plugins to be run. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
459 |
* @return options for plugins |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
460 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
461 |
public Set<List<String>> getPluginOpts() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
462 |
String plugins = options.get(Option.PLUGIN); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
463 |
if (plugins == null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
464 |
return Collections.emptySet(); |
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 |
Set<List<String>> pluginOpts = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
467 |
for (String plugin: plugins.split("\\x00")) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
468 |
pluginOpts.add(List.from(plugin.split("\\s+"))); |
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 |
return Collections.unmodifiableSet(pluginOpts); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
471 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
472 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
473 |
/** |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
474 |
* Gets any options specifying how doclint should be run. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
475 |
* 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
|
476 |
* or if the only doclint option is -Xdoclint:none. |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
477 |
* @return options for doclint |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
478 |
*/ |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
479 |
public List<String> getDocLintOpts() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
480 |
String xdoclint = options.get(Option.XDOCLINT); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
481 |
String xdoclintCustom = options.get(Option.XDOCLINT_CUSTOM); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
482 |
if (xdoclint == null && xdoclintCustom == null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
483 |
return List.nil(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
484 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
485 |
Set<String> doclintOpts = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
486 |
if (xdoclint != null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
487 |
doclintOpts.add(DocLint.XMSGS_OPTION); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
488 |
if (xdoclintCustom != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
489 |
for (String s: xdoclintCustom.split("\\s+")) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
490 |
if (s.isEmpty()) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
491 |
continue; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
492 |
doclintOpts.add(s.replace(Option.XDOCLINT_CUSTOM.text, DocLint.XMSGS_CUSTOM_PREFIX)); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
493 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
494 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
495 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
496 |
if (doclintOpts.equals(Collections.singleton(DocLint.XMSGS_CUSTOM_PREFIX + "none"))) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
497 |
return List.nil(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
498 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
499 |
// standard doclet normally generates H1, H2, |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
500 |
// so for now, allow user comments to assume that |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
501 |
doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
502 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
503 |
return List.from(doclintOpts.toArray(new String[doclintOpts.size()])); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
504 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
505 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
506 |
private boolean checkDirectory(Option option) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
507 |
String value = options.get(option); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
508 |
if (value == null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
509 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
510 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
511 |
File file = new File(value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
512 |
if (!file.exists()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
513 |
error("err.dir.not.found", value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
514 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
515 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
516 |
if (!file.isDirectory()) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
517 |
error("err.file.not.directory", value); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
518 |
return false; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
519 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
520 |
return true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
521 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
522 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
523 |
void error(String key, Object... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
524 |
errors = true; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
525 |
switch (errorMode) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
526 |
case ILLEGAL_ARGUMENT: { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
527 |
String msg = log.localize(PrefixKind.JAVAC, key, args); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
528 |
throw new PropagatedException(new IllegalArgumentException(msg)); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
529 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
530 |
case ILLEGAL_STATE: { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
531 |
String msg = log.localize(PrefixKind.JAVAC, key, args); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
532 |
throw new PropagatedException(new IllegalStateException(msg)); |
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 |
case LOG: |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
535 |
report(key, args); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
536 |
log.printLines(PrefixKind.JAVAC, "msg.usage", ownName); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
537 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
538 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
539 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
540 |
void warning(String key, Object... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
541 |
report(key, args); |
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 |
private void report(String key, Object... args) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
545 |
log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args)); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
546 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
547 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
548 |
private JavaFileManager getFileManager() { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
549 |
if (fileManager == null) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
550 |
fileManager = context.get(JavaFileManager.class); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
551 |
return fileManager; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
552 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
553 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
554 |
<T> ListBuffer<T> toList(Iterable<? extends T> items) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
555 |
ListBuffer<T> list = new ListBuffer<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
556 |
if (items != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
557 |
for (T item : items) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
558 |
list.add(item); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
559 |
} |
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 |
return list; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
562 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
563 |
|
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
564 |
<T> Set<T> toSet(Iterable<? extends T> items) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
565 |
Set<T> set = new LinkedHashSet<>(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
566 |
if (items != null) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
567 |
for (T item : items) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
568 |
set.add(item); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
569 |
} |
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 |
return set; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
572 |
} |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff
changeset
|
573 |
} |