jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java
author redestad
Fri, 17 Feb 2017 18:12:55 +0100
changeset 43837 51a9f82cff03
parent 42330 bd999576b78d
permissions -rw-r--r--
8175026: Capture build-time parameters to --generate-jli-classes Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
package jdk.tools.jlink.internal.plugins;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.io.File;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.IOException;
42330
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 39834
diff changeset
    29
import java.io.UncheckedIOException;
38871
ec08bf1979d4 8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents: 38320
diff changeset
    30
import java.nio.file.FileSystem;
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    31
import java.nio.file.Files;
38871
ec08bf1979d4 8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents: 38320
diff changeset
    32
import java.nio.file.PathMatcher;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.ArrayList;
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    34
import java.util.HashMap;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.util.Map;
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    37
import java.util.function.ToIntFunction;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.tools.jlink.plugin.PluginException;
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    39
import jdk.tools.jlink.plugin.ResourcePool;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    40
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    41
import jdk.tools.jlink.plugin.ResourcePoolEntry;
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39308
diff changeset
    42
import jdk.tools.jlink.plugin.Plugin;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import jdk.tools.jlink.internal.Utils;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 *
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    47
 * Order Resources plugin
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
 */
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39308
diff changeset
    49
public final class OrderResourcesPlugin implements Plugin {
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    50
    public static final String NAME = "order-resources";
38871
ec08bf1979d4 8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents: 38320
diff changeset
    51
    private static final FileSystem JRT_FILE_SYSTEM = Utils.jrtFileSystem();
ec08bf1979d4 8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents: 38320
diff changeset
    52
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    53
    private final List<ToIntFunction<String>> filters;
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    54
    private final Map<String, Integer> orderedPaths;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    56
    public OrderResourcesPlugin() {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    57
        this.filters = new ArrayList<>();
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    58
        this.orderedPaths = new HashMap<>();
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    59
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        return NAME;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    static class SortWrapper {
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    67
        private final ResourcePoolEntry resource;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        private final int ordinal;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    70
        SortWrapper(ResourcePoolEntry resource, int ordinal) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            this.resource = resource;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
            this.ordinal = ordinal;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    75
        ResourcePoolEntry getResource() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
            return resource;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        String getPath() {
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    80
            return resource.path();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        int getOrdinal() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            return ordinal;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    88
    private String stripModule(String path) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    89
        if (path.startsWith("/")) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    90
            int index = path.indexOf('/', 1);
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    91
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    92
            if (index != -1) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    93
                return path.substring(index + 1);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        }
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    96
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
    97
        return path;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   100
    private int getOrdinal(ResourcePoolEntry resource) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   101
        String path = resource.path();
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   102
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   103
        Integer value = orderedPaths.get(stripModule(path));
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   104
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   105
        if (value != null) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   106
            return value;
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   107
        }
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   108
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   109
        for (ToIntFunction<String> function : filters) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   110
            int ordinal = function.applyAsInt(path);
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   111
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   112
            if (ordinal != Integer.MAX_VALUE) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   113
                return ordinal;
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   114
            }
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   115
        }
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   116
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   117
        return Integer.MAX_VALUE;
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   118
    }
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   119
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   120
    private static int compare(SortWrapper wrapper1, SortWrapper wrapper2) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   121
        int compare = wrapper1.getOrdinal() - wrapper2.getOrdinal();
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   122
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   123
        if (compare != 0) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   124
            return compare;
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   125
        }
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   126
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   127
        return wrapper1.getPath().compareTo(wrapper2.getPath());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    @Override
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   131
    public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37888
diff changeset
   132
        in.entries()
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   133
                .filter(resource -> resource.type()
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   134
                        .equals(ResourcePoolEntry.Type.CLASS_OR_RESOURCE))
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   135
                .map((resource) -> new SortWrapper(resource, getOrdinal(resource)))
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   136
                .sorted(OrderResourcesPlugin::compare)
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   137
                .forEach((wrapper) -> out.add(wrapper.getResource()));
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37888
diff changeset
   138
        in.entries()
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   139
                .filter(other -> !other.type()
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   140
                        .equals(ResourcePoolEntry.Type.CLASS_OR_RESOURCE))
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   141
                .forEach((other) -> out.add(other));
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   142
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   143
        return out.build();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
    @Override
39129
4b2086305b68 8159593: Plugin Set<Category> getType() should return a Category
sundar
parents: 39042
diff changeset
   147
    public Category getType() {
4b2086305b68 8159593: Plugin Set<Category> getType() should return a Category
sundar
parents: 39042
diff changeset
   148
        return Category.SORTER;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
    public String getDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        return PluginsResourceBundle.getDescription(NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
    public boolean hasArguments() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        return true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    public String getArgumentsDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
       return PluginsResourceBundle.getArgument(NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    public void configure(Map<String, String> config) {
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38871
diff changeset
   168
        List<String> patterns = Utils.parseList(config.get(NAME));
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   169
        int ordinal = 0;
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   170
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   171
        for (String pattern : patterns) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   172
            if (pattern.startsWith("@")) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   173
                File file = new File(pattern.substring(1));
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   174
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   175
                if (file.exists()) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   176
                    List<String> lines;
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   177
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   178
                    try {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   179
                        lines = Files.readAllLines(file.toPath());
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   180
                    } catch (IOException ex) {
42330
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 39834
diff changeset
   181
                        throw new UncheckedIOException(ex);
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   182
                    }
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   183
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   184
                    for (String line : lines) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   185
                        if (!line.startsWith("#")) {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   186
                            orderedPaths.put(line + ".class", ordinal++);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                }
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   190
            } else {
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   191
                final int result = ordinal++;
38871
ec08bf1979d4 8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents: 38320
diff changeset
   192
                final PathMatcher matcher = Utils.getPathMatcher(JRT_FILE_SYSTEM, pattern);
ec08bf1979d4 8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents: 38320
diff changeset
   193
                ToIntFunction<String> function = (path)-> matcher.matches(JRT_FILE_SYSTEM.getPath(path)) ? result : Integer.MAX_VALUE;
37888
c34e01b87292 8155237: jlink plugin to order resources should take a class list as input
jlaskey
parents: 36511
diff changeset
   194
                filters.add(function);
38871
ec08bf1979d4 8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents: 38320
diff changeset
   195
             }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
}