Search in sources :

Example 6 with TargetTypeBuildScope

use of org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope in project android by JetBrains.

the class AndroidGradleBuildTargetScopeProvider method getBuildTargetScopes.

@Override
@NotNull
public List<TargetTypeBuildScope> getBuildTargetScopes(@NotNull CompileScope baseScope, @NotNull CompilerFilter filter, @NotNull Project project, boolean forceBuild) {
    if (!AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
        return Collections.emptyList();
    }
    BuildSettings buildSettings = BuildSettings.getInstance(project);
    String runConfigurationTypeId = baseScope.getUserData(CompilerManager.RUN_CONFIGURATION_TYPE_ID_KEY);
    buildSettings.setRunConfigurationTypeId(runConfigurationTypeId);
    if (baseScope instanceof ProjectCompileScope) {
        // Make or Rebuild project
        BuildMode buildMode = forceBuild ? BuildMode.REBUILD : BuildMode.ASSEMBLE;
        if (buildSettings.getBuildMode() == null) {
            buildSettings.setBuildMode(buildMode);
        }
        Module[] modulesToBuild = ModuleManager.getInstance(project).getModules();
        buildSettings.setModulesToBuild(modulesToBuild);
    } else if (baseScope instanceof ModuleCompileScope) {
        String userDataString = ((ModuleCompileScope) baseScope).getUserDataString();
        Module[] modulesToBuild;
        if (userDataString.contains("RUN_CONFIGURATION")) {
            // Triggered by a "Run Configuration"
            modulesToBuild = baseScope.getAffectedModules();
        } else {
            // Triggered by menu item.
            // Make selected modules
            modulesToBuild = Projects.getModulesToBuildFromSelection(project, null);
        }
        buildSettings.setModulesToBuild(modulesToBuild);
        buildSettings.setBuildMode(BuildMode.ASSEMBLE);
    } else if (baseScope instanceof CompositeScope) {
        // Compile selected modules
        buildSettings.setModulesToBuild(Projects.getModulesToBuildFromSelection(project, null));
        buildSettings.setBuildMode(BuildMode.COMPILE_JAVA);
    }
    TargetTypeBuildScope scope = CmdlineProtoUtil.createTargetsScope(AndroidGradleBuildTargetConstants.TARGET_TYPE_ID, Collections.singletonList(AndroidGradleBuildTargetConstants.TARGET_ID), forceBuild);
    return Collections.singletonList(scope);
}
Also used : ProjectCompileScope(com.intellij.compiler.impl.ProjectCompileScope) CompositeScope(com.intellij.compiler.impl.CompositeScope) BuildSettings(com.android.tools.idea.gradle.project.BuildSettings) BuildMode(com.android.tools.idea.gradle.util.BuildMode) Module(com.intellij.openapi.module.Module) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with TargetTypeBuildScope

use of org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope in project intellij-community by JetBrains.

the class CompileDriver method compileInExternalProcess.

