use of org.jetbrains.jps.android.builder.AndroidPreDexBuildTarget in project android by JetBrains.
the class AndroidPreDexBuilder method doBuild.
private static boolean doBuild(@NotNull AndroidPreDexBuildTarget target, @NotNull DirtyFilesHolder<AndroidPreDexBuildTarget.MyRootDescriptor, AndroidPreDexBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws IOException, ProjectBuildException {
final List<Pair<File, String>> filesToPreDex = new ArrayList<Pair<File, String>>();
holder.processDirtyFiles(new FileProcessor<AndroidPreDexBuildTarget.MyRootDescriptor, AndroidPreDexBuildTarget>() {
@Override
public boolean apply(AndroidPreDexBuildTarget target, File file, AndroidPreDexBuildTarget.MyRootDescriptor root) throws IOException {
if (canBePreDexed(file) && file.isFile()) {
filesToPreDex.add(Pair.create(file, root.getModuleName()));
}
return true;
}
});
final JpsProject project = target.getProject();
AndroidPlatform platform = null;
for (JpsModule module : project.getModules()) {
if (AndroidJpsUtil.getExtension(module) != null) {
platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
break;
}
}
if (platform == null) {
return false;
}
if (!filesToPreDex.isEmpty()) {
final File outputDir = target.getOutputFile(context);
for (Pair<File, String> pair : filesToPreDex) {
context.checkCanceled();
final File srcFile = pair.getFirst();
final String moduleName = pair.getSecond();
final String srcFilePath = srcFile.getAbsolutePath();
final File outputFile;
if (moduleName != null) {
context.processMessage(new ProgressMessage("Pre-dex [" + moduleName + "]"));
outputFile = new File(new File(outputDir, moduleName), srcFile.getName());
} else {
context.processMessage(new ProgressMessage("Pre-dex: " + srcFile.getName()));
final String outputFileName = getOutputFileNameForExternalJar(srcFile);
if (outputFileName == null) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot pre-dex file " + srcFilePath + ": incorrect path", srcFilePath));
return false;
}
outputFile = new File(outputDir, outputFileName);
}
if (AndroidJpsUtil.createDirIfNotExist(outputFile.getParentFile(), context, BUILDER_NAME) == null) {
return false;
}
if (!AndroidDexBuilder.runDex(platform, outputFile.getPath(), new String[] { srcFilePath }, context, project, outputConsumer, BUILDER_NAME, srcFile.getName(), null)) {
return false;
}
}
}
return true;
}
Aggregations