// TODO: All JDT checks now before even building TypeOracle?
module.getCompilationState(logger);
if (options.isValidateOnly()) {
TreeLogger branch = logger.branch(TreeLogger.INFO,
"Validating compilation " + module.getName());
if (!validate(branch, options, module, options.getGenDir(),
compilerWorkDir, options.getDumpSignatureFile())) {
branch.log(TreeLogger.ERROR, "Validation failed");
return false;
}
branch.log(TreeLogger.INFO, "Validation succeeded");
} else {
TreeLogger branch = logger.branch(TreeLogger.INFO,
"Precompiling module " + module.getName());
PropertyPermutations allPermutations = new PropertyPermutations(
module.getProperties());
int potentialPermutations = allPermutations.size();
int permutationsPerIteration = options.getMaxPermsPerPrecompile();
if (permutationsPerIteration <= 0) {
permutationsPerIteration = potentialPermutations;
}
/*
* The potential number of permutations to precompile >= the actual
* number of permutations that end up being precompiled, because some of
* the permutations might collapse due to identical rebind results. So
* we have to track these two counts and ids separately.
*/
int actualPermutations = 0;
for (int potentialFirstPerm = 0; potentialFirstPerm < potentialPermutations; potentialFirstPerm += permutationsPerIteration) {
int numPermsToPrecompile = Math.min(potentialPermutations
- potentialFirstPerm, permutationsPerIteration);
// Select only the range of property permutations that we want
PropertyPermutations localPermutations = new PropertyPermutations(
allPermutations, potentialFirstPerm, numPermsToPrecompile);
Precompilation precompilation = precompile(branch, options, module,
actualPermutations, localPermutations, options.getGenDir(),
compilerWorkDir, options.getDumpSignatureFile());
if (precompilation == null) {
branch.log(TreeLogger.ERROR, "Precompilation failed");
return false;
}
int actualNumPermsPrecompiled = precompilation.getPermutations().length;
String precompilationFilename = PrecompilationFile.fileNameForPermutations(
actualPermutations, actualNumPermsPrecompiled);
try {
precompilationJar.putNextEntry(new ZipEntry(precompilationFilename));
Util.writeObjectToStream(precompilationJar, precompilation);
} catch (IOException e) {
branch.log(TreeLogger.ERROR,
"Failed to write a precompilation result", e);
return false;
}
actualPermutations += actualNumPermsPrecompiled;
branch.log(TreeLogger.DEBUG, "Compiled " + actualNumPermsPrecompiled
+ " permutations starting from " + potentialFirstPerm);
}
try {
precompilationJar.close();
} catch (IOException e) {
branch.log(TreeLogger.ERROR, "Failed to finalize "
+ PRECOMPILE_FILENAME, e);
return false;
}
Util.writeStringAsFile(branch, new File(compilerWorkDir,
PERM_COUNT_FILENAME), String.valueOf(actualPermutations));
branch.log(TreeLogger.INFO,
"Precompilation succeeded, number of permutations: "
+ actualPermutations);
}
}
return true;