Search in sources :

Example 1 with AndroidPreDexBuildTarget

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;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) AndroidPreDexBuildTarget(org.jetbrains.jps.android.builder.AndroidPreDexBuildTarget) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsProject(org.jetbrains.jps.model.JpsProject) File(java.io.File) Pair(com.intellij.openapi.util.Pair)

Aggregations

Pair (com.intellij.openapi.util.Pair)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AndroidPreDexBuildTarget (org.jetbrains.jps.android.builder.AndroidPreDexBuildTarget)1 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)1 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)1 JpsProject (org.jetbrains.jps.model.JpsProject)1 JpsModule (org.jetbrains.jps.model.module.JpsModule)1