Search in sources :

Example 21 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project android by JetBrains.

the class AndroidPackagingBuilder method doPackagingForModule.

private static boolean doPackagingForModule(@NotNull CompileContext context, @NotNull JpsModule module, @NotNull AndroidApkBuilderConfigStateStorage apkBuilderConfigStateStorage, @NotNull AndroidPackagingStateStorage packagingStateStorage, boolean release, boolean hasDirtyFiles, @NotNull BuildOutputConsumer outputConsumer) throws IOException {
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    if (extension == null || extension.isLibrary()) {
        return true;
    }
    final String[] resourceRoots = AndroidJpsUtil.toPaths(AndroidJpsUtil.getJavaOutputRootsForModuleAndDependencies(module));
    Arrays.sort(resourceRoots);
    final File moduleOutputDir = ProjectPaths.getModuleOutputDir(module, false);
    if (moduleOutputDir == null) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.output.dir.not.specified", module.getName())));
        return false;
    }
    final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
    if (platform == null) {
        return false;
    }
    final Set<String> externalJarsSet = new HashSet<String>();
    for (String jarPath : AndroidJpsUtil.getExternalLibraries(context, module, platform)) {
        if (new File(jarPath).exists()) {
            externalJarsSet.add(jarPath);
        }
    }
    final BuildDataPaths dataPaths = context.getProjectDescriptor().dataManager.getDataPaths();
    final File resPackage = AndroidResourcePackagingBuildTarget.getOutputFile(dataPaths, module);
    final File classesDexFile = AndroidDexBuildTarget.getOutputFile(dataPaths, module);
    final String sdkPath = platform.getSdk().getHomePath();
    final String outputPath = AndroidJpsUtil.getApkPath(extension, moduleOutputDir);
    if (outputPath == null) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.cannot.compute.output.apk", module.getName())));
        return false;
    }
    final String customKeyStorePath = FileUtil.toSystemDependentName(extension.getCustomDebugKeyStorePath());
    final String[] nativeLibDirs = AndroidPackagingBuildTarget.collectNativeLibsFolders(extension, true);
    final String resPackagePath = resPackage.getPath();
    final String classesDexFilePath = classesDexFile.getPath();
    final String[] externalJars = ArrayUtil.toStringArray(externalJarsSet);
    Arrays.sort(externalJars);
    final List<AndroidNativeLibData> additionalNativeLibs = extension.getAdditionalNativeLibs();
    final AndroidApkBuilderConfigState currentApkBuilderConfigState = new AndroidApkBuilderConfigState(outputPath, customKeyStorePath, additionalNativeLibs);
    if (!hasDirtyFiles) {
        final AndroidApkBuilderConfigState savedApkBuilderConfigState = apkBuilderConfigStateStorage.getState(module.getName());
        final AndroidPackagingStateStorage.MyState packagingState = packagingStateStorage.read();
        if (currentApkBuilderConfigState.equalsTo(savedApkBuilderConfigState) && packagingState != null && packagingState.isRelease() == release) {
            return true;
        }
    }
    context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.packaging", AndroidJpsUtil.getApkName(module))));
    final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApkBuilder.execute(resPackagePath, classesDexFilePath, resourceRoots, externalJars, nativeLibDirs, additionalNativeLibs, outputPath, release, sdkPath, platform.getTarget(), customKeyStorePath, new MyExcludedSourcesFilter(context.getProjectDescriptor().getProject()));
    if (messages.get(AndroidCompilerMessageKind.ERROR).size() == 0) {
        final List<String> srcFiles = new ArrayList<String>();
        srcFiles.add(resPackagePath);
        srcFiles.add(classesDexFilePath);
        for (String resourceRoot : resourceRoots) {
            FileUtil.processFilesRecursively(new File(resourceRoot), new Processor<File>() {

                @Override
                public boolean process(File file) {
                    if (file.isFile() && AndroidApkBuilder.checkFileForPackaging(file)) {
                        srcFiles.add(file.getPath());
                    }
                    return true;
                }
            });
        }
        Collections.addAll(srcFiles, externalJars);
        for (String nativeLibDir : nativeLibDirs) {
            FileUtil.processFilesRecursively(new File(nativeLibDir), new Processor<File>() {

                @Override
                public boolean process(File file) {
                    if (file.isFile()) {
                        srcFiles.add(file.getPath());
                    }
                    return true;
                }
            });
        }
        outputConsumer.registerOutputFile(new File(outputPath), srcFiles);
    }
    AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName());
    final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty();
    apkBuilderConfigStateStorage.update(module.getName(), success ? currentApkBuilderConfigState : null);
    packagingStateStorage.saveState(new AndroidPackagingStateStorage.MyState(release));
    return success;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) AndroidNativeLibData(org.jetbrains.android.util.AndroidNativeLibData) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) File(java.io.File) HashSet(com.intellij.util.containers.HashSet)

