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