Thu, 20 Jun 2013 08:45:43 +0100
8016613: javac should avoid source 8 only analysis when compiling for source 7
Reviewed-by: jjg
Contributed-by: maurizio.cimadamore@oracle.com
ohrstrom@1504 | 1 | /* |
ohrstrom@1504 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
ohrstrom@1504 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohrstrom@1504 | 4 | * |
ohrstrom@1504 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohrstrom@1504 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohrstrom@1504 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohrstrom@1504 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohrstrom@1504 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohrstrom@1504 | 10 | * |
ohrstrom@1504 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohrstrom@1504 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohrstrom@1504 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohrstrom@1504 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohrstrom@1504 | 15 | * accompanied this code). |
ohrstrom@1504 | 16 | * |
ohrstrom@1504 | 17 | * You should have received a copy of the GNU General Public License version |
ohrstrom@1504 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohrstrom@1504 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohrstrom@1504 | 20 | * |
ohrstrom@1504 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohrstrom@1504 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohrstrom@1504 | 23 | * questions. |
ohrstrom@1504 | 24 | */ |
ohrstrom@1504 | 25 | |
ohrstrom@1504 | 26 | package com.sun.tools.sjavac; |
ohrstrom@1504 | 27 | |
ohrstrom@1504 | 28 | import java.io.File; |
ohrstrom@1504 | 29 | import java.util.Arrays; |
ohrstrom@1504 | 30 | import java.util.HashSet; |
ohrstrom@1504 | 31 | import java.util.Set; |
ohrstrom@1504 | 32 | import java.util.StringTokenizer; |
ohrstrom@1504 | 33 | |
ohrstrom@1504 | 34 | /** |
ohrstrom@1504 | 35 | * Utilities. |
ohrstrom@1504 | 36 | * |
ohrstrom@1504 | 37 | * <p><b>This is NOT part of any supported API. |
ohrstrom@1504 | 38 | * If you write code that depends on this, you do so at your own |
ohrstrom@1504 | 39 | * risk. This code and its internal interfaces are subject to change |
ohrstrom@1504 | 40 | * or deletion without notice.</b></p> |
ohrstrom@1504 | 41 | */ |
ohrstrom@1504 | 42 | public class Util { |
ohrstrom@1504 | 43 | |
ohrstrom@1504 | 44 | public static String toFileSystemPath(String pkgId) { |
ohrstrom@1504 | 45 | if (pkgId == null || pkgId.length()==0) return null; |
ohrstrom@1504 | 46 | String pn; |
ohrstrom@1504 | 47 | if (pkgId.charAt(0) == ':') { |
ohrstrom@1504 | 48 | // When the module is the default empty module. |
ohrstrom@1504 | 49 | // Do not prepend the module directory, because there is none. |
ohrstrom@1504 | 50 | // Thus :java.foo.bar translates to java/foo/bar (or \) |
ohrstrom@1504 | 51 | pn = pkgId.substring(1).replace('.',File.separatorChar); |
ohrstrom@1504 | 52 | } else { |
ohrstrom@1504 | 53 | // There is a module. Thus jdk.base:java.foo.bar translates |
ohrstrom@1504 | 54 | // into jdk.base/java/foo/bar |
ohrstrom@1504 | 55 | int cp = pkgId.indexOf(':'); |
ohrstrom@1504 | 56 | String mn = pkgId.substring(0,cp); |
ohrstrom@1504 | 57 | pn = mn+File.separatorChar+pkgId.substring(cp+1).replace('.',File.separatorChar); |
ohrstrom@1504 | 58 | } |
ohrstrom@1504 | 59 | return pn; |
ohrstrom@1504 | 60 | } |
ohrstrom@1504 | 61 | |
ohrstrom@1504 | 62 | public static String justPackageName(String pkgName) { |
ohrstrom@1504 | 63 | int c = pkgName.indexOf(":"); |
ohrstrom@1504 | 64 | assert(c != -1); |
ohrstrom@1504 | 65 | return pkgName.substring(c+1); |
ohrstrom@1504 | 66 | } |
ohrstrom@1504 | 67 | |
ohrstrom@1504 | 68 | public static String extractStringOption(String opName, String s) { |
ohrstrom@1504 | 69 | int p = s.indexOf(opName+"="); |
ohrstrom@1504 | 70 | if (p == -1) return null; |
ohrstrom@1504 | 71 | p+=opName.length()+1; |
ohrstrom@1504 | 72 | int pe = s.indexOf(',', p); |
ohrstrom@1504 | 73 | if (pe == -1) pe = s.length(); |
ohrstrom@1504 | 74 | return s.substring(p, pe); |
ohrstrom@1504 | 75 | } |
ohrstrom@1504 | 76 | |
ohrstrom@1504 | 77 | public static int extractIntOption(String opName, String s) { |
ohrstrom@1504 | 78 | int p = s.indexOf(opName+"="); |
ohrstrom@1504 | 79 | if (p == -1) return 0; |
ohrstrom@1504 | 80 | p+=opName.length()+1; |
ohrstrom@1504 | 81 | int pe = s.indexOf(',', p); |
ohrstrom@1504 | 82 | if (pe == -1) pe = s.length(); |
ohrstrom@1504 | 83 | int v = 0; |
ohrstrom@1504 | 84 | try { |
ohrstrom@1504 | 85 | v = Integer.parseInt(s.substring(p, pe)); |
ohrstrom@1504 | 86 | } catch (Exception e) {} |
ohrstrom@1504 | 87 | return v; |
ohrstrom@1504 | 88 | } |
ohrstrom@1504 | 89 | |
ohrstrom@1504 | 90 | /** |
ohrstrom@1504 | 91 | * Clean out unwanted sub options supplied inside a primary option. |
ohrstrom@1504 | 92 | * For example to only had portfile remaining from: |
ohrstrom@1504 | 93 | * settings="--server:id=foo,portfile=bar" |
ohrstrom@1504 | 94 | * do settings = cleanOptions("--server:",Util.set("-portfile"),settings); |
ohrstrom@1504 | 95 | * now settings equals "--server:portfile=bar" |
ohrstrom@1504 | 96 | * |
ohrstrom@1504 | 97 | * @param optionPrefix The option name, including colon, eg --server: |
ohrstrom@1504 | 98 | * @param allowsSubOptions A set of the allowed sub options, id portfile etc. |
ohrstrom@1504 | 99 | * @param s The option settings string. |
ohrstrom@1504 | 100 | */ |
ohrstrom@1504 | 101 | public static String cleanSubOptions(String optionPrefix, Set<String> allowedSubOptions, String s) { |
ohrstrom@1504 | 102 | StringBuilder sb = new StringBuilder(); |
ohrstrom@1504 | 103 | if (!s.startsWith(optionPrefix)) return ""; |
ohrstrom@1504 | 104 | StringTokenizer st = new StringTokenizer(s.substring(optionPrefix.length()), ","); |
ohrstrom@1504 | 105 | while (st.hasMoreTokens()) { |
ohrstrom@1504 | 106 | String o = st.nextToken(); |
ohrstrom@1504 | 107 | int p = o.indexOf('='); |
ohrstrom@1504 | 108 | if (p>0) { |
ohrstrom@1504 | 109 | String key = o.substring(0,p); |
ohrstrom@1504 | 110 | String val = o.substring(p+1); |
ohrstrom@1504 | 111 | if (allowedSubOptions.contains(key)) { |
ohrstrom@1504 | 112 | if (sb.length() > 0) sb.append(','); |
ohrstrom@1504 | 113 | sb.append(key+"="+val); |
ohrstrom@1504 | 114 | } |
ohrstrom@1504 | 115 | } |
ohrstrom@1504 | 116 | } |
ohrstrom@1504 | 117 | return sb.toString(); |
ohrstrom@1504 | 118 | } |
ohrstrom@1504 | 119 | |
ohrstrom@1504 | 120 | /** |
ohrstrom@1504 | 121 | * Convenience method to create a set with strings. |
ohrstrom@1504 | 122 | */ |
ohrstrom@1504 | 123 | public static Set<String> set(String... ss) { |
ohrstrom@1504 | 124 | Set<String> set = new HashSet<String>(); |
ohrstrom@1504 | 125 | set.addAll(Arrays.asList(ss)); |
ohrstrom@1504 | 126 | return set; |
ohrstrom@1504 | 127 | } |
ohrstrom@1504 | 128 | |
ohrstrom@1504 | 129 | /** |
ohrstrom@1504 | 130 | * Normalize windows drive letter paths to upper case to enable string |
ohrstrom@1504 | 131 | * comparison. |
ohrstrom@1504 | 132 | * |
ohrstrom@1504 | 133 | * @param file File name to normalize |
ohrstrom@1504 | 134 | * @return The normalized string if file has a drive letter at the beginning, |
ohrstrom@1504 | 135 | * otherwise the original string. |
ohrstrom@1504 | 136 | */ |
ohrstrom@1504 | 137 | public static String normalizeDriveLetter(String file) { |
ohrstrom@1504 | 138 | if (file.length() > 2 && file.charAt(1) == ':') { |
ohrstrom@1504 | 139 | return Character.toUpperCase(file.charAt(0)) + file.substring(1); |
ohrstrom@1504 | 140 | } else if (file.length() > 3 && file.charAt(0) == '*' |
ohrstrom@1504 | 141 | && file.charAt(2) == ':') { |
ohrstrom@1504 | 142 | // Handle a wildcard * at the beginning of the string. |
ohrstrom@1504 | 143 | return file.substring(0, 1) + Character.toUpperCase(file.charAt(1)) |
ohrstrom@1504 | 144 | + file.substring(2); |
ohrstrom@1504 | 145 | } |
ohrstrom@1504 | 146 | return file; |
ohrstrom@1504 | 147 | } |
ohrstrom@1504 | 148 | |
ohrstrom@1504 | 149 | /** |
ohrstrom@1504 | 150 | * Locate the setting for the server properties. |
ohrstrom@1504 | 151 | */ |
ohrstrom@1504 | 152 | public static String findServerSettings(String[] args) { |
ohrstrom@1504 | 153 | for (String s : args) { |
ohrstrom@1504 | 154 | if (s.startsWith("--server:")) { |
ohrstrom@1504 | 155 | return s; |
ohrstrom@1504 | 156 | } |
ohrstrom@1504 | 157 | } |
ohrstrom@1504 | 158 | return null; |
ohrstrom@1504 | 159 | } |
ohrstrom@1504 | 160 | } |