Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/customizesecurityfile/AddToRestrictedPkgs.java
32287 views
/*1* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package build.tools.customizesecurityfile;2627import java.io.*;2829/**30* Adds additional packages to the package.access and package.definition31* security properties.32*/33public class AddToRestrictedPkgs {3435private static final String PKG_ACC = "package.access";36private static final String PKG_DEF = "package.definition";37private static final int PKG_ACC_INDENT = 15;38private static final int PKG_DEF_INDENT = 19;3940public static void main(String[] args) throws Exception {4142if (args.length < 3) {43System.err.println("Usage: java AddToRestrictedPkgs " +44"[input java.security file name] " +45"[output java.security file name] " +46"[packages ...]");47System.exit(1);48}4950try (FileReader fr = new FileReader(args[0]);51BufferedReader br = new BufferedReader(fr);52FileWriter fw = new FileWriter(args[1]);53BufferedWriter bw = new BufferedWriter(fw))54{55// parse the file line-by-line, looking for pkg access properties56String line = br.readLine();57while (line != null) {58if (line.startsWith(PKG_ACC)) {59writePackages(br, bw, line, PKG_ACC_INDENT, args);60} else if (line.startsWith(PKG_DEF)) {61writePackages(br, bw, line, PKG_DEF_INDENT, args);62} else {63writeLine(bw, line);64}65line = br.readLine();66}67bw.flush();68}69}7071private static void writePackages(BufferedReader br, BufferedWriter bw,72String line, int numSpaces,73String[] args) throws IOException {74// parse property until EOL, not including line breaks75while (line.endsWith("\\")) {76writeLine(bw, line);77line = br.readLine();78}79// append comma and line-break to last package80writeLine(bw, line + ",\\");81// add new packages, one per line82for (int i = 2; i < args.length - 1; i++) {83indent(bw, numSpaces);84writeLine(bw, args[i] + ",\\");85}86indent(bw, numSpaces);87writeLine(bw, args[args.length - 1]);88}8990private static void writeLine(BufferedWriter bw, String line)91throws IOException92{93bw.write(line);94bw.newLine();95}9697private static void indent(BufferedWriter bw, int numSpaces)98throws IOException99{100for (int i = 0; i < numSpaces; i++) {101bw.append(' ');102}103}104}105106107