langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java
author jlahoda
Wed, 01 Jul 2015 09:51:48 +0200
changeset 31506 4e07f827a794
parent 29780 8f8e54a1fa20
child 31936 02f1cfc234a0
permissions -rw-r--r--
8072480: javac should support compilation for a specific platform version Summary: Adding a new javac option for compiling for JDK N: -release N; including history data for previous version of JDK. Reviewed-by: erikj, ihse, jjg, mcimadamore, mr Contributed-by: jan.lahoda@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com
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
/*
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     4
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    10
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    15
 * accompanied this code).
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    16
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    20
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    23
 * questions.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    24
 */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    25
package com.sun.tools.javac.main;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    26
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    27
import java.io.File;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    28
import java.io.IOException;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    29
import java.nio.file.Path;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    30
import java.util.Collection;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    31
import java.util.Collections;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    32
import java.util.Iterator;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    33
import java.util.LinkedHashMap;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    34
import java.util.LinkedHashSet;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    35
import java.util.Map;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    36
import java.util.Optional;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    37
import java.util.ServiceLoader;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    38
import java.util.Set;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    39
import java.util.stream.Stream;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    40
import java.util.stream.StreamSupport;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    41
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    42
import javax.tools.JavaFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    43
import javax.tools.JavaFileObject;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    44
import javax.tools.StandardJavaFileManager;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    45
import javax.tools.StandardLocation;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    46
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    47
import com.sun.tools.doclint.DocLint;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    48
import com.sun.tools.javac.code.Lint.LintCategory;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    49
import com.sun.tools.javac.code.Source;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    50
import com.sun.tools.javac.file.BaseFileManager;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    51
import com.sun.tools.javac.file.JavacFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    52
import com.sun.tools.javac.jvm.Profile;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    53
import com.sun.tools.javac.jvm.Target;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    54
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
    55
import com.sun.tools.javac.platform.PlatformDescription;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    56
import com.sun.tools.javac.platform.PlatformProvider;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    57
import com.sun.tools.javac.platform.PlatformProvider.PlatformNotSupported;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    58
import com.sun.tools.javac.util.Context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    59
import com.sun.tools.javac.util.List;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    60
import com.sun.tools.javac.util.ListBuffer;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    61
import com.sun.tools.javac.util.Log;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    62
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
    63
import com.sun.tools.javac.util.Log.WriterKind;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    64
import com.sun.tools.javac.util.Options;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    65
import com.sun.tools.javac.util.PropagatedException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    66
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    67
/**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    68
 * 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
    69
 */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    70
