Search in sources :

Example 1 with ModuleExcludeIndex

use of org.jetbrains.jps.indices.ModuleExcludeIndex in project intellij-community by JetBrains.

the class JpsBuildTestCase method createProjectDescriptor.

protected ProjectDescriptor createProjectDescriptor(final BuildLoggingManager buildLoggingManager) {
    try {
        BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(myModel);
        ModuleExcludeIndex index = new ModuleExcludeIndexImpl(myModel);
        IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(myModel);
        BuildDataPaths dataPaths = new BuildDataPathsImpl(myDataStorageRoot);
        BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, myModel, index, dataPaths, ignoredFileIndex);
        BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
        BuildTargetsState targetsState = new BuildTargetsState(dataPaths, myModel, buildRootIndex);
        ProjectTimestamps timestamps = new ProjectTimestamps(myDataStorageRoot, targetsState);
        BuildDataManager dataManager = new BuildDataManager(dataPaths, targetsState, true);
        return new ProjectDescriptor(myModel, new BuildFSState(true), timestamps, dataManager, buildLoggingManager, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ProjectTimestamps(org.jetbrains.jps.incremental.storage.ProjectTimestamps) BuildTargetRegistryImpl(org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl) BuildRootIndexImpl(org.jetbrains.jps.builders.impl.BuildRootIndexImpl) IgnoredFileIndexImpl(org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl) BuildTargetIndexImpl(org.jetbrains.jps.builders.impl.BuildTargetIndexImpl) IOException(java.io.IOException) BuildTargetsState(org.jetbrains.jps.incremental.storage.BuildTargetsState) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) ModuleExcludeIndexImpl(org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl) BuildDataPathsImpl(org.jetbrains.jps.builders.impl.BuildDataPathsImpl) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 2 with ModuleExcludeIndex

use of org.jetbrains.jps.indices.ModuleExcludeIndex in project intellij-community by JetBrains.

the class CompilerEncodingConfigurationTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(myModel);
    ModuleExcludeIndex index = new ModuleExcludeIndexImpl(myModel);
    IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(myModel);
    myDataStorageRoot = FileUtil.createTempDirectory("compile-server-" + StringUtil.decapitalize(StringUtil.trimStart(getName(), "test")), null);
    BuildDataPaths dataPaths = new BuildDataPathsImpl(myDataStorageRoot);
    myRootIndex = new BuildRootIndexImpl(targetRegistry, myModel, index, dataPaths, ignoredFileIndex);
}
Also used : BuildTargetRegistryImpl(org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) BuildRootIndexImpl(org.jetbrains.jps.builders.impl.BuildRootIndexImpl) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ModuleExcludeIndexImpl(org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl) IgnoredFileIndexImpl(org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl) BuildDataPathsImpl(org.jetbrains.jps.builders.impl.BuildDataPathsImpl)

Example 3 with ModuleExcludeIndex

use of org.jetbrains.jps.indices.ModuleExcludeIndex in project intellij-community by JetBrains.

the class IncProjectBuilder method clearOutputs.

