com.intellij.openapi.compiler.CompileScope Java Examples

The following examples show how to use com.intellij.openapi.compiler.CompileScope. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompositeScope.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addScope(CompileScope scope) {
  if (scope instanceof CompositeScope) {
    final CompositeScope compositeScope = (CompositeScope)scope;
    for (CompileScope childScope : compositeScope.myScopes) {
      addScope(childScope);
    }
  }
  else {
    myScopes.add(scope);
  }

  Map<Key, Object> map = scope.exportUserData();
  for (Map.Entry<Key, Object> entry : map.entrySet()) {
    putUserData(entry.getKey(), entry.getValue());
  }
}
 
Example #2
Source File: CreateIpaAction.java    From robovm-idea with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(final AnActionEvent e) {
    final CreateIpaDialog dialog = new CreateIpaDialog(e.getProject());
    dialog.show();
    if(dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        // create IPA
        IpaConfig ipaConfig = dialog.getIpaConfig();
        CompileScope scope = CompilerManager.getInstance(e.getProject()).createModuleCompileScope(ipaConfig.module, true);
        scope.putUserData(IPA_CONFIG_KEY, ipaConfig);
        CompilerManager.getInstance(e.getProject()).compile(scope, new CompileStatusNotification() {
            @Override
            public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
                RoboVmPlugin.logInfo(e.getProject(), "IPA creation complete, %d errors, %d warnings", errors, warnings);
            }
        });
    }
}
 
Example #3
Source File: AbstractRefactoringPanel.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
/**
 * Compiles the project and runs the task only if there are no compilation errors.
 */
private static void runAfterCompilationCheck(ProjectInfo projectInfo, Task task) {
    ApplicationManager.getApplication().invokeLater(() -> {
        List<PsiClass> classes = projectInfo.getClasses();

        if (!classes.isEmpty()) {
            VirtualFile[] virtualFiles = classes.stream()
                    .map(classObject -> classObject.getContainingFile().getVirtualFile()).toArray(VirtualFile[]::new);
            Project project = projectInfo.getProject();

            CompilerManager compilerManager = CompilerManager.getInstance(project);
            CompileStatusNotification callback = (aborted, errors, warnings, compileContext) -> {
                if (errors == 0 && !aborted) {
                    ProgressManager.getInstance().run(task);
                } else {
                    task.onCancel();
                    AbstractRefactoringPanel.showCompilationErrorNotification(project);
                }
            };
            CompileScope compileScope = compilerManager.createFilesCompileScope(virtualFiles);
            compilerManager.make(compileScope, callback);
        } else {
            ProgressManager.getInstance().run(task);
        }
    });
}
 
Example #4
Source File: ExternalSystemTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private void compile(@NotNull CompileScope scope) {
  try {
    CompilerTester tester = new CompilerTester(myProject, Arrays.asList(scope.getAffectedModules()), null);
    try {
      List<CompilerMessage> messages = tester.make(scope);
      for (CompilerMessage message : messages) {
        switch (message.getCategory()) {
          case ERROR:
            fail("Compilation failed with error: " + message.getMessage());
            break;
          case WARNING:
            System.out.println("Compilation warning: " + message.getMessage());
            break;
          case INFORMATION:
            break;
          case STATISTICS:
            break;
        }
      }
    }
    finally {
      tester.tearDown();
    }
  }
  catch (Exception e) {
    ExceptionUtilRt.rethrow(e);
  }
}
 
Example #5
Source File: CompositeScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public VirtualFile[] getFiles(FileType fileType, boolean inSourceOnly) {
  Set<VirtualFile> allFiles = new THashSet<VirtualFile>();
  for (CompileScope scope : myScopes) {
    final VirtualFile[] files = scope.getFiles(fileType, inSourceOnly);
    if (files.length > 0) {
      ContainerUtil.addAll(allFiles, files);
    }
  }
  return VfsUtil.toVirtualFileArray(allFiles);
}
 
Example #6
Source File: CompositeScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean belongs(String url) {
  for (CompileScope scope : myScopes) {
    if (scope.belongs(url)) {
      return true;
    }
  }
  return false;
}
 
Example #7
Source File: CompositeScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Module[] getAffectedModules() {
  Set<Module> modules = new HashSet<Module>();
  for (final CompileScope compileScope : myScopes) {
    ContainerUtil.addAll(modules, compileScope.getAffectedModules());
  }
  return modules.toArray(new Module[modules.size()]);
}
 
Example #8
Source File: CompositeScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
public <T> T getUserData(@Nonnull Key<T> key) {
  for (CompileScope compileScope : myScopes) {
    T userData = compileScope.getUserData(key);
    if (userData != null) {
      return userData;
    }
  }
  return super.getUserData(key);
}
 
