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