ExcludeFilesPlugin.java revision 14837:cc6fcc165e5d
1/*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25package jdk.tools.jlink.internal.plugins;
26
27import java.io.UncheckedIOException;
28import java.util.Collections;
29import java.util.HashSet;
30import java.util.Map;
31import java.util.Set;
32import java.util.function.Predicate;
33import jdk.tools.jlink.plugin.TransformerPlugin;
34import jdk.tools.jlink.plugin.ModulePool;
35import jdk.tools.jlink.plugin.ModuleEntry;
36import jdk.tools.jlink.internal.Utils;
37
38/**
39 *
40 * Exclude files plugin
41 */
42public final class ExcludeFilesPlugin implements TransformerPlugin {
43
44    public static final String NAME = "exclude-files";
45    private Predicate<String> predicate;
46
47    @Override
48    public String getName() {
49        return NAME;
50    }
51
52    @Override
53    public void visit(ModulePool in, ModulePool out) {
54        in.transformAndCopy((file) -> {
55            if (!file.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
56                file = predicate.test(file.getPath()) ? file : null;
57            }
58            return file;
59        }, out);
60    }
61
62    @Override
63    public Set<Category> getType() {
64        Set<Category> set = new HashSet<>();
65        set.add(Category.FILTER);
66        return Collections.unmodifiableSet(set);
67    }
68
69    @Override
70    public String getDescription() {
71        return PluginsResourceBundle.getDescription(NAME);
72    }
73
74    @Override
75    public boolean hasArguments() {
76        return true;
77    }
78
79    @Override
80    public String getArgumentsDescription() {
81       return PluginsResourceBundle.getArgument(NAME);
82    }
83
84    @Override
85    public void configure(Map<String, String> config) {
86        predicate = ResourceFilter.excludeFilter(config.get(NAME));
87    }
88}
89