From: <cg...@us...> - 2008-10-20 01:01:47
|
Revision: 5475 http://jython.svn.sourceforge.net/jython/?rev=5475&view=rev Author: cgroves Date: 2008-10-20 01:01:39 +0000 (Mon, 20 Oct 2008) Log Message: ----------- Add an ant resource collection that's like union except it combines based on the name of the resource instead of its full path. Use this to exclude the unexposed version of classes from jython.jar to keep it quiet. Resource collections didn't appear until Ant 1.7, but that came out nearly 2 years ago, so I'm hoping most people already have it. Modified Paths: -------------- trunk/jython/build.xml Added Paths: ----------- trunk/jython/src/org/python/util/NameUnionAntType.java Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2008-10-20 00:44:52 UTC (rev 5474) +++ trunk/jython/build.xml 2008-10-20 01:01:39 UTC (rev 5475) @@ -549,9 +549,17 @@ </target> <target name="jar" depends="compile,expose,jarjar"> - <jar destfile="${dist.dir}/jython.jar" duplicate="preserve"> - <fileset dir="${exposed.dir}"/> - <fileset dir="${compile.dir}"/> + <typedef name="nameunion" classname="org.python.util.NameUnionAntType"> + <classpath> + <path refid="main.classpath" /> + <pathelement path="${compile.dir}" /> + </classpath> + </typedef> + <jar destfile="${dist.dir}/jython.jar" duplicate="fail"> + <nameunion> + <fileset dir="${exposed.dir}"/> + <fileset dir="${compile.dir}"/> + </nameunion> <fileset dir="${jarjar.dir}"> <include name="org/python/objectweb/asm/ClassReader.class" /> </fileset> Added: trunk/jython/src/org/python/util/NameUnionAntType.java =================================================================== --- trunk/jython/src/org/python/util/NameUnionAntType.java (rev 0) +++ trunk/jython/src/org/python/util/NameUnionAntType.java 2008-10-20 01:01:39 UTC (rev 5475) @@ -0,0 +1,35 @@ +package org.python.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.ResourceCollection; +import org.apache.tools.ant.types.resources.BaseResourceCollectionContainer; + +/** + * Unions several resource collections by the name of their contained resources. + */ +public class NameUnionAntType extends BaseResourceCollectionContainer { + @SuppressWarnings("unchecked") + @Override + protected Collection<Resource> getCollection() { + List<ResourceCollection> collections = getResourceCollections(); + // preserve order-encountered using a list; keep track of the items with a set + Set<String> seenNames = new HashSet<String>(); + List<Resource> union = new ArrayList(); + for (ResourceCollection rc : collections) { + for (Iterator<Resource> resources = rc.iterator(); resources.hasNext();) { + Resource r = resources.next(); + if (seenNames.add(r.getName())) { + union.add(r); + } + } + } + return union; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |