static boolean isValidRoot (File file, File[] relatedRoots, File projectFolder) {
Project p;
if ((p = FileOwnerQuery.getOwner(file.toURI()))!=null
&& !file.getAbsolutePath().startsWith(projectFolder.getAbsolutePath()+File.separatorChar)) {
final Sources sources = (Sources) p.getLookup().lookup(Sources.class);
if (sources == null) {
return false;
}
final SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
final SourceGroup[] javaGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
final SourceGroup[] groups = new SourceGroup [sourceGroups.length + javaGroups.length];
System.arraycopy(sourceGroups,0,groups,0,sourceGroups.length);
System.arraycopy(javaGroups,0,groups,sourceGroups.length,javaGroups.length);
final FileObject projectDirectory = p.getProjectDirectory();
final FileObject fileObject = FileUtil.toFileObject(file);