make/jdk/src/classes/build/tools/makejavasecurity/MakeJavaSecurity.java
author jpai
Sat, 24 Aug 2019 09:31:15 +0530
changeset 58053 1a296c9064dc
parent 47216 71c04702a3d5
permissions -rw-r--r--
8177389: Hyphen "-" should be removed in URL class documentation Summary: javadoc of java.net.URL constructor updated to remove an unnecessary hyphen Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
     1
/*
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
     4
 *
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    10
 *
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    15
 * accompanied this code).
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    16
 *
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    20
 *
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    23
 * questions.
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    24
 */
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    25
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    26
package build.tools.makejavasecurity;
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    27
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    28
import java.io.*;
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    29
import java.nio.file.Files;
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    30
import java.nio.file.Paths;
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    31
import java.util.*;
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    32
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    33
/**
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    34
 * Builds the java.security file, including
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    35
 *
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    36
 * 1. Adds additional packages to the package.access and
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    37
 *    package.definition security properties.
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
    38
 * 2. Filter out platform-unrelated parts.
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
    39
 * 3. Set the JCE jurisdiction policy directory.
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    40
 *
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    41
 * In order to easily maintain platform-related entries, every item
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    42
 * (including the last line) in package.access and package.definition
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    43
 * MUST end with ',\'. A blank line MUST exist after the last line.
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    44
 */
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    45
public class MakeJavaSecurity {
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    46
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    47
    private static final String PKG_ACC = "package.access";
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    48
    private static final String PKG_DEF = "package.definition";
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    49
    private static final int PKG_ACC_INDENT = 15;
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    50
    private static final int PKG_DEF_INDENT = 19;
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    51
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    52
    public static void main(String[] args) throws Exception {
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    53
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
    54
        if (args.length < 5) {
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    55
            System.err.println("Usage: java MakeJavaSecurity " +
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    56
                               "[input java.security file name] " +
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    57
                               "[output java.security file name] " +
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    58
                               "[openjdk target os] " +
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25974
diff changeset
    59
                               "[openjdk target cpu architecture]" +
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
    60
                               "[JCE jurisdiction policy directory]" +
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    61
                               "[more restricted packages file name?]");
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25974
diff changeset
    62
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25974
diff changeset
    63
                    System.exit(1);
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    64
        }
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    65
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    66
        // more restricted packages
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    67
        List<String> extraLines;
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
    68
        if (args.length == 6) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
    69
            extraLines = Files.readAllLines(Paths.get(args[5]));
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    70
        } else {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    71
            extraLines = Collections.emptyList();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    72
        }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    73
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    74
        List<String> lines = new ArrayList<>();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    75
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    76
        // read raw java.security and add more restricted packages
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    77
        try (FileReader fr = new FileReader(args[0]);
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    78
                BufferedReader br = new BufferedReader(fr)) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    79
            // looking for pkg access properties
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    80
            String line = br.readLine();
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    81
            while (line != null) {
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    82
                if (line.startsWith(PKG_ACC)) {
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    83
                    addPackages(br, lines, line, PKG_ACC_INDENT, extraLines);
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    84
                } else if (line.startsWith(PKG_DEF)) {
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    85
                    addPackages(br, lines, line, PKG_DEF_INDENT, extraLines);
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    86
                } else {
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    87
                    lines.add(line);
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    88
                }
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    89
                line = br.readLine();
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
    90
            }
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    91
        }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    92
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    93
        // Filter out platform-unrelated ones. We only support
