langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java
author jjg
Thu, 03 Nov 2016 13:59:15 -0700
changeset 41938 8e66bf10fcec
parent 40308 274367a99f98
child 42407 f3702cff2933
child 42260 2b4da2bf6660
permissions -rw-r--r--
8167975: align javac --add-* modules options with launcher Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     1
/*
36157
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 34752
diff changeset
     2
 * Copyright (c) 1999, 2016, 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
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    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
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    35
import java.util.EnumSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    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
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    42
import java.util.regex.Matcher;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    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
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    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
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    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
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 31506
diff changeset
    63
import com.sun.tools.javac.platform.PlatformUtils;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    64
import com.sun.tools.javac.resources.CompilerProperties.Errors;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    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
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
    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
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   164
        public void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   165
            Arguments.this.error(key, args);
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
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   169
        public void error(JCDiagnostic.Error error) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   170
            Arguments.this.error(error);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   171
        }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   172
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   173
        @Override
36157
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 34752
diff changeset
   174
        public void addFile(Path p) {
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 34752
diff changeset
   175
            files.add(p);
26264
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
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 void addClassName(String s) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   180
            classNames.add(s);
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
    };
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
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   186
     * 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
   187
     * 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
   188
     * command line options, including -help, -version etc.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   189
     * The args may also contain class names and filenames.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   190
     * 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
   191
     * to the log.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   192
     * @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
   193
     * @param args the args to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   194
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   195
    public void init(String ownName, String... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   196
        this.ownName = ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   197
        errorMode = ErrorMode.LOG;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   198
        files = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   199
        deferredFileManagerOptions = new LinkedHashMap<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   200
        fileObjects = null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   201
        classNames = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   202
        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
   203
        if (errors) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   204
            log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   205
        }
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   206
    }
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
    private final OptionHelper apiHelper = new GrumpyHelper(null) {
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 String get(Option option) {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   211
            return options.get(option);
26264
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 void put(String name, String value) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   216
            options.put(name, value);
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
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   220
        public void remove(String name) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   221
            options.remove(name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   222
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   223
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   224
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   225
        public void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   226
            Arguments.this.error(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   227
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   228
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   229
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   230
        public Log getLog() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   231
            return Arguments.this.log;
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
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   236
     * Initializes this Args instance with the parameters for a JavacTask.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   237
     * 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
   238
     * of tool options, which does not include -help, -version, etc,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   239
     * 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
   240
     * separately.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   241
     * File manager options are handled directly by the file manager.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   242
     * Any errors found while processing individual args will be reported
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   243
     * via IllegalArgumentException.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   244
     * Any subsequent errors during validate will be reported via IllegalStateException.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   245
     * @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
   246
     * @param options the options to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   247
     * @param classNames the classes to be subject to annotation processing
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   248
     * @param files the files to be compiled
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
    public void init(String ownName,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   251
            Iterable<String> options,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   252
            Iterable<String> classNames,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   253
            Iterable<? extends JavaFileObject> files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   254
        this.ownName = ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   255
        this.classNames = toSet(classNames);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   256
        this.fileObjects = toSet(files);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   257
        this.files = null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   258
        errorMode = ErrorMode.ILLEGAL_ARGUMENT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   259
        if (options != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   260
            processArgs(toList(options), Option.getJavacToolOptions(), apiHelper, false, true);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   261
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   262
        errorMode = ErrorMode.ILLEGAL_STATE;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   263
    }
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
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   266
     * Gets the files to be compiled.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   267
     * @return the files to be compiled
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   268
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   269
    public Set<JavaFileObject> getFileObjects() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   270
        if (fileObjects == null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   271
            fileObjects = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   272
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   273
        if (files != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   274
            JavacFileManager jfm = (JavacFileManager) getFileManager();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   275
            for (JavaFileObject fo: jfm.getJavaFileObjectsFromPaths(files))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   276
                fileObjects.add(fo);
26264
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
        return fileObjects;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   279
    }
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
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   282
     * Gets the classes to be subject to annotation processing.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   283
     * @return the classes to be subject to annotation processing
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
    public Set<String> getClassNames() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   286
        return classNames;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   287
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   288
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   289
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   290
     * Processes strings containing options and operands.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   291
     * @param args the strings to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   292
     * @param allowableOpts the set of option declarations that are applicable
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   293
     * @param helper a help for use by Option.process
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   294
     * @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
   295
     * @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
   296
     *      options which are not recognized by any of allowableOpts
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   297
     * @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
   298
     * @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
   299
     *      ILLEGAL_ARGUMENT
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   300
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   301
    private boolean processArgs(Iterable<String> args,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   302
            Set<Option> allowableOpts, OptionHelper helper,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   303
            boolean allowOperands, boolean checkFileManager) {
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   304
        if (!doProcessArgs(args, allowableOpts, helper, allowOperands, checkFileManager))
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   305
            return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   306
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   307
        String platformString = options.get(Option.RELEASE);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   308
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   309
        checkOptionAllowed(platformString == null,
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   310
                option -> error("err.release.bootclasspath.conflict", option.getPrimaryName()),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   311
                Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   312
                Option.XBOOTCLASSPATH_PREPEND,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   313
                Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   314
                Option.EXTDIRS, Option.DJAVA_EXT_DIRS,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   315
                Option.SOURCE, Option.TARGET);
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   316
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   317
        if (platformString != null) {
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 31506
diff changeset
   318
            PlatformDescription platformDescription = PlatformUtils.lookupPlatformDescription(platformString);
31506
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
            if (platformDescription == null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   321
                error("err.unsupported.release.version", platformString);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   322
                return false;
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
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   325
            options.put(Option.SOURCE, platformDescription.getSourceVersion());
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   326
            options.put(Option.TARGET, platformDescription.getTargetVersion());
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   327
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   328
            context.put(PlatformDescription.class, platformDescription);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   329
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   330
            if (!doProcessArgs(platformDescription.getAdditionalOptions(), allowableOpts, helper, allowOperands, checkFileManager))
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   331
                return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   332
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   333
            Collection<Path> platformCP = platformDescription.getPlatformPath();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   334
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   335
            if (platformCP != null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   336
                JavaFileManager fm = getFileManager();
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
                if (!(fm instanceof StandardJavaFileManager)) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   339
                    error("err.release.not.standard.file.manager");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   340
                    return false;
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
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   343
                try {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   344
                    StandardJavaFileManager sfm = (StandardJavaFileManager) fm;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   345
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   346
                    sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   347
                } catch (IOException ex) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   348
                    log.printLines(PrefixKind.JAVAC, "msg.io");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   349
                    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   350
                    return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   351
                }
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
        }
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
        options.notifyListeners();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   356
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   357
        return true;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   358
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   359
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   360
    private boolean doProcessArgs(Iterable<String> args,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   361
            Set<Option> allowableOpts, OptionHelper helper,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   362
            boolean allowOperands, boolean checkFileManager) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   363
        JavaFileManager fm = checkFileManager ? getFileManager() : null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   364
        Iterator<String> argIter = args.iterator();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   365
        while (argIter.hasNext()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   366
            String arg = argIter.next();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   367
            if (arg.isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   368
                error("err.invalid.flag", arg);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   369
                return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   370
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   371
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   372
            Option option = null;
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   373
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   374
            // first, check the provided set of javac options
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   375
            if (arg.startsWith("-")) {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   376
                option = Option.lookup(arg, allowableOpts);
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   377
            } else if (allowOperands && Option.SOURCEFILE.matches(arg)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   378
                option = Option.SOURCEFILE;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   379
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   380
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   381
            if (option != null) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   382
                if (!option.handleOption(helper, arg, argIter)) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   383
                    return false;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   384
                }
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   385
                continue;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   386
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   387
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   388
            // check file manager option
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   389
            if (fm != null && fm.handleOption(arg, argIter)) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   390
                continue;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   391
            }
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   392
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   393
            // none of the above
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   394
            error("err.invalid.flag", arg);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   395
            return false;
26264
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
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   398
        return true;
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
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   402
     * Validates the overall consistency of the options and operands
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   403
     * processed by processOptions.
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   404
     * @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
   405
     * @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
   406
     *      ILLEGAL_STATE
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
    public boolean validate() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   409
        JavaFileManager fm = getFileManager();
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   410
        if (options.isSet(Option.MODULE)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   411
            if (!fm.hasLocation(StandardLocation.CLASS_OUTPUT)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   412
                log.error(Errors.OutputDirMustBeSpecifiedWithDashMOption);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   413
            } else if (!fm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   414
                log.error(Errors.ModulesourcepathMustBeSpecifiedWithDashMOption);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   415
            } else {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   416
                java.util.List<String> modules = Arrays.asList(options.get(Option.MODULE).split(","));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   417
                try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   418
                    for (String module : modules) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   419
                        Location sourceLoc = fm.getModuleLocation(StandardLocation.MODULE_SOURCE_PATH, module);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   420
                        if (sourceLoc == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   421
                            log.error(Errors.ModuleNotFoundInModuleSourcePath(module));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   422
                        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   423
                            Location classLoc = fm.getModuleLocation(StandardLocation.CLASS_OUTPUT, module);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   424
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   425
                            for (JavaFileObject file : fm.list(sourceLoc, "", EnumSet.of(JavaFileObject.Kind.SOURCE), true)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   426
                                String className = fm.inferBinaryName(sourceLoc, file);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   427
                                JavaFileObject classFile = fm.getJavaFileForInput(classLoc, className, Kind.CLASS);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   428
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   429
                                if (classFile == null || classFile.getLastModified() < file.getLastModified()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   430
                                    if (fileObjects == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   431
                                        fileObjects = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   432
                                    fileObjects.add(file);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   433
                                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   434
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   435
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   436
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   437
                } catch (IOException ex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   438
                    log.printLines(PrefixKind.JAVAC, "msg.io");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   439
                    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   440
                    return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   441
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   442
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   443
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   444
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   445
        if (isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   446
            // 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
   447
            // 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
   448
            if (options.isSet(Option.HELP)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   449
                || options.isSet(Option.X)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   450
                || options.isSet(Option.VERSION)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   451
                || options.isSet(Option.FULLVERSION)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   452
                || options.isSet(Option.MODULE))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   453
                return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   454
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   455
            if (emptyAllowed)
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   456
                return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   457
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   458
            if (!errors) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   459
                if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   460
                    error("err.no.source.files.classes");
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   461
                } else {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   462
                    error("err.no.source.files");
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   463
                }
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   464
            }
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   465
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   466
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   467
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   468
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   469
        if (!checkDirectory(Option.D)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   470
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   471
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   472
        if (!checkDirectory(Option.S)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   473
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   474
        }
34480
124ac002c969 8143268: Langtools tools should create output directories as needed.
jjg
parents: 32454
diff changeset
   475
        if (!checkDirectory(Option.H)) {
124ac002c969 8143268: Langtools tools should create output directories as needed.
jjg
parents: 32454
diff changeset
   476
            return false;
124ac002c969 8143268: Langtools tools should create output directories as needed.
jjg
parents: 32454
diff changeset
   477
        }
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   478
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   479
        // The following checks are to help avoid accidental confusion between
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   480
        // directories of modules and exploded module directories.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   481
        if (fm instanceof StandardJavaFileManager) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   482
            StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   483
            if (sfm.hasLocation(StandardLocation.CLASS_OUTPUT)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   484
                Path outDir = sfm.getLocationAsPaths(StandardLocation.CLASS_OUTPUT).iterator().next();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   485
                if (sfm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   486
                    // multi-module mode
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   487
                    if (Files.exists(outDir.resolve("module-info.class"))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   488
                        log.error(Errors.MultiModuleOutdirCannotBeExplodedModule(outDir));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   489
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   490
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   491
                    // single-module or legacy mode
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   492
                    boolean lintPaths = options.isUnset(Option.XLINT_CUSTOM,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   493
                            "-" + LintCategory.PATH.option);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   494
                    if (lintPaths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   495
                        Path outDirParent = outDir.getParent();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   496
                        if (outDirParent != null && Files.exists(outDirParent.resolve("module-info.class"))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   497
                            log.warning(LintCategory.PATH, Warnings.OutdirIsInExplodedModule(outDir));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   498
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   499
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   500
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   501
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   502
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   503
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   504
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   505
        String sourceString = options.get(Option.SOURCE);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   506
        Source source = (sourceString != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   507
                ? Source.lookup(sourceString)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   508
                : Source.DEFAULT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   509
        String targetString = options.get(Option.TARGET);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   510
        Target target = (targetString != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   511
                ? Target.lookup(targetString)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   512
                : Target.DEFAULT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   513
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   514
        // We don't check source/target consistency for CLDC, as J2ME
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   515
        // profiles are not aligned with J2SE targets; moreover, a
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   516
        // single CLDC target may have many profiles.  In addition,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   517
        // this is needed for the continued functioning of the JSR14
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   518
        // prototype.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   519
        if (Character.isDigit(target.name.charAt(0))) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   520
            if (target.compareTo(source.requiredTarget()) < 0) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   521
                if (targetString != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   522
                    if (sourceString == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   523
                        error("warn.target.default.source.conflict",
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   524
                                targetString,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   525
                                source.requiredTarget().name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   526
                    } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   527
                        error("warn.source.target.conflict",
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   528
                                sourceString,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   529
                                source.requiredTarget().name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   530
                    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   531
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   532
                } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   533
                    target = source.requiredTarget();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   534
                    options.put("-target", target.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   535
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   536
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   537
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   538
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   539
        String profileString = options.get(Option.PROFILE);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   540
        if (profileString != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   541
            Profile profile = Profile.lookup(profileString);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   542
            if (!profile.isValid(target)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   543
                error("warn.profile.target.conflict", profileString, target.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   544
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   545
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   546
            // This check is only effective in command line mode,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   547
            // where the file manager options are added to options
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   548
            if (options.get(Option.BOOT_CLASS_PATH) != null) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   549
                error("err.profile.bootclasspath.conflict");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   550
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   551
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   552
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   553
        if (options.isSet(Option.SOURCE_PATH) && options.isSet(Option.MODULE_SOURCE_PATH)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   554
            error("err.sourcepath.modulesourcepath.conflict");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   555
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   556
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   557
        boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   558
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   559
        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
   560
            if (fm instanceof BaseFileManager) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   561
                if (((BaseFileManager) fm).isDefaultBootClassPath())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   562
                    log.warning(LintCategory.OPTIONS, "source.no.bootclasspath", source.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   563
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   564
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   565
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   566
        boolean obsoleteOptionFound = false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   567
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   568
        if (source.compareTo(Source.MIN) < 0) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   569
            log.error(Errors.OptionRemovedSource(source.name, Source.MIN.name));
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   570
        } else if (source == Source.MIN && lintOptions) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   571
            log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteSource(source.name));
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   572
            obsoleteOptionFound = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   573
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   574
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   575
        if (target.compareTo(Target.MIN) < 0) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   576
            log.error(Errors.OptionRemovedTarget(target.name, Target.MIN.name));
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   577
        } else if (target == Target.MIN && lintOptions) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   578
            log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteTarget(target.name));
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   579
            obsoleteOptionFound = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   580
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   581
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   582
        final Target t = target;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   583
        checkOptionAllowed(t.compareTo(Target.JDK1_8) <= 0,
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   584
                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
   585
                Option.BOOT_CLASS_PATH,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   586
                Option.XBOOTCLASSPATH_PREPEND, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   587
                Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   588
                Option.EXTDIRS, Option.DJAVA_EXT_DIRS);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   589
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   590
        checkOptionAllowed(t.compareTo(Target.JDK1_9) >= 0,
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   591
                option -> error("err.option.not.allowed.with.target", option.getPrimaryName(), t.name),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   592
                Option.MODULE_SOURCE_PATH, Option.UPGRADE_MODULE_PATH,
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   593
                Option.SYSTEM, Option.MODULE_PATH, Option.ADD_MODULES, Option.LIMIT_MODULES,
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   594
                Option.PATCH_MODULE);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   595
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   596
        if (fm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   597
            if (!options.isSet(Option.PROC, "only")
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   598
                    && !fm.hasLocation(StandardLocation.CLASS_OUTPUT)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   599
                log.error(Errors.NoOutputDir);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   600
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   601
            if (options.isSet(Option.XMODULE)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   602
                log.error(Errors.XmoduleNoModuleSourcepath);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   603
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   604
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   605
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   606
        if (fm.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH) &&
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   607
            fm.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   608
            log.error(Errors.ProcessorpathNoProcessormodulepath);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   609
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   610
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   611
        if (obsoleteOptionFound)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   612
            log.warning(LintCategory.OPTIONS, "option.obsolete.suppression");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   613
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   614
        SourceVersion sv = Source.toSourceVersion(source);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   615
        validateAddExports(sv);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   616
        validateAddModules(sv);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   617
        validateAddReads(sv);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   618
        validateLimitModules(sv);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   619
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   620
        return !errors && (log.nerrors == 0);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   621
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   622
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   623
    private void validateAddExports(SourceVersion sv) {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   624
        String addExports = options.get(Option.ADD_EXPORTS);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   625
        if (addExports != null) {
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   626
            // 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
   627
            // 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
   628
            // Empty items in the target-list are ignored.
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   629
            // 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
   630
            Pattern p = Option.ADD_EXPORTS.getPattern();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   631
            for (String e : addExports.split("\0")) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   632
                Matcher m = p.matcher(e);
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   633
                if (m.matches()) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   634
                    String sourceModuleName = m.group(1);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   635
                    if (!SourceVersion.isName(sourceModuleName, sv)) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   636
                        // 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
   637
                        log.warning(Warnings.BadNameForOption(Option.ADD_EXPORTS, sourceModuleName));
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   638
                    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   639
                    String sourcePackageName = m.group(2);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   640
                    if (!SourceVersion.isName(sourcePackageName, sv)) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   641
                        // 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
   642
                        log.warning(Warnings.BadNameForOption(Option.ADD_EXPORTS, sourcePackageName));
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   643
                    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   644
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   645
                    String targetNames = m.group(3);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   646
                    for (String targetName : targetNames.split(",")) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   647
                        switch (targetName) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   648
                            case "":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   649
                            case "ALL-UNNAMED":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   650
                                break;
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   651
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   652
                            default:
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   653
                                if (!SourceVersion.isName(targetName, sv)) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   654
                                    // 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
   655
                                    log.warning(Warnings.BadNameForOption(Option.ADD_EXPORTS, targetName));
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   656
                                }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   657
                                break;
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   658
                        }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   659
                    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   660
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   661
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   662
        }
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   663
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   664
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   665
    private void validateAddReads(SourceVersion sv) {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   666
        String addReads = options.get(Option.ADD_READS);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   667
        if (addReads != null) {
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   668
            // 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
   669
            // comma-separated list of module or ALL-UNNAMED.
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   670
            // Empty items in the target list are ignored.
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   671
            // 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
   672
            Pattern p = Option.ADD_READS.getPattern();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   673
            for (String e : addReads.split("\0")) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   674
                Matcher m = p.matcher(e);
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   675
                if (m.matches()) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   676
                    String sourceName = m.group(1);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   677
                    if (!SourceVersion.isName(sourceName, sv)) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   678
                        // syntactically invalid source name:  e.g. --add-reads m!=m2
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   679
                        log.warning(Warnings.BadNameForOption(Option.ADD_READS, sourceName));
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   680
                    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   681
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   682
                    String targetNames = m.group(2);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   683
                    for (String targetName : targetNames.split(",", -1)) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   684
                        switch (targetName) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   685
                            case "":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   686
                            case "ALL-UNNAMED":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   687
                                break;
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   688
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   689
                            default:
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   690
                                if (!SourceVersion.isName(targetName, sv)) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   691
                                    // syntactically invalid target name:  e.g. --add-reads m1=m!
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   692
                                    log.warning(Warnings.BadNameForOption(Option.ADD_READS, targetName));
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   693
                                }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   694
                                break;
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   695
                        }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   696
                    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   697
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   698
            }
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   699
        }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   700
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   701
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   702
    private void validateAddModules(SourceVersion sv) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   703
        String addModules = options.get(Option.ADD_MODULES);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   704
        if (addModules != null) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   705
            // 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
   706
            // 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
   707
            // or ALL-MODULE_PATH.
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   708
            // Empty items in the target list are ignored.
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   709
            // 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
   710
            for (String moduleName : addModules.split(",")) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   711
                switch (moduleName) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   712
                    case "":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   713
                    case "ALL-DEFAULT":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   714
                    case "ALL-SYSTEM":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   715
                    case "ALL-MODULE-PATH":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   716
                        break;
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   717
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   718
                    default:
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   719
                        if (!SourceVersion.isName(moduleName, sv)) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   720
                            // syntactically invalid module name:  e.g. --add-modules m1,m!
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   721
                            log.warning(Warnings.BadNameForOption(Option.ADD_MODULES, moduleName));
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   722
                        }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   723
                        break;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   724
                }
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   725
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   726
        }
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   727
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   728
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   729
    private void validateLimitModules(SourceVersion sv) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   730
        String limitModules = options.get(Option.LIMIT_MODULES);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   731
        if (limitModules != null) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   732
            // 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
   733
            // 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
   734
            // or ALL-MODULE_PATH.
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   735
            // Empty items in the target list are ignored.
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   736
            // 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
   737
            for (String moduleName : limitModules.split(",")) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   738
                switch (moduleName) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   739
                    case "":
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   740
                        break;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   741
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   742
                    default:
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   743
                        if (!SourceVersion.isName(moduleName, sv)) {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   744
                            // syntactically invalid module name:  e.g. --limit-modules m1,m!
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   745
                            log.warning(Warnings.BadNameForOption(Option.LIMIT_MODULES, moduleName));
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   746
                        }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   747
                        break;
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
            }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 40308
diff changeset
   750
        }
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   751
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   752
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
     * 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
   755
     * @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
   756
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   757
    public boolean isEmpty() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   758
        return ((files == null) || files.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   759
                && ((fileObjects == null) || fileObjects.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   760
                && classNames.isEmpty();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   761
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   762
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   763
    public void allowEmpty() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   764
        this.emptyAllowed = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   765
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   766
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   767
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   768
     * Gets the file manager options which may have been deferred
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   769
     * during processArgs.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   770
     * @return the deferred file manager options
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   771
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   772
    public Map<Option, String> getDeferredFileManagerOptions() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   773
        return deferredFileManagerOptions;
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
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   776
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   777
     * Gets any options specifying plugins to be run.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   778
     * @return options for plugins
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   779
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   780
    public Set<List<String>> getPluginOpts() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   781
        String plugins = options.get(Option.PLUGIN);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   782
        if (plugins == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   783
            return Collections.emptySet();
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
        Set<List<String>> pluginOpts = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   786
        for (String plugin: plugins.split("\\x00")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   787
            pluginOpts.add(List.from(plugin.split("\\s+")));
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
        return Collections.unmodifiableSet(pluginOpts);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   790
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   791
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   792
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   793
     * Gets any options specifying how doclint should be run.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   794
     * 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
   795
     * or if the only doclint option is -Xdoclint:none.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   796
     * @return options for doclint
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
    public List<String> getDocLintOpts() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   799
        String xdoclint = options.get(Option.XDOCLINT);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   800
        String xdoclintCustom = options.get(Option.XDOCLINT_CUSTOM);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   801
        if (xdoclint == null && xdoclintCustom == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   802
            return List.nil();
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
        Set<String> doclintOpts = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   805
        if (xdoclint != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   806
            doclintOpts.add(DocLint.XMSGS_OPTION);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   807
        if (xdoclintCustom != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   808
            for (String s: xdoclintCustom.split("\\s+")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   809
                if (s.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   810
                    continue;
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   811
                doclintOpts.add(DocLint.XMSGS_CUSTOM_PREFIX + s);
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   812
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   813
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   814
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   815
        if (doclintOpts.equals(Collections.singleton(DocLint.XMSGS_CUSTOM_PREFIX + "none")))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   816
            return List.nil();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   817
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   818
        String checkPackages = options.get(Option.XDOCLINT_PACKAGE);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   819
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   820
        if (checkPackages != null) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   821
            for (String s : checkPackages.split("\\s+")) {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   822
                doclintOpts.add(DocLint.XCHECK_PACKAGE + s);
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   823
            }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   824
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   825
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   826
        // standard doclet normally generates H1, H2,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   827
        // so for now, allow user comments to assume that
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   828
        doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   829
        return List.from(doclintOpts.toArray(new String[doclintOpts.size()]));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   830
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   831
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   832
    private boolean checkDirectory(Option option) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   833
        String value = options.get(option);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   834
        if (value == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   835
            return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   836
        }
36157
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 34752
diff changeset
   837
        Path file = Paths.get(value);
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 34752
diff changeset
   838
        if (Files.exists(file) && !Files.isDirectory(file)) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   839
            error("err.file.not.directory", value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   840
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   841
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   842
        return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   843
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   844
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   845
    private interface ErrorReporter {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   846
        void report(Option o);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   847
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   848
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   849
    void checkOptionAllowed(boolean allowed, ErrorReporter r, Option... opts) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   850
        if (!allowed) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   851
            Stream.of(opts)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   852
                  .filter(options :: isSet)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   853
                  .forEach(r :: report);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   854
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   855
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   856
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   857
    void error(JCDiagnostic.Error error) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   858
        errors = true;
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   859
        switch (errorMode) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   860
            case ILLEGAL_ARGUMENT: {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   861
                String msg = log.localize(error);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   862
                throw new PropagatedException(new IllegalArgumentException(msg));
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   863
            }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   864
            case ILLEGAL_STATE: {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   865
                String msg = log.localize(error);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   866
                throw new PropagatedException(new IllegalStateException(msg));
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   867
            }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   868
            case LOG:
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   869
                report(error);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   870
        }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   871
    }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   872
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   873
    void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   874
        errors = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   875
        switch (errorMode) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   876
            case ILLEGAL_ARGUMENT: {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   877
                String msg = log.localize(PrefixKind.JAVAC, key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   878
                throw new PropagatedException(new IllegalArgumentException(msg));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   879
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   880
            case ILLEGAL_STATE: {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   881
                String msg = log.localize(PrefixKind.JAVAC, key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   882
                throw new PropagatedException(new IllegalStateException(msg));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   883
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   884
            case LOG:
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   885
                report(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   886
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   887
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   888
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   889
    void warning(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   890
        report(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   891
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   892
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   893
    private void report(String key, Object... args) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36157
diff changeset
   894
        // Would be good to have support for -XDrawDiagnostics here
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   895
        log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
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
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   898
    private void report(JCDiagnostic.Error error) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   899
        // 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
   900
        log.printRawLines(ownName + ": " + log.localize(error));
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   901
    }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
   902
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   903
    private JavaFileManager getFileManager() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   904
        if (fileManager == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   905
            fileManager = context.get(JavaFileManager.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   906
        return fileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   907
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   908
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   909
    <T> ListBuffer<T> toList(Iterable<? extends T> items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   910
        ListBuffer<T> list = new ListBuffer<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   911
        if (items != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   912
            for (T item : items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   913
                list.add(item);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   914
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   915
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   916
        return list;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   917
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   918
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   919
    <T> Set<T> toSet(Iterable<? extends T> items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   920
        Set<T> set = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   921
        if (items != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   922
            for (T item : items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   923
                set.add(item);
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
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   926
        return set;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   927
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   928
}