package gw.vark.interactive;
import gw.lang.Gosu;
import gw.lang.launch.ArgInfo;
import gw.lang.parser.exceptions.ParseResultsException;
import gw.lang.reflect.IType;
import gw.lang.reflect.ITypeRef;
import gw.lang.reflect.TypeSystem;
import gw.util.GosuClassUtil;
import gw.vark.Aardvark;
import gw.vark.AardvarkProgram;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
private HashMap<File,Long> _timestamps = new HashMap<File, Long>();
private final ArgInfo.IProgramSource _programSource;
private List<File> _cpDirs;
private AardvarkProgram _aardvarkProject;
_programSource = programSource;
}
return _aardvarkProject;
}
maybeParseVarkFile();
scanForChanges();
}
boolean newProject = false;
if (_aardvarkProject == null) {
newProject = true;
}
if (_programSource.getFile() != null) {
File varkFile = _programSource.getFile();
long timestamp = varkFile.lastModified();
Long lastTimestamp = _timestamps.get(varkFile);
if (lastTimestamp == null || timestamp != lastTimestamp) {
newProject = true;
}
_timestamps.put(varkFile, timestamp);
}
if (newProject) {
Project antProject = new Project();
Aardvark.setProject(antProject, new DefaultLogger());
_aardvarkProject = AardvarkProgram.parse(antProject, _programSource);
}
}
boolean updateResources = true;
if (_cpDirs == null) {
_cpDirs = parseClasspathDirs();
updateResources = false;
}
for (File cpDir : _cpDirs) {
checkForClassFileChanges(cpDir, cpDir, updateResources);
}
if (updateResources) {
TypeSystem.getGosuClassLoader().reloadChangedClasses();
}
}
if (file.isFile()) {
String ext = GosuClassUtil.getFileExtension(file);
if (".gs".equals(ext) || ".gsx".equals(ext)) {
long modified = file.lastModified();
if (updateResources) {
Long lastTimeStamp = _timestamps.get(file);
if (lastTimeStamp == null || modified != lastTimeStamp) {
fireResourceUpdate(cpDir, file);
}
}
_timestamps.put(file, modified);
}
} else if (file.isDirectory()) {
for (File child : file.listFiles()) {
checkForClassFileChanges(cpDir, child, updateResources);
}
}
}
String filePath = file.getPath();
String rootPath = cpDir.getPath();
String relPath = filePath.substring(rootPath.length() + 1, filePath.lastIndexOf('.'));
String typeName = relPath.replace(File.separatorChar, '.');
IType type = TypeSystem.getByFullNameIfValid(typeName);
if (type != null) {
TypeSystem.refresh((ITypeRef) type, true);
}
}
List<File> dirs = new ArrayList<File>();
for (File file : Gosu.deriveClasspathFrom(Aardvark.class)) {
if (file.isDirectory()) {
dirs.add(file);
}
}
return dirs;
}
}