if (!container.exists()) {
throw new RuntimeException("The directory passed: " + container + " no longer exists.");
}
File file = container.getLocation().toFile();
PyFileListing pyFilesBelow = new PyFileListing();
if (file.exists()) {
pyFilesBelow = PyFileListing.getPyFilesBelow(file, monitor, true, false);
}
if (pyFilesBelow.getFoundPyFileInfos().size() == 0) { //no files
return;
}
//add the folders to the cache
boolean added = false;
for (Iterator<File> it = pyFilesBelow.getFoundFolders().iterator(); it.hasNext();) {
File f = it.next();
if (!added) {
cache.addFolder(f);
added = true;
} else {
cache.addFolder(f, f.getParentFile());
}
}
PythonNature nature = PythonNature.getPythonNature(container);
if (nature == null) {
throw new RuntimeException("The directory passed: " + container
+ " does not have an associated nature.");
}
AbstractRunner runner = UniversalRunner.getRunner(nature);
//First, combine the results of the many runs we may have.
Tuple<String, String> output = runner.runScriptAndGetOutput(PythonRunnerConfig.getCoverageScript(),
new String[] { "combine" }, getCoverageDirLocation(), monitor);
if (output.o1 != null && output.o1.length() > 0) {
Log.logInfo(output.o1);
}
if (output.o2 != null && output.o2.length() > 0) {
if (output.o2.startsWith("Coverage.py warning:")) {
Log.logInfo(output.o2);
} else {
Log.log(output.o2);
}
}
//we have to make a process to execute the script. it should look
// like:
//coverage.py -r [-m] FILE1 FILE2 ...
//Report on the statement coverage for the given files. With the -m
//option, show line numbers of the statements that weren't
// executed.
//python coverage.py -r -m files....
monitor.setTaskName("Starting shell to get info...");
monitor.worked(1);
Process p = null;
try {
// Tuple<Process, String> tup = runner.createProcess(
// PythonRunnerConfig.getCoverageScript(), new String[]{
// "-r", "-m", "--include", ".*"}, getCoverageDirLocation(), monitor);
Tuple<Process, String> tup = runner.createProcess(PythonRunnerConfig.getCoverageScript(),
new String[] { "--pydev-analyze" }, getCoverageDirLocation(), monitor);
p = tup.o1;
try {
p.exitValue();
throw new RuntimeException("Some error happened... the process could not be created.");
} catch (Exception e) {
//that's ok
}
String files = "";
for (Iterator<PyFileInfo> iter = pyFilesBelow.getFoundPyFileInfos().iterator(); iter.hasNext();) {
String fStr = iter.next().getFile().toString();
files += fStr + "|";
}
files += "\r";
monitor.setTaskName("Writing to shell...");