ExcludeFilesPlugin.java revision 14906:5cfbcb4e6009
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.util.Map; 28import java.util.function.Predicate; 29import jdk.tools.jlink.plugin.TransformerPlugin; 30import jdk.tools.jlink.plugin.ModulePool; 31import jdk.tools.jlink.plugin.ModuleEntry; 32 33/** 34 * 35 * Exclude files plugin 36 */ 37public final class ExcludeFilesPlugin implements TransformerPlugin { 38 39 public static final String NAME = "exclude-files"; 40 private Predicate<String> predicate; 41 42 @Override 43 public String getName() { 44 return NAME; 45 } 46 47 @Override 48 public void visit(ModulePool in, ModulePool out) { 49 in.transformAndCopy((file) -> { 50 if (!file.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) { 51 file = predicate.test(file.getPath()) ? file : null; 52 } 53 return file; 54 }, out); 55 } 56 57 @Override 58 public Category getType() { 59 return Category.FILTER; 60 } 61 62 @Override 63 public String getDescription() { 64 return PluginsResourceBundle.getDescription(NAME); 65 } 66 67 @Override 68 public boolean hasArguments() { 69 return true; 70 } 71 72 @Override 73 public String getArgumentsDescription() { 74 return PluginsResourceBundle.getArgument(NAME); 75 } 76 77 @Override 78 public void configure(Map<String, String> config) { 79 predicate = ResourceFilter.excludeFilter(config.get(NAME)); 80 } 81} 82