Example 22 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project android by JetBrains.

the class AndroidDexBuilder method doDexBuild.

private static boolean doDexBuild(@NotNull AndroidDexBuildTarget target, @NotNull CompileContext context, boolean hasDirtyFiles, @NotNull BuildOutputConsumer outputConsumer) throws IOException {
    final JpsModule module = target.getModule();
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    assert extension != null;
    assert !extension.isLibrary();
    final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, DEX_BUILDER_NAME);
    if (platform == null) {
        return false;
    }
    File dexOutputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
    dexOutputDir = AndroidJpsUtil.createDirIfNotExist(dexOutputDir, context, DEX_BUILDER_NAME);
    if (dexOutputDir == null) {
        return false;
    }
    final ProGuardOptions proGuardOptions = AndroidJpsUtil.getProGuardConfigIfShouldRun(context, extension);
    if (proGuardOptions != null) {
        if (proGuardOptions.getCfgFiles() == null) {
            context.processMessage(new CompilerMessage(DEX_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.cannot.find.proguard.cfg", module.getName())));
            return false;
        }
    }
    final File proguardCfgOutputFile = new File(dexOutputDir, AndroidCommonUtils.PROGUARD_CFG_OUTPUT_FILE_NAME);
    final AndroidProGuardStateStorage proGuardOptionsStorage = context.getProjectDescriptor().dataManager.getStorage(target, AndroidProGuardOptionsStorageProvider.INSTANCE);
    final AndroidProGuardStateStorage.MyState oldProGuardState = proGuardOptionsStorage.read();
    final Set<String> fileSet;
    AndroidProGuardStateStorage.MyState newProGuardState = null;
    try {
        if (proGuardOptions != null) {
            final List<String> proguardCfgFilePathsList = new ArrayList<String>();
            for (File file : proGuardOptions.getCfgFiles()) {
                proguardCfgFilePathsList.add(file.getAbsolutePath());
            }
            proguardCfgFilePathsList.add(proguardCfgOutputFile.getPath());
            final String[] proguardCfgFilePaths = ArrayUtil.toStringArray(proguardCfgFilePathsList);
            final String outputJarPath = FileUtil.toSystemDependentName(dexOutputDir.getPath() + '/' + AndroidCommonUtils.PROGUARD_OUTPUT_JAR_NAME);
            final Pair<Boolean, AndroidProGuardStateStorage.MyState> pair = runProguardIfNecessary(extension, target, platform, context, outputJarPath, proguardCfgFilePaths, hasDirtyFiles, oldProGuardState);
            if (pair == null) {
                // error reported
                return false;
            }
            if (!pair.getFirst()) {
                // nothing changed
                return true;
            }
            newProGuardState = pair.getSecond();
            assert newProGuardState != null;
            fileSet = Collections.singleton(outputJarPath);
        } else {
            if (!hasDirtyFiles && oldProGuardState == null) {
                return true;
            }
            final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
            fileSet = new HashSet<String>();
            final boolean predexingEnabled = extension.isPreDexingEnabled() && isPredexingInScope(context);
            for (BuildRootDescriptor root : roots) {
                final File rootFile = root.getRootFile();
                if (!rootFile.exists()) {
                    continue;
                }
                if (root instanceof AndroidDexBuildTarget.MyClassesDirBuildRootDescriptor) {
                    final AndroidDexBuildTarget.ClassesDirType type = ((AndroidDexBuildTarget.MyClassesDirBuildRootDescriptor) root).getClassesDirType();
                    if (type == AndroidDexBuildTarget.ClassesDirType.JAVA) {
                        fileSet.add(rootFile.getPath());
                    } else if (type == AndroidDexBuildTarget.ClassesDirType.ANDROID_APP) {
                        AndroidJpsUtil.addSubdirectories(rootFile, fileSet);
                    }
                } else if (root instanceof AndroidDexBuildTarget.MyJarBuildRootDescriptor) {
                    if (((AndroidDexBuildTarget.MyJarBuildRootDescriptor) root).isPreDexed() == predexingEnabled) {
                        fileSet.add(rootFile.getPath());
                    }
                }
            }
        }
        final boolean success;
        if (fileSet.size() > 0) {
            final String[] files = new String[fileSet.size()];
            int i = 0;
            for (String filePath : fileSet) {
                files[i++] = FileUtil.toSystemDependentName(filePath);
            }
            context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.dex", module.getName())));
            Arrays.sort(files);
            success = runDex(platform, dexOutputDir.getPath(), files, context, module, outputConsumer);
        } else {
            success = true;
        }
        if (success) {
            proGuardOptionsStorage.update(newProGuardState);
        }
        return success;
    } catch (IOException e) {
        AndroidJpsUtil.reportExceptionError(context, null, e, DEX_BUILDER_NAME);
        return false;
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AndroidDexBuildTarget(org.jetbrains.jps.android.builder.AndroidDexBuildTarget) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) IOException(java.io.IOException) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) File(java.io.File)

Example 23 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-plugins by JetBrains.

the class FlexResourceBuilder method build.

public void build(@NotNull final FlexResourceBuildTarget target, @NotNull final DirtyFilesHolder<BuildRootDescriptor, FlexResourceBuildTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject());
    final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
    try {
        holder.processDirtyFiles(new FileProcessor<BuildRootDescriptor, FlexResourceBuildTarget>() {

            public boolean apply(final FlexResourceBuildTarget target, final File file, final BuildRootDescriptor root) throws IOException {
                if (excludes.isExcluded(file))
                    return true;
                final String relativePath = FileUtil.toSystemIndependentName(FileUtil.getRelativePath(root.getRootFile(), file));
                if (target.isTests()) {
                    if (!FlexCommonUtils.isSourceFile(file.getName())) {
                        final String outputRootUrl = JpsJavaExtensionService.getInstance().getOutputUrl(target.getModule(), target.isTests());
                        if (outputRootUrl == null)
                            return true;
                        final String targetPath = JpsPathUtil.urlToPath(outputRootUrl) + '/' + relativePath;
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, Collections.singleton(targetPath), outputConsumer);
                    }
                } else {
                    final Collection<String> targetPaths = new ArrayList<>();
                    for (JpsFlexBuildConfiguration bc : target.getModule().getProperties().getBuildConfigurations()) {
                        if (bc.isSkipCompile() || !FlexCommonUtils.canHaveResourceFiles(bc.getNature()) || bc.getCompilerOptions().getResourceFilesMode() == JpsFlexCompilerOptions.ResourceFilesMode.None) {
                            continue;
                        }
                        final JpsFlexCompilerOptions.ResourceFilesMode mode = bc.getCompilerOptions().getResourceFilesMode();
                        if (mode == JpsFlexCompilerOptions.ResourceFilesMode.All && !FlexCommonUtils.isSourceFile(file.getName()) || mode == JpsFlexCompilerOptions.ResourceFilesMode.ResourcePatterns && configuration.isResourceFile(file, root.getRootFile())) {
                            final String outputFolder = PathUtilRt.getParentPath(bc.getActualOutputFilePath());
                            targetPaths.add(outputFolder + "/" + relativePath);
                        }
                    }
                    if (!targetPaths.isEmpty()) {
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, targetPaths, outputConsumer);
                    }
                }
                return true;
            }
        });
    } catch (Exception e) {
        throw new ProjectBuildException(e.getMessage(), e);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) FlexResourceBuildTarget(com.intellij.flex.build.FlexResourceBuildTarget) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) Collection(java.util.Collection) JpsFlexBuildConfiguration(com.intellij.flex.model.bc.JpsFlexBuildConfiguration) File(java.io.File)

