make/jdk/src/classes/build/tools/jarreorder/JarReorder.java
author minqi
Wed, 21 Feb 2018 14:23:45 -0800
changeset 48927 847a988152b8
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194154: System property user.dir should not be changed Summary: Cached user.dir so getCanonicalPath uses the cached value. Reviewed-by: alanb, bpb, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21805
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Read an input file which is output from a java -verbose run,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * combine with an argument list of files and directories, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * write a list of items to be included in a jar file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package build.tools.jarreorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.FileReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    38
import java.util.Collections;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.FileOutputStream;
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    42
import java.util.ArrayList;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    43
import java.util.List;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    44
import java.util.Set;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class JarReorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // To deal with output
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    49
    private PrintStream out;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    51
    private void usage() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        String help;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        help =
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
    54
                "Usage:  jar JarReorder [-m] [-o <outputfile>] <order_list> <exclude_list> <file> ...\n"
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
    55
                + "   -m            activate module mode, where every direct sub\n"
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
    56
                + "                 directory of the current working directory\n"
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
    57
                + "                 will be assumed to be a separate source root\n"
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    58
                + "   order_list    is a file containing names of files to load\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    59
                + "                 in order at the end of a jar file unless\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    60
                + "                 excluded in the exclude list.\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    61
                + "   exclude_list  is a file containing names of files/directories\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    62
                + "                 NOT to be included in a jar file.\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    63
                + "\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    64
                + "The order_list or exclude_list may be replaced by a \"-\" if no\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    65
                + "data is to be provided.\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    66
                + "\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    67
                + "   The remaining arguments are files or directories to be included\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    68
                + "   in a jar file, from which will be excluded those entries which\n"
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    69
                + "   appear in the exclude list.\n";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.err.println(help);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /*
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    75
     * Create the file list to be included in a jar file, such that the
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    76
     * list will appear in a specific order, and allowing certain
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * files and directories to be excluded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    79
     * Command path arguments are
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
    80
     *    - optional -m for module mode.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *    - optional -o outputfile
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    82
     *    - name of a file containing a set of files to be included in a jar file.
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    83
     *    - name of a file containing a set of files (or directories) to be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *      excluded from the jar file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *    - names of files or directories to be searched for files to include
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *      in the jar file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static void main(String[] args) {
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    89
        JarReorder jr = new JarReorder();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    90
        jr.run(args);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    91
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    93
    private void run(String args[]) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
    94
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        int arglen = args.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        int argpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
    98
        boolean moduleMode = false;
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
    99
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   100
        if (arglen > 0) {
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   101
            // Check for module mode
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   102
            if (args[argpos].equals("-m")) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   103
                moduleMode = true;
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   104
                argpos++;
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   105
                arglen--;
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   106
            }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   107
            // Look for "-o outputfilename" option
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   108
            if (arglen >= 2 && args[argpos].equals("-o")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                try {
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   110
                    out = new PrintStream(new FileOutputStream(args[argpos+1]));
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   111
                } catch (FileNotFoundException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    System.err.println("Error: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    e.printStackTrace(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                argpos += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                arglen -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                System.err.println("Error: Illegal arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            out = System.out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   126
        // Should be 2 or more args left
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   127
        if (arglen <= 2) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            usage();
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   129
            System.exit(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   132
        // Read the ordered set of files to be included in rt.jar.
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   133
        // Read the set of files/directories to be excluded from rt.jar.
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   134
        String classListFile = args[argpos];
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   135
        String excludeListFile = args[argpos + 1];
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   136
        argpos += 2;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   137
        arglen -= 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   139
        // If we run module mode, this will contain the list of subdirs to use
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   140
        // as source roots. Otherwise it will just contain the current working
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   141
        // dir.
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   142
        List<File> moduleDirs = findModuleDirs(moduleMode);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   143
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   144
        // Create 2 lists and a set of processed files
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   145
        List<String> orderList = readListFromFile(classListFile, true, moduleDirs);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   146
        List<String> excludeList = readListFromFile(excludeListFile, false, moduleDirs);
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   147
        Set<String> processed = new HashSet<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   149
        // Create set of all files and directories excluded, then expand
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   150
        //   that list completely
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   151
        Set<String> excludeSet = new HashSet<String>(excludeList);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   152
        Set<String> allFilesExcluded = expand(null, excludeSet, processed);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   153
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   154
        // Indicate all these have been processed, orderList too, kept to end.
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   155
        processed.addAll(orderList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // The remaining arguments are names of files/directories to be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // in the jar file.
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   159
        Set<String> inputSet = new HashSet<String>();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   160
        for (int i = 0; i < arglen; ++i) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   161
            String name = args[argpos + i];
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   162
            for (File dir : moduleDirs) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   163
                String cleanName = cleanPath(new File(dir, name));
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   164
                if ( cleanName != null && cleanName.length() > 0 && !inputSet.contains(cleanName) ) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   165
                    inputSet.add(cleanName);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   166
                }
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   167
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   170
        // Expand file/directory input so we get a complete set (except ordered)
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   171
        //   Should be everything not excluded and not in order list.
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   172
        Set<String> allFilesIncluded = expand(null, inputSet, processed);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   174
        // Create simple sorted list so we can add ordered items at end.
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   175
        List<String> allFiles = new ArrayList<String>(allFilesIncluded);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   176
        Collections.sort(allFiles);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   178
        // Now add the ordered set to the end of the list.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // Add in REVERSE ORDER, so that the first element is closest to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        // the end (and the index).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        for (int i = orderList.size() - 1; i >= 0; --i) {
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   182
            String s = orderList.get(i);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   183
            if (allFilesExcluded.contains(s)) {
15681
8ca785029fe2 8004265: Add build support for Compact Profiles
dholmes
parents: 7668
diff changeset
   184
                // Disable this warning until 8005688 is fixed
8ca785029fe2 8004265: Add build support for Compact Profiles
dholmes
parents: 7668
diff changeset
   185
                // System.err.println("Included order file " + s
8ca785029fe2 8004265: Add build support for Compact Profiles
dholmes
parents: 7668
diff changeset
   186
                //    + " is also excluded, skipping.");
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   187
            } else if (new File(s).exists()) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   188
                allFiles.add(s);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   189
            } else {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   190
                System.err.println("Included order file " + s
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   191
                    + " missing, skipping.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   195
        // Print final results.
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   196
        for (String str : allFiles) {
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   197
            // If running in module mode, each line must be prepended with a
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   198
            // '-C dir ' which points to the source root where that file is
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   199
            // found.
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   200
            if (moduleMode) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   201
                int firstPathSep = str.indexOf(File.separator);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   202
                String moduleDir;
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   203
                if (firstPathSep < 0) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   204
                    moduleDir = ".";
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   205
                } else {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   206
                    moduleDir = str.substring(0, firstPathSep);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   207
                }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   208
                String filePath = str.substring(firstPathSep + 1);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   209
                out.println("-C " + moduleDir + " " + filePath);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   210
            } else {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   211
                out.println(str);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   212
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /*
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   219
     * Read a file containing a list of files and directories into a List.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   221
    private List<String> readListFromFile(String fileName,
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   222
            boolean addClassSuffix, List<File> moduleDirs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        BufferedReader br = null;
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   225
        List<String> list = new ArrayList<String>();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   226
        // If you see "-" for the name, just assume nothing was provided.
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   227
        if ("-".equals(fileName)) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   228
            return list;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   229
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            br = new BufferedReader(new FileReader(fileName));
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   232
            // Read the input file a path at a time. # in column 1 is a comment.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            while (true) {
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   234
                String path = br.readLine();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   235
                if (path == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    break;
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   237
                }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   238
                // Look for comments
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   239
                path = path.trim();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   240
                if (path.length() == 0
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   241
                        || path.charAt(0) == '#') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    continue;
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   243
                }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   244
                // Add trailing .class if necessary
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   245
                if (addClassSuffix && !path.endsWith(".class")) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   246
                    path = path + ".class";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                }
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   248
                // Look for file in each module source root
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   249
                boolean pathFound = false;
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   250
                for (File dir : moduleDirs) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   251
                    File file = new File(dir, path);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   252
                    if (file.exists()) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   253
                        pathFound = true;
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   254
                        // Normalize the path
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   255
                        String cleanPath = cleanPath(new File(dir, path));
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   256
                        // Add to list
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   257
                        if (cleanPath != null && cleanPath.length() > 0 && !list.contains(cleanPath)) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   258
                            list.add(cleanPath);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   259
                        }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   260
                    }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   261
                }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   262
                if (!pathFound) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   263
                    System.err.println("WARNING: Path does not exist as file or directory: " + path);
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   264
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            br.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            System.err.println("Can't find file \"" + fileName + "\".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            System.exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   274
        return list;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /*
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   278
     * Expands inputSet (files or dirs) into full set of all files that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * can be found by recursively descending directories.
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   280
     * @param dir root directory
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   281
     * @param inputSet set of files or dirs to look into
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   282
     * @param processed files or dirs already processed
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   283
     * @return set of files
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   285
    private Set<String> expand(File dir,
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   286
            Set<String> inputSet,
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   287
            Set<String> processed) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   288
        Set<String> includedFiles = new HashSet<String>();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   289
        if (inputSet.isEmpty()) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   290
            return includedFiles;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   292
        for (String name : inputSet) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   293
            // Depending on start location
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   294
            File f = (dir == null) ? new File(name)
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   295
                    : new File(dir, name);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   296
            // Normalized path to use
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   297
            String path = cleanPath(f);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   298
            if (path != null && path.length() > 0
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   299
                    && !processed.contains(path)) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   300
                if (f.isFile()) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   301
                    // Not in the excludeList, add it to both lists
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   302
                    includedFiles.add(path);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   303
                    processed.add(path);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   304
                } else if (f.isDirectory()) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   305
                    // Add the directory entries
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   306
                    String[] dirList = f.list();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   307
                    Set<String> dirInputSet = new HashSet<String>();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   308
                    for (String x : dirList) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   309
                        dirInputSet.add(x);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   310
                    }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   311
                    // Process all entries in this directory
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   312
                    Set<String> subList = expand(f, dirInputSet, processed);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   313
                    includedFiles.addAll(subList);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   314
                    processed.add(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   318
        return includedFiles;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   320
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   321
    /**
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   322
     * Find all module sub directories to be used as source roots.
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   323
     * @param moduleMode If true, assume sub directories are modules, otherwise
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   324
     *                   just use current working directory.
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   325
     * @return List of all found source roots
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   326
     */
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   327
    private List<File> findModuleDirs(boolean moduleMode) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   328
        File cwd = new File(".");
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   329
        List<File> moduleDirs = new ArrayList<File>();
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   330
        if (moduleMode) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   331
            for (File f : cwd.listFiles()) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   332
                if (f.isDirectory()) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   333
                    moduleDirs.add(f);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   334
                }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   335
            }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   336
        } else {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   337
            moduleDirs.add(cwd);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   338
        }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   339
        return moduleDirs;
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   340
    }
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   341
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   342
    private String cleanPath(File f) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   343
        String path = f.getPath();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   344
        if (f.isFile()) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   345
            path = cleanFilePath(path);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   346
        } else if (f.isDirectory()) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   347
            path = cleanDirPath(path);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   348
        } else {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   349
            System.err.println("WARNING: Path does not exist as file or directory: " + path);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   350
            path = null;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   351
        }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   352
        return path;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   353
    }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   354
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   355
    private String cleanFilePath(String path) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   356
        // Remove leading and trailing whitespace
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   357
        path = path.trim();
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   358
        // Make all / and \ chars one
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   359
        if (File.separatorChar == '/') {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   360
            path = path.replace('\\', '/');
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   361
        } else {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   362
            path = path.replace('/', '\\');
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   363
        }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   364
        // Remove leading ./
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   365
        while (path.startsWith("." + File.separator)) {
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   366
            path = path.substring(2);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   367
        }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   368
        return path;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   369
    }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   370
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   371
    private String cleanDirPath(String path) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   372
        path = cleanFilePath(path);
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   373
        // Make sure it ends with a file separator
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   374
        if (!path.endsWith(File.separator)) {
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   375
            path = path + File.separator;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   376
        }
25859
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   377
        // Remove any /./ in the path.
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   378
        if (path.endsWith(File.separator + "." + File.separator)) {
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   379
            path = path.substring(0, path.length() - 2);
3317bb8137f4 8054834: Modular Source Code
chegar
parents: 23010
diff changeset
   380
        }
5967
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   381
        return path;
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   382
    }
26b773bf22ea 6933622: Duplicate class files in rt.jar and charsets.jar
ohair
parents: 5506
diff changeset
   383
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
}