// Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package com.twitter.intellij.pants.jps.incremental.scala;

import com.twitter.intellij.pants.jps.incremental.model.JpsPantsProjectExtension;
import com.twitter.intellij.pants.jps.incremental.serialization.PantsJpsProjectExtensionSerializer;
import com.twitter.intellij.pants.jps.util.PantsJpsUtil;
import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.incremental.scala.ChunkExclusionService;
import org.jetbrains.jps.model.module.JpsModule;

import java.util.Set;

public class PantsScalaChunkExclusionService extends ChunkExclusionService {
  @Override
  public boolean isExcluded(ModuleChunk chunk) {
    final Set<JpsModule> modules = chunk.getModules();
    if (modules.isEmpty()) {
      return false;
    }

    final JpsPantsProjectExtension pantsProjectExtension =
      PantsJpsProjectExtensionSerializer.findPantsProjectExtension(modules.iterator().next().getProject());
    if (pantsProjectExtension == null) {
      return false;
    }
    return PantsJpsUtil.containsPantsModules(modules);
  }
}

// Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package com.twitter.intellij.pants.jps.incremental.scala;

import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.incremental.scala.ChunkExclusionService;

public class PantsScalaChunkExclusionService extends ChunkExclusionService {
  @Override
  public boolean isExcluded(ModuleChunk chunk) {
    // All compilations are handled by Pants, thus excluded from scala plugin.
    return true;
  }
}

Exclude all from scala plugin compilation
Exclude all from scala plugin compilation

Some user hit the issue that after pants finishes, scala plugin compiler builder also started to build and cause error. Since all comiplation can/should be handled by pants, we should completely block scala plugin from compiling our code.

Testing Done:
https://travis-ci.org/wisechengyi/intellij-pants-plugin/builds/110483748

Reviewed at https://rbcommons.com/s/twitter/r/3483/
