langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/sym/Profiles.java
author vasya
Mon, 14 Dec 2015 20:18:19 +0100
changeset 34752 9c262a013456
parent 25874 83c19f00452c
permissions -rw-r--r--
8145342: Some copyright notices are inconsistently and ill formatted Summary: Adjusted formatting of copyright notices. Reviewed-by: darcy, alundblad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     1
/*
23807
a85a06f3b9d8 8037881: javax.crypto is not listed in the compact* profiles javadoc
ksrini
parents: 22165
diff changeset
     2
 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     4
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    10
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    15
 * accompanied this code).
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    16
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    20
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    23
 * questions.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    24
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 25874
diff changeset
    25
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    26
package com.sun.tools.javac.sym;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    27
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    28
import java.io.BufferedInputStream;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    29
import java.io.BufferedWriter;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    30
import java.io.File;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    31
import java.io.FileInputStream;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    32
import java.io.FileWriter;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    33
import java.io.IOException;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    34
import java.nio.charset.Charset;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    35
import java.nio.file.Files;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    36
import java.util.HashMap;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    37
import java.util.Map;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    38
import java.util.Properties;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    39
import java.util.Set;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    40
import java.util.TreeMap;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    41
import java.util.TreeSet;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    42
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    43
import com.sun.tools.javac.util.Assert;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    44
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    45
/**
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    46
 * Provide details about profile contents.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    47
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    48
 * <p><b>This is NOT part of any supported API.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    49
 * If you write code that depends on this, you do so at your own
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    50
 * risk.  This code and its internal interfaces are subject to change
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    51
 * or deletion without notice.</b></p>
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    52
 */
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    53
public abstract class Profiles {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    54
    // for debugging
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    55
    public static void main(String[] args) throws IOException {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    56
        Profiles p = Profiles.read(new File(args[0]));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    57
        if (args.length >= 2) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    58
            Map<Integer,Set<String>> lists = new TreeMap<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    59
            for (int i = 1; i <= 4; i++)
22165
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
    60
                lists.put(i, new TreeSet<String>());
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    61
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    62
            File rt_jar_lst = new File(args[1]);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    63
            for (String line: Files.readAllLines(rt_jar_lst.toPath(), Charset.defaultCharset())) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    64
                if (line.endsWith(".class")) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    65
                    String type = line.substring(0, line.length() - 6);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    66
                    int profile = p.getProfile(type);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    67
                    for (int i = profile; i <= 4; i++)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    68
                        lists.get(i).add(type);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    69
                }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    70
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    71
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    72
            for (int i = 1; i <= 4; i++) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19653
diff changeset
    73
                try (BufferedWriter out = new BufferedWriter(new FileWriter(i + ".txt"))) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19653
diff changeset
    74
                    for (String type : lists.get(i)) {
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    75
                        out.write(type);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    76
                        out.newLine();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    77
                    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    78
                }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    79
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    80
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    81
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    82
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    83
    public static Profiles read(File file) throws IOException {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19653
diff changeset
    84
        try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) {
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    85
            Properties p = new Properties();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    86
            p.load(in);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    87
            if (p.containsKey("java/lang/Object"))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    88
                return new SimpleProfiles(p);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    89
            else
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    90
                return new MakefileProfiles(p);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    91
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    92
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    93
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    94
    public abstract int getProfileCount();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    95
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    96
    public abstract int getProfile(String typeName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    97
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    98
    public abstract Set<String> getPackages(int profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    99
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   100
    private static class MakefileProfiles extends Profiles {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   101
        static class Package {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   102
            final Package parent;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   103
            final String name;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   104
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   105
            Map<String, Package> subpackages = new TreeMap<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   106
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   107
            int profile;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   108
            Map<String, Integer> includedTypes = new TreeMap<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   109
            Map<String, Integer> excludedTypes = new TreeMap<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   110
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   111
            Package(Package parent, String name) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   112
                this.parent = parent;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   113
                this.name = name;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   114
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   115
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   116
            int getProfile() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   117
                return (parent == null) ? profile : Math.max(parent.getProfile(), profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   118
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   119
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   120
            int getProfile(String simpleTypeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   121
                Integer i;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   122
                if ((i = includedTypes.get(simpleTypeName)) != null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   123
                    return i;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   124
                if ((i = includedTypes.get("*")) != null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   125
                    return i;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   126
                if ((i = excludedTypes.get(simpleTypeName)) != null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   127
                    return i + 1;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   128
                if ((i = excludedTypes.get("*")) != null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   129
                    return i + 1;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   130
                return getProfile();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   131
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   132
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   133
            String getName() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   134
                return (parent == null) ? name : (parent.getName() + "/" + name);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   135
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   136
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   137
            void getPackages(int profile, Set<String> results) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   138
                int prf = getProfile();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   139
                if (prf != 0 && profile >= prf)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   140
                    results.add(getName());
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   141
                for (Package pkg: subpackages.values())
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   142
                    pkg.getPackages(profile, results);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   143
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   144
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   145
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   146
        final Map<String, Package> packages = new TreeMap<>();
16548
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   147
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   148
        final int maxProfile = 4;  // Three compact profiles plus full JRE
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   149
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   150
        MakefileProfiles(Properties p) {
23808
6ec86ba2dfb6 8039231: [javadoc] test failure caused by javax.crypto fix
ksrini
parents: 23807
diff changeset
   151
            // consider crypto, only if java/lang package exists
6ec86ba2dfb6 8039231: [javadoc] test failure caused by javax.crypto fix
ksrini
parents: 23807
diff changeset
   152
            boolean foundJavaLang = false;
16548
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   153
            for (int profile = 1; profile <= maxProfile; profile++) {
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   154
                String prefix = (profile < maxProfile ? "PROFILE_" + profile : "FULL_JRE");
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   155
                String inclPackages = p.getProperty(prefix + "_RTJAR_INCLUDE_PACKAGES");
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   156
                if (inclPackages == null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   157
                    break;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   158
                for (String pkg: inclPackages.substring(1).trim().split("\\s+")) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   159
                    if (pkg.endsWith("/"))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   160
                        pkg = pkg.substring(0, pkg.length() - 1);
23808
6ec86ba2dfb6 8039231: [javadoc] test failure caused by javax.crypto fix
ksrini
parents: 23807
diff changeset
   161
                    if (foundJavaLang == false && pkg.equals("java/lang"))
6ec86ba2dfb6 8039231: [javadoc] test failure caused by javax.crypto fix
ksrini
parents: 23807
diff changeset
   162
                        foundJavaLang = true;
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   163
                    includePackage(profile, pkg);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   164
                }
16548
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   165
                String inclTypes =  p.getProperty(prefix + "_RTJAR_INCLUDE_TYPES");
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   166
                if (inclTypes != null) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   167
                    for (String type: inclTypes.replace("$$", "$").split("\\s+")) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   168
                        if (type.endsWith(".class"))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   169
                            includeType(profile, type.substring(0, type.length() - 6));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   170
                    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   171
                }
16548
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   172
                String exclTypes =  p.getProperty(prefix + "_RTJAR_EXCLUDE_TYPES");
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   173
                if (exclTypes != null) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   174
                    for (String type: exclTypes.replace("$$", "$").split("\\s+")) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   175
                        if (type.endsWith(".class"))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   176
                            excludeType(profile, type.substring(0, type.length() - 6));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   177
                    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   178
                }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   179
            }
23807
a85a06f3b9d8 8037881: javax.crypto is not listed in the compact* profiles javadoc
ksrini
parents: 22165
diff changeset
   180
            /*
a85a06f3b9d8 8037881: javax.crypto is not listed in the compact* profiles javadoc
ksrini
parents: 22165
diff changeset
   181
             * A hack to force javax/crypto package into the compact1 profile,
a85a06f3b9d8 8037881: javax.crypto is not listed in the compact* profiles javadoc
ksrini
parents: 22165
diff changeset
   182
             * because this package exists in jce.jar, and therefore not in
a85a06f3b9d8 8037881: javax.crypto is not listed in the compact* profiles javadoc
ksrini
parents: 22165
diff changeset
   183
             * ct.sym. Note javax/crypto should exist in a profile along with
a85a06f3b9d8 8037881: javax.crypto is not listed in the compact* profiles javadoc
ksrini
parents: 22165
diff changeset
   184
             * javax/net/ssl package. Thus, this package is added to compact1,
a85a06f3b9d8 8037881: javax.crypto is not listed in the compact* profiles javadoc
ksrini
parents: 22165
diff changeset
   185
             * implying that it should exist in all three profiles.
a85a06f3b9d8 8037881: javax.crypto is not listed in the compact* profiles javadoc
ksrini
parents: 22165
diff changeset
   186
             */
23808
6ec86ba2dfb6 8039231: [javadoc] test failure caused by javax.crypto fix
ksrini
parents: 23807
diff changeset
   187
            if (foundJavaLang)
6ec86ba2dfb6 8039231: [javadoc] test failure caused by javax.crypto fix
ksrini
parents: 23807
diff changeset
   188
                includePackage(1, "javax/crypto");
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   189
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   190
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   191
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   192
        public int getProfileCount() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   193
            return maxProfile;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   194
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   195
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   196
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   197
        public int getProfile(String typeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   198
            int sep = typeName.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   199
            String packageName = typeName.substring(0, sep);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   200
            String simpleName = typeName.substring(sep + 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   201
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   202
            Package p = getPackage(packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   203
            return p.getProfile(simpleName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   204
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   205
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   206
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   207
        public Set<String> getPackages(int profile) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   208
            Set<String> results = new TreeSet<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   209
            for (Package p: packages.values())
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   210
                p.getPackages(profile, results);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   211
            return results;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   212
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   213
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   214
        private void includePackage(int profile, String packageName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   215
//            System.err.println("include package " + packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   216
            Package p = getPackage(packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   217
            Assert.check(p.profile == 0);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   218
            p.profile = profile;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   219
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   220
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   221
        private void includeType(int profile, String typeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   222
//            System.err.println("include type " + typeName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   223
            int sep = typeName.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   224
            String packageName = typeName.substring(0, sep);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   225
            String simpleName = typeName.substring(sep + 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   226
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   227
            Package p = getPackage(packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   228
            Assert.check(!p.includedTypes.containsKey(simpleName));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   229
            p.includedTypes.put(simpleName, profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   230
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   231
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   232
        private void excludeType(int profile, String typeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   233
//            System.err.println("exclude type " + typeName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   234
            int sep = typeName.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   235
            String packageName = typeName.substring(0, sep);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   236
            String simpleName = typeName.substring(sep + 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   237
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   238
            Package p = getPackage(packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   239
            Assert.check(!p.excludedTypes.containsKey(simpleName));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   240
            p.excludedTypes.put(simpleName, profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   241
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   242
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   243
        private Package getPackage(String packageName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   244
            int sep = packageName.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   245
            Package parent;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   246
            Map<String, Package> parentSubpackages;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   247
            String simpleName;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   248
            if (sep == -1) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   249
                parent = null;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   250
                parentSubpackages = packages;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   251
                simpleName = packageName;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   252
            } else {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   253
                parent = getPackage(packageName.substring(0, sep));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   254
                parentSubpackages = parent.subpackages;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   255
                simpleName = packageName.substring(sep + 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   256
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   257
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   258
            Package p = parentSubpackages.get(simpleName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   259
            if (p == null) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   260
                parentSubpackages.put(simpleName, p = new Package(parent, simpleName));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   261
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   262
            return p;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   263
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   264
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   265
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   266
    private static class SimpleProfiles extends Profiles {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   267
        private final Map<String, Integer> map;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   268
        private final int profileCount;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   269
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   270
        SimpleProfiles(Properties p) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   271
            int max = 0;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   272
            map = new HashMap<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   273
            for (Map.Entry<Object,Object> e: p.entrySet()) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   274
                String typeName = (String) e.getKey();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   275
                int profile = Integer.valueOf((String) e.getValue());
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   276
                map.put(typeName, profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   277
                max = Math.max(max, profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   278
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   279
            profileCount = max;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   280
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   281
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   282
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   283
        public int getProfileCount() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   284
            return profileCount;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   285
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   286
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   287
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   288
        public int getProfile(String typeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   289
            return map.get(typeName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   290
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   291
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   292
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   293
        public Set<String> getPackages(int profile) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   294
            Set<String> results = new TreeSet<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   295
            for (Map.Entry<String,Integer> e: map.entrySet()) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   296
                String tn = e.getKey();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   297
                int prf = e.getValue();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   298
                int sep = tn.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   299
                if (sep > 0 && profile >= prf)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   300
                    results.add(tn);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   301
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   302
            return results;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   303
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   304
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   305
}