Example 24 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method runRenderscriptCompiler.

private static boolean runRenderscriptCompiler(@NotNull final CompileContext context, @NotNull Map<File, ModuleBuildTarget> files, @NotNull Map<JpsModule, MyModuleData> moduleDataMap) {
    if (files.size() > 0) {
        context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.renderscript")));
    }
    boolean success = true;
    for (Map.Entry<File, ModuleBuildTarget> entry : files.entrySet()) {
        final File file = entry.getKey();
        final ModuleBuildTarget buildTarget = entry.getValue();
        final MyModuleData moduleData = moduleDataMap.get(buildTarget.getModule());
        if (!LOG.assertTrue(moduleData != null)) {
            context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.internal.error")));
            success = false;
            continue;
        }
        final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
        final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(buildTarget.getModule(), dataManager);
        final File rsOutputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.RENDERSCRIPT_GENERATED_SOURCE_ROOT_NAME);
        if (!rsOutputDirectory.exists() && !rsOutputDirectory.mkdirs()) {
            context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", rsOutputDirectory.getPath())));
            success = false;
            continue;
        }
        final File generatedResourcesDir = AndroidJpsUtil.getGeneratedResourcesStorage(buildTarget.getModule(), dataManager);
        final File rawDir = new File(generatedResourcesDir, "raw");
        if (!rawDir.exists() && !rawDir.mkdirs()) {
            context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", rawDir.getPath())));
            success = false;
            continue;
        }
        final AndroidPlatform platform = moduleData.getPlatform();
        final IAndroidTarget target = platform.getTarget();
        final String sdkLocation = platform.getSdk().getHomePath();
        final String filePath = file.getPath();
        File tmpOutputDirectory = null;
        try {
            tmpOutputDirectory = FileUtil.createTempDirectory("generated-rs-temp", null);
            final String depFolderPath = getDependencyFolder(context, file, tmpOutputDirectory);
            final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidRenderscript.execute(sdkLocation, target, filePath, tmpOutputDirectory.getPath(), depFolderPath, rawDir.getPath());
            addMessages(context, messages, filePath, ANDROID_RENDERSCRIPT_COMPILER);
            if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
                success = false;
            } else {
                final List<File> newFiles = new ArrayList<File>();
                AndroidCommonUtils.moveAllFiles(tmpOutputDirectory, rsOutputDirectory, newFiles);
                final File bcFile = new File(rawDir, FileUtil.getNameWithoutExtension(file) + ".bc");
                if (bcFile.exists()) {
                    newFiles.add(bcFile);
                }
                final List<String> newFilePaths = Arrays.asList(AndroidJpsUtil.toPaths(newFiles.toArray(new File[newFiles.size()])));
                final SourceToOutputMapping sourceToOutputMap = dataManager.getSourceToOutputMap(buildTarget);
                sourceToOutputMap.setOutputs(filePath, newFilePaths);
                for (File newFile : newFiles) {
                    FSOperations.markDirty(context, CompilationRound.CURRENT, newFile);
                }
            }
        } catch (IOException e) {
            AndroidJpsUtil.reportExceptionError(context, filePath, e, ANDROID_RENDERSCRIPT_COMPILER);
            success = false;
        } finally {
            if (tmpOutputDirectory != null) {
                FileUtil.delete(tmpOutputDirectory);
            }
        }
    }
    return success;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IAndroidTarget(com.android.sdklib.IAndroidTarget) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap)

