📄 patternset.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package org.apache.tools.ant.types;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.util.Enumeration;import java.util.StringTokenizer;import java.util.Vector;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Project;/** * Named collection of include/exclude tags. * * <p>Moved out of MatchingTask to make it a standalone object that * could be referenced (by scripts for example). * */public class PatternSet extends DataType implements Cloneable { private Vector includeList = new Vector(); private Vector excludeList = new Vector(); private Vector includesFileList = new Vector(); private Vector excludesFileList = new Vector(); /** * inner class to hold a name on list. "If" and "Unless" attributes * may be used to invalidate the entry based on the existence of a * property (typically set thru the use of the Available task). */ public class NameEntry { private String name; private String ifCond; private String unlessCond; /** * Sets the name pattern. * * @param name The pattern string. */ public void setName(String name) { this.name = name; } /** * Sets the if attribute. This attribute and the "unless" * attribute are used to validate the name, based in the * existence of the property. * * @param cond A property name. If this property is not * present, the name is invalid. */ public void setIf(String cond) { ifCond = cond; } /** * Sets the unless attribute. This attribute and the "if" * attribute are used to validate the name, based in the * existence of the property. * * @param cond A property name. If this property is * present, the name is invalid. */ public void setUnless(String cond) { unlessCond = cond; } /** * @return the name attribute. */ public String getName() { return name; } /** * This validates the name - checks the if and unless * properties. * * @param p the current project, used to check the presence or * absence of a property. * @return the name attribute or null if the "if" or "unless" * properties are not/are set. */ public String evalName(Project p) { return valid(p) ? name : null; } private boolean valid(Project p) { if (ifCond != null && p.getProperty(ifCond) == null) { return false; } else if (unlessCond != null && p.getProperty(unlessCond) != null) { return false; } return true; } /** * @return a printable form of this object. */ public String toString() { StringBuffer buf = new StringBuffer(); if (name == null) { buf.append("noname"); } else { buf.append(name); } if ((ifCond != null) || (unlessCond != null)) { buf.append(":"); String connector = ""; if (ifCond != null) { buf.append("if->"); buf.append(ifCond); connector = ";"; } if (unlessCond != null) { buf.append(connector); buf.append("unless->"); buf.append(unlessCond); } } return buf.toString(); } } private static final class InvertedPatternSet extends PatternSet { private InvertedPatternSet(PatternSet p) { setProject(p.getProject()); addConfiguredPatternset(p); } public String[] getIncludePatterns(Project p) { return super.getExcludePatterns(p); } public String[] getExcludePatterns(Project p) { return super.getIncludePatterns(p); } } /** * Creates a new <code>PatternSet</code> instance. */ public PatternSet() { super(); } /** * Makes this instance in effect a reference to another PatternSet * instance. * * <p>You must not set another attribute or nest elements inside * this element if you make it a reference.</p> * @param r the reference to another patternset. * @throws BuildException on error. */ public void setRefid(Reference r) throws BuildException { if (!includeList.isEmpty() || !excludeList.isEmpty()) { throw tooManyAttributes(); } super.setRefid(r); } /** * This is a patternset nested element. * * @param p a configured patternset nested element. */ public void addConfiguredPatternset(PatternSet p) { if (isReference()) { throw noChildrenAllowed(); } String[] nestedIncludes = p.getIncludePatterns(getProject()); String[] nestedExcludes = p.getExcludePatterns(getProject()); if (nestedIncludes != null) { for (int i = 0; i < nestedIncludes.length; i++) { createInclude().setName(nestedIncludes[i]); } } if (nestedExcludes != null) { for (int i = 0; i < nestedExcludes.length; i++) { createExclude().setName(nestedExcludes[i]); } } } /** * add a name entry on the include list * @return a nested include element to be configured. */ public NameEntry createInclude() { if (isReference()) { throw noChildrenAllowed(); } return addPatternToList(includeList); } /** * add a name entry on the include files list * @return a nested includesfile element to be configured. */ public NameEntry createIncludesFile() { if (isReference()) { throw noChildrenAllowed(); } return addPatternToList(includesFileList); } /** * add a name entry on the exclude list * @return a nested exclude element to be configured. */ public NameEntry createExclude() { if (isReference()) { throw noChildrenAllowed(); } return addPatternToList(excludeList); } /** * add a name entry on the exclude files list * @return a nested excludesfile element to be configured. */ public NameEntry createExcludesFile() { if (isReference()) { throw noChildrenAllowed(); } return addPatternToList(excludesFileList); } /** * Appends <code>includes</code> to the current list of include patterns. * Patterns may be separated by a comma or a space. * * @param includes the string containing the include patterns */ public void setIncludes(String includes) { if (isReference()) { throw tooManyAttributes(); } if (includes != null && includes.length() > 0) { StringTokenizer tok = new StringTokenizer(includes, ", ", false); while (tok.hasMoreTokens()) { createInclude().setName(tok.nextToken()); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -