1 /* |
1 /* |
2 * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
25 |
25 |
26 package com.sun.tools.javac.main; |
26 package com.sun.tools.javac.main; |
27 |
27 |
28 import java.io.FileWriter; |
28 import java.io.FileWriter; |
29 import java.io.PrintWriter; |
29 import java.io.PrintWriter; |
|
30 import java.lang.module.ModuleDescriptor; |
30 import java.nio.file.Files; |
31 import java.nio.file.Files; |
31 import java.nio.file.Path; |
32 import java.nio.file.Path; |
32 import java.nio.file.Paths; |
33 import java.nio.file.Paths; |
33 import java.text.Collator; |
34 import java.text.Collator; |
34 import java.util.Arrays; |
35 import java.util.Arrays; |
45 import java.util.stream.Collectors; |
46 import java.util.stream.Collectors; |
46 import java.util.stream.StreamSupport; |
47 import java.util.stream.StreamSupport; |
47 |
48 |
48 import javax.lang.model.SourceVersion; |
49 import javax.lang.model.SourceVersion; |
49 |
50 |
|
51 import jdk.internal.misc.VM; |
|
52 |
50 import com.sun.tools.doclint.DocLint; |
53 import com.sun.tools.doclint.DocLint; |
51 import com.sun.tools.javac.code.Lint; |
54 import com.sun.tools.javac.code.Lint; |
52 import com.sun.tools.javac.code.Lint.LintCategory; |
55 import com.sun.tools.javac.code.Lint.LintCategory; |
53 import com.sun.tools.javac.code.Source; |
56 import com.sun.tools.javac.code.Source; |
54 import com.sun.tools.javac.code.Type; |
57 import com.sun.tools.javac.code.Type; |
55 import com.sun.tools.javac.jvm.Profile; |
58 import com.sun.tools.javac.jvm.Profile; |
56 import com.sun.tools.javac.jvm.Target; |
59 import com.sun.tools.javac.jvm.Target; |
57 import com.sun.tools.javac.platform.PlatformProvider; |
60 import com.sun.tools.javac.platform.PlatformProvider; |
58 import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
61 import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
59 import com.sun.tools.javac.util.Assert; |
62 import com.sun.tools.javac.util.Assert; |
60 import com.sun.tools.javac.util.JDK9Wrappers; |
|
61 import com.sun.tools.javac.util.Log; |
63 import com.sun.tools.javac.util.Log; |
62 import com.sun.tools.javac.util.Log.PrefixKind; |
64 import com.sun.tools.javac.util.Log.PrefixKind; |
63 import com.sun.tools.javac.util.Log.WriterKind; |
65 import com.sun.tools.javac.util.Log.WriterKind; |
64 import com.sun.tools.javac.util.Options; |
66 import com.sun.tools.javac.util.Options; |
65 import com.sun.tools.javac.util.StringUtils; |
67 import com.sun.tools.javac.util.StringUtils; |
648 @Override |
650 @Override |
649 public void process(OptionHelper helper, String option, String arg) throws InvalidValueException { |
651 public void process(OptionHelper helper, String option, String arg) throws InvalidValueException { |
650 if (arg.isEmpty()) { |
652 if (arg.isEmpty()) { |
651 throw helper.newInvalidValueException("err.no.value.for.option", option); |
653 throw helper.newInvalidValueException("err.no.value.for.option", option); |
652 } else { |
654 } else { |
|
655 // use official parser if available |
653 try { |
656 try { |
654 Class.forName(JDK9Wrappers.ModuleDescriptor.Version.CLASSNAME); |
657 ModuleDescriptor.Version.parse(arg); |
655 // use official parser if available |
658 } catch (IllegalArgumentException e) { |
656 try { |
659 throw helper.newInvalidValueException("err.bad.value.for.option", option, arg); |
657 JDK9Wrappers.ModuleDescriptor.Version.parse(arg); |
|
658 } catch (IllegalArgumentException e) { |
|
659 throw helper.newInvalidValueException("err.bad.value.for.option", option, arg); |
|
660 } |
|
661 } catch (ClassNotFoundException ex) { |
|
662 // fall-back to simplistic rules when running on older platform |
|
663 if (!(arg.charAt(0) >= '0' && arg.charAt(0) <= '9') || |
|
664 arg.endsWith("-") || |
|
665 arg.endsWith("+")) { |
|
666 throw helper.newInvalidValueException("err.bad.value.for.option", option, arg); |
|
667 } |
|
668 } |
660 } |
669 } |
661 } |
670 super.process(helper, option, arg); |
662 super.process(helper, option, arg); |
671 } |
663 } |
672 }, |
664 }, |
715 |
707 |
716 INHERIT_RUNTIME_ENVIRONMENT("--inherit-runtime-environment", "opt.inherit_runtime_environment", |
708 INHERIT_RUNTIME_ENVIRONMENT("--inherit-runtime-environment", "opt.inherit_runtime_environment", |
717 HIDDEN, BASIC) { |
709 HIDDEN, BASIC) { |
718 @Override |
710 @Override |
719 public void process(OptionHelper helper, String option) throws InvalidValueException { |
711 public void process(OptionHelper helper, String option) throws InvalidValueException { |
720 try { |
712 String[] runtimeArgs = VM.getRuntimeArguments(); |
721 Class.forName(JDK9Wrappers.VMHelper.CLASSNAME); |
713 for (String arg : runtimeArgs) { |
722 String[] runtimeArgs = JDK9Wrappers.VMHelper.getRuntimeArguments(); |
714 // Handle any supported runtime options; ignore all others. |
723 for (String arg : runtimeArgs) { |
715 // The runtime arguments always use the single token form, e.g. "--name=value". |
724 // Handle any supported runtime options; ignore all others. |
716 for (Option o : getSupportedRuntimeOptions()) { |
725 // The runtime arguments always use the single token form, e.g. "--name=value". |
717 if (o.matches(arg)) { |
726 for (Option o : getSupportedRuntimeOptions()) { |
718 switch (o) { |
727 if (o.matches(arg)) { |
719 case ADD_MODULES: |
728 switch (o) { |
720 int eq = arg.indexOf('='); |
729 case ADD_MODULES: |
721 Assert.check(eq > 0, () -> ("invalid runtime option:" + arg)); |
730 int eq = arg.indexOf('='); |
722 // --add-modules=ALL-DEFAULT is not supported at compile-time |
731 Assert.check(eq > 0, () -> ("invalid runtime option:" + arg)); |
723 // so remove it from list, and only process the rest |
732 // --add-modules=ALL-DEFAULT is not supported at compile-time |
724 // if the set is non-empty. |
733 // so remove it from list, and only process the rest |
725 // Note that --add-modules=ALL-DEFAULT is automatically added |
734 // if the set is non-empty. |
726 // by the standard javac launcher. |
735 // Note that --add-modules=ALL-DEFAULT is automatically added |
727 String mods = Arrays.stream(arg.substring(eq + 1).split(",")) |
736 // by the standard javac launcher. |
728 .filter(s -> !s.isEmpty() && !s.equals("ALL-DEFAULT")) |
737 String mods = Arrays.stream(arg.substring(eq + 1).split(",")) |
729 .collect(Collectors.joining(",")); |
738 .filter(s -> !s.isEmpty() && !s.equals("ALL-DEFAULT")) |
730 if (!mods.isEmpty()) { |
739 .collect(Collectors.joining(",")); |
731 String updatedArg = arg.substring(0, eq + 1) + mods; |
740 if (!mods.isEmpty()) { |
732 o.handleOption(helper, updatedArg, Collections.emptyIterator()); |
741 String updatedArg = arg.substring(0, eq + 1) + mods; |
733 } |
742 o.handleOption(helper, updatedArg, Collections.emptyIterator()); |
734 break; |
743 } |
735 default: |
744 break; |
736 o.handleOption(helper, arg, Collections.emptyIterator()); |
745 default: |
737 break; |
746 o.handleOption(helper, arg, Collections.emptyIterator()); |
|
747 break; |
|
748 } |
|
749 break; |
|
750 } |
738 } |
|
739 break; |
751 } |
740 } |
752 } |
741 } |
753 } catch (ClassNotFoundException | SecurityException e) { |
|
754 throw helper.newInvalidValueException("err.cannot.access.runtime.env"); |
|
755 } |
742 } |
756 } |
743 } |
757 |
744 |
758 private Option[] getSupportedRuntimeOptions() { |
745 private Option[] getSupportedRuntimeOptions() { |
759 Option[] supportedRuntimeOptions = { |
746 Option[] supportedRuntimeOptions = { |