Example #9
Source File: ArtifactCompileScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Set<Artifact> getArtifactsToBuild(final Project project,
                                                final CompileScope compileScope,
                                                final boolean addIncludedArtifactsWithOutputPathsOnly) {
  final Artifact[] artifactsFromScope = getArtifacts(compileScope);
  final ArtifactManager artifactManager = ArtifactManager.getInstance(project);
  PackagingElementResolvingContext context = artifactManager.getResolvingContext();
  if (artifactsFromScope != null) {
    return addIncludedArtifacts(Arrays.asList(artifactsFromScope), context, addIncludedArtifactsWithOutputPathsOnly);
  }

  final Set<Artifact> cached = compileScope.getUserData(CACHED_ARTIFACTS_KEY);
  if (cached != null) {
    return cached;
  }

  Set<Artifact> artifacts = new HashSet<Artifact>();
  final Set<Module> modules = new HashSet<Module>(Arrays.asList(compileScope.getAffectedModules()));
  final List<Module> allModules = Arrays.asList(ModuleManager.getInstance(project).getModules());
  for (Artifact artifact : artifactManager.getArtifacts()) {
    if (artifact.isBuildOnMake()) {
      if (modules.containsAll(allModules)
          || containsModuleOutput(artifact, modules, context)) {
        artifacts.add(artifact);
      }
    }
  }
  Set<Artifact> result = addIncludedArtifacts(artifacts, context, addIncludedArtifactsWithOutputPathsOnly);
  compileScope.putUserData(CACHED_ARTIFACTS_KEY, result);
  return result;
}
 
Example #10
Source File: ArtifactCompileScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static CompileScope createScopeWithArtifacts(final CompileScope baseScope,
                                                    @Nonnull Collection<Artifact> artifacts,
                                                    boolean useCustomContentId,
                                                    final boolean forceArtifactBuild) {
  baseScope.putUserData(ARTIFACTS_KEY, artifacts.toArray(new Artifact[artifacts.size()]));
  if (useCustomContentId) {
    baseScope.putUserData(CompilerManager.CONTENT_ID_KEY, ARTIFACTS_CONTENT_ID_KEY);
  }
  if (forceArtifactBuild) {
    baseScope.putUserData(FORCE_ARTIFACT_BUILD, Boolean.TRUE);
  }
  return baseScope;
}
 
Example #11
Source File: BuildArtifactAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void doBuild(@Nonnull Project project, final @Nonnull List<ArtifactPopupItem> items, boolean rebuild) {
  final Set<Artifact> artifacts = getArtifacts(items, project);
  final CompileScope scope = ArtifactCompileScope.createArtifactsScope(project, artifacts, rebuild);

  ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(artifacts);
  if (!rebuild) {
    //in external build we can set 'rebuild' flag per target type
    CompilerManager.getInstance(project).make(scope, null);
  }
  else {
    CompilerManager.getInstance(project).compile(scope, null);
  }
}
 
Example #12
Source File: RoboVmPlugin.java    From robovm-idea with GNU General Public License v2.0 5 votes vote down vote up
private static void compileIfChanged(VirtualFileEvent event, final Project project) {
    if(!RoboVmGlobalConfig.isCompileOnSave()) {
        return;
    }
    VirtualFile file = event.getFile();
    Module module = null;
    for(Module m: ModuleManager.getInstance(project).getModules()) {
        if(ModuleRootManager.getInstance(m).getFileIndex().isInContent(file)) {
            module = m;
            break;
        }
    }

    if(module != null) {
        if(isRoboVmModule(module)) {
            final Module foundModule = module;
            OrderEntry orderEntry = ModuleRootManager.getInstance(module).getFileIndex().getOrderEntryForFile(file);
            if(orderEntry != null && orderEntry.getFiles(OrderRootType.SOURCES).length != 0) {
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        if(!CompilerManager.getInstance(project).isCompilationActive()) {
                            CompileScope scope = CompilerManager.getInstance(project).createModuleCompileScope(foundModule, true);
                            CompilerManager.getInstance(project).compile(scope, null);
                        }
                    }
                });
            }
        }
    }
}
 
Example #13
Source File: ExternalSystemTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private CompileScope createArtifactsScope(String[] artifactNames) {
  List<Artifact> artifacts = new ArrayList<>();
  for (String name : artifactNames) {
    artifacts.add(ArtifactsTestUtil.findArtifact(myProject, name));
  }
  return ArtifactCompileScope.createArtifactsScope(myProject, artifacts);
}
 
Example #14
Source File: ExternalSystemTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private CompileScope createModulesCompileScope(final String[] moduleNames) {
  final List<Module> modules = new ArrayList<>();
  for (String name : moduleNames) {
    modules.add(getModule(name));
  }
  return new ModuleCompileScope(myProject, modules.toArray(Module.EMPTY_ARRAY), false);
}
 
Example #15
Source File: CompileContextExProxy.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void addScope(final CompileScope additionalScope) {
  myDelegate.addScope(additionalScope);
}
 