@Nullable
private TaskFuture compileInExternalProcess(@NotNull final CompileContextImpl compileContext, final boolean onlyCheckUpToDate) throws Exception {
    final CompileScope scope = compileContext.getCompileScope();
    final Collection<String> paths = CompileScopeUtil.fetchFiles(compileContext);
    List<TargetTypeBuildScope> scopes = getBuildScopes(compileContext, scope, paths);
    // need to pass scope's user data to server
    final Map<String, String> builderParams;
    if (onlyCheckUpToDate) {
        builderParams = Collections.emptyMap();
    } else {
        final Map<Key, Object> exported = scope.exportUserData();
        if (!exported.isEmpty()) {
            builderParams = new HashMap<>();
            for (Map.Entry<Key, Object> entry : exported.entrySet()) {
                final String _key = entry.getKey().toString();
                final String _value = entry.getValue().toString();
                builderParams.put(_key, _value);
            }
        } else {
            builderParams = Collections.emptyMap();
        }
    }
    final MessageBus messageBus = myProject.getMessageBus();
    final MultiMap<String, Artifact> outputToArtifact = ArtifactCompilerUtil.containsArtifacts(scopes) ? ArtifactCompilerUtil.createOutputToArtifactMap(myProject) : null;
    final BuildManager buildManager = BuildManager.getInstance();
    buildManager.cancelAutoMakeTasks(myProject);
    return buildManager.scheduleBuild(myProject, compileContext.isRebuild(), compileContext.isMake(), onlyCheckUpToDate, scopes, paths, builderParams, new DefaultMessageHandler(myProject) {

        @Override
        public void sessionTerminated(final UUID sessionId) {
            if (compileContext.shouldUpdateProblemsView()) {
                final ProblemsView view = ProblemsView.SERVICE.getInstance(myProject);
                view.clearProgress();
                view.clearOldMessages(compileContext.getCompileScope(), compileContext.getSessionId());
            }
        }

        @Override
        public void handleFailure(UUID sessionId, CmdlineRemoteProto.Message.Failure failure) {
            compileContext.addMessage(CompilerMessageCategory.ERROR, failure.hasDescription() ? failure.getDescription() : "", null, -1, -1);
            final String trace = failure.hasStacktrace() ? failure.getStacktrace() : null;
            if (trace != null) {
                LOG.info(trace);
            }
            compileContext.putUserData(COMPILE_SERVER_BUILD_STATUS, ExitStatus.ERRORS);
        }

        @Override
        protected void handleCompileMessage(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
            final CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind kind = message.getKind();
            //System.out.println(compilerMessage.getText());
            final String messageText = message.getText();
            if (kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.PROGRESS) {
                final ProgressIndicator indicator = compileContext.getProgressIndicator();
                indicator.setText(messageText);
                if (message.hasDone()) {
                    indicator.setFraction(message.getDone());
                }
            } else {
                final CompilerMessageCategory category = kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.ERROR ? CompilerMessageCategory.ERROR : kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.WARNING ? CompilerMessageCategory.WARNING : CompilerMessageCategory.INFORMATION;
                String sourceFilePath = message.hasSourceFilePath() ? message.getSourceFilePath() : null;
                if (sourceFilePath != null) {
                    sourceFilePath = FileUtil.toSystemIndependentName(sourceFilePath);
                }
                final long line = message.hasLine() ? message.getLine() : -1;
                final long column = message.hasColumn() ? message.getColumn() : -1;
                final String srcUrl = sourceFilePath != null ? VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, sourceFilePath) : null;
                compileContext.addMessage(category, messageText, srcUrl, (int) line, (int) column);
                if (compileContext.shouldUpdateProblemsView() && kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.JPS_INFO) {
                    // treat JPS_INFO messages in a special way: add them as info messages to the problems view
                    final Project project = compileContext.getProject();
                    ProblemsView.SERVICE.getInstance(project).addMessage(new CompilerMessageImpl(project, category, messageText), compileContext.getSessionId());
                }
            }
        }

        @Override
        protected void handleBuildEvent(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event) {
            final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Type eventType = event.getEventType();
            switch(eventType) {
                case FILES_GENERATED:
                    final List<CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile> generated = event.getGeneratedFilesList();
                    final CompilationStatusListener publisher = !myProject.isDisposed() ? messageBus.syncPublisher(CompilerTopics.COMPILATION_STATUS) : null;
                    Set<String> writtenArtifactOutputPaths = outputToArtifact != null ? new THashSet<>(FileUtil.PATH_HASHING_STRATEGY) : null;
                    for (CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile generatedFile : generated) {
                        final String root = FileUtil.toSystemIndependentName(generatedFile.getOutputRoot());
                        final String relativePath = FileUtil.toSystemIndependentName(generatedFile.getRelativePath());
                        if (publisher != null) {
                            publisher.fileGenerated(root, relativePath);
                        }
                        if (outputToArtifact != null) {
                            Collection<Artifact> artifacts = outputToArtifact.get(root);
                            if (!artifacts.isEmpty()) {
                                for (Artifact artifact : artifacts) {
                                    ArtifactsCompiler.addChangedArtifact(compileContext, artifact);
                                }
                                writtenArtifactOutputPaths.add(FileUtil.toSystemDependentName(DeploymentUtil.appendToPath(root, relativePath)));
                            }
                        }
                    }
                    if (writtenArtifactOutputPaths != null && !writtenArtifactOutputPaths.isEmpty()) {
                        ArtifactsCompiler.addWrittenPaths(compileContext, writtenArtifactOutputPaths);
                    }
                    break;
                case BUILD_COMPLETED:
                    ExitStatus status = ExitStatus.SUCCESS;
                    if (event.hasCompletionStatus()) {
                        final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status completionStatus = event.getCompletionStatus();
                        switch(completionStatus) {
                            case CANCELED:
                                status = ExitStatus.CANCELLED;
                                break;
                            case ERRORS:
                                status = ExitStatus.ERRORS;
                                break;
                            case SUCCESS:
                                status = ExitStatus.SUCCESS;
                                break;
                            case UP_TO_DATE:
                                status = ExitStatus.UP_TO_DATE;
                                break;
                        }
                    }
                    compileContext.putUserDataIfAbsent(COMPILE_SERVER_BUILD_STATUS, status);
                    break;
                case CUSTOM_BUILDER_MESSAGE:
                    if (event.hasCustomBuilderMessage()) {
                        final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.CustomBuilderMessage message = event.getCustomBuilderMessage();
                        if (GlobalOptions.JPS_SYSTEM_BUILDER_ID.equals(message.getBuilderId()) && GlobalOptions.JPS_UNPROCESSED_FS_CHANGES_MESSAGE_ID.equals(message.getMessageType())) {
                            final String text = message.getMessageText();
                            if (!StringUtil.isEmpty(text)) {
                                compileContext.addMessage(CompilerMessageCategory.INFORMATION, text, null, -1, -1);
                            }
                        }
                    }
                    break;
            }
        }
    });
}
Also used : THashSet(gnu.trove.THashSet) MessageBus(com.intellij.util.messages.MessageBus) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) DefaultMessageHandler(com.intellij.compiler.server.DefaultMessageHandler) CmdlineRemoteProto(org.jetbrains.jps.api.CmdlineRemoteProto) Artifact(com.intellij.packaging.artifacts.Artifact) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) MessageType(com.intellij.openapi.ui.MessageType) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) BuildManager(com.intellij.compiler.server.BuildManager) HashMap(com.intellij.util.containers.HashMap) MultiMap(com.intellij.util.containers.MultiMap) Key(com.intellij.openapi.util.Key) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with TargetTypeBuildScope