private void clearOutputs(CompileContext context) throws ProjectBuildException {
    final long cleanStart = System.currentTimeMillis();
    final MultiMap<File, BuildTarget<?>> rootsToDelete = MultiMap.createSet();
    final Set<File> allSourceRoots = ContainerUtil.newTroveSet(FileUtil.FILE_HASHING_STRATEGY);
    final ProjectDescriptor projectDescriptor = context.getProjectDescriptor();
    final List<? extends BuildTarget<?>> allTargets = projectDescriptor.getBuildTargetIndex().getAllTargets();
    for (BuildTarget<?> target : allTargets) {
        if (target instanceof ModuleBasedTarget) {
            for (File file : target.getOutputRoots(context)) {
                rootsToDelete.putValue(file, target);
            }
        } else {
            if (context.getScope().isBuildForced(target)) {
                clearOutputFilesUninterruptibly(context, target);
            }
        }
    }
    final ModuleExcludeIndex moduleIndex = projectDescriptor.getModuleExcludeIndex();
    for (BuildTarget<?> target : allTargets) {
        for (BuildRootDescriptor descriptor : projectDescriptor.getBuildRootIndex().getTargetRoots(target, context)) {
            // excluding from checks roots with generated sources; because it is safe to delete generated stuff
            if (!descriptor.isGenerated()) {
                File rootFile = descriptor.getRootFile();
                //However if a root isn't excluded it means that its content will be shown in 'Project View' and an user can create new files under it so it would be dangerous to clean such roots
                if (moduleIndex.isInContent(rootFile)) {
                    allSourceRoots.add(rootFile);
                }
            }
        }
    }
    // check that output and source roots are not overlapping
    final CompileScope compileScope = context.getScope();
    final List<File> filesToDelete = new ArrayList<>();
    final Predicate<BuildTarget<?>> forcedBuild = new Predicate<BuildTarget<?>>() {

        public boolean apply(BuildTarget<?> input) {
            return compileScope.isBuildForced(input);
        }
    };
    for (Map.Entry<File, Collection<BuildTarget<?>>> entry : rootsToDelete.entrySet()) {
        context.checkCanceled();
        final File outputRoot = entry.getKey();
        final Collection<BuildTarget<?>> rootTargets = entry.getValue();
        final Applicability applicability = Applicability.calculate(forcedBuild, rootTargets);
        if (applicability == Applicability.NONE) {
            continue;
        }
        boolean okToDelete = applicability == Applicability.ALL;
        if (okToDelete && !moduleIndex.isExcluded(outputRoot)) {
            // so in this case it is safe to delete such root
            if (JpsPathUtil.isUnder(allSourceRoots, outputRoot)) {
                okToDelete = false;
            } else {
                final Set<File> _outRoot = ContainerUtil.newTroveSet(FileUtil.FILE_HASHING_STRATEGY, outputRoot);
                for (File srcRoot : allSourceRoots) {
                    if (JpsPathUtil.isUnder(_outRoot, srcRoot)) {
                        okToDelete = false;
                        break;
                    }
                }
            }
        }
        if (okToDelete) {
            // do not delete output root itself to avoid lots of unnecessary "roots_changed" events in IDEA
            final File[] children = outputRoot.listFiles();
            if (children != null) {
                for (File child : children) {
                    if (!child.delete()) {
                        filesToDelete.add(child);
                    }
                }
            } else {
                // the output root must be file
                if (!outputRoot.delete()) {
                    filesToDelete.add(outputRoot);
                }
            }
            registerTargetsWithClearedOutput(context, rootTargets);
        } else {
            if (applicability == Applicability.ALL) {
                // only warn if unable to delete because of roots intersection
                context.processMessage(new CompilerMessage("", BuildMessage.Kind.WARNING, "Output path " + outputRoot.getPath() + " intersects with a source root. Only files that were created by build will be cleaned."));
            }
            context.processMessage(new ProgressMessage("Cleaning output directories..."));
            // clean only those files we are aware of
            for (BuildTarget<?> target : rootTargets) {
                if (compileScope.isBuildForced(target)) {
                    clearOutputFilesUninterruptibly(context, target);
                }
            }
        }
    }
    if (!filesToDelete.isEmpty()) {
        context.processMessage(new ProgressMessage("Cleaning output directories..."));
        if (SYNC_DELETE) {
            for (File file : filesToDelete) {
                context.checkCanceled();
                FileUtil.delete(file);
            }
        } else {
            myAsyncTasks.add(FileUtil.asyncDelete(filesToDelete));
        }
    }
    LOG.info("Cleaned output directories in " + (System.currentTimeMillis() - cleanStart) + " ms");
}
Also used : Predicate(com.intellij.util.containers.Predicate) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) File(java.io.File) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap)

Example 4 with ModuleExcludeIndex

use of org.jetbrains.jps.indices.ModuleExcludeIndex in project intellij-community by JetBrains.

the class BuildRunner method load.

