{
throw new RuntimeException(
"Java Contract Suite: error list of source files is empty or no matches for pattern(s), no files to process!");
}
DependencyAnalyzer da = new DependencyAnalyzer();
Graph dependencyGraph = null;
log.info("parsing input files to determine dependencies.");
long start = System.currentTimeMillis();
MultipleCompilationUnitState multipleCompilationUnitState = new MultipleCompilationUnitState();
try
{
for (int targetIndex = 0; targetIndex < targets.size(); targetIndex++)
{
String filename = ((Target) targets.elementAt(targetIndex)).getName();
try
{
Reader is = new FileReader(filename);
try
{
BufferedReader bufferedIs = new BufferedReader(is);
try
{
recent_file = filename;
if (++number_of_files % 50 == 0 && number_of_files > 0)
{
log.info(" (" + number_of_files + " files parsed)");
}
net.sf.jcontracts.codeparser.Parser parser = new net.sf.jcontracts.codeparser.Parser(
bufferedIs, filename, multipleCompilationUnitState);
MetaclassFactory metaclassFactory = new MetaclassFactory(filename);
parser.setMetaclassFactory(metaclassFactory);
Vector v = parser.getUsedTypes();
da.process(v);
}
finally
{
bufferedIs.close();
}
}
finally
{
is.close();
}
}
catch (FileNotFoundException _ex)
{
throw new RuntimeException("Java Contract Suite: error file " + filename + " not found!", _ex);
}
}
long end = System.currentTimeMillis();
log.info("Analyzed " + targets.size() + " files in " + (end - start) / 1000D + " s.");
}
catch (Exception e)
{
log.error("parsing problem while looking at " + recent_file);
throw e;
}
if (multipleCompilationUnitState.hasUnresolvedNames())
{
String unresolvedNames = multipleCompilationUnitState.getUnresolvedNamesAsString();
log.error("could not resolve the following type names:\n" + unresolvedNames);
throw new RuntimeException("could not resolve the following type names:\n" + unresolvedNames);
}
dependencyGraph = da.getGraph();
log.info("found " + dependencyGraph.getSize() + " relavant types referenced in the " + targets.size()
+ " files.");
AllOption allOption = null;
for (int i = 0; i < options.size(); i++)
{
if ("a".compareTo(((Option) options.elementAt(i)).getName()) == 0)
{
allOption = (AllOption) options.elementAt(i);
}
}
OutputOption tmpOutputOption = null;
for (int i = 0; i < options.size(); i++)
{
if ("o".compareTo(((Option) options.elementAt(i)).getName()) == 0)
{
tmpOutputOption = (OutputOption) options.elementAt(i);
}
}
final OutputOption outputOption = tmpOutputOption;
Hashtable dep = null;
log.info("starting dependency analysis (among " + dependencyGraph.getSize() + " types)");
if (outputOption != null)
{
if (allOption != null)
{
log.info("unconditionally instrumenting all files (-a).");
dep = dependencyGraph.getFileDependencyTable(new BooleanBlockWithNodeArg()
{
public boolean eval(Node n)
{
return true;
}
});
}
else
{
dep = dependencyGraph.getFileDependencyTable(new BooleanBlockWithNodeArg()
{
public boolean eval(Node n)
{
boolean needsUpdate = false;
if (!n.getFilename().equals("???"))
{
String fon = "";
try
{
fon = outputOption.getOutputFileName(n.getFilename(), n.getPackagename());
}
catch (IOException e)
{
throw new RuntimeException("File " + n.getFilename()
+ " got deleted although the last check indicated its presence."
+ e.toString());
}
File fo = new File(fon);
File fcmc = new File(n.getFilename());
if (fo.lastModified() <= fcmc.lastModified())
{
needsUpdate = true;
log.info("**Java Contract Suite:INFO " + fon + " needs to be updated based on "
+ n.getFilename());
}
else
{
log.info("**Java Contract Suite:INFO " + fon + " up to date.");
}
if (!needsUpdate)
{
log.info("instrumented " + n.getName() + " (" + fon + ") is up to date.");
}
}
return needsUpdate;
}
});
}
}
else
{
dep = dependencyGraph.getFileDependencyTable(new BooleanBlockWithNodeArg()
{
public boolean eval(Node n)
{
return true;
}
});
}
int level = dependencyGraph.getMaxRank();
log.info("dependency analysis completed (" + level + " levels).");
Vector allFileList = new Vector();
for (; dep.containsKey(new Integer(level)); level--)
{
Vector fileList = new Vector();
Vector candidates = (Vector) dep.get(new Integer(level));
for (Enumeration e = candidates.elements(); e.hasMoreElements();)
{
String targetName = (String) e.nextElement();
for (int i = 0; i < targets.size(); i++)
{
Target candidateTarget = (Target) targets.elementAt(i);
if (targetName.equals(candidateTarget.getName()))
{
fileList.addElement(candidateTarget.getName());
if (!allFileList.contains(candidateTarget.getName()))
{
allFileList.addElement(candidateTarget.getName());
}
}
}
}
}
boolean needToRun = false;
Vector v;
for (Enumeration e = dep.elements(); !needToRun && e.hasMoreElements(); needToRun = !v.isEmpty())
{
v = (Vector) e.nextElement();
}
if (!needToRun)
{
throw new AllFilesUpToDateException(
"No need to update any instrumented files. All sourcesfiles older than instrumented files.");
}
for (level = dependencyGraph.getMaxRank(); dep.containsKey(new Integer(level)); level--)
{
Vector fileList = new Vector();
Vector candidates = (Vector) dep.get(new Integer(level));
Enumeration candidateElementsEnum = candidates.elements();
while (candidateElementsEnum.hasMoreElements())