Example #16
Source File: CompileContextExProxy.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public CompileScope getCompileScope() {
  return myDelegate.getCompileScope();
}
 
Example #17
Source File: CompileStepBeforeRun.java    From consulo with Apache License 2.0 4 votes vote down vote up
static AsyncResult<Void> doMake(UIAccess uiAccess, final Project myProject, final RunConfiguration configuration, final boolean ignoreErrors) {
  if (!(configuration instanceof RunProfileWithCompileBeforeLaunchOption)) {
    return AsyncResult.rejected();
  }

  if (configuration instanceof RunConfigurationBase && ((RunConfigurationBase)configuration).excludeCompileBeforeLaunchOption()) {
    return AsyncResult.resolved();
  }

  final RunProfileWithCompileBeforeLaunchOption runConfiguration = (RunProfileWithCompileBeforeLaunchOption)configuration;
  AsyncResult<Void> result = AsyncResult.undefined();
  try {
    final CompileStatusNotification callback = (aborted, errors, warnings, compileContext) -> {
      if ((errors == 0 || ignoreErrors) && !aborted) {
        result.setDone();
      }
      else {
        result.setRejected();
      }
    };

    TransactionGuard.submitTransaction(myProject, () -> {
      CompileScope scope;
      final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
      if (Comparing.equal(Boolean.TRUE.toString(), System.getProperty(MAKE_PROJECT_ON_RUN_KEY))) {
        // user explicitly requested whole-project make
        scope = compilerManager.createProjectCompileScope();
      }
      else {
        final Module[] modules = runConfiguration.getModules();
        if (modules.length > 0) {
          for (Module module : modules) {
            if (module == null) {
              LOG.error("RunConfiguration should not return null modules. Configuration=" + runConfiguration.getName() + "; class=" + runConfiguration.getClass().getName());
            }
          }
          scope = compilerManager.createModulesCompileScope(modules, true);
        }
        else {
          scope = compilerManager.createProjectCompileScope();
        }
      }

      if (!myProject.isDisposed()) {
        compilerManager.make(scope, callback);
      }
      else {
        result.setRejected();
      }
    });
  }
  catch (Exception e) {
    result.rejectWithThrowable(e);
  }

  return result;
}
 
Example #18
Source File: AdditionalCompileScopeProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@javax.annotation.Nullable
public abstract CompileScope getAdditionalScope(@Nonnull CompileScope baseScope,
                                                @Nonnull Condition<com.intellij.openapi.compiler.Compiler> filter,
                                                @Nonnull Project project);
 
Example #19
Source File: CompositeScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Collection<CompileScope> getScopes() {
  return Collections.unmodifiableList(myScopes);
}
 
Example #20
Source File: SandCompiler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean validateConfiguration(CompileScope scope) {
  return true;
}
 
Example #21
Source File: CompositeScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public CompositeScope(Collection<? extends CompileScope> scopes) {
  for (CompileScope scope : scopes) {
    addScope(scope);
  }
}
 
Example #22
Source File: CompositeScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public CompositeScope(CompileScope[] scopes) {
  for (CompileScope scope : scopes) {
    addScope(scope);
  }
}
 
Example #23
Source File: CompositeScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public CompositeScope(CompileScope scope1, CompileScope scope2) {
  addScope(scope1);
  addScope(scope2);
}
 
Example #24
Source File: ArtifactCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isArtifactRebuildForced(@Nonnull CompileScope scope) {
  return Boolean.TRUE.equals(scope.getUserData(FORCE_ARTIFACT_BUILD));
}
 
Example #25
Source File: ArtifactCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public static Artifact[] getArtifacts(CompileScope compileScope) {
  return compileScope.getUserData(ARTIFACTS_KEY);
}
 
Example #26
Source File: ArtifactCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static CompileScope createScopeWithArtifacts(final CompileScope baseScope,
                                                    @Nonnull Collection<Artifact> artifacts,
                                                    boolean useCustomContentId) {
  return createScopeWithArtifacts(baseScope, artifacts, useCustomContentId, false);
}
 
Example #27
Source File: ArtifactCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static CompileScope createArtifactsScope(@Nonnull Project project,
                                                @Nonnull Collection<Artifact> artifacts,
                                                final boolean forceArtifactBuild) {
  return createScopeWithArtifacts(createScopeForModulesInArtifacts(project, artifacts), artifacts, true, forceArtifactBuild);
}
 
Example #28
Source File: ArtifactCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static CompileScope createArtifactsScope(@Nonnull Project project,
                                                @Nonnull Collection<Artifact> artifacts) {
  return createArtifactsScope(project, artifacts, false);
}
 
Example #29
Source File: GenericCompiler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean validateConfiguration(CompileScope scope) {
  return true;
}
 
Example #30
Source File: CompileContextEx.java    From consulo with Apache License 2.0 votes vote down vote up
void addScope(CompileScope additionalScope);