[Clirr-devel] CVS: clirr/core/src/java/net/sf/clirr/ant PatternSetFilter.java,NONE,1.1 AntTask.java,
Status: Alpha
Brought to you by:
lkuehne
From: <lk...@us...> - 2005-03-06 17:01:46
|
Update of /cvsroot/clirr/clirr/core/src/java/net/sf/clirr/ant In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19003/src/java/net/sf/clirr/ant Modified Files: AntTask.java Added Files: PatternSetFilter.java Log Message: The Ant task now allows to exclude classes from compatibility checks via the 'apiclasses' subelement. --- NEW FILE --- ////////////////////////////////////////////////////////////////////////////// // Clirr: compares two versions of a java library for binary compatibility // Copyright (C) 2003 - 2004 Lars Kühne // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ////////////////////////////////////////////////////////////////////////////// package net.sf.clirr.ant; import net.sf.clirr.core.ClassFilter; import java.util.List; import java.io.File; import org.apache.bcel.classfile.JavaClass; import org.apache.tools.ant.types.selectors.SelectorUtils; import org.apache.tools.ant.types.PatternSet; import org.apache.tools.ant.Project; /** * A ClassFilter that uses Ant PatternSets as the decision criteria. * * @author lkuehne */ class PatternSetFilter implements ClassFilter { private final Project project; private final List patternSets; /** * Creates a new PatternSetFilter. * @param project the current Ant project * @param patternSets a List of Ant PatternSet objects */ public PatternSetFilter(Project project, List patternSets) { this.project = project; this.patternSets = patternSets; } public boolean isSelected(JavaClass clazz) { // The patternset evaluation code below was copied from Apache Ant's Expand task. // I feel this code should be available as a library function inside Ant somewhere... String className = clazz.getClassName(); String name = className.replace('.', '/'); if (patternSets == null || patternSets.isEmpty()) { return true; } boolean included = false; for (int i = 0; i < patternSets.size(); i++) { PatternSet p = (PatternSet) patternSets.get(i); p.getIncludePatterns(project); String[] incls = p.getIncludePatterns(project); if (incls == null || incls.length == 0) { // no include pattern implicitly means includes="**" incls = new String[] {"**"}; } for (int w = 0; w < incls.length; w++) { String pattern = incls[w].replace('/', File.separatorChar) .replace('\\', File.separatorChar); if (pattern.endsWith(File.separator)) { pattern += "**"; } included = SelectorUtils.matchPath(pattern, name); if (included) { break; } } if (!included) { break; } String[] excls = p.getExcludePatterns(project); if (excls != null) { for (int w = 0; w < excls.length; w++) { String pattern = excls[w] .replace('/', File.separatorChar) .replace('\\', File.separatorChar); if (pattern.endsWith(File.separator)) { pattern += "**"; } included = !(SelectorUtils.matchPath(pattern, name)); if (!included) { break; } } } } System.out.println("included " + className + " = " + included); return included; } } Index: AntTask.java =================================================================== RCS file: /cvsroot/clirr/clirr/core/src/java/net/sf/clirr/ant/AntTask.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AntTask.java 3 Sep 2004 23:05:07 -0000 1.3 +++ AntTask.java 6 Mar 2005 17:01:34 -0000 1.4 @@ -32,6 +32,8 @@ import net.sf.clirr.core.CheckerException; import net.sf.clirr.core.PlainDiffListener; import net.sf.clirr.core.XmlDiffListener; +import net.sf.clirr.core.ClassSelector; +import net.sf.clirr.core.ClassFilter; import net.sf.clirr.core.internal.ExceptionUtil; import org.apache.tools.ant.BuildException; @@ -40,6 +42,8 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.PatternSet; +import org.apache.bcel.classfile.JavaClass; /** @@ -88,6 +92,25 @@ } } + /** + * Class Filter that returns the logical "and" of two underlying class filters. + */ + private static class CompoundClassFilter implements ClassFilter + { + private final ClassFilter patternSetFilter; + private final ClassFilter scopeSelector; + + public CompoundClassFilter(ClassFilter patternSetFilter, ClassFilter scopeSelector) + { + this.patternSetFilter = patternSetFilter; + this.scopeSelector = scopeSelector; + } + + public boolean isSelected(JavaClass clazz) + { + return patternSetFilter.isSelected(clazz) && scopeSelector.isSelected(clazz); + } + } private FileSet origFiles = null; private FileSet newFiles = null; @@ -99,6 +122,7 @@ private boolean failOnSrcError = true; private boolean failOnSrcWarning = false; private List formatters = new LinkedList(); + private List patternSets = new LinkedList(); public Path createNewClassPath() @@ -186,6 +210,11 @@ formatters.add(formatter); } + public void addApiClasses(PatternSet set) + { + patternSets.add(set); + } + public void execute() { log("Running Clirr, built from tag $Name$", Project.MSG_VERBOSE); @@ -266,7 +295,7 @@ try { checker.reportDiffs( - origJars, newJars, origThirdPartyLoader, newThirdPartyLoader, null); + origJars, newJars, origThirdPartyLoader, newThirdPartyLoader, buildClassFilter()); } catch (CheckerException ex) { @@ -286,6 +315,13 @@ } } + private ClassFilter buildClassFilter() + { + final PatternSetFilter patternSetFilter = new PatternSetFilter(getProject(), patternSets); + final ClassFilter scopeSelector = new ClassSelector(ClassSelector.MODE_UNLESS); + return new CompoundClassFilter(patternSetFilter, scopeSelector); + } + private ClassLoader createClasspathLoader(Path classpath) { @@ -328,4 +364,5 @@ } return ret; } + } |