Getting a syntax error at line:
`List<Class> findClasses(File directory)` throws `ClassNotFoundException`...
Not able to figure out why. Here is my code.
import org.apache.tools.ant.Task;
import java.util.*;
import java.io.*;
public class CreateTestPackage extends Task
{
String allTestsFile = getProject().getProperty("alltestfiles")+ getProject().getProperty("testfile");
public void execute()
{
List<Class> findClasses(File directory) throws ClassNotFoundException
{
List<Class> classes = new ArrayList<Class>();
if (!directory.exists())
{
return classes;
}
File[] files = directory.listFiles(new FilenameFilter()
{
public boolean accept( File dir, String name )
{
return name.matches("test.*\\.class");
}
});
for (File file : files)
{
if (file.isDirectory())
{
assert !file.getName().contains(".");
classes.addAll(findClasses(file));
}
else if (file.getName().endsWith(".class"))
{
classes.add(Class.forName(file.getName().substring(0, file.getName().length() - 6)));
}
}
return classes;
}
for(Class c : classes)
{
string packageName=c.getPackage().getName();
BufferedWriter out =null;
try
{
out = new BufferedWriter(new FileWriter(testfile));
out.write(packageName+"\n");
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (out!=null)
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
}