public class Arguments {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    71
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    72
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    73
     * The context key for the arguments.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    74
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    75
    protected static final Context.Key<Arguments> argsKey = new Context.Key<>();
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
    private String ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    78
    private Set<String> classNames;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    79
    private Set<File> files;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    80
    private Map<Option, String> deferredFileManagerOptions;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    81
    private Set<JavaFileObject> fileObjects;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    82
    private final Options options;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    83
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    84
    private JavaFileManager fileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    85
    private final Log log;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    86
    private final Context context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    87
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    88
    private enum ErrorMode { ILLEGAL_ARGUMENT, ILLEGAL_STATE, LOG };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    89
    private ErrorMode errorMode;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    90
    private boolean errors;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    91
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    92
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    93
     * Gets the Arguments instance for this context.
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
     * @param context the content
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    96
     * @return the Arguments instance for this context.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    97
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    98
    public static Arguments instance(Context context) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    99
        Arguments instance = context.get(argsKey);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   100
        if (instance == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   101
            instance = new Arguments(context);
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
        return instance;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   104
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   105
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   106
    protected Arguments(Context context) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   107
        context.put(argsKey, this);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   108
        options = Options.instance(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   109
        log = Log.instance(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   110
        this.context = context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   111
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   112
        // 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
   113
        // needed, but right now, initializing a file manager triggers
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   114
        // initialization of other items in the context, such as Lint
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   115
        // and FSInfo, which should not be initialized until after
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   116
        // processArgs
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   117
        //        fileManager = context.get(JavaFileManager.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   118
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   119
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   120
    private final OptionHelper cmdLineHelper = new OptionHelper() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   121
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   122
        public String get(Option option) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   123
            return options.get(option);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   124
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   125
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   126
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   127
        public void put(String name, String value) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   128
            options.put(name, value);
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
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   132
        public void remove(String name) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   133
            options.remove(name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   134
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   135
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   136
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   137
        public boolean handleFileManagerOption(Option option, String value) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   138
            options.put(option.getText(), value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   139
            deferredFileManagerOptions.put(option, value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   140
            return true;
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
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   143
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   144
        public Log getLog() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   145
            return log;
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
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   148
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   149
        public String getOwnName() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   150
            return ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   151
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   152
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   153
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   154
        public void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   155
            Arguments.this.error(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   156
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   157
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   158
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   159
        public void addFile(File f) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   160
            files.add(f);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   161
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   162
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   163
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   164
        public void addClassName(String s) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   165
            classNames.add(s);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   166
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   167
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   168
    };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   169
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   170
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   171
     * 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
   172
     * 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
   173
     * command line options, including -help, -version etc.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   174
     * The args may also contain class names and filenames.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   175
     * 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
   176
     * to the log.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   177
     * @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
   178
     * @param args the args to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   179
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   180
    public void init(String ownName, String... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   181
        this.ownName = ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   182
        errorMode = ErrorMode.LOG;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   183
        files = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   184
        deferredFileManagerOptions = new LinkedHashMap<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   185
        fileObjects = null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   186
        classNames = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   187
        processArgs(List.from(args), Option.getJavaCompilerOptions(), cmdLineHelper, true, false);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   188
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   189
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   190
    private final OptionHelper apiHelper = new GrumpyHelper(null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   191
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   192
        public String get(Option option) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   193
            return options.get(option.getText());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   194
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   195
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   196
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   197
        public void put(String name, String value) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   198
            options.put(name, value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   199
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   200
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   201
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   202
        public void remove(String name) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   203
            options.remove(name);
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
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   206
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   207
        public void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   208
            Arguments.this.error(key, args);
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
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   211
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   212
        public Log getLog() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   213
            return Arguments.this.log;
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
    };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   216
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   217
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   218
     * Initializes this Args instance with the parameters for a JavacTask.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   219
     * 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
   220
     * of tool options, which does not include -help, -version, etc,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   221
     * 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
   222
     * separately.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   223
     * File manager options are handled directly by the file manager.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   224
     * Any errors found while processing individual args will be reported
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   225
     * via IllegalArgumentException.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   226
     * Any subsequent errors during validate will be reported via IllegalStateException.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   227
     * @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
   228
     * @param options the options to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   229
     * @param classNames the classes to be subject to annotation processing
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   230
     * @param files the files to be compiled
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   231
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   232
    public void init(String ownName,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   233
            Iterable<String> options,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   234
            Iterable<String> classNames,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   235
            Iterable<? extends JavaFileObject> files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   236
        this.ownName = ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   237
        this.classNames = toSet(classNames);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   238
        this.fileObjects = toSet(files);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   239
        this.files = null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   240
        errorMode = ErrorMode.ILLEGAL_ARGUMENT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   241
        if (options != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   242
            processArgs(toList(options), Option.getJavacToolOptions(), apiHelper, false, true);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   243
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   244
        errorMode = ErrorMode.ILLEGAL_STATE;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   245
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   246
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   247
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   248
     * Gets the files to be compiled.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   249
     * @return the files to be compiled
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
    public Set<JavaFileObject> getFileObjects() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   252
        if (fileObjects == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   253
            if (files == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   254
                fileObjects = Collections.emptySet();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   255
            } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   256
                fileObjects = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   257
                JavacFileManager jfm = (JavacFileManager) getFileManager();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   258
                for (JavaFileObject fo: jfm.getJavaFileObjectsFromFiles(files))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   259
                    fileObjects.add(fo);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   260
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   261
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   262
        return fileObjects;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   263
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   265
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   266
     * Gets the classes to be subject to annotation processing.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   267
     * @return the classes to be subject to annotation processing
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   268
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   269
    public Set<String> getClassNames() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   270
        return classNames;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   271
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   272
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   273
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   274
     * Processes strings containing options and operands.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   275
     * @param args the strings to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   276
     * @param allowableOpts the set of option declarations that are applicable
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   277
     * @param helper a help for use by Option.process
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   278
     * @param allowOperands whether or not to check for files and classes
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   279
     * @param checkFileManager whether or not to check if the file manager can handle
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   280
     *      options which are not recognized by any of allowableOpts
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   281
     * @return true if all the strings were successfully processed; false otherwise
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   282
     * @throws IllegalArgumentException if a problem occurs and errorMode is set to
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   283
     *      ILLEGAL_ARGUMENT
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
    private boolean processArgs(Iterable<String> args,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   286
            Set<Option> allowableOpts, OptionHelper helper,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   287
            boolean allowOperands, boolean checkFileManager) {
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   288
        if (!doProcessArgs(args, allowableOpts, helper, allowOperands, checkFileManager))
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   289
            return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   290
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   291
        String platformString = options.get(Option.RELEASE);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   292
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   293
        checkOptionAllowed(platformString == null,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   294
                option -> error("err.release.bootclasspath.conflict", option.getText()),
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   295
                Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   296
                Option.XBOOTCLASSPATH_PREPEND, Option.ENDORSEDDIRS, Option.EXTDIRS, Option.SOURCE,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   297
                Option.TARGET);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   298
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   299
        if (platformString != null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   300
            PlatformDescription platformDescription = lookupDescription(platformString);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   301
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   302
            if (platformDescription == null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   303
                error("err.unsupported.release.version", platformString);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   304
                return false;
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
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   307
            options.put(Option.SOURCE, platformDescription.getSourceVersion());
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   308
            options.put(Option.TARGET, platformDescription.getTargetVersion());
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   309
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   310
            context.put(PlatformDescription.class, platformDescription);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   311
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   312
            if (!doProcessArgs(platformDescription.getAdditionalOptions(), allowableOpts, helper, allowOperands, checkFileManager))
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   313
                return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   314
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   315
            Collection<Path> platformCP = platformDescription.getPlatformPath();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   316
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   317
            if (platformCP != null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   318
                JavaFileManager fm = getFileManager();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   319
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   320
                if (!(fm instanceof StandardJavaFileManager)) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   321
                    error("err.release.not.standard.file.manager");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   322
                    return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   323
                }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   324
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   325
                try {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   326
                    StandardJavaFileManager sfm = (StandardJavaFileManager) fm;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   327
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   328
                    sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   329
                } catch (IOException ex) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   330
                    log.printLines(PrefixKind.JAVAC, "msg.io");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   331
                    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   332
                    return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   333
                }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   334
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   335
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   336
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   337
        options.notifyListeners();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   338
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   339
        return true;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   340
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   341
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   342
    private boolean doProcessArgs(Iterable<String> args,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   343
            Set<Option> allowableOpts, OptionHelper helper,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   344
            boolean allowOperands, boolean checkFileManager) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   345
        JavaFileManager fm = checkFileManager ? getFileManager() : null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   346
        Iterator<String> argIter = args.iterator();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   347
        while (argIter.hasNext()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   348
            String arg = argIter.next();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   349
            if (arg.isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   350
                error("err.invalid.flag", arg);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   351
                return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   352
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   353
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   354
            Option option = null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   355
            if (arg.startsWith("-")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   356
                for (Option o : allowableOpts) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   357
                    if (o.matches(arg)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   358
                        option = o;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   359
                        break;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   360
                    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   361
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   362
            } else if (allowOperands && Option.SOURCEFILE.matches(arg)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   363
                option = Option.SOURCEFILE;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   364
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   365
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   366
            if (option == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   367
                if (fm != null && fm.handleOption(arg, argIter)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   368
                    continue;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   369
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   370
                error("err.invalid.flag", arg);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   371
                return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   372
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   373
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   374
            if (option.hasArg()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   375
                if (!argIter.hasNext()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   376
                    error("err.req.arg", arg);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   377
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   378
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   379
                String operand = argIter.next();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   380
                if (option.process(helper, arg, operand)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   381
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   382
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   383
            } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   384
                if (option.process(helper, arg)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   385
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   386
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   387
            }
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
        return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   391
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   392
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   393
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   394
     * Validates the overall consistency of the options and operands
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   395
     * processed by processOptions.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   396
     * @return true if all args are successfully validating; false otherwise.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   397
     * @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
   398
     *      ILLEGAL_STATE
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   399
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   400
    public boolean validate() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   401
        if (isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   402
            // 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
   403
            // 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
   404
            if (options.isSet(Option.HELP)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   405
                || options.isSet(Option.X)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   406
                || options.isSet(Option.VERSION)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   407
                || options.isSet(Option.FULLVERSION))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   408
                return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   409
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   410
            if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   411
                error("err.no.source.files.classes");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   412
            } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   413
                error("err.no.source.files");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   414
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   415
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   416
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   417
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   418
        if (!checkDirectory(Option.D)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   419
            return false;
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
        if (!checkDirectory(Option.S)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   422
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   423
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   424
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   425
        String sourceString = options.get(Option.SOURCE);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   426
        Source source = (sourceString != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   427
                ? Source.lookup(sourceString)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   428
                : Source.DEFAULT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   429
        String targetString = options.get(Option.TARGET);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   430
        Target target = (targetString != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   431
                ? Target.lookup(targetString)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   432
                : Target.DEFAULT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   433
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   434
        // 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
   435
        // profiles are not aligned with J2SE targets; moreover, a
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   436
        // single CLDC target may have many profiles.  In addition,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   437
        // this is needed for the continued functioning of the JSR14
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   438
        // prototype.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   439
        if (Character.isDigit(target.name.charAt(0))) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   440
            if (target.compareTo(source.requiredTarget()) < 0) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   441
                if (targetString != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   442
                    if (sourceString == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   443
                        error("warn.target.default.source.conflict",
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   444
                                targetString,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   445
                                source.requiredTarget().name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   446
                    } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   447
                        error("warn.source.target.conflict",
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   448
                                sourceString,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   449
                                source.requiredTarget().name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   450
                    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   451
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   452
                } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   453
                    target = source.requiredTarget();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   454
                    options.put("-target", target.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   455
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   456
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   457
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   458
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   459
        String profileString = options.get(Option.PROFILE);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   460
        if (profileString != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   461
            Profile profile = Profile.lookup(profileString);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   462
            if (!profile.isValid(target)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   463
                error("warn.profile.target.conflict", profileString, target.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   464
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   465
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   466
            // This check is only effective in command line mode,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   467
            // where the file manager options are added to options
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   468
            if (options.get(Option.BOOTCLASSPATH) != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   469
                error("err.profile.bootclasspath.conflict");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   470
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   471
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   472
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   473
        boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   474
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   475
        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
   476
            JavaFileManager fm = getFileManager();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   477
            if (fm instanceof BaseFileManager) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   478
                if (((BaseFileManager) fm).isDefaultBootClassPath())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   479
                    log.warning(LintCategory.OPTIONS, "source.no.bootclasspath", source.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   480
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   481
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   482
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   483
        boolean obsoleteOptionFound = false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   484
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   485
        if (source.compareTo(Source.MIN) < 0) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   486
            log.error("option.removed.source", source.name, Source.MIN.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   487
        } else if (source == Source.MIN && lintOptions) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   488
            log.warning(LintCategory.OPTIONS, "option.obsolete.source", source.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   489
            obsoleteOptionFound = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   490
        }
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 (target.compareTo(Target.MIN) < 0) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   493
            log.error("option.removed.target", target.name, Target.MIN.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   494
        } else if (target == Target.MIN && lintOptions) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   495
            log.warning(LintCategory.OPTIONS, "option.obsolete.target", target.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   496
            obsoleteOptionFound = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   497
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   498
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   499
        if (obsoleteOptionFound)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   500
            log.warning(LintCategory.OPTIONS, "option.obsolete.suppression");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   501
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   502
        return !errors;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   503
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   504
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   505
    private PlatformDescription lookupDescription(String platformString) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   506
        int separator = platformString.indexOf(":");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   507
        String platformProviderName =
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   508
                separator != (-1) ? platformString.substring(0, separator) : platformString;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   509
        String platformOptions =
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   510
                separator != (-1) ? platformString.substring(separator + 1) : "";
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   511
        Iterable<PlatformProvider> providers =
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   512
                ServiceLoader.load(PlatformProvider.class, Arguments.class.getClassLoader());
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   513
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   514
        return StreamSupport.stream(providers.spliterator(), false)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   515
                            .filter(provider -> StreamSupport.stream(provider.getSupportedPlatformNames()
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   516
                                                                             .spliterator(),
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   517
                                                                     false)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   518
                                                             .anyMatch(platformProviderName::equals))
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   519
                            .findFirst()
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   520
                            .flatMap(provider -> {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   521
                                try {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   522
                                    return Optional.of(provider.getPlatform(platformProviderName, platformOptions));
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   523
                                } catch (PlatformNotSupported pns) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   524
                                    return Optional.empty();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   525
                                }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   526
                            })
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   527
                            .orElse(null);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   528
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   529
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   530
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   531
     * 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
   532
     * @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
   533
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   534
    public boolean isEmpty() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   535
        return ((files == null) || files.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   536
                && ((fileObjects == null) || fileObjects.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   537
                && classNames.isEmpty();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   538
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   539
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   540
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   541
     * Gets the file manager options which may have been deferred
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   542
     * during processArgs.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   543
     * @return the deferred file manager options
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   544
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   545
    public Map<Option, String> getDeferredFileManagerOptions() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   546
        return deferredFileManagerOptions;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   547
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   548
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   549
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   550
     * Gets any options specifying plugins to be run.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   551
     * @return options for plugins
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   552
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   553
    public Set<List<String>> getPluginOpts() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   554
        String plugins = options.get(Option.PLUGIN);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   555
        if (plugins == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   556
            return Collections.emptySet();
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
        Set<List<String>> pluginOpts = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   559
        for (String plugin: plugins.split("\\x00")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   560
            pluginOpts.add(List.from(plugin.split("\\s+")));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   561
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   562
        return Collections.unmodifiableSet(pluginOpts);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   563
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   564
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   565
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   566
     * Gets any options specifying how doclint should be run.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   567
     * 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
   568
     * or if the only doclint option is -Xdoclint:none.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   569
     * @return options for doclint
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
    public List<String> getDocLintOpts() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   572
        String xdoclint = options.get(Option.XDOCLINT);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   573
        String xdoclintCustom = options.get(Option.XDOCLINT_CUSTOM);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   574
        if (xdoclint == null && xdoclintCustom == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   575
            return List.nil();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   576
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   577
        Set<String> doclintOpts = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   578
        if (xdoclint != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   579
            doclintOpts.add(DocLint.XMSGS_OPTION);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   580
        if (xdoclintCustom != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   581
            for (String s: xdoclintCustom.split("\\s+")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   582
                if (s.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   583
                    continue;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   584
                doclintOpts.add(s.replace(Option.XDOCLINT_CUSTOM.text, DocLint.XMSGS_CUSTOM_PREFIX));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   585
            }
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
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   588
        if (doclintOpts.equals(Collections.singleton(DocLint.XMSGS_CUSTOM_PREFIX + "none")))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   589
            return List.nil();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   590
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   591
        String checkPackages = options.get(Option.XDOCLINT_PACKAGE);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   592
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   593
        if (checkPackages != null) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   594
            for (String s : checkPackages.split("\\s+")) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   595
                doclintOpts.add(s.replace(Option.XDOCLINT_PACKAGE.text, DocLint.XCHECK_PACKAGE));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   596
            }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   597
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   598
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   599
        // standard doclet normally generates H1, H2,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   600
        // so for now, allow user comments to assume that
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   601
        doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   602
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   603
        return List.from(doclintOpts.toArray(new String[doclintOpts.size()]));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   604
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   605
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   606
    private boolean checkDirectory(Option option) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   607
        String value = options.get(option);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   608
        if (value == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   609
            return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   610
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   611
        File file = new File(value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   612
        if (!file.exists()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   613
            error("err.dir.not.found", value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   614
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   615
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   616
        if (!file.isDirectory()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   617
            error("err.file.not.directory", value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   618
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   619
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   620
        return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   621
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   622
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   623
    private interface ErrorReporter {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   624
        void report(Option o);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   625
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   626
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   627
    void checkOptionAllowed(boolean allowed, ErrorReporter r, Option... opts) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   628
        if (!allowed) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   629
            Stream.of(opts)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   630
                  .filter(options :: isSet)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   631
                  .forEach(r :: report);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   632
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   633
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   634
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   635
    void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   636
        errors = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   637
        switch (errorMode) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   638
            case ILLEGAL_ARGUMENT: {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   639
                String msg = log.localize(PrefixKind.JAVAC, key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   640
                throw new PropagatedException(new IllegalArgumentException(msg));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   641
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   642
            case ILLEGAL_STATE: {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   643
                String msg = log.localize(PrefixKind.JAVAC, key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   644
                throw new PropagatedException(new IllegalStateException(msg));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   645
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   646
            case LOG:
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   647
                report(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   648
                log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   649
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   650
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   651
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   652
    void warning(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   653
        report(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   654
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   655
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   656
    private void report(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   657
        log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   658
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   659
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   660
    private JavaFileManager getFileManager() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   661
        if (fileManager == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   662
            fileManager = context.get(JavaFileManager.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   663
        return fileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   664
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   665
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   666
    <T> ListBuffer<T> toList(Iterable<? extends T> items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   667
        ListBuffer<T> list = new ListBuffer<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   668
        if (items != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   669
            for (T item : items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   670
                list.add(item);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   671
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   672
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   673
        return list;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   674
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   675
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   676
    <T> Set<T> toSet(Iterable<? extends T> items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   677
        Set<T> set = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   678
        if (items != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   679
            for (T item : items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   680
                set.add(item);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   681
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   682
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   683
        return set;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   684
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   685
}