langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsFilter.java
author mchung
Mon, 19 Dec 2016 12:30:39 -0800
changeset 42840 dfe1a03d4db4
parent 41860 906670ff49c7
permissions -rw-r--r--
8171418: Remove jdeps internal --include-system-modules option Reviewed-by: dfuchs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
package com.sun.tools.jdeps;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import com.sun.tools.classfile.Dependencies;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import com.sun.tools.classfile.Dependency;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import com.sun.tools.classfile.Dependency.Location;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.HashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.regex.Pattern;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 * Filter configured based on the input jdeps option
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 * 1. -p and -regex to match target dependencies
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 * 2. -filter:package to filter out same-package dependencies
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 *    This filter is applied when jdeps parses the class files
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 *    and filtered dependencies are not stored in the Analyzer.
41860
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
    41
 * 3. --require specifies to match target dependence from the given module
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 *    This gets expanded into package lists to be filtered.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
 * 4. -filter:archive to filter out same-archive dependencies
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 *    This filter is applied later in the Analyzer as the
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
 *    containing archive of a target class may not be known until
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 *    the entire archive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 */
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    48
public class JdepsFilter implements Dependency.Filter, Analyzer.Filter {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    49
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    50
    public static final JdepsFilter DEFAULT_FILTER =
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    51
        new JdepsFilter.Builder().filter(true, true).build();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    52
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private final Dependency.Filter filter;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private final Pattern filterPattern;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private final boolean filterSamePackage;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private final boolean filterSameArchive;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    private final boolean findJDKInternals;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    private final Pattern includePattern;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    59
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    60
    private final Set<String> requires;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    private JdepsFilter(Dependency.Filter filter,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                        Pattern filterPattern,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                        boolean filterSamePackage,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                        boolean filterSameArchive,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                        boolean findJDKInternals,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                        Pattern includePattern,
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    68
                        Set<String> requires) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        this.filter = filter;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        this.filterPattern = filterPattern;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        this.filterSamePackage = filterSamePackage;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        this.filterSameArchive = filterSameArchive;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        this.findJDKInternals = findJDKInternals;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        this.includePattern = includePattern;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    75
        this.requires = requires;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
     * Tests if the given class matches the pattern given in the -include option
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
     * @param cn fully-qualified name
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    public boolean matches(String cn) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    84
        if (includePattern == null)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        if (includePattern != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            return includePattern.matcher(cn).matches();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    /**
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    94
     * Tests if the given source includes classes specified in -include option
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
     * This method can be used to determine if the given source should eagerly
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
     * be processed.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
    public boolean matches(Archive source) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   100
        if (includePattern != null) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   101
            return source.reader().entries().stream()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   102
                    .map(name -> name.replace('/', '.'))
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   103
                    .filter(name -> !name.equals("module-info.class"))
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   104
                    .anyMatch(this::matches);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   106
        return hasTargetFilter();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   107
    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   108
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   109
    public boolean hasIncludePattern() {
42840
dfe1a03d4db4 8171418: Remove jdeps internal --include-system-modules option
mchung
parents: 41860
diff changeset
   110
        return includePattern != null;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   111
    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   112
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   113
    public boolean hasTargetFilter() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   114
        return filter != null;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   115
    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   116
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   117
    public Set<String> requiresFilter() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   118
        return requires;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    // ----- Dependency.Filter -----
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    public boolean accepts(Dependency d) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        if (d.getOrigin().equals(d.getTarget()))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        // filter same package dependency
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        String pn = d.getTarget().getPackageName();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        if (filterSamePackage && d.getOrigin().getPackageName().equals(pn)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        // filter if the target package matches the given filter
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        if (filterPattern != null && filterPattern.matcher(pn).matches()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        // filter if the target matches the given filtered package name or regex
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        return filter != null ? filter.accepts(d) : true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    // ----- Analyzer.Filter ------
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
     * Filter depending on the containing archive or module
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    public boolean accepts(Location origin, Archive originArchive,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                           Location target, Archive targetArchive) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        if (findJDKInternals) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
            // accepts target that is JDK class but not exported
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            Module module = targetArchive.getModule();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
            return originArchive != targetArchive &&
41860
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   155
                    isJDKInternalPackage(module, target.getPackageName());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        } else if (filterSameArchive) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            // accepts origin and target that from different archive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
            return originArchive != targetArchive;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
41860
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   163
    /**
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   164
     * Tests if the package is an internal package of the given module.
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   165
     */
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   166
    public boolean isJDKInternalPackage(Module module, String pn) {
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   167
        if (module.isJDKUnsupported()) {
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   168
            // its exported APIs are unsupported
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   169
            return true;
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   170
        }
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   171
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   172
        return module.isJDK() && !module.isExported(pn);
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   173
    }
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 38524
diff changeset
   174
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
    public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        StringBuilder sb = new StringBuilder();
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   178
        sb.append("include pattern: ").append(includePattern).append("\n");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        sb.append("filter same archive: ").append(filterSameArchive).append("\n");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        sb.append("filter same package: ").append(filterSamePackage).append("\n");
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   181
        sb.append("requires: ").append(requires).append("\n");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        return sb.toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   185
    public static class Builder {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        Pattern filterPattern;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   187
        Pattern regex;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        boolean filterSamePackage;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        boolean filterSameArchive;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        boolean findJDKInterals;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        // source filters
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        Pattern includePattern;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   193
        Set<String> requires = new HashSet<>();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   194
        Set<String> targetPackages = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
42840
dfe1a03d4db4 8171418: Remove jdeps internal --include-system-modules option
mchung
parents: 41860
diff changeset
   196
        public Builder() {};
dfe1a03d4db4 8171418: Remove jdeps internal --include-system-modules option
mchung
parents: 41860
diff changeset
   197
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        public Builder packages(Set<String> packageNames) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   199
            this.targetPackages.addAll(packageNames);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
            return this;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        public Builder regex(Pattern regex) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   203
            this.regex = regex;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
            return this;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        public Builder filter(Pattern regex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
            this.filterPattern = regex;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
            return this;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        public Builder filter(boolean samePackage, boolean sameArchive) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
            this.filterSamePackage = samePackage;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
            this.filterSameArchive = sameArchive;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
            return this;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   215
        public Builder requires(String name, Set<String> packageNames) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   216
            this.requires.add(name);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   217
            this.targetPackages.addAll(packageNames);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   218
            return this;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   219
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        public Builder findJDKInternals(boolean value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
            this.findJDKInterals = value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
            return this;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        public Builder includePattern(Pattern regex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
            this.includePattern = regex;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
            return this;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   229
        public JdepsFilter build() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   230
            Dependency.Filter filter = null;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   231
            if (regex != null)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   232
                filter = Dependencies.getRegexFilter(regex);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   233
            else if (!targetPackages.isEmpty()) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   234
                filter = Dependencies.getPackageFilter(targetPackages, false);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   235
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            return new JdepsFilter(filter,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                                   filterPattern,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                                   filterSamePackage,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                                   filterSameArchive,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                                   findJDKInterals,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                                   includePattern,
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   242
                                   requires);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
}