@Override
protected Pair<SyntheticArtifact, MultipleDependencyGraphRecorder> splitJsIntoFragments(
PermProps props, int permutationId, JavaToJavaScriptMap jjsmap) {
Pair<SyntheticArtifact, MultipleDependencyGraphRecorder> dependenciesAndRecorder;
MultipleDependencyGraphRecorder dependencyRecorder = null;
SyntheticArtifact dependencies = null;
if (options.isRunAsyncEnabled()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int expectedFragmentCount = options.getFragmentCount();
// -1 is the default value, we trap 0 just in case (0 is not a legal value in any case)
if (expectedFragmentCount <= 0) {
// Fragment count not set check fragments merge.
int numberOfMerges = options.getFragmentsMerge();
if (numberOfMerges > 0) {
// + 1 for left over, + 1 for initial gave us the total number
// of fragments without splitting.
expectedFragmentCount =
Math.max(0, jprogram.getRunAsyncs().size() + 2 - numberOfMerges);
}
}
int minFragmentSize = props.getConfigProps().getInteger(CodeSplitters.MIN_FRAGMENT_SIZE, 0);
dependencyRecorder = chooseDependencyRecorder(baos);
CodeSplitter.exec(logger, jprogram, jsProgram, jjsmap, expectedFragmentCount,
minFragmentSize, dependencyRecorder);
if (baos.size() == 0) {
dependencyRecorder = recordNonSplitDependencies(baos);
}
if (baos.size() > 0) {
dependencies = new SyntheticArtifact(
SoycReportLinker.class, "dependencies" + permutationId + ".xml.gz",
baos.toByteArray());
}
} else if (options.isSoycEnabled() || options.isJsonSoycEnabled()) {
dependencyRecorder = recordNonSplitDependencies(new ByteArrayOutputStream());