use of org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope in project intellij-community by JetBrains.

the class CompileScopeUtil method addScopesForModules.

public static void addScopesForModules(Collection<Module> modules, List<TargetTypeBuildScope> scopes, boolean forceBuild) {
    if (!modules.isEmpty()) {
        for (JavaModuleBuildTargetType type : JavaModuleBuildTargetType.ALL_TYPES) {
            TargetTypeBuildScope.Builder builder = TargetTypeBuildScope.newBuilder().setTypeId(type.getTypeId()).setForceBuild(forceBuild);
            for (Module module : modules) {
                builder.addTargetId(module.getName());
            }
            scopes.add(builder.build());
        }
    }
}
Also used : JavaModuleBuildTargetType(org.jetbrains.jps.builders.java.JavaModuleBuildTargetType) Module(com.intellij.openapi.module.Module) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope)

Example 9 with TargetTypeBuildScope

use of org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope in project intellij-community by JetBrains.

the class BuildRunner method createCompilationScope.

private static CompileScope createCompilationScope(ProjectDescriptor pd, List<TargetTypeBuildScope> scopes, Collection<String> paths, final boolean forceClean, final boolean includeDependenciesToScope) throws Exception {
    Set<BuildTargetType<?>> targetTypes = new HashSet<>();
    Set<BuildTargetType<?>> targetTypesToForceBuild = new HashSet<>();
    Set<BuildTarget<?>> targets = new HashSet<>();
    Map<BuildTarget<?>, Set<File>> files;
    final TargetTypeRegistry typeRegistry = TargetTypeRegistry.getInstance();
    for (TargetTypeBuildScope scope : scopes) {
        final BuildTargetType<?> targetType = typeRegistry.getTargetType(scope.getTypeId());
        if (targetType == null) {
            LOG.info("Unknown target type: " + scope.getTypeId());
            continue;
        }
        if (scope.getForceBuild() || forceClean) {
            targetTypesToForceBuild.add(targetType);
        }
        if (scope.getAllTargets()) {
            targetTypes.add(targetType);
        } else {
            BuildTargetLoader<?> loader = targetType.createLoader(pd.getModel());
            for (String targetId : scope.getTargetIdList()) {
                BuildTarget<?> target = loader.createTarget(targetId);
                if (target != null) {
                    targets.add(target);
                } else {
                    LOG.info("Unknown " + targetType + " target id: " + targetId);
                }
            }
        }
    }
    if (includeDependenciesToScope) {
        includeDependenciesToScope(targetTypes, targets, targetTypesToForceBuild, pd);
    }
    final Timestamps timestamps = pd.timestamps.getStorage();
    if (!paths.isEmpty()) {
        boolean forceBuildAllModuleBasedTargets = false;
        for (BuildTargetType<?> type : targetTypesToForceBuild) {
            if (type instanceof JavaModuleBuildTargetType) {
                forceBuildAllModuleBasedTargets = true;
                break;
            }
        }
        files = new HashMap<>();
        for (String path : paths) {
            final File file = new File(path);
            final Collection<BuildRootDescriptor> descriptors = pd.getBuildRootIndex().findAllParentDescriptors(file, null);
            for (BuildRootDescriptor descriptor : descriptors) {
                Set<File> fileSet = files.get(descriptor.getTarget());
                if (fileSet == null) {
                    fileSet = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
                    files.put(descriptor.getTarget(), fileSet);
                }
                final boolean added = fileSet.add(file);
                if (added) {
                    final BuildTargetType<?> targetType = descriptor.getTarget().getTargetType();
                    if (targetTypesToForceBuild.contains(targetType) || (forceBuildAllModuleBasedTargets && targetType instanceof ModuleBasedBuildTargetType)) {
                        pd.fsState.markDirty(null, file, descriptor, timestamps, false);
                    }
                }
            }
        }
    } else {
        files = Collections.emptyMap();
    }
    return new CompileScopeImpl(targetTypes, targetTypesToForceBuild, targets, files);
}
Also used : THashSet(gnu.trove.THashSet) ProjectTimestamps(org.jetbrains.jps.incremental.storage.ProjectTimestamps) Timestamps(org.jetbrains.jps.incremental.storage.Timestamps) JavaModuleBuildTargetType(org.jetbrains.jps.builders.java.JavaModuleBuildTargetType) File(java.io.File) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) THashSet(gnu.trove.THashSet) JavaModuleBuildTargetType(org.jetbrains.jps.builders.java.JavaModuleBuildTargetType)