34383
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
    94
        // #ifdef, #ifndef, #else, and #endif. Nesting not supported (yet).
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    95
        int mode = 0;   // 0: out of block, 1: in match, 2: in non-match
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    96
        Iterator<String> iter = lines.iterator();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    97
        while (iter.hasNext()) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    98
            String line = iter.next();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
    99
            if (line.startsWith("#endif")) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   100
                mode = 0;
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   101
                iter.remove();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   102
            } else if (line.startsWith("#ifdef ")) {
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25974
diff changeset
   103
                if (line.indexOf('-') > 0) {
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25974
diff changeset
   104
                    mode = line.endsWith(args[2]+"-"+args[3]) ? 1 : 2;
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25974
diff changeset
   105
                } else {
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25974
diff changeset
   106
                    mode = line.endsWith(args[2]) ? 1 : 2;
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25974
diff changeset
   107
                }
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   108
                iter.remove();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   109
            } else if (line.startsWith("#ifndef ")) {
34383
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   110
                if (line.indexOf('-') > 0) {
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   111
                    mode = line.endsWith(args[2]+"-"+args[3]) ? 2 : 1;
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   112
                } else {
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   113
                    mode = line.endsWith(args[2]) ? 2 : 1;
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   114
                }
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   115
                iter.remove();
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   116
            } else if (line.startsWith("#else")) {
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   117
                if (mode == 0) {
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   118
                    throw new IllegalStateException("#else not in #if block");
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   119
                }
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   120
                mode = 3 - mode;
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   121
                iter.remove();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   122
            } else {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   123
                if (mode == 2) iter.remove();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   124
            }
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   125
        }
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   126
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   127
        // Update .tbd to .1, .2, etc.
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   128
        Map<String,Integer> count = new HashMap<>();
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   129
        for (int i=0; i<lines.size(); i++) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   130
            String line = lines.get(i);
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   131
            int index = line.indexOf(".tbd");
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   132
            if (index >= 0) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   133
                String prefix = line.substring(0, index);
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   134
                int n = count.getOrDefault(prefix, 1);
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   135
                count.put(prefix, n+1);
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   136
                lines.set(i, prefix + "." + n + line.substring(index+4));
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   137
            }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   138
        }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   139
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   140
        // Set the JCE policy value
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   141
        for (int i = 0; i < lines.size(); i++) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   142
            String line = lines.get(i);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   143
            int index = line.indexOf("crypto.policydir-tbd");
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   144
            if (index >= 0) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   145
                String prefix = line.substring(0, index);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   146
                lines.set(i, prefix + args[4]);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   147
            }
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   148
        }
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 34383
diff changeset
   149
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   150
        // Clean up the last line of PKG_ACC and PKG_DEF blocks.
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   151
        // Not really necessary since a blank line follows.
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   152
        boolean inBlock = false;
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   153
        for (int i=0; i<lines.size(); i++) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   154
            String line = lines.get(i);
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   155
            if (line.startsWith(PKG_ACC) || line.startsWith(PKG_DEF)) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   156
                inBlock = true;
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   157
            }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   158
            if (inBlock) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   159
                if (line.isEmpty()) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   160
                    String lastLine = lines.get(i-1);
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   161
                    lines.set(i-1, lastLine.substring(0, lastLine.length()-2));
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   162
                    inBlock = false;
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   163
                }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   164
            }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   165
        }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   166
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   167
        Files.write(Paths.get(args[1]), lines);
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   168
    }
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   169
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   170
    private static void addPackages(BufferedReader br, List<String> lines,
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   171
                                    String line, int numSpaces,
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   172
                                    List<String> args) throws IOException {
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   173
        // parse property until EOL, not including line breaks
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   174
        boolean first = true;
34383
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   175
        while (line != null && !line.isEmpty()) {
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   176
            if (!line.startsWith("#")) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   177
                if (!line.endsWith(",\\") ||
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   178
                        (!first && line.contains("="))) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   179
                    throw new IOException("Invalid line: " + line);
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   180
                }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   181
            }
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   182
            lines.add(line);
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   183
            line = br.readLine();
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   184
            first = false;
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   185
        }
25974
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   186
        // add new packages, one per line
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   187
        for (String arg: args) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   188
            if (arg.startsWith("#")) {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   189
                lines.add(arg);
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   190
            } else {
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   191
                lines.add(String.format("%"+numSpaces+"s", "") + arg + ",\\");
850dc36ea410 6997010: Consolidate java.security files into one file with modifications
weijun
parents: 21805
diff changeset
   192
            }
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   193
        }
34383
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   194
        if (line != null) {
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   195
            lines.add(line);
15dce969f2a4 8141690: JDK-8133151 change to MakeJavaSecurity.java is not complete
weijun
parents: 33241
diff changeset
   196
        }
20774
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   197
    }
330ea6efa3fd 8007292: Add JavaFX internal packages to package.access
mullan
parents:
diff changeset
   198
}