There are no built in selectors. But you can write your own and plug in via
<typedef>.
Here is a working example. But it has the drawback, that the *.class files must
be in the same directory as the *.java files (which is mostly NOT the case).
Jan
<project>
<typedef name="deprecated" classname="AnnotationSelector"
classpath="C:\TEMP\ec-test\AntSelector\bin"/>
<fileset id="fs" dir="." includes="**/*.java">
<deprecated/>
</fileset>
<echo>selected Files: ${toString:fs}</echo>
</project>
import java.io.File;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.net.URLClassLoader;
public class AnnotationSelector extends
org.apache.tools.ant.types.selectors.BaseSelector {
private static final Class<? extends Annotation> ANNOTATION_TO_SELECT =
Deprecated.class;
@Override
public boolean isSelected(File basedir, String filename, File file) {
try {
return selectIfAnnotated(basedir, filename, file);
} catch (ClassNotFoundException e) {
System.err.print("Class '");
System.err.print(e.getMessage());
System.err.print("' could not be found. Are the
BINARIES on the classpath? Therefore ");
System.err.print(filename);
System.err.println(" is deselected.");
return false;
} catch (Exception e) {
return false;
}
}
private boolean selectIfAnnotated(File basedir, String filename, File
file) throws Exception {
// Create a ClassLoader for the filesets basedir which we can
use for analyzing the specified class.
URLClassLoader loader = new URLClassLoader(new
URL[]{basedir.toURI().toURL()});
// Get a class name from the file name.
String classname = filename.substring(0,
filename.lastIndexOf('.')).replaceAll("\\\\", "\\.");
// Load that class.
Class<?> clazz = loader.loadClass(classname);
// Check the presence of the annotation an select if annotated.
return clazz.isAnnotationPresent(ANNOTATION_TO_SELECT);
}
}
>-----Ursprüngliche Nachricht-----
>Von: news [mailto:[EMAIL PROTECTED] Im Auftrag von Chris
>Gesendet: Mittwoch, 22. Oktober 2008 02:48
>An: [email protected]
>Betreff: Building a <fileset> using annotations
>
>Is it possible in Ant to create a <fileset> that consists of
>.java files
>that have some annotation?
>
>For example, if I create a custom annotation, like "@published", and
>attach it to several classes, is there some way to get a list of such
>classes in a fileset?
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]