Example 10 with TargetTypeBuildScope

use of org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope in project intellij-community by JetBrains.

the class ArtifactBuildTargetScopeProvider method getBuildTargetScopes.

@NotNull
@Override
public List<TargetTypeBuildScope> getBuildTargetScopes(@NotNull final CompileScope baseScope, @NotNull CompilerFilter filter, @NotNull final Project project, final boolean forceBuild) {
    final ArtifactsCompiler compiler = ArtifactsCompiler.getInstance(project);
    if (compiler == null || !filter.acceptCompiler(compiler)) {
        return Collections.emptyList();
    }
    final List<TargetTypeBuildScope> scopes = new ArrayList<>();
    new ReadAction() {

        protected void run(@NotNull final Result result) {
            final Set<Artifact> artifacts = ArtifactCompileScope.getArtifactsToBuild(project, baseScope, false);
            if (ArtifactCompileScope.getArtifacts(baseScope) == null) {
                Set<Module> modules = ArtifactUtil.getModulesIncludedInArtifacts(artifacts, project);
                CompileScopeUtil.addScopesForModules(modules, scopes, forceBuild);
            }
            if (!artifacts.isEmpty()) {
                TargetTypeBuildScope.Builder builder = TargetTypeBuildScope.newBuilder().setTypeId(ArtifactBuildTargetType.INSTANCE.getTypeId()).setForceBuild(forceBuild || ArtifactCompileScope.isArtifactRebuildForced(baseScope));
                for (Artifact artifact : artifacts) {
                    builder.addTargetId(artifact.getName());
                }
                scopes.add(builder.build());
            }
        }
    }.execute();
    return scopes;
}
Also used : Set(java.util.Set) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) Artifact(com.intellij.packaging.artifacts.Artifact) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TargetTypeBuildScope (org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope)11 JavaModuleBuildTargetType (org.jetbrains.jps.builders.java.JavaModuleBuildTargetType)4 Module (com.intellij.openapi.module.Module)3 NotNull (org.jetbrains.annotations.NotNull)3 Project (com.intellij.openapi.project.Project)2 Artifact (com.intellij.packaging.artifacts.Artifact)2 THashSet (gnu.trove.THashSet)2 BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 CompositeScope (com.intellij.compiler.impl.CompositeScope)1 ModuleCompileScope (com.intellij.compiler.impl.ModuleCompileScope)1 ProjectCompileScope (com.intellij.compiler.impl.ProjectCompileScope)1 BuildManager (com.intellij.compiler.server.BuildManager)1 DefaultMessageHandler (com.intellij.compiler.server.DefaultMessageHandler)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Result (com.intellij.openapi.application.Result)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 MessageType (com.intellij.openapi.ui.MessageType)1 Key (com.intellij.openapi.util.Key)1 HashMap (com.intellij.util.containers.HashMap)1