public ProjectDescriptor load(MessageHandler msgHandler, File dataStorageRoot, BuildFSState fsState) throws IOException {
    final JpsModel jpsModel = myModelLoader.loadModel();
    BuildDataPaths dataPaths = new BuildDataPathsImpl(dataStorageRoot);
    BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(jpsModel);
    ModuleExcludeIndex index = new ModuleExcludeIndexImpl(jpsModel);
    IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(jpsModel);
    BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, jpsModel, index, dataPaths, ignoredFileIndex);
    BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
    BuildTargetsState targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
    ProjectTimestamps projectTimestamps = null;
    BuildDataManager dataManager = null;
    try {
        projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
        dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
        if (dataManager.versionDiffers()) {
            myForceCleanCaches = true;
            msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Dependency data format has changed, project rebuild required"));
        }
    } catch (Exception e) {
        // second try
        LOG.info(e);
        if (projectTimestamps != null) {
            projectTimestamps.close();
        }
        if (dataManager != null) {
            dataManager.close();
        }
        myForceCleanCaches = true;
        FileUtil.delete(dataStorageRoot);
        targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
        projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
        dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
        // second attempt succeeded
        msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Project rebuild forced: " + e.getMessage()));
    }
    return new ProjectDescriptor(jpsModel, fsState, projectTimestamps, dataManager, BuildLoggingManager.DEFAULT, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
}
Also used : ProjectTimestamps(org.jetbrains.jps.incremental.storage.ProjectTimestamps) BuildTargetRegistryImpl(org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl) JpsModel(org.jetbrains.jps.model.JpsModel) BuildRootIndexImpl(org.jetbrains.jps.builders.impl.BuildRootIndexImpl) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IgnoredFileIndexImpl(org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl) BuildTargetIndexImpl(org.jetbrains.jps.builders.impl.BuildTargetIndexImpl) BuildTargetsState(org.jetbrains.jps.incremental.storage.BuildTargetsState) IOException(java.io.IOException) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ModuleExcludeIndexImpl(org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl) BuildDataPathsImpl(org.jetbrains.jps.builders.impl.BuildDataPathsImpl) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 5 with ModuleExcludeIndex

use of org.jetbrains.jps.indices.ModuleExcludeIndex in project intellij-elixir by KronicDeth.

the class JpsBuildTestCase method createProjectDescriptor.

protected ProjectDescriptor createProjectDescriptor(BuildLoggingManager buildLoggingManager) {
    try {
        BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(myModel);
        ModuleExcludeIndex index = new ModuleExcludeIndexImpl(myModel);
        IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(myModel);
        BuildDataPaths dataPaths = new BuildDataPathsImpl(myDataStorageRoot);
        BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, myModel, index, dataPaths, ignoredFileIndex);
        BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
        BuildTargetsState targetsState = new BuildTargetsState(dataPaths, myModel, buildRootIndex);
        PathRelativizerService relativizer = new PathRelativizerService(myModel.getProject());
        ProjectStamps timestamps = new ProjectStamps(myDataStorageRoot, targetsState, relativizer);
        BuildDataManager dataManager = new BuildDataManager(dataPaths, targetsState, relativizer);
        return new ProjectDescriptor(myModel, new BuildFSState(true), timestamps, dataManager, buildLoggingManager, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : BuildTargetRegistryImpl(org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl) BuildRootIndexImpl(org.jetbrains.jps.builders.impl.BuildRootIndexImpl) PathRelativizerService(org.jetbrains.jps.incremental.relativizer.PathRelativizerService) IgnoredFileIndexImpl(org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl) BuildTargetIndexImpl(org.jetbrains.jps.builders.impl.BuildTargetIndexImpl) IOException(java.io.IOException) BuildTargetsState(org.jetbrains.jps.incremental.storage.BuildTargetsState) ProjectStamps(org.jetbrains.jps.incremental.storage.ProjectStamps) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) ModuleExcludeIndexImpl(org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl) BuildDataPathsImpl(org.jetbrains.jps.builders.impl.BuildDataPathsImpl) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Aggregations

ModuleExcludeIndex (org.jetbrains.jps.indices.ModuleExcludeIndex)5 BuildDataPathsImpl (org.jetbrains.jps.builders.impl.BuildDataPathsImpl)4 BuildRootIndexImpl (org.jetbrains.jps.builders.impl.BuildRootIndexImpl)4 BuildTargetRegistryImpl (org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl)4 BuildDataPaths (org.jetbrains.jps.builders.storage.BuildDataPaths)4 IgnoredFileIndexImpl (org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl)4 ModuleExcludeIndexImpl (org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl)4 IOException (java.io.IOException)3 BuildTargetIndexImpl (org.jetbrains.jps.builders.impl.BuildTargetIndexImpl)3 ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)3 BuildDataManager (org.jetbrains.jps.incremental.storage.BuildDataManager)3 BuildTargetsState (org.jetbrains.jps.incremental.storage.BuildTargetsState)3 BuildFSState (org.jetbrains.jps.incremental.fs.BuildFSState)2 ProjectTimestamps (org.jetbrains.jps.incremental.storage.ProjectTimestamps)2 MultiMap (com.intellij.util.containers.MultiMap)1 Predicate (com.intellij.util.containers.Predicate)1 THashMap (gnu.trove.THashMap)1 File (java.io.File)1 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)1 PathRelativizerService (org.jetbrains.jps.incremental.relativizer.PathRelativizerService)1