Search in sources :

Example 1 with GenericCompilerPersistentData

use of com.intellij.compiler.impl.generic.GenericCompilerPersistentData in project intellij-community by JetBrains.

the class GenericCompilerRunner method invokeCompiler.

private <T extends BuildTarget, Item extends CompileItem<Key, SourceState, OutputState>, Key, SourceState, OutputState> boolean invokeCompiler(GenericCompiler<Key, SourceState, OutputState> compiler, final GenericCompilerInstance<T, Item, Key, SourceState, OutputState> instance) throws IOException, ExitException {
    final GenericCompilerCache<Key, SourceState, OutputState> cache = CompilerCacheManager.getInstance(myProject).getGenericCompilerCache(compiler);
    GenericCompilerPersistentData data = new GenericCompilerPersistentData(getGenericCompilerCacheDir(myProject, compiler), compiler.getVersion());
    if (data.isVersionChanged()) {
        LOG.info("Clearing cache for " + compiler.getDescription());
        cache.wipe();
        data.save();
    }
    final Set<String> targetsToRemove = new HashSet<>(data.getAllTargets());
    new ReadAction() {

        protected void run(@NotNull final Result result) {
            for (T target : instance.getAllTargets()) {
                targetsToRemove.remove(target.getId());
            }
        }
    }.execute();
    if (!myOnlyCheckStatus) {
        for (final String target : targetsToRemove) {
            final int id = data.removeId(target);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Removing obsolete target '" + target + "' (id=" + id + ")");
            }
            final List<Key> keys = new ArrayList<>();
            CompilerUtil.runInContext(myContext, "Processing obsolete targets...", () -> {
                cache.processSources(id, new CommonProcessors.CollectProcessor<>(keys));
                List<GenericCompilerCacheState<Key, SourceState, OutputState>> obsoleteSources = new ArrayList<>();
                for (Key key : keys) {
                    final GenericCompilerCache.PersistentStateData<SourceState, OutputState> state = cache.getState(id, key);
                    obsoleteSources.add(new GenericCompilerCacheState<>(key, state.mySourceState, state.myOutputState));
                }
                instance.processObsoleteTarget(target, obsoleteSources);
            });
            checkForErrorsOrCanceled();
            for (Key key : keys) {
                cache.remove(id, key);
            }
        }
    }
    final List<T> selectedTargets = new ReadAction<List<T>>() {

        protected void run(@NotNull final Result<List<T>> result) {
            result.setResult(instance.getSelectedTargets());
        }
    }.execute().getResultObject();
    boolean didSomething = false;
    for (T target : selectedTargets) {
        int id = data.getId(target.getId());
        didSomething |= processTarget(target, id, compiler, instance, cache);
    }
    data.save();
    return didSomething;
}
Also used : GenericCompilerCache(com.intellij.compiler.impl.generic.GenericCompilerCache) NotNull(org.jetbrains.annotations.NotNull) GenericCompilerPersistentData(com.intellij.compiler.impl.generic.GenericCompilerPersistentData) Result(com.intellij.openapi.application.Result) RunResult(com.intellij.openapi.application.RunResult) ReadAction(com.intellij.openapi.application.ReadAction) CommonProcessors(com.intellij.util.CommonProcessors) THashSet(gnu.trove.THashSet)

Aggregations

GenericCompilerCache (com.intellij.compiler.impl.generic.GenericCompilerCache)1 GenericCompilerPersistentData (com.intellij.compiler.impl.generic.GenericCompilerPersistentData)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Result (com.intellij.openapi.application.Result)1 RunResult (com.intellij.openapi.application.RunResult)1 CommonProcessors (com.intellij.util.CommonProcessors)1 THashSet (gnu.trove.THashSet)1 NotNull (org.jetbrains.annotations.NotNull)1