Example 25 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.

the class IncArtifactBuilder method build.

@Override
public void build(@NotNull ArtifactBuildTarget target, @NotNull DirtyFilesHolder<ArtifactRootDescriptor, ArtifactBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException {
    JpsArtifact artifact = target.getArtifact();
    String outputFilePath = artifact.getOutputFilePath();
    if (StringUtil.isEmpty(outputFilePath)) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot build '" + artifact.getName() + "' artifact: output path is not specified"));
        return;
    }
    final ProjectDescriptor pd = context.getProjectDescriptor();
    final ArtifactSorter sorter = new ArtifactSorter(pd.getModel());
    final Map<JpsArtifact, JpsArtifact> selfIncludingNameMap = sorter.getArtifactToSelfIncludingNameMap();
    final JpsArtifact selfIncluding = selfIncludingNameMap.get(artifact);
    if (selfIncluding != null) {
        String name = selfIncluding.equals(artifact) ? "it" : "'" + selfIncluding.getName() + "' artifact";
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot build '" + artifact.getName() + "' artifact: " + name + " includes itself in the output layout"));
        return;
    }
    try {
        final Collection<String> deletedFiles = holder.getRemovedFiles(target);
        String messageText = "Building artifact '" + artifact.getName() + "'...";
        context.processMessage(new ProgressMessage(messageText));
        LOG.debug(messageText);
        runArtifactTasks(context, target.getArtifact(), ArtifactBuildTaskProvider.ArtifactBuildPhase.PRE_PROCESSING);
        final SourceToOutputMapping srcOutMapping = pd.dataManager.getSourceToOutputMap(target);
        final ArtifactOutputToSourceMapping outSrcMapping = pd.dataManager.getStorage(target, ArtifactOutToSourceStorageProvider.INSTANCE);
        final TIntObjectHashMap<Set<String>> filesToProcess = new TIntObjectHashMap<>();
        final MultiMap<String, String> filesToDelete = new MultiMap<>();
        final Set<String> deletedOutputPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
        for (String sourcePath : deletedFiles) {
            final Collection<String> outputPaths = srcOutMapping.getOutputs(sourcePath);
            if (outputPaths != null) {
                for (String outputPath : outputPaths) {
                    if (deletedOutputPaths.add(outputPath)) {
                        collectSourcesCorrespondingToOutput(outputPath, sourcePath, deletedFiles, outSrcMapping, filesToProcess, filesToDelete);
                    }
                }
            }
        }
        final Set<String> changedOutputPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
        holder.processDirtyFiles(new FileProcessor<ArtifactRootDescriptor, ArtifactBuildTarget>() {

            @Override
            public boolean apply(ArtifactBuildTarget target, File file, ArtifactRootDescriptor root) throws IOException {
                int rootIndex = root.getRootIndex();
                String sourcePath = FileUtil.toSystemIndependentName(file.getPath());
                addFileToProcess(filesToProcess, rootIndex, sourcePath, deletedFiles);
                final Collection<String> outputPaths = srcOutMapping.getOutputs(sourcePath);
                if (outputPaths != null) {
                    for (String outputPath : outputPaths) {
                        if (changedOutputPaths.add(outputPath)) {
                            collectSourcesCorrespondingToOutput(outputPath, sourcePath, deletedFiles, outSrcMapping, filesToProcess, filesToDelete);
                        }
                    }
                }
                return true;
            }
        });
        BuildOperations.cleanOutputsCorrespondingToChangedFiles(context, holder);
        for (String outputPath : changedOutputPaths) {
            outSrcMapping.remove(outputPath);
        }
        if (filesToDelete.isEmpty() && filesToProcess.isEmpty()) {
            return;
        }
        deleteOutdatedFiles(filesToDelete, context, srcOutMapping, outSrcMapping);
        context.checkCanceled();
        context.processMessage(new ProgressMessage("Building artifact '" + artifact.getName() + "': copying files..."));
        final Set<JarInfo> changedJars = new THashSet<>();
        for (ArtifactRootDescriptor descriptor : pd.getBuildRootIndex().getTargetRoots(target, context)) {
            context.checkCanceled();
            final Set<String> sourcePaths = filesToProcess.get(descriptor.getRootIndex());
            if (sourcePaths == null)
                continue;
            for (String sourcePath : sourcePaths) {
                if (!descriptor.getFilter().shouldBeCopied(sourcePath, pd)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("File " + sourcePath + " will be skipped because it isn't accepted by filter");
                    }
                    continue;
                }
                DestinationInfo destination = descriptor.getDestinationInfo();
                if (destination instanceof ExplodedDestinationInfo) {
                    descriptor.copyFromRoot(sourcePath, descriptor.getRootIndex(), destination.getOutputPath(), context, outputConsumer, outSrcMapping);
                } else {
                    List<ArtifactOutputToSourceMapping.SourcePathAndRootIndex> sources = outSrcMapping.getState(destination.getOutputFilePath());
                    if (sources == null || sources.size() > 0 && sources.get(0).getRootIndex() == descriptor.getRootIndex()) {
                        outSrcMapping.update(destination.getOutputFilePath(), Collections.<ArtifactOutputToSourceMapping.SourcePathAndRootIndex>emptyList());
                        changedJars.add(((JarDestinationInfo) destination).getJarInfo());
                    }
                }
            }
        }
        context.checkCanceled();
        JarsBuilder builder = new JarsBuilder(changedJars, context, outputConsumer, outSrcMapping);
        builder.buildJars();
        runArtifactTasks(context, artifact, ArtifactBuildTaskProvider.ArtifactBuildPhase.FINISHING_BUILD);
        runArtifactTasks(context, artifact, ArtifactBuildTaskProvider.ArtifactBuildPhase.POST_PROCESSING);
    } catch (IOException e) {
        throw new ProjectBuildException(e);
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) ArtifactSorter(org.jetbrains.jps.incremental.artifacts.impl.ArtifactSorter) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) JarsBuilder(org.jetbrains.jps.incremental.artifacts.impl.JarsBuilder) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) File(java.io.File)

Aggregations

ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)32 File (java.io.File)20 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)17 IOException (java.io.IOException)14 JpsModule (org.jetbrains.jps.model.module.JpsModule)10 THashSet (gnu.trove.THashSet)8 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)7 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)5 IAndroidTarget (com.android.sdklib.IAndroidTarget)4 HashMap (com.intellij.util.containers.HashMap)4 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)4 ArrayList (java.util.ArrayList)4 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)4 Pair (com.intellij.openapi.util.Pair)3 HashSet (com.intellij.util.containers.HashSet)3 AndroidBuildTestingManager (org.jetbrains.android.util.AndroidBuildTestingManager)3 BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)3 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)3 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)3 JpsProject (org.jetbrains.jps.